use of org.olat.core.logging.DBRuntimeException in project OpenOLAT by OpenOLAT.
the class DBImpl method updateObject.
/**
* Update an object.
*
* @param object
*/
@Override
public void updateObject(Object object) {
EntityManager em = getCurrentEntityManager();
EntityTransaction trx = em.getTransaction();
if (unusableTrx(trx)) {
// some program bug
throw new DBRuntimeException("cannot update in a transaction that is rolledback or committed " + object);
}
try {
getSession(em).update(object);
} catch (HibernateException e) {
// we have some error
trx.setRollbackOnly();
getData().setError(e);
throw new DBRuntimeException("Update object failed in transaction. Query: " + object, e);
}
}
use of org.olat.core.logging.DBRuntimeException in project OpenOLAT by OpenOLAT.
the class DBImpl method deleteObject.
/**
* Delete an object.
*
* @param object
*/
@Override
public void deleteObject(Object object) {
EntityManager em = getCurrentEntityManager();
EntityTransaction trx = em.getTransaction();
if (unusableTrx(trx)) {
// some program bug
throw new DBRuntimeException("cannot delete in a transaction that is rolledback or committed " + object);
}
try {
Object relaoded = em.merge(object);
em.remove(relaoded);
if (log.isDebug()) {
log.debug("delete (trans " + trx.hashCode() + ") class " + object.getClass().getName() + " = " + object.toString());
}
} catch (HibernateException e) {
// we have some error
trx.setRollbackOnly();
getData().setError(e);
throw new DBRuntimeException("Delete of object failed: " + object, e);
}
}
use of org.olat.core.logging.DBRuntimeException in project OpenOLAT by OpenOLAT.
the class WebDAVAuthManager method updateWebDAVPassword.
private void updateWebDAVPassword(Identity doer, Identity identity, String authUsername, String password, String provider, List<Authentication> authentications) {
Authentication authentication = getAndRemoveAuthentication(provider, authentications);
if (authentication == null) {
// create new authentication for provider OLAT
try {
dbInstance.commit();
Identity reloadedIdentity = securityManager.loadIdentityByKey(identity.getKey());
securityManager.createAndPersistAuthentication(reloadedIdentity, provider, authUsername, password, loginModule.getDefaultHashAlgorithm());
log.audit(doer.getName() + " created new WebDAV authentication for identity: " + identity.getKey() + " (" + authUsername + ")");
} catch (DBRuntimeException e) {
log.error("Cannot create webdav password with provider " + provider + " for identity:" + identity, e);
dbInstance.commit();
}
} else {
try {
dbInstance.commit();
securityManager.updateCredentials(authentication, password, loginModule.getDefaultHashAlgorithm());
log.audit(doer.getName() + " set new WebDAV password for identity: " + identity.getKey() + " (" + authUsername + ")");
} catch (Exception e) {
log.error("Cannot update webdav password with provider " + provider + " for identity:" + identity, e);
dbInstance.commit();
}
}
}
use of org.olat.core.logging.DBRuntimeException in project OpenOLAT by OpenOLAT.
the class ClusterLocker method event.
/**
* receives all sign on / sign off events so it can release locks of users
* which have or are logged off
*
* @see org.olat.core.util.event.GenericEventListener#event(org.olat.core.gui.control.Event)
*/
@Override
public void event(Event event) {
SignOnOffEvent se = (SignOnOffEvent) event;
if (!se.isSignOn() && se.isEventOnThisNode()) {
// it is a "logout" event - we are only interested in logout events
// and it is from our VM => only release all locks from within one VM
Long identKey = se.getIdentityKey();
// since the lock is reentrant, a lock could be freed while a session still is in a locked workflow (2x lock and then once freed)
try {
clusterLockManager.releaseAllLocksFor(identKey);
DBFactory.getInstance().commit();
} catch (DBRuntimeException dbEx) {
log.warn("releaseAllLocksFor failed, close session and try it again for identName=" + identKey);
// TODO: 2010-04-23 Transactions [eglis]: OLAT-4318: this rollback has possibly unwanted
// side effects, as it rolls back any changes with this transaction during this
// event handling. Nicer would be to be done in the outmost-possible place, e.g. dofire()
DBFactory.getInstance().rollbackAndCloseSession();
// try again with new db-session
log.info("try again to release all locks for identName=" + identKey);
clusterLockManager.releaseAllLocksFor(identKey);
log.info("Done, released all locks for identName=" + identKey);
}
}
}
use of org.olat.core.logging.DBRuntimeException in project OpenOLAT by OpenOLAT.
the class LockTest method testSaveEvent.
@Test
public void testSaveEvent() {
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("lock-save-event-");
dbInstance.closeSession();
log.info("Created identity=" + identity);
// The group has no creation date -> commit will fail
GroupImpl entry = new GroupImpl();
entry.setName("bar");
try {
dbInstance.saveObject(entry);
dbInstance.commit();
fail("Should generate an error");
} catch (DBRuntimeException dre) {
log.info("DB connection is in error-state");
}
// DB transaction must be in error state for this test
try {
Locker locker = clusterCoordinator.getLocker();
assertTrue(locker instanceof ClusterLocker);
log.info("ClusterLocker created");
Event event = new SignOnOffEvent(identity, false);
log.info("START locker.event(event)");
((ClusterLocker) locker).event(event);
log.info("DONE locker.event(event)");
} catch (Exception ex) {
log.error("", ex);
fail("BLOCKER : ClusterLocker.event is not error-safe, db exception could happen and de-register event-listener");
}
}
Aggregations