Package org.castor.persist

Examples of org.castor.persist.TransactionContext


            throw new PersistenceException("Identities can't be null!");
        }
        if (_scope == null) {
            throw new PersistenceException(Messages.message("jdo.dbClosed"));
        }
        TransactionContext tx = getTransaction();
        ClassMolder molder = _scope.getClassMolder(type);
        ProposedEntity proposedObject = new ProposedEntity(molder);
        return tx.load(new Identity(identity), proposedObject, mode);
    }
View Full Code Here


    /**
     * {@inheritDoc}
     */
    public void create(final Object object) throws PersistenceException {
        TransactionContext tx = getTransaction();
        ClassMolder molder = _scope.getClassMolder(object.getClass());
        tx.create(molder, object, null);
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public void update(final Object object) throws PersistenceException {
       
        TransactionContext tx = getTransaction();
        ClassMolder molder = _scope.getClassMolder(object.getClass());
        tx.update(molder, object, null);
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public void remove(final Object object) throws PersistenceException {
       
        TransactionContext tx = getTransaction();
        _scope.getClassMolder(object.getClass());
        tx.delete(object);
    }
View Full Code Here

            throw new XAException(XAException.XAER_INVAL);
        }
       
        switch (flags) {
        case TMNOFLAGS:
            TransactionContext tx1;
           
            // Must assure transaction context is created only once
            // for a given Xid
            synchronized (_engine.getXATransactions()) {
                tx1 = (TransactionContext) _engine.getXATransactions().get(xid);
                if (tx1 == null) {
                    tx1 = _xaSource.createTransactionContext(xid);
                    _engine.getXATransactions().put(xid, tx1);
                }
            }
            // Associate XAResource with transaction
            _xaSource.setTransactionContext(tx1);
            break;
        case TMJOIN:
        case TMRESUME:
            TransactionContext tx2;
           
            tx2 = (TransactionContext) _engine.getXATransactions().get(xid);
            if ((tx2 == null) || !tx2.isOpen()) {
                throw new XAException(XAException.XAER_NOTA);
            }
            // Associate XAResource with transaction
            _xaSource.setTransactionContext(tx2);
            break;
View Full Code Here

        // General checks.
        if (xid == null) {
            throw new XAException(XAException.XAER_INVAL);
        }
       
        TransactionContext tx;
       
        tx = (TransactionContext) _engine.getXATransactions().get(xid);
        if (tx == null) {
            throw new XAException(XAException.XAER_NOTA);
        }
       
        // Make sure the XA source is associated with any
        // transaction otherwise this is an invalid Xid
        if (_xaSource.getTransactionContext() == null) {
            throw new XAException(XAException.XAER_INVAL);
        }
        switch (flags) {
        case TMSUCCESS:
            // Expect prepare/rollback next
            break;
        case TMFAIL:
            // Failure implies rolling back transaction,
            // and terminating XA source
            _xaSource.xaFailed();
            _xaSource.setTransactionContext(null);
            if (tx.isOpen()) {
                try {
                    tx.rollback();
                } catch (Exception except) {
                    LOG.debug("Exception at rollback of TransactionContext.");
                }
            }
            break;
View Full Code Here

        if (xid == null) {
            throw new XAException(XAException.XAER_INVAL);
        }
       
        synchronized (_engine.getXATransactions()) {
            TransactionContext tx;
           
            tx = (TransactionContext) _engine.getXATransactions().remove(xid);
            if (tx == null) {
                throw new XAException(XAException.XAER_NOTA);
            }
            // Dissociate XA source from transaction
            if (_xaSource.getTransactionContext() == tx) {
                _xaSource.setTransactionContext(null);
            }
           
            // Forget is never called on an open transaction, but one
            // can never tell.
            if (tx.isOpen()) {
                try {
                    tx.rollback();
                } catch (Exception except) {
                    LOG.debug("Exception at rollback of TransactionContext.");
                }
                throw new XAException(XAException.XAER_PROTO);
            }
View Full Code Here

    public synchronized int prepare(final Xid xid) throws XAException {
        if (xid == null) {
            throw new XAException(XAException.XAER_INVAL);
        }
       
        TransactionContext tx;
       
        tx = (TransactionContext) _engine.getXATransactions().get(xid);
        if (tx == null) {
            throw new XAException(XAException.XAER_NOTA);
        }
       
        switch (tx.getStatus()) {
        case Status.STATUS_PREPARED:
        case Status.STATUS_ACTIVE:
            // Can only prepare an active transaction. And error
            // is reported as vote to rollback the transaction.
            try {
              return tx.prepare() ? XA_OK : XA_RDONLY;
               
            } catch (TransactionAbortedException except) {
                throw new XAException(XAException.XA_RBROLLBACK);
            } catch (IllegalStateException except) {
                throw new XAException(XAException.XAER_PROTO);
View Full Code Here

    public synchronized void commit(final Xid xid, final boolean onePhase) throws XAException {
        if (xid == null) {
            throw new XAException(XAException.XAER_INVAL);
        }
       
        TransactionContext tx;
       
        tx = (TransactionContext) _engine.getXATransactions().get(xid);
        if (tx == null) {
            throw new XAException(XAException.XAER_NOTA);
        }
        switch (tx.getStatus()) {
        case Status.STATUS_COMMITTED:
            // Allowed to make multiple commit attempts.
            return;
        case Status.STATUS_ROLLEDBACK:
            // This should not happen unless someone interfered
            // by calling rollback directly or failing a commit,
            // but is still a valid heuristic condition on our behalf.
            throw new XAException(XAException.XA_HEURRB);
        case Status.STATUS_PREPARED:
            // Commit can only occur after a prepare, so must be
            // in prepared state first. Any ODMG error is reported
            // as a heuristic decision to rollback.
            try {
                tx.commit();
            } catch (TransactionAbortedException except) {
                // Transaction cannot commit and was rolledback
                throw new XAException(XAException.XA_HEURRB);
            } catch (IllegalStateException except) {
                throw new XAException(XAException.XAER_PROTO);
View Full Code Here

    public synchronized void rollback(final Xid xid) throws XAException {
        if (xid == null) {
            throw new XAException(XAException.XAER_INVAL);
        }
       
        TransactionContext tx;
       
        tx = (TransactionContext) _engine.getXATransactions().get(xid);
        if (tx == null) {
            throw new XAException(XAException.XAER_NOTA);
        }
        switch (tx.getStatus()) {
        case Status.STATUS_COMMITTED:
            // This should not happen unless someone interfered
            // by calling commit directly, but is still a valid
            // heuristic condition on our behalf.
            throw new XAException(XAException.XA_HEURCOM);
        case Status.STATUS_ROLLEDBACK:
            // Allowed to make multiple rollback attempts.
            return;
        case Status.STATUS_ACTIVE:
        case Status.STATUS_MARKED_ROLLBACK:
            // Rollback never fails with an application exception.
            try {
                tx.rollback();
            } catch (IllegalStateException except) {
                throw new XAException(XAException.XAER_PROTO);
            }
            return;
        default:
View Full Code Here

TOP

Related Classes of org.castor.persist.TransactionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.