use of org.olat.core.logging.DBRuntimeException in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class DBImpl method createQuery.
/**
* Create a DBQuery
*
* @param query
* @return DBQuery
*/
@Override
public DBQuery createQuery(String query) {
try {
EntityManager em = getCurrentEntityManager();
Query q = getSession(em).createQuery(query);
return new DBQueryImpl(q);
} catch (HibernateException he) {
getData().setError(he);
throw new DBRuntimeException("Error while creating DBQueryImpl: ", he);
}
}
use of org.olat.core.logging.DBRuntimeException in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class DBImpl method saveObject.
/**
* Save an object.
*
* @param object
*/
@Override
public void saveObject(Object object) {
EntityManager em = getCurrentEntityManager();
EntityTransaction trx = em.getTransaction();
if (unusableTrx(trx)) {
// some program bug
throw new DBRuntimeException("cannot save in a transaction that is rolledback or committed: " + object);
}
try {
em.persist(object);
} catch (Exception e) {
// we have some error
log.error("", e);
trx.setRollbackOnly();
getData().setError(e);
throw new DBRuntimeException("Save failed in transaction. object: " + object, e);
}
}
use of org.olat.core.logging.DBRuntimeException in project OpenOLAT by OpenOLAT.
the class IQTESTCourseNode method updateUserScoreEvaluation.
/**
* @see org.olat.course.nodes.AssessableCourseNode#updateUserScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation,
* org.olat.course.run.userview.UserCourseEnvironment,
* org.olat.core.id.Identity)
*/
@Override
public void updateUserScoreEvaluation(ScoreEvaluation scoreEvaluation, UserCourseEnvironment userCourseEnvironment, Identity coachingIdentity, boolean incrementAttempts, Role by) {
AssessmentManager am = userCourseEnvironment.getCourseEnvironment().getAssessmentManager();
Identity mySelf = userCourseEnvironment.getIdentityEnvironment().getIdentity();
try {
am.saveScoreEvaluation(this, coachingIdentity, mySelf, scoreEvaluation, userCourseEnvironment, incrementAttempts, by);
} catch (DBRuntimeException ex) {
throw new KnownIssueException("DBRuntimeException - Row was updated or deleted...", 3570, ex);
}
}
Aggregations