Search in sources :

Example 31 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class AbstractShellIT method assertRelationshipDoesntExist.

protected void assertRelationshipDoesntExist(long id) {
    try (Transaction ignore = db.beginTx()) {
        db.getRelationshipById(id);
        fail("Relationship " + id + " shouldn't exist");
    } catch (NotFoundException e) {
    // Good
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) NotFoundException(org.neo4j.graphdb.NotFoundException)

Example 32 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class AbstractShellIT method setProperty.

protected void setProperty(Node node, String key, Object value) {
    try (Transaction tx = db.beginTx()) {
        node.setProperty(key, value);
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction)

Example 33 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class AbstractShellIT method createRelationshipChain.

protected Relationship[] createRelationshipChain(RelationshipType type, int length) {
    try (Transaction transaction = db.beginTx()) {
        Relationship[] relationshipChain = createRelationshipChain(db.createNode(), type, length);
        transaction.success();
        return relationshipChain;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Relationship(org.neo4j.graphdb.Relationship)

Example 34 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class AbstractShellIT method deleteRelationship.

protected void deleteRelationship(Relationship relationship) {
    try (Transaction tx = db.beginTx()) {
        relationship.delete();
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction)

Example 35 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class Cluster method leaderTx.

/**
     * Perform a transaction against the leader of the core cluster, retrying as necessary.
     */
private CoreClusterMember leaderTx(BiConsumer<CoreGraphDatabase, Transaction> op, int timeout, TimeUnit timeUnit) throws Exception {
    ThrowingSupplier<CoreClusterMember, Exception> supplier = () -> {
        CoreClusterMember member = awaitLeader(timeout, timeUnit);
        CoreGraphDatabase db = member.database();
        if (db == null) {
            throw new DatabaseShutdownException();
        }
        try (Transaction tx = db.beginTx()) {
            op.accept(db, tx);
            return member;
        } catch (Throwable e) {
            if (isTransientFailure(e)) {
                // this is not the best, but it helps in debugging
                System.err.println("Transient failure in leader transaction, trying again.");
                e.printStackTrace();
                return null;
            } else {
                throw e;
            }
        }
    };
    return awaitEx(supplier, notNull()::test, timeout, timeUnit);
}
Also used : Transaction(org.neo4j.graphdb.Transaction) DatabaseShutdownException(org.neo4j.graphdb.DatabaseShutdownException) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) TimeoutException(java.util.concurrent.TimeoutException) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) IdGenerationException(org.neo4j.causalclustering.core.state.machines.id.IdGenerationException) ExecutionException(java.util.concurrent.ExecutionException) NoLeaderFoundException(org.neo4j.causalclustering.core.consensus.NoLeaderFoundException) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) DatabaseShutdownException(org.neo4j.graphdb.DatabaseShutdownException) AcquireLockTimeoutException(org.neo4j.storageengine.api.lock.AcquireLockTimeoutException)

Aggregations

Transaction (org.neo4j.graphdb.Transaction)2409 Node (org.neo4j.graphdb.Node)1086 Test (org.junit.jupiter.api.Test)751 Test (org.junit.Test)607 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)352 Relationship (org.neo4j.graphdb.Relationship)307 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)302 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)241 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)177 Label (org.neo4j.graphdb.Label)154 Result (org.neo4j.graphdb.Result)142 HashMap (java.util.HashMap)105 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)104 MethodSource (org.junit.jupiter.params.provider.MethodSource)103 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)86 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)77 File (java.io.File)74 ArrayList (java.util.ArrayList)73 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)67 Path (java.nio.file.Path)64