Search in sources :

Example 41 with PropertyManager

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);
    }
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property) DBRuntimeException(org.olat.core.logging.DBRuntimeException) Test(org.junit.Test)

Example 42 with PropertyManager

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);
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property) DBRuntimeException(org.olat.core.logging.DBRuntimeException) Test(org.junit.Test)

Example 43 with PropertyManager

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;
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property)

Example 44 with PropertyManager

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;
}
Also used : Quota(org.olat.core.util.vfs.Quota) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) PropertyManager(org.olat.properties.PropertyManager) ArrayList(java.util.ArrayList) Property(org.olat.properties.Property)

Example 45 with PropertyManager

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);
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) PropertyManager(org.olat.properties.PropertyManager) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) EventBus(org.olat.core.util.event.EventBus) Property(org.olat.properties.Property) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Aggregations

PropertyManager (org.olat.properties.PropertyManager)50 Property (org.olat.properties.Property)48 Test (org.junit.Test)10 Identity (org.olat.core.id.Identity)8 DBRuntimeException (org.olat.core.logging.DBRuntimeException)8 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)6 ArrayList (java.util.ArrayList)4 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 UserSession (org.olat.core.util.UserSession)4 NarrowedPropertyManager (org.olat.properties.NarrowedPropertyManager)4 OLATResourceable (org.olat.core.id.OLATResourceable)3 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)3 File (java.io.File)2 IOException (java.io.IOException)2 Calendar (java.util.Calendar)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2