Search in sources :

Example 1 with UpdateFailedException

use of org.jaffa.persistence.exceptions.UpdateFailedException in project jaffa-framework by jaffa-projects.

the class UOW method commit.

/**
 * Objects that have been added, objects that have been deleted,
 * and objects that have been updated, will all be persisted via
 * an invocation of this method.
 * Note: After a successful commit, this object will free up its connection to the database,
 * and will no longer be available.
 *
 * @throws AddFailedException    if any error occurs during the addition of objects to the persistent store.
 * @throws UpdateFailedException if any error occurs while updating the objects of the persistent store.
 * @throws DeleteFailedException if any error occurs while deleting the objects of the persistent store.
 * @throws CommitFailedException if any error occurs during the commit.
 */
public void commit() throws AddFailedException, UpdateFailedException, DeleteFailedException, CommitFailedException {
    ensureActiveState();
    Collection deletes = m_engine.getDeletes();
    if (deletes != null) {
        if (m_messagingEngine == null) {
            try {
                m_messagingEngine = MessagingEngineFactory.newInstance(this);
            } catch (FrameworkException e) {
            // failed creating the messaging engine, do not fail the overall commit
            } catch (ApplicationExceptions applicationExceptions) {
            // failed creating the messaging engine, do not fail the overall commit
            }
        }
        if (m_messagingEngine != null) {
            m_messagingEngine.prepareDeletesForCommit(deletes);
        }
    }
    // commit the persistence engine
    m_engine.commit();
    // commit the messaging engine
    if (m_messagingEngine != null) {
        try {
            m_messagingEngine.commit();
        } catch (Exception e) {
            log.fatal("The database transaction has been committed. Exception raised while sending Message(s) to the JMS system", e);
            throw new CommitFailedException(null, e);
        }
    }
    close();
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) FrameworkException(org.jaffa.exceptions.FrameworkException) Collection(java.util.Collection) CommitFailedException(org.jaffa.persistence.exceptions.CommitFailedException) InvalidUowRuntimeException(org.jaffa.persistence.exceptions.InvalidUowRuntimeException) UpdateFailedException(org.jaffa.persistence.exceptions.UpdateFailedException) DeleteFailedException(org.jaffa.persistence.exceptions.DeleteFailedException) UOWException(org.jaffa.persistence.exceptions.UOWException) CommitFailedException(org.jaffa.persistence.exceptions.CommitFailedException) PostLoadFailedException(org.jaffa.persistence.exceptions.PostLoadFailedException) FrameworkException(org.jaffa.exceptions.FrameworkException) AddFailedException(org.jaffa.persistence.exceptions.AddFailedException) InactiveUowRuntimeException(org.jaffa.persistence.exceptions.InactiveUowRuntimeException) QueryFailedException(org.jaffa.persistence.exceptions.QueryFailedException) AlreadyLockedObjectException(org.jaffa.persistence.exceptions.AlreadyLockedObjectException) RollbackFailedException(org.jaffa.persistence.exceptions.RollbackFailedException)

Example 2 with UpdateFailedException

use of org.jaffa.persistence.exceptions.UpdateFailedException in project jaffa-framework by jaffa-projects.

the class UpdateInterceptor method invoke.

/**
 *Performs the logic associated with updating Persistent objects in the database.
 * This will update each object in the PersistentTransaction's UPDATE collection in the database, utilising the JdbcBridge.
 * It will then pass on the control to the next Interceptor in the chain.
 * @param pt The PersistentTransaction object, on which the Interceptor is to be executed.
 * @throws UOWException if any error occurs.
 * @return the output from the next Interceptor in the chain.
 */
public Object invoke(PersistentTransaction pt) throws UOWException {
    Collection objects = pt.getUpdates();
    if (objects != null) {
        // updates the objects in the database
        for (Iterator i = objects.iterator(); i.hasNext(); ) {
            IPersistent object = (IPersistent) i.next();
            try {
                if (log.isDebugEnabled())
                    log.debug("Invoking JdbcBridge.executeUpdate() for the object " + object);
                JdbcBridge.executeUpdate(object, pt.getDataSource());
                pt.getDataSource().clearObjectCache();
            } catch (Exception e) {
                String str = "Error while updating the Persistent object in the database: " + object;
                log.error(str, e);
                throw new UpdateFailedException(null, e);
            }
            i.remove();
        }
    }
    // pass control to the next interceptor in the chain
    if (getNextInterceptor() != null) {
        if (log.isDebugEnabled())
            log.debug("Invoking the next Interceptor in the chain " + getNextInterceptor().getClass().getName());
        return getNextInterceptor().invoke(pt);
    } else {
        if (log.isDebugEnabled())
            log.debug("This is the end of the Interceptor chain");
        return null;
    }
}
Also used : IPersistent(org.jaffa.persistence.IPersistent) UpdateFailedException(org.jaffa.persistence.exceptions.UpdateFailedException) UpdateFailedException(org.jaffa.persistence.exceptions.UpdateFailedException) UOWException(org.jaffa.persistence.exceptions.UOWException)

Aggregations

UOWException (org.jaffa.persistence.exceptions.UOWException)2 UpdateFailedException (org.jaffa.persistence.exceptions.UpdateFailedException)2 Collection (java.util.Collection)1 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 IPersistent (org.jaffa.persistence.IPersistent)1 AddFailedException (org.jaffa.persistence.exceptions.AddFailedException)1 AlreadyLockedObjectException (org.jaffa.persistence.exceptions.AlreadyLockedObjectException)1 CommitFailedException (org.jaffa.persistence.exceptions.CommitFailedException)1 DeleteFailedException (org.jaffa.persistence.exceptions.DeleteFailedException)1 InactiveUowRuntimeException (org.jaffa.persistence.exceptions.InactiveUowRuntimeException)1 InvalidUowRuntimeException (org.jaffa.persistence.exceptions.InvalidUowRuntimeException)1 PostLoadFailedException (org.jaffa.persistence.exceptions.PostLoadFailedException)1 QueryFailedException (org.jaffa.persistence.exceptions.QueryFailedException)1 RollbackFailedException (org.jaffa.persistence.exceptions.RollbackFailedException)1