Example usage for javax.transaction.xa XAException XAException

List of usage examples for javax.transaction.xa XAException XAException

Introduction

In this page you can find the example usage for javax.transaction.xa XAException XAException.

Prototype

public XAException(int errcode) 

Source Link

Document

Create an XAException with a given error code.

Usage

From source file:it.doqui.index.ecmengine.business.personalization.multirepository.index.lucene.RepositoryAwareAbstractLuceneIndexerAndSearcherFactory.java

public int prepare(Xid xid) throws XAException {
    // TODO: Track state OK, ReadOnly, Exception (=> rolled back?)
    Map<String, LuceneIndexer> indexers = activeIndexersInGlobalTx.get(xid);

    if (indexers == null) {
        if (suspendedIndexersInGlobalTx.containsKey(xid)) {
            throw new XAException("Trying to commit indexes for a suspended transaction.");
        } else {/*from ww  w  . j a va  2s  .c  o m*/
            // nothing to do
            return XAResource.XA_OK;
        }
    }

    boolean isPrepared = true;
    boolean isModified = false;

    for (LuceneIndexer indexer : indexers.values()) {
        try {
            isModified |= indexer.isModified();
            indexer.prepare();
        } catch (IndexerException e) {
            isPrepared = false;
        }
    }

    if (isPrepared) {
        return (isModified) ? XAResource.XA_OK : XAResource.XA_RDONLY;
    } else {
        throw new XAException("Failed to prepare: requires rollback");
    }
}

From source file:it.doqui.index.ecmengine.business.personalization.multirepository.index.lucene.RepositoryAwareAbstractLuceneIndexerAndSearcherFactory.java

public void rollback(Xid xid) throws XAException {
    // TODO: What to do if all do not roll back?
    try {//  w  w  w .j  av  a 2  s . c  o m
        Map<String, LuceneIndexer> indexers = activeIndexersInGlobalTx.get(xid);

        if (indexers == null) {
            if (suspendedIndexersInGlobalTx.containsKey(xid)) {
                throw new XAException("Trying to commit indexes for a suspended transaction.");
            } else {
                // nothing to do
                return;
            }
        }

        for (LuceneIndexer indexer : indexers.values()) {
            indexer.rollback();
        }
    } finally {
        activeIndexersInGlobalTx.remove(xid);
    }
}

From source file:it.doqui.index.ecmengine.business.personalization.multirepository.index.lucene.RepositoryAwareAbstractLuceneIndexerAndSearcherFactory.java

public void start(Xid xid, int flag) throws XAException {

    Map<String, LuceneIndexer> active = activeIndexersInGlobalTx.get(xid);
    Map<String, LuceneIndexer> suspended = suspendedIndexersInGlobalTx.get(xid);

    if (flag == XAResource.TMJOIN) {
        // must be active
        if ((active != null) && (suspended == null)) {
            return;
        } else {/*from  w  w w. j  av  a 2 s .c  om*/
            throw new XAException("Trying to rejoin transaction in an invalid state");
        }

    } else if (flag == XAResource.TMRESUME) {
        // must be suspended
        if ((active == null) && (suspended != null)) {
            suspendedIndexersInGlobalTx.remove(xid);
            activeIndexersInGlobalTx.put(xid, suspended);
            return;
        } else {
            throw new XAException("Trying to rejoin transaction in an invalid state");
        }

    } else if (flag == XAResource.TMNOFLAGS) {
        if ((active == null) && (suspended == null)) {
            return;
        } else {
            throw new XAException("Trying to start an existing or suspended transaction");
        }
    } else {
        throw new XAException("Unkown flags for start " + flag);
    }
}

From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerAndSearcherFactory.java

public void commit(Xid xid, boolean onePhase) throws XAException {
    try {/*  w  w w. java  2 s.  co m*/
        // TODO: Should be remembering overall state
        // TODO: Keep track of prepare responses
        Map<StoreRef, LuceneIndexer> indexers = activeIndexersInGlobalTx.get(xid);
        if (indexers == null) {
            if (suspendedIndexersInGlobalTx.containsKey(xid)) {
                throw new XAException("Trying to commit indexes for a suspended transaction.");
            } else {
                // nothing to do
                return;
            }
        }

        if (onePhase) {
            if (indexers.size() == 0) {
                return;
            } else if (indexers.size() == 1) {
                for (LuceneIndexer indexer : indexers.values()) {
                    indexer.commit();
                }
                return;
            } else {
                throw new XAException("Trying to do one phase commit on more than one index");
            }
        } else
        // two phase
        {
            for (LuceneIndexer indexer : indexers.values()) {
                indexer.commit();
            }
            return;
        }
    } finally {
        activeIndexersInGlobalTx.remove(xid);
    }
}

From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerAndSearcherFactory.java

