Search in sources :

Example 21 with TransactionFailureException

use of org.neo4j.graphdb.TransactionFailureException in project neo4j-mobile-android by neo4j-contrib.

the class PersistenceManager method delistResourcesForTransaction.

void delistResourcesForTransaction() throws NotInTransactionException {
    Transaction tx = this.getCurrentTransaction();
    if (tx == null) {
        throw new NotInTransactionException();
    }
    NeoStoreTransaction con = txConnectionMap.get(tx);
    if (con != null) {
        try {
            tx.delistResource(con.getXAResource(), XAResource.TMSUCCESS);
        } catch (SystemException e) {
            throw new TransactionFailureException("Failed to delist resource '" + con + "' from current transaction.", e);
        }
    }
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException)

Example 22 with TransactionFailureException

use of org.neo4j.graphdb.TransactionFailureException in project neo4j-mobile-android by neo4j-contrib.

the class EmbeddedGraphDbImpl method beginTx.

/**
 * @throws TransactionFailureException if unable to start transaction
 */
public Transaction beginTx() {
    if (graphDbInstance.transactionRunning()) {
        if (placeboTransaction == null) {
            placeboTransaction = new PlaceboTransaction(graphDbInstance.getTransactionManager());
        }
        return placeboTransaction;
    }
    TransactionManager txManager = graphDbInstance.getTransactionManager();
    Transaction result = null;
    try {
        txManager.begin();
        result = new TopLevelTransaction(txManager, txManager.getTransaction());
    } catch (Exception e) {
        throw new TransactionFailureException("Unable to begin transaction", e);
    }
    return result;
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) Transaction(org.neo4j.graphdb.Transaction) TransactionManager(javax.transaction.TransactionManager) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) NotFoundException(org.neo4j.graphdb.NotFoundException) NoSuchElementException(java.util.NoSuchElementException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 23 with TransactionFailureException

use of org.neo4j.graphdb.TransactionFailureException in project neo4j-mobile-android by neo4j-contrib.

the class DefaultRelationshipTypeCreator method getOrCreate.

public int getOrCreate(TransactionManager txManager, EntityIdGenerator idGenerator, PersistenceManager persistence, RelationshipTypeHolder relTypeHolder, String name) {
    RelTypeCreater createrThread = new RelTypeCreater(name, txManager, idGenerator, persistence);
    synchronized (createrThread) {
        createrThread.start();
        while (createrThread.isAlive()) {
            try {
                createrThread.wait(50);
            } catch (InterruptedException e) {
                Thread.interrupted();
            }
        }
    }
    if (createrThread.succeded()) {
        int id = createrThread.getRelTypeId();
        relTypeHolder.addRawRelationshipType(new RelationshipTypeData(id, name));
        return id;
    }
    throw new TransactionFailureException("Unable to create relationship type " + name);
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) RelationshipTypeData(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeData)

Example 24 with TransactionFailureException

use of org.neo4j.graphdb.TransactionFailureException in project neo4j-mobile-android by neo4j-contrib.

the class LockReleaser method releaseCows.

void releaseCows(Transaction cowTxId, int param) {
    PrimitiveElement element = cowMap.remove(cowTxId);
    if (element == null) {
        return;
    }
    ArrayMap<Long, CowNodeElement> cowNodeElements = element.nodes;
    Set<Entry<Long, CowNodeElement>> nodeEntrySet = cowNodeElements.entrySet();
    for (Entry<Long, CowNodeElement> entry : nodeEntrySet) {
        NodeImpl node = nodeManager.getNodeIfCached(entry.getKey());
        if (node != null) {
            CowNodeElement nodeElement = entry.getValue();
            if (param == Status.STATUS_COMMITTED) {
                node.commitRelationshipMaps(nodeElement.relationshipAddMap, nodeElement.relationshipRemoveMap);
                node.commitPropertyMaps(nodeElement.propertyAddMap, nodeElement.propertyRemoveMap);
            } else if (param != Status.STATUS_ROLLEDBACK) {
                throw new TransactionFailureException("Unknown transaction status: " + param);
            }
        }
    }
    ArrayMap<Long, CowRelElement> cowRelElements = element.relationships;
    Set<Entry<Long, CowRelElement>> relEntrySet = cowRelElements.entrySet();
    for (Entry<Long, CowRelElement> entry : relEntrySet) {
        RelationshipImpl rel = nodeManager.getRelIfCached(entry.getKey());
        if (rel != null) {
            CowRelElement relElement = entry.getValue();
            if (param == Status.STATUS_COMMITTED) {
                rel.commitPropertyMaps(relElement.propertyAddMap, relElement.propertyRemoveMap);
            } else if (param != Status.STATUS_ROLLEDBACK) {
                throw new TransactionFailureException("Unknown transaction status: " + param);
            }
        }
    }
    cowMap.remove(cowTxId);
}
Also used : Entry(java.util.Map.Entry) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException)

Example 25 with TransactionFailureException

use of org.neo4j.graphdb.TransactionFailureException in project graphdb by neo4j-attic.

the class TestUpgradeStore method makeSureStoreCantBeUpgradedIfNotExplicitlyToldTo.

@Test
public void makeSureStoreCantBeUpgradedIfNotExplicitlyToldTo() throws Exception {
    String path = path(11);
    new EmbeddedGraphDatabase(path).shutdown();
    setOlderNeoStoreVersion(path);
    try {
        new EmbeddedGraphDatabase(path);
        fail("Shouldn't be able to upgrade if not told to");
    } catch (TransactionFailureException e) {
        if (!(e.getCause() instanceof IllegalStoreVersionException)) {
            throw e;
        }
    }
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) Test(org.junit.Test)

Aggregations

TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)56 Transaction (org.neo4j.graphdb.Transaction)16 NotFoundException (org.neo4j.graphdb.NotFoundException)9 Test (org.junit.Test)7 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)7 Node (org.neo4j.graphdb.Node)7 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 LinkedList (java.util.LinkedList)6 SystemException (javax.transaction.SystemException)6 XAException (javax.transaction.xa.XAException)6 XAResource (javax.transaction.xa.XAResource)6 KernelException (org.neo4j.exceptions.KernelException)6 EntityNotFoundException (org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException)6 InvalidTransactionTypeKernelException (org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException)6 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)6 IllegalTokenNameException (org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException)6 TokenCapacityExceededKernelException (org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException)6 XaDataSource (org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)6 XaResource (org.neo4j.kernel.impl.transaction.xaframework.XaResource)6 IOException (java.io.IOException)5