| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
package net.smartlab.web; |
| 24 |
|
|
| 25 |
|
import java.net.URL; |
| 26 |
|
|
| 27 |
|
import net.smartlab.config.Configuration; |
| 28 |
|
import net.smartlab.config.ConfigurationException; |
| 29 |
|
import net.smartlab.web.config.DomainConfigurationStrategy; |
| 30 |
|
import net.smartlab.web.config.FileDomainConfigurationStrategy; |
| 31 |
|
|
| 32 |
|
import org.apache.commons.logging.Log; |
| 33 |
|
import org.apache.commons.logging.LogFactory; |
| 34 |
|
import org.hibernate.HibernateException; |
| 35 |
|
import org.hibernate.StaleObjectStateException; |
| 36 |
|
import org.hibernate.Transaction; |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
@author |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
|
|
|
| 0% |
Uncovered Elements: 55 (55) |
Complexity: 22 |
Complexity Density: 0,67 |
|
| 44 |
|
public abstract class Domain implements ManageableDomain { |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
protected final Log logger = LogFactory.getLog(this.getClass()); |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
private Configuration config; |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
private static DomainConfigurationStrategy strategy = new FileDomainConfigurationStrategy(); |
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0,6 |
|
| 60 |
0
|
static {... |
| 61 |
0
|
try { |
| 62 |
0
|
String strategy = System.getProperty("smartweb.domain.strategy"); |
| 63 |
0
|
if (strategy != null) { |
| 64 |
0
|
Domain.strategy = (DomainConfigurationStrategy)Class.forName(strategy).newInstance(); |
| 65 |
|
} else { |
| 66 |
0
|
LogFactory.getLog(Domain.class).warn("No configuration found: falling back to default configuration"); |
| 67 |
|
} |
| 68 |
|
} catch (Exception e) { |
| 69 |
|
LogFactory.getLog(Domain.class).fatal("Error configuring SmartWeb", e); |
| 70 |
|
} |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
@param |
| 82 |
|
@return |
| 83 |
|
@throws |
| 84 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 3 |
Complexity Density: 1,5 |
|
| 85 |
0
|
protected Transaction begin(BusinessObjectFactory factory) throws BusinessException {... |
| 86 |
0
|
try { |
| 87 |
0
|
return factory.current().beginTransaction(); |
| 88 |
|
} catch (HibernateException he) { |
| 89 |
|
logger.error("[ smartweb ] failed to begin transaction"); |
| 90 |
|
throw new BusinessException("persistence.error.begin", he); |
| 91 |
|
} catch (DAOException boe) { |
| 92 |
|
throw new BusinessException(boe); |
| 93 |
|
} |
| 94 |
|
} |
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
@param |
| 101 |
|
@throws |
| 102 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 3 |
Complexity Density: 1,5 |
|
| 103 |
0
|
protected void commit(Transaction transaction) throws BusinessException {... |
| 104 |
0
|
try { |
| 105 |
0
|
transaction.commit(); |
| 106 |
|
} catch (StaleObjectStateException sose) { |
| 107 |
|
logger.info("[ smartweb ] optimistical locking collision"); |
| 108 |
|
throw new BusinessException("persistence.locking.collision", sose); |
| 109 |
|
} catch (HibernateException he) { |
| 110 |
|
logger.error("[ smartweb ] failed to commit transaction"); |
| 111 |
|
throw new BusinessException("persistence.error.commit", he); |
| 112 |
|
} |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
@param |
| 120 |
|
@throws |
| 121 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 2 |
Complexity Density: 1 |
|
| 122 |
0
|
protected void rollback(Transaction transaction) throws BusinessException {... |
| 123 |
0
|
try { |
| 124 |
0
|
transaction.rollback(); |
| 125 |
|
} catch (HibernateException he) { |
| 126 |
|
logger.warn("[ smartweb ] failed to rollback transaction"); |
| 127 |
|
} |
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
|
| 131 |
|
|
| 132 |
|
|
| 133 |
|
@param |
| 134 |
|
|
| 135 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 136 |
0
|
public static void setConfigurationStrategy(DomainConfigurationStrategy strategy) {... |
| 137 |
0
|
Domain.strategy = strategy; |
| 138 |
|
} |
| 139 |
|
|
| 140 |
|
|
| 141 |
|
|
| 142 |
|
|
| 143 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 144 |
0
|
protected Domain() {... |
| 145 |
0
|
if (logger.isDebugEnabled()) { |
| 146 |
0
|
logger.debug(this.getClass().getName() + " instantiated."); |
| 147 |
|
} |
| 148 |
|
} |
| 149 |
|
|
| 150 |
|
|
| 151 |
|
|
| 152 |
|
|
| 153 |
|
@return |
| 154 |
|
@throws |
| 155 |
|
|
| 156 |
|
|
| 157 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
| 158 |
0
|
public Configuration getConfiguration() throws ConfigurationException {... |
| 159 |
0
|
if (config == null) { |
| 160 |
0
|
this.config = strategy.getConfiguration(this); |
| 161 |
|
} |
| 162 |
0
|
return config; |
| 163 |
|
} |
| 164 |
|
|
| 165 |
|
|
| 166 |
|
|
| 167 |
|
|
| 168 |
|
@param |
| 169 |
|
@return |
| 170 |
|
@throws |
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
| 174 |
0
|
public Configuration getConfiguration(String filename) throws ConfigurationException {... |
| 175 |
0
|
if (config == null) { |
| 176 |
0
|
config = strategy.getConfiguration(this, filename); |
| 177 |
|
} |
| 178 |
0
|
return config; |
| 179 |
|
} |
| 180 |
|
|
| 181 |
|
|
| 182 |
|
|
| 183 |
|
|
| 184 |
|
|
| 185 |
|
@param |
| 186 |
|
@param |
| 187 |
|
|
| 188 |
|
@return |
| 189 |
|
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0,33 |
|
| 190 |
0
|
public static URL getResource(Class context, String[] names) {... |
| 191 |
0
|
Log logger = LogFactory.getLog(context); |
| 192 |
0
|
URL resource = null; |
| 193 |
0
|
for (int i = 0; i < names.length; i++) { |
| 194 |
0
|
resource = context.getResource(names[i]); |
| 195 |
0
|
logger.trace(" trying `" + names[i] + "`"); |
| 196 |
0
|
if (resource != null) { |
| 197 |
0
|
break; |
| 198 |
|
} |
| 199 |
|
} |
| 200 |
0
|
logger.debug(" resource is `" + resource + "`"); |
| 201 |
0
|
return resource; |
| 202 |
|
} |
| 203 |
|
|
| 204 |
|
|
| 205 |
|
|
| 206 |
|
|
| 207 |
|
|
| 208 |
|
@param |
| 209 |
|
@return |
| 210 |
|
|
| 211 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
| 212 |
0
|
public static String getLastArchiveName(Class type) {... |
| 213 |
0
|
Log logger = LogFactory.getLog(type); |
| 214 |
0
|
String path = type.getProtectionDomain().getCodeSource().getLocation().getFile(); |
| 215 |
0
|
logger.debug(" archive path is `" + path + "`"); |
| 216 |
0
|
return path.substring(path.lastIndexOf('/') + 1); |
| 217 |
|
} |
| 218 |
|
} |