Search in sources :

Example 21 with DBRuntimeException

use of org.olat.core.logging.DBRuntimeException in project openolat by klemens.

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 22 with DBRuntimeException

use of org.olat.core.logging.DBRuntimeException in project openolat by klemens.

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

Example 23 with DBRuntimeException

use of org.olat.core.logging.DBRuntimeException in project openolat by klemens.

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

Example 24 with DBRuntimeException

use of org.olat.core.logging.DBRuntimeException in project openolat by klemens.

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