public void end(Xid xid, int flag) throws XAException {
    Map<StoreRef, LuceneIndexer> indexers = activeIndexersInGlobalTx.get(xid);
    if (indexers == null) {
        if (suspendedIndexersInGlobalTx.containsKey(xid)) {
            throw new XAException("Trying to commit indexes for a suspended transaction.");
        } else {//w ww . j  ava 2s .  com
            // nothing to do
            return;
        }
    }
    if (flag == XAResource.TMSUSPEND) {
        activeIndexersInGlobalTx.remove(xid);
        suspendedIndexersInGlobalTx.put(xid, indexers);
    } else if (flag == TMFAIL) {
        activeIndexersInGlobalTx.remove(xid);
        suspendedIndexersInGlobalTx.remove(xid);
    } else if (flag == TMSUCCESS) {
        activeIndexersInGlobalTx.remove(xid);
    }
}

From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerAndSearcherFactory.java

public int prepare(Xid xid) throws XAException {
    // TODO: Track state OK, ReadOnly, Exception (=> rolled back?)
    Map<StoreRef, LuceneIndexer> indexers = activeIndexersInGlobalTx.get(xid);
    if (indexers == null) {
        if (suspendedIndexersInGlobalTx.containsKey(xid)) {
            throw new XAException("Trying to commit indexes for a suspended transaction.");
        } else {//from   w  w w.  j  av a  2  s  . co m
            // nothing to do
            return XAResource.XA_OK;
        }
    }
    boolean isPrepared = true;
    boolean isModified = false;
    for (LuceneIndexer indexer : indexers.values()) {
        try {
            isModified |= indexer.isModified();
            indexer.prepare();
        } catch (IndexerException e) {
            isPrepared = false;
        }
    }
    if (isPrepared) {
        if (isModified) {
            return XAResource.XA_OK;
        } else {
            return XAResource.XA_RDONLY;
        }
    } else {
        throw new XAException("Failed to prepare: requires rollback");
    }
}

From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerAndSearcherFactory.java

public void rollback(Xid xid) throws XAException {
    // TODO: What to do if all do not roll back?
    try {/*  w  ww  . j a  v  a 2 s.co m*/
        Map<StoreRef, LuceneIndexer> indexers = activeIndexersInGlobalTx.get(xid);
        if (indexers == null) {
            if (suspendedIndexersInGlobalTx.containsKey(xid)) {
                throw new XAException("Trying to commit indexes for a suspended transaction.");
            } else {
                // nothing to do
                return;
            }
        }
        for (LuceneIndexer indexer : indexers.values()) {
            indexer.rollback();
        }
    } finally {
        activeIndexersInGlobalTx.remove(xid);
    }
}

From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerAndSearcherFactory.java

public void start(Xid xid, int flag) throws XAException {
    Map<StoreRef, LuceneIndexer> active = activeIndexersInGlobalTx.get(xid);
    Map<StoreRef, LuceneIndexer> suspended = suspendedIndexersInGlobalTx.get(xid);
    if (flag == XAResource.TMJOIN) {
        // must be active
        if ((active != null) && (suspended == null)) {
            return;
        } else {//w  w  w. j  a  va  2s.com
            throw new XAException("Trying to rejoin transaction in an invalid state");
        }

    } else if (flag == XAResource.TMRESUME) {
        // must be suspended
        if ((active == null) && (suspended != null)) {
            suspendedIndexersInGlobalTx.remove(xid);
            activeIndexersInGlobalTx.put(xid, suspended);
            return;
        } else {
            throw new XAException("Trying to rejoin transaction in an invalid state");
        }

    } else if (flag == XAResource.TMNOFLAGS) {
        if ((active == null) && (suspended == null)) {
            return;
        } else {
            throw new XAException("Trying to start an existing or suspended transaction");
        }
    } else {
        throw new XAException("Unkown flags for start " + flag);
    }

}

From source file:org.apache.hadoop.hbase.client.transactional.JtaXAResource.java

public void commit(final Xid xid, final boolean onePhase) throws XAException {
    LOG.trace("commit [" + xid.toString() + "] " + (onePhase ? "one phase" : "two phase"));
    TransactionState state = xidToTransactionState.remove(xid);
    if (state == null) {
        throw new XAException(XAException.XAER_NOTA);
    }//from  ww w  . j  a  v  a 2 s . c  om
    try {
        if (onePhase) {
            transactionManager.tryCommit(state);
        } else {
            transactionManager.doCommit(state);
        }
    } catch (CommitUnsuccessfulException e) {
        throw new XAException(XAException.XA_RBROLLBACK);
    } catch (UnsuccessfulDDLException e) {
        throw new XAException(XAException.XA_RBROLLBACK);
    } catch (IOException e) {
        XAException xae = new XAException(XAException.XAER_RMERR);
        xae.initCause(e);
        throw xae;
    } finally {
        threadLocalTransactionState.remove();
    }

}

From source file:org.apache.hadoop.hbase.client.transactional.JtaXAResource.java

public void forget(final Xid xid) throws XAException {
    LOG.trace("forget [" + xid.toString() + "] ");
    threadLocalTransactionState.remove();
    TransactionState state = xidToTransactionState.remove(xid);
    if (state != null) {
        try {//  www  .  j  av a 2s .  c om
            transactionManager.abort(state);
        } catch (Exception e) {
            XAException xae = new XAException(XAException.XAER_RMERR);
            xae.initCause(e);
            throw xae;
        }
    }
}