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);
}
}
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);
}
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);
}
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);
}
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;
}
Aggregations