[Minor] code cleanup

- extracted constants for configuration
- fixed redundant null check
- cleaned up compiler warnings on i18n
This commit is contained in:
Robert von Burg 2014-08-24 10:19:42 +02:00
parent 77de155b17
commit 42fe3b4122
5 changed files with 25 additions and 22 deletions

View File

@ -57,13 +57,13 @@ public class CachedRealm extends StrolchRealm {
@Override
public StrolchTransaction openTx(Certificate certificate, String action) {
DBC.PRE.assertNotNull("Certificate must be set!", certificate);
DBC.PRE.assertNotNull("Certificate must be set!", certificate); //$NON-NLS-1$
return this.persistenceHandler.openTx(this, certificate, action);
}
@Override
public StrolchTransaction openTx(Certificate certificate, Class<?> clazz) {
DBC.PRE.assertNotNull("Certificate must be set!", certificate);
DBC.PRE.assertNotNull("Certificate must be set!", certificate); //$NON-NLS-1$
return this.persistenceHandler.openTx(this, certificate, clazz.getName());
}
@ -93,10 +93,10 @@ public class CachedRealm extends StrolchRealm {
DefaultRealmHandler.PROP_ENABLE_AUDIT_TRAIL);
if (configuration.getBoolean(enableAuditKey, Boolean.FALSE)) {
this.auditTrail = new CachedAuditTrail();
logger.info("Enabling AuditTrail for realm " + getRealm());
logger.info("Enabling AuditTrail for realm " + getRealm()); //$NON-NLS-1$
} else {
this.auditTrail = new NoStrategyAuditTrail();
logger.info("AuditTrail is disabled for realm " + getRealm());
logger.info("AuditTrail is disabled for realm " + getRealm()); //$NON-NLS-1$
}
}
@ -107,7 +107,7 @@ public class CachedRealm extends StrolchRealm {
int nrOfOrders = 0;
int nrOfResources = 0;
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), "agent_boot")) {
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), DefaultRealmHandler.AGENT_BOOT)) {
ResourceDao resourceDao = tx.getPersistenceHandler().getResourceDao(tx);
Set<String> resourceTypes = resourceDao.queryTypes();
for (String type : resourceTypes) {
@ -119,7 +119,7 @@ public class CachedRealm extends StrolchRealm {
}
}
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), "agent_boot")) {
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), DefaultRealmHandler.AGENT_BOOT)) {
OrderDao orderDao = tx.getPersistenceHandler().getOrderDao(tx);
Set<String> orderTypes = orderDao.queryTypes();
for (String type : orderTypes) {

View File

@ -38,6 +38,9 @@ import ch.eitchnet.utils.dbc.DBC;
*/
public class DefaultRealmHandler extends StrolchComponent implements RealmHandler {
private static final String SYSTEM_USER_AGENT = "agent"; //$NON-NLS-1$
public static final String AGENT_BOOT = "agent_boot"; //$NON-NLS-1$
public static final String PROP_ENABLE_AUDIT_TRAIL = "enableAuditTrail"; //$NON-NLS-1$
public static final String PREFIX_DATA_STORE_MODE = "dataStoreMode"; //$NON-NLS-1$
public static final String PROP_REALMS = "realms"; //$NON-NLS-1$
@ -110,7 +113,7 @@ public class DefaultRealmHandler extends StrolchComponent implements RealmHandle
public void start() {
PrivilegeHandler privilegeHandler = getContainer().getComponent(PrivilegeHandler.class);
privilegeHandler.runAsSystem("agent", new StartRealms(this));
privilegeHandler.runAsSystem(SYSTEM_USER_AGENT, new StartRealms(this));
super.start();
}

View File

@ -51,13 +51,13 @@ public class EmptyRealm extends StrolchRealm {
@Override
public StrolchTransaction openTx(Certificate certificate, String action) {
DBC.PRE.assertNotNull("Certificate must be set!", certificate);
DBC.PRE.assertNotNull("Certificate must be set!", certificate); //$NON-NLS-1$
return this.persistenceHandler.openTx(this, certificate, action);
}
@Override
public StrolchTransaction openTx(Certificate certificate, Class<?> clazz) {
DBC.PRE.assertNotNull("Certificate must be set!", certificate);
DBC.PRE.assertNotNull("Certificate must be set!", certificate); //$NON-NLS-1$
return this.persistenceHandler.openTx(this, certificate, clazz.getName());
}
@ -87,10 +87,10 @@ public class EmptyRealm extends StrolchRealm {
DefaultRealmHandler.PROP_ENABLE_AUDIT_TRAIL);
if (configuration.getBoolean(enableAuditKey, Boolean.FALSE)) {
this.auditTrail = new TransactionalAuditTrail();
logger.info("Enabling AuditTrail for realm " + getRealm());
logger.info("Enabling AuditTrail for realm " + getRealm()); //$NON-NLS-1$
} else {
this.auditTrail = new NoStrategyAuditTrail();
logger.info("AuditTrail is disabled for realm " + getRealm());
logger.info("AuditTrail is disabled for realm " + getRealm()); //$NON-NLS-1$
}
}

View File

@ -51,13 +51,13 @@ public class TransactionalRealm extends StrolchRealm {
@Override
public StrolchTransaction openTx(Certificate certificate, String action) {
DBC.PRE.assertNotNull("Certificate must be set!", certificate);
DBC.PRE.assertNotNull("Certificate must be set!", certificate); //$NON-NLS-1$
return this.persistenceHandler.openTx(this, certificate, action);
}
@Override
public StrolchTransaction openTx(Certificate certificate, Class<?> clazz) {
DBC.PRE.assertNotNull("Certificate must be set!", certificate);
DBC.PRE.assertNotNull("Certificate must be set!", certificate); //$NON-NLS-1$
return this.persistenceHandler.openTx(this, certificate, clazz.getName());
}
@ -87,10 +87,10 @@ public class TransactionalRealm extends StrolchRealm {
if (configuration.getBoolean(enableAuditKey, Boolean.FALSE)) {
this.auditTrail = new TransactionalAuditTrail();
logger.info("Enabling AuditTrail for realm " + getRealm());
logger.info("Enabling AuditTrail for realm " + getRealm()); //$NON-NLS-1$
} else {
this.auditTrail = new NoStrategyAuditTrail();
logger.info("AuditTrail is disabled for realm " + getRealm());
logger.info("AuditTrail is disabled for realm " + getRealm()); //$NON-NLS-1$
}
this.persistenceHandler = container.getComponent(PersistenceHandler.class);
@ -103,11 +103,11 @@ public class TransactionalRealm extends StrolchRealm {
int nrOfOrders = 0;
int nrOfResources = 0;
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), "agent_boot")) {
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), DefaultRealmHandler.AGENT_BOOT)) {
nrOfOrders = this.orderMap.getAllKeys(tx).size();
}
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), "agent_boot")) {
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), DefaultRealmHandler.AGENT_BOOT)) {
nrOfResources = this.resourceMap.getAllKeys(tx).size();
}

