Search in sources :

Example 16 with DBRuntimeException

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();
            }
        }
    }
}
Also used : DBRuntimeException(org.olat.core.logging.DBRuntimeException) Authentication(org.olat.basesecurity.Authentication) Identity(org.olat.core.id.Identity)

Example 17 with DBRuntimeException

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);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) Query(org.hibernate.Query) HibernateException(org.hibernate.HibernateException) DBRuntimeException(org.olat.core.logging.DBRuntimeException)

Example 18 with DBRuntimeException

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);
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) DBRuntimeException(org.olat.core.logging.DBRuntimeException) RollbackException(javax.persistence.RollbackException) AssertException(org.olat.core.logging.AssertException) DBRuntimeException(org.olat.core.logging.DBRuntimeException) SQLException(java.sql.SQLException) RollbackException(javax.persistence.RollbackException) HibernateException(org.hibernate.HibernateException)

Example 19 with DBRuntimeException

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);
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) DBRuntimeException(org.olat.core.logging.DBRuntimeException) AssertException(org.olat.core.logging.AssertException) DBRuntimeException(org.olat.core.logging.DBRuntimeException) SQLException(java.sql.SQLException) RollbackException(javax.persistence.RollbackException) HibernateException(org.hibernate.HibernateException)

Example 20 with DBRuntimeException

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);
    }
}
Also used : DBRuntimeException(org.olat.core.logging.DBRuntimeException) AssessmentManager(org.olat.course.assessment.AssessmentManager) KnownIssueException(org.olat.core.logging.KnownIssueException) Identity(org.olat.core.id.Identity)

Aggregations

DBRuntimeException (org.olat.core.logging.DBRuntimeException)24 HibernateException (org.hibernate.HibernateException)10 EntityManager (javax.persistence.EntityManager)8 EntityTransaction (javax.persistence.EntityTransaction)8 Identity (org.olat.core.id.Identity)8 AssertException (org.olat.core.logging.AssertException)6 SQLException (java.sql.SQLException)4 RollbackException (javax.persistence.RollbackException)4 Test (org.junit.Test)4 Authentication (org.olat.basesecurity.Authentication)4 GroupImpl (org.olat.basesecurity.model.GroupImpl)4 KnownIssueException (org.olat.core.logging.KnownIssueException)4 SignOnOffEvent (org.olat.core.util.SignOnOffEvent)4 Date (java.util.Date)2 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)2 Query (org.hibernate.Query)2 StaleObjectStateException (org.hibernate.StaleObjectStateException)2 CollaborationTools (org.olat.collaboration.CollaborationTools)2 Event (org.olat.core.gui.control.Event)2 Locker (org.olat.core.util.coordinate.Locker)2