use of org.olat.core.logging.DBRuntimeException in project openolat by klemens.
the class DBImpl method commit.
/**
* Call this to commit a transaction opened by beginTransaction().
*/
@Override
public void commit() {
boolean debug = log.isDebug();
if (debug)
log.debug("commit start...", null);
try {
if (hasTransaction() && !isError()) {
if (debug)
log.debug("has Transaction and is in Transaction => commit", null);
getData().incrementCommitCounter();
if (debug) {
if ((maxCommitCounter != 0) && (getData().getCommitCounter() > maxCommitCounter)) {
log.info("Call too many commit in a db-session, commitCounter=" + getData().getCommitCounter() + "; could be a performance problem", null);
}
}
EntityTransaction trx = getCurrentEntityManager().getTransaction();
if (trx != null) {
trx.commit();
}
if (debug)
log.debug("Commit DONE hasTransaction()=" + hasTransaction(), null);
} else if (hasTransaction() && isError()) {
EntityTransaction trx = getCurrentEntityManager().getTransaction();
if (trx != null && trx.isActive()) {
throw new DBRuntimeException("Try to commit a transaction in error status");
}
} else {
if (debug)
log.debug("Call commit without starting transaction", null);
}
} catch (Error er) {
log.error("Uncaught Error in DBImpl.commit.", er);
throw er;
} catch (Exception e) {
// Filter Exception form async TaskExecutorThread, there are exception allowed
if (!Thread.currentThread().getName().equals("TaskExecutorThread")) {
log.warn("Caught Exception in DBImpl.commit.", e);
}
// Error when trying to commit
try {
if (hasTransaction()) {
EntityTransaction trx = getCurrentEntityManager().getTransaction();
if (trx != null && trx.isActive()) {
if (trx.getRollbackOnly()) {
try {
trx.commit();
} catch (RollbackException e1) {
// we wait for this exception
}
} else {
trx.rollback();
}
}
}
} catch (Error er) {
log.error("Uncaught Error in DBImpl.commit.catch(Exception).", er);
throw er;
} catch (Exception ex) {
log.warn("Could not rollback transaction after commit!", ex);
throw new DBRuntimeException("rollback after commit failed", e);
}
throw new DBRuntimeException("commit failed, rollback transaction", e);
}
}
use of org.olat.core.logging.DBRuntimeException in project openolat by klemens.
the class WebDAVAuthManager method updateDigestPassword.
private void updateDigestPassword(Identity doer, Identity identity, String authUsername, String password, String provider, List<Authentication> authentications) {
String digestToken = authUsername + ":" + WebDAVManagerImpl.BASIC_AUTH_REALM + ":" + password;
Authentication authHa1 = getAndRemoveAuthentication(provider, authentications);
if (authHa1 == null) {
// create new authentication for provider OLAT
try {
dbInstance.commit();
Identity reloadedIdentity = securityManager.loadIdentityByKey(identity.getKey());
securityManager.createAndPersistAuthentication(reloadedIdentity, provider, authUsername, digestToken, Encoder.Algorithm.md5_noSalt);
log.audit(doer.getName() + " created new WebDAV (HA1) authentication for identity: " + identity.getKey() + " (" + authUsername + ")");
} catch (DBRuntimeException e) {
log.error("Cannot create digest password with provider " + provider + " for identity:" + identity, e);
dbInstance.commit();
}
} else {
String md5DigestToken = Encoder.encrypt(digestToken, null, Encoder.Algorithm.md5_noSalt);
if (!md5DigestToken.equals(authHa1.getCredential()) || !authHa1.getAuthusername().equals(authUsername)) {
try {
authHa1.setCredential(md5DigestToken);
authHa1.setAuthusername(authUsername);
securityManager.updateAuthentication(authHa1);
log.audit(doer.getName() + " set new WebDAV (HA1) password for identity: " + identity.getKey() + " (" + authUsername + ")");
} catch (DBRuntimeException e) {
log.error("Cannot update digest password with provider " + provider + " for identity:" + identity, e);
dbInstance.commit();
}
}
}
}
use of org.olat.core.logging.DBRuntimeException in project openolat by klemens.
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 klemens.
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 DBTest method testErrorHandling.
/**
* testErrorHandling
*/
@Test
public void testErrorHandling() {
GroupImpl entry = new GroupImpl();
entry.setName("foo");
try {
dbInstance.saveObject(entry);
fail("Should generate an error");
} catch (DBRuntimeException dre) {
assertTrue(dbInstance.isError());
Assert.assertNotNull(dbInstance.getError());
}
// the close must clear the transaction
dbInstance.closeSession();
// a second try must work
GroupImpl entryTwo = new GroupImpl();
entryTwo.setName("bar");
entryTwo.setCreationDate(new Date());
dbInstance.saveObject(entryTwo);
dbInstance.commitAndCloseSession();
}
Aggregations