Search in sources :

Example 26 with PropertyManager

use of org.olat.properties.PropertyManager in project openolat by klemens.

the class UserManagerImpl method setUserCharset.

@Override
public void setUserCharset(Identity identity, String charset) {
    PropertyManager pm = PropertyManager.getInstance();
    Property p = pm.findProperty(identity, null, null, null, CHARSET);
    if (p != null) {
        p.setStringValue(charset);
        pm.updateProperty(p);
    } else {
        Property newP = pm.createUserPropertyInstance(identity, null, CHARSET, null, null, charset, null);
        pm.saveProperty(newP);
    }
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property)

Example 27 with PropertyManager

use of org.olat.properties.PropertyManager in project openolat by klemens.

the class DBTest method testRollbackNonTransactional.

@Test
public void testRollbackNonTransactional() {
    String propertyKey1 = "testNonTransactional-1";
    String testValue1 = "testNonTransactional-1";
    String propertyKey2 = "testNonTransactional-2";
    String testValue2 = "testNonTransactional-2";
    String testValue3 = "testNonTransactional-3";
    try {
        PropertyManager pm = PropertyManager.getInstance();
        Property p1 = pm.createPropertyInstance(null, null, null, null, propertyKey1, null, null, testValue1, null);
        pm.saveProperty(p1);
        Property p2 = pm.createPropertyInstance(null, null, null, null, propertyKey2, null, null, testValue2, null);
        pm.saveProperty(p2);
        // name is null => generated DB error => rollback ?
        Property p3 = pm.createPropertyInstance(null, null, null, null, null, null, null, testValue3, null);
        pm.saveProperty(p3);
        dbInstance.commit();
        fail("Should generate error for rollback.");
        dbInstance.closeSession();
    } catch (Exception ex) {
        dbInstance.closeSession();
    }
    // check if p1 & p2 is NOT rollbacked
    PropertyManager pm = PropertyManager.getInstance();
    Property p_1 = pm.findProperty(null, null, null, null, propertyKey1);
    assertNull("Property1 is NOT rollbacked", p_1);
    Property p_2 = pm.findProperty(null, null, null, null, propertyKey2);
    assertNull("Property2 is NOT rollbacked", p_2);
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property) DBRuntimeException(org.olat.core.logging.DBRuntimeException) Test(org.junit.Test)

Example 28 with PropertyManager

use of org.olat.properties.PropertyManager in project openolat by klemens.

the class DBTest method testDBUTF8capable.

@Test
public void testDBUTF8capable() {
    PropertyManager pm = PropertyManager.getInstance();
    String uuid = UUID.randomUUID().toString();
    String unicodetest = "a-greek a\u03E2a\u03EAa\u03E8 arab \u0630a\u0631 chinese:\u3150a\u3151a\u3152a\u3153a\u3173a\u3110-z";
    Property p = pm.createPropertyInstance(null, null, null, null, uuid, null, null, unicodetest, null);
    pm.saveProperty(p);
    // forget session cache etc.
    dbInstance.closeSession();
    Property p2 = pm.findProperty(null, null, null, null, uuid);
    String lStr = p2.getStringValue();
    assertEquals(unicodetest, lStr);
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Property(org.olat.properties.Property) Test(org.junit.Test)

Example 29 with PropertyManager

use of org.olat.properties.PropertyManager in project openolat by klemens.

the class AbstractStatisticUpdateManagerTest method setLastUpdate.

protected void setLastUpdate(Calendar ref, int dayInThePast) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, ref.get(Calendar.YEAR));
    cal.set(Calendar.MONTH, ref.get(Calendar.MONTH));
    cal.set(Calendar.DATE, 1);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.add(Calendar.DATE, -dayInThePast);
    long lastUpdated = cal.getTimeInMillis();
    PropertyManager pm = PropertyManager.getInstance();
    Property p = pm.findProperty(null, null, null, "STATISTICS_PROPERTIES", "LAST_UPDATED");
    if (p == null) {
        p = pm.createPropertyInstance(null, null, null, "STATISTICS_PROPERTIES", "LAST_UPDATED", null, lastUpdated, null, null);
    } else {
        p.setLongValue(lastUpdated);
    }
    pm.saveProperty(p);
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Calendar(java.util.Calendar) Property(org.olat.properties.Property)

Example 30 with PropertyManager

use of org.olat.properties.PropertyManager in project openolat by klemens.

the class DBPersistentLockManager method aquirePersistentLock.

/**
 * @see org.olat.core.util.locks.PersistentLockManager#aquirePersistentLock(org.olat.core.id.OLATResourceable,
 *      org.olat.core.id.Identity, java.lang.String)
 */
@Override
public LockResult aquirePersistentLock(OLATResourceable ores, Identity ident, String locksubkey) {
    // synchronisation is solved in the LockManager
    LockResult lres;
    PropertyManager pm = PropertyManager.getInstance();
    String derivedLockString = OresHelper.createStringRepresenting(ores, locksubkey);
    long aqTime;
    Identity lockOwner;
    boolean success;
    Property p;
    p = pm.findProperty(null, null, null, CATEGORY_PERSISTENTLOCK, derivedLockString);
    if (p == null) {
        // no persistent lock acquired yet
        // save a property: cat = o_lock, key = derivedLockString, Longvalue = key
        // of identity acquiring the lock
        Property newp = pm.createPropertyInstance(null, null, null, CATEGORY_PERSISTENTLOCK, derivedLockString, null, ident.getKey(), null, null);
        pm.saveProperty(newp);
        aqTime = System.currentTimeMillis();
        lockOwner = ident;
        success = true;
    } else {
        // already acquired, but check on reaquiring
        aqTime = p.getLastModified().getTime();
        Long lockOwnerKey = p.getLongValue();
        if (ident.getKey().equals(lockOwnerKey)) {
            // reaquire ok
            success = true;
        } else {
            // already locked by an other person
            success = false;
        }
        // FIXME:fj:c find a better way to retrieve information about the
        // lock-holder
        lockOwner = BaseSecurityManager.getInstance().loadIdentityByKey(lockOwnerKey);
    }
    LockEntry le = new LockEntry(derivedLockString, aqTime, lockOwner);
    lres = new LockResultImpl(success, le);
    return lres;
}
Also used : PropertyManager(org.olat.properties.PropertyManager) Identity(org.olat.core.id.Identity) Property(org.olat.properties.Property)

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