Search in sources :

Example 6 with DBRuntimeException

use of org.olat.core.logging.DBRuntimeException in project OpenOLAT by OpenOLAT.

the class BusinessGroupServiceImpl method deleteBusinessGroup.

@Override
public void deleteBusinessGroup(BusinessGroup group) {
    try {
        OLATResourceableJustBeforeDeletedEvent delEv = new OLATResourceableJustBeforeDeletedEvent(group);
        // notify all (currently running) BusinessGroupXXXcontrollers
        // about the deletion which will occur.
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(delEv, group);
        // refresh object to avoid stale object exceptions
        group = loadBusinessGroup(group);
        // 0) Loop over all deletableGroupData
        Map<String, DeletableGroupData> deleteListeners = CoreSpringFactory.getBeansOfType(DeletableGroupData.class);
        for (DeletableGroupData deleteListener : deleteListeners.values()) {
            if (log.isDebug()) {
                log.debug("deleteBusinessGroup: call deleteListener=" + deleteListener);
            }
            deleteListener.deleteGroupDataFor(group);
        }
        // 1) Delete all group properties
        CollaborationTools ct = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group);
        // deletes everything concerning properties&collabTools
        ct.deleteTools(group);
        // 1.c)delete user in security groups
        // removeFromRepositoryEntrySecurityGroup(group);
        // 2) Delete the group areas
        areaManager.deleteBGtoAreaRelations(group);
        // 3) Delete the relations
        businessGroupRelationDAO.deleteRelationsToRepositoryEntry(group);
        assessmentModeDao.deleteAssessmentModesToGroup(group);
        // 4) delete properties
        propertyManager.deleteProperties(null, group, null, null, null);
        propertyManager.deleteProperties(null, null, group, null, null);
        // 5) delete the publisher attached to this group (e.g. the forum and folder
        // publisher)
        notificationsManager.deletePublishersOf(group);
        // 6) delete info messages and subscription context associated with this group
        infoMessageManager.removeInfoMessagesAndSubscriptionContext(group);
        // 7) the group
        businessGroupDAO.delete(group);
        // 8) delete the associated security groups
        // TODO group
        dbInstance.commit();
        log.audit("Deleted Business Group", group.toString());
    } catch (DBRuntimeException dbre) {
        Throwable th = dbre.getCause();
        if ((th instanceof ObjectNotFoundException) && th.getMessage().contains("org.olat.group.BusinessGroupImpl")) {
            // group already deleted
            return;
        }
        if ((th instanceof StaleObjectStateException) && (th.getMessage().startsWith("Row was updated or deleted by another transaction"))) {
            // known issue OLAT-3654
            log.info("Group was deleted by another user in the meantime. Known issue OLAT-3654");
            throw new KnownIssueException("Group was deleted by another user in the meantime", 3654);
        } else {
            throw dbre;
        }
    }
}
Also used : DeletableGroupData(org.olat.group.DeletableGroupData) DBRuntimeException(org.olat.core.logging.DBRuntimeException) KnownIssueException(org.olat.core.logging.KnownIssueException) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) CollaborationTools(org.olat.collaboration.CollaborationTools) OLATResourceableJustBeforeDeletedEvent(org.olat.core.util.resource.OLATResourceableJustBeforeDeletedEvent) StaleObjectStateException(org.hibernate.StaleObjectStateException)

Example 7 with DBRuntimeException

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

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");
    }
}
Also used : Locker(org.olat.core.util.coordinate.Locker) DBRuntimeException(org.olat.core.logging.DBRuntimeException) GroupImpl(org.olat.basesecurity.model.GroupImpl) SignOnOffEvent(org.olat.core.util.SignOnOffEvent) SignOnOffEvent(org.olat.core.util.SignOnOffEvent) Event(org.olat.core.gui.control.Event) Identity(org.olat.core.id.Identity) DBRuntimeException(org.olat.core.logging.DBRuntimeException) Test(org.junit.Test)

Example 8 with DBRuntimeException

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

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();
}
Also used : DBRuntimeException(org.olat.core.logging.DBRuntimeException) GroupImpl(org.olat.basesecurity.model.GroupImpl) Date(java.util.Date) Test(org.junit.Test)

Example 9 with DBRuntimeException

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

the class BusinessGroupServiceImpl method deleteBusinessGroup.

@Override
public void deleteBusinessGroup(BusinessGroup group) {
    try {
        OLATResourceableJustBeforeDeletedEvent delEv = new OLATResourceableJustBeforeDeletedEvent(group);
        // notify all (currently running) BusinessGroupXXXcontrollers
        // about the deletion which will occur.
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(delEv, group);
        // refresh object to avoid stale object exceptions
        group = loadBusinessGroup(group);
        // 0) Loop over all deletableGroupData
        Map<String, DeletableGroupData> deleteListeners = CoreSpringFactory.getBeansOfType(DeletableGroupData.class);
        for (DeletableGroupData deleteListener : deleteListeners.values()) {
            if (log.isDebug()) {
                log.debug("deleteBusinessGroup: call deleteListener=" + deleteListener);
            }
            deleteListener.deleteGroupDataFor(group);
        }
        // 1) Delete all group properties
        CollaborationTools ct = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group);
        // deletes everything concerning properties&collabTools
        ct.deleteTools(group);
        // 1.c)delete user in security groups
        // removeFromRepositoryEntrySecurityGroup(group);
        // 2) Delete the group areas
        areaManager.deleteBGtoAreaRelations(group);
        // 3) Delete the relations
        businessGroupRelationDAO.deleteRelationsToRepositoryEntry(group);
        assessmentModeDao.deleteAssessmentModesToGroup(group);
        // 4) delete properties
        propertyManager.deleteProperties(null, group, null, null, null);
        propertyManager.deleteProperties(null, null, group, null, null);
        // 5) delete the publisher attached to this group (e.g. the forum and folder
        // publisher)
        notificationsManager.deletePublishersOf(group);
        // 6) delete info messages and subscription context associated with this group
        infoMessageManager.removeInfoMessagesAndSubscriptionContext(group);
        // 7) the group
        businessGroupDAO.delete(group);
        // 8) delete the associated security groups
        // TODO group
        dbInstance.commit();
        log.audit("Deleted Business Group", group.toString());
    } catch (DBRuntimeException dbre) {
        Throwable th = dbre.getCause();
        if ((th instanceof ObjectNotFoundException) && th.getMessage().contains("org.olat.group.BusinessGroupImpl")) {
            // group already deleted
            return;
        }
        if ((th instanceof StaleObjectStateException) && (th.getMessage().startsWith("Row was updated or deleted by another transaction"))) {
            // known issue OLAT-3654
            log.info("Group was deleted by another user in the meantime. Known issue OLAT-3654");
            throw new KnownIssueException("Group was deleted by another user in the meantime", 3654);
        } else {
            throw dbre;
        }
    }
}
Also used : DeletableGroupData(org.olat.group.DeletableGroupData) DBRuntimeException(org.olat.core.logging.DBRuntimeException) KnownIssueException(org.olat.core.logging.KnownIssueException) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) CollaborationTools(org.olat.collaboration.CollaborationTools) OLATResourceableJustBeforeDeletedEvent(org.olat.core.util.resource.OLATResourceableJustBeforeDeletedEvent) StaleObjectStateException(org.hibernate.StaleObjectStateException)

Example 10 with DBRuntimeException

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

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)

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