View File

@ -63,13 +63,13 @@ public class TransientRealm extends StrolchRealm {
@Override
public StrolchTransaction openTx(Certificate certificate, String action) {
DBC.PRE.assertNotNull("Certificate must be set!", certificate);
DBC.PRE.assertNotNull("Certificate must be set!", certificate); //$NON-NLS-1$
return this.persistenceHandler.openTx(this, certificate, action);
}
@Override
public StrolchTransaction openTx(Certificate certificate, Class<?> clazz) {
DBC.PRE.assertNotNull("Certificate must be set!", certificate);
DBC.PRE.assertNotNull("Certificate must be set!", certificate); //$NON-NLS-1$
return this.persistenceHandler.openTx(this, certificate, clazz.getName());
}
@ -112,10 +112,10 @@ public class TransientRealm extends StrolchRealm {
DefaultRealmHandler.PROP_ENABLE_AUDIT_TRAIL);
if (configuration.getBoolean(enableAuditKey, Boolean.FALSE)) {
this.auditTrail = new TransactionalAuditTrail();
logger.info("Enabling AuditTrail for realm " + getRealm());
logger.info("Enabling AuditTrail for realm " + getRealm()); //$NON-NLS-1$
} else {
this.auditTrail = new NoStrategyAuditTrail();
logger.info("AuditTrail is disabled for realm " + getRealm());
logger.info("AuditTrail is disabled for realm " + getRealm()); //$NON-NLS-1$
}
}
@ -123,7 +123,7 @@ public class TransientRealm extends StrolchRealm {
public void start(PrivilegeContext privilegeContext) {
ModelStatistics statistics;
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), "agent_boot")) {
try (StrolchTransaction tx = openTx(privilegeContext.getCertificate(), DefaultRealmHandler.AGENT_BOOT)) {
InMemoryElementListener elementListener = new InMemoryElementListener(tx);
XmlModelSaxFileReader handler = new XmlModelSaxFileReader(elementListener, this.modelFile);
handler.parseFile();