use of org.olat.properties.PropertyManager in project openolat by klemens.
the class DBTest method testDbPerf.
@Test
public void testDbPerf() {
int loops = 1000;
long timeWithoutTransction = 0;
log.info("start testDbPerf with loops=" + loops);
try {
long startTime = System.currentTimeMillis();
for (int loopCounter = 0; loopCounter < loops; loopCounter++) {
String propertyKey = "testDbPerfKey-" + loopCounter;
PropertyManager pm = PropertyManager.getInstance();
String testValue = "testDbPerfValue-" + loopCounter;
Property p = pm.createPropertyInstance(null, null, null, null, propertyKey, null, null, testValue, null);
pm.saveProperty(p);
// forget session cache etc.
dbInstance.closeSession();
pm.deleteProperty(p);
}
long endTime = System.currentTimeMillis();
timeWithoutTransction = endTime - startTime;
log.info("testDbPerf without transaction takes :" + timeWithoutTransction + "ms");
} catch (Exception ex) {
fail("Exception in testDbPerf without transaction ex=" + ex);
}
try {
long startTime = System.currentTimeMillis();
for (int loopCounter = 0; loopCounter < loops; loopCounter++) {
String propertyKey = "testDbPerfKey-" + loopCounter;
PropertyManager pm = PropertyManager.getInstance();
String testValue = "testDbPerfValue-" + loopCounter;
Property p = pm.createPropertyInstance(null, null, null, null, propertyKey, null, null, testValue, null);
pm.saveProperty(p);
// forget session cache etc.
dbInstance.closeSession();
pm.deleteProperty(p);
}
long endTime = System.currentTimeMillis();
long timeWithTransction = endTime - startTime;
log.info("testDbPerf with transaction takes :" + timeWithTransction + "ms");
log.info("testDbPerf diff between transaction and without transaction :" + (timeWithTransction - timeWithoutTransction) + "ms");
} catch (Exception ex) {
fail("Exception in testDbPerf with transaction ex=" + ex);
}
}
use of org.olat.properties.PropertyManager in project openolat by klemens.
the class DBTest method testRollback.
@Test
public void testRollback() {
String propertyKey = "testRollback-1";
String testValue = "testRollback-1";
try {
PropertyManager pm = PropertyManager.getInstance();
Property p1 = pm.createPropertyInstance(null, null, null, null, propertyKey, null, null, testValue, null);
pm.saveProperty(p1);
String testValue2 = "testRollback-2";
// name is null => generated DB error => rollback
Property p2 = pm.createPropertyInstance(null, null, null, null, null, null, null, testValue2, null);
pm.saveProperty(p2);
dbInstance.commit();
fail("Should generate error for rollback.");
} catch (Exception ex) {
dbInstance.closeSession();
}
// check if p1 is rollbacked
PropertyManager pm = PropertyManager.getInstance();
Property p = pm.findProperty(null, null, null, null, propertyKey);
assertNull("Property.save is NOT rollbacked", p);
}
use of org.olat.properties.PropertyManager in project openolat by klemens.
the class AdminModule method checkToken.
private boolean checkToken(HttpServletRequest request, String tokenPropertyName) {
String submittedToken = request.getParameter("token");
if (submittedToken == null) {
log.audit("Trying to set maintenance message without using a token. Remote address::" + request.getRemoteAddr());
return false;
}
// get token and compare
PropertyManager pm = PropertyManager.getInstance();
Property p = pm.findProperty(null, null, null, AdminModule.SYSTEM_PROPERTY_CATEGORY, tokenPropertyName);
String token = (p == null ? "" : p.getStringValue());
if (token.equals(submittedToken)) {
// limit access to token
return true;
}
log.audit("Trying to set maintenance message using a wrong token. Remote address::" + request.getRemoteAddr());
return false;
}
use of org.olat.properties.PropertyManager in project openolat by klemens.
the class QuotaManagerImpl method listCustomQuotasKB.
/**
* Get a list of all objects which have an individual quota.
*
* @return list of quotas.
*/
@Override
public List<Quota> listCustomQuotasKB() {
if (defaultQuotas == null) {
throw new OLATRuntimeException(QuotaManagerImpl.class, "Quota manager has not been initialized properly! Must call init() first.", null);
}
List<Quota> results = new ArrayList<Quota>();
PropertyManager pm = PropertyManager.getInstance();
List<Property> props = pm.listProperties(null, null, quotaResource, QUOTA_CATEGORY, null);
if (props == null || props.size() == 0)
return results;
for (Iterator<Property> iter = props.iterator(); iter.hasNext(); ) {
Property prop = iter.next();
results.add(parseQuota(prop));
}
return results;
}
use of org.olat.properties.PropertyManager in project openolat by klemens.
the class InfoMessageManager method setInfoMessage.
/**
* @param message The new info message that will show up on the login screen
* Synchronized to prevent two users creating or updating the info message property
* at the same time
*/
public void setInfoMessage(final String message) {
// o_clusterOK synchronized
OLATResourceable ores = OresHelper.createOLATResourceableInstance(INFO_MSG, KEY);
coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() {
public void execute() {
PropertyManager pm = PropertyManager.getInstance();
Property p = pm.findProperty(null, null, null, "_o3_", INFO_MSG);
if (p == null) {
p = pm.createPropertyInstance(null, null, null, "_o3_", INFO_MSG, null, null, null, "");
pm.saveProperty(p);
}
p.setTextValue(message);
// set Message in RAM
InfoMessageManager.infoMessage = message;
pm.updateProperty(p);
}
});
// end syncerCallback
EventBus eb = coordinatorManager.getCoordinator().getEventBus();
MultiUserEvent mue = new MultiUserEvent(message);
eb.fireEventToListenersOf(mue, INFO_MESSAGE_ORES);
}
Aggregations