Search in sources :

Example 6 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class TransitionalTxManagementKernelTransaction method rollback.

public void rollback() {
    try {
        KernelTransaction kernelTransactionBoundToThisThread = bridge.getKernelTransactionBoundToThisThread(false);
        kernelTransactionBoundToThisThread.failure();
        kernelTransactionBoundToThisThread.close();
    } catch (TransactionFailureException e) {
        throw new RuntimeException(e);
    } finally {
        bridge.unbindTransactionFromCurrentThread();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException)

Example 7 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class IndexProceduresTest method closeStatementOnClose.

@Test
public void closeStatementOnClose() throws Exception {
    KernelTransaction kernelTransaction = mock(KernelTransaction.class);
    Statement statement = mock(Statement.class);
    when(kernelTransaction.acquireStatement()).thenReturn(statement);
    //noinspection EmptyTryBlock
    try (IndexProcedures ignored = new IndexProcedures(kernelTransaction, null)) {
    }
    verify(statement).close();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 8 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class ConstraintIndexCreator method dropUniquenessConstraintIndex.

/**
     * You MUST hold a schema write lock before you call this method.
     */
public void dropUniquenessConstraintIndex(NewIndexDescriptor descriptor) throws TransactionFailureException, DropIndexFailureException {
    try (KernelTransaction transaction = kernelSupplier.get().newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
        Statement statement = transaction.acquireStatement()) {
        // NOTE: This creates the index (obviously) but it DOES NOT grab a schema
        // write lock. It is assumed that the transaction that invoked this "inner" transaction
        // holds a schema write lock, and that it will wait for this inner transaction to do its
        // work.
        // TODO (Ben+Jake): The Transactor is really part of the kernel internals, so it needs access to the
        // internal implementation of Statement. However it is currently used by the external
        // RemoveOrphanConstraintIndexesOnStartup job. This needs revisiting.
        ((KernelStatement) statement).txState().indexDoDrop(descriptor);
        transaction.success();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement)

Example 9 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class ConstraintIndexCreator method createConstraintIndex.

public NewIndexDescriptor createConstraintIndex(final LabelSchemaDescriptor schema) {
    try (KernelTransaction transaction = kernelSupplier.get().newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
        Statement statement = transaction.acquireStatement()) {
        // NOTE: This creates the index (obviously) but it DOES NOT grab a schema
        // write lock. It is assumed that the transaction that invoked this "inner" transaction
        // holds a schema write lock, and that it will wait for this inner transaction to do its
        // work.
        // TODO (Ben+Jake): The Transactor is really part of the kernel internals, so it needs access to the
        // internal implementation of Statement. However it is currently used by the external
        // RemoveOrphanConstraintIndexesOnStartup job. This needs revisiting.
        NewIndexDescriptor index = NewIndexDescriptorFactory.uniqueForSchema(schema);
        ((KernelStatement) statement).txState().indexRuleDoAdd(index);
        transaction.success();
        return index;
    } catch (TransactionFailureException e) {
        throw new RuntimeException(e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement)

Example 10 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class IsolatedTransactionTokenCreator method getOrCreate.

@Override
public synchronized int getOrCreate(String name) throws org.neo4j.kernel.api.exceptions.KernelException {
    KernelAPI kernel = kernelSupplier.get();
    try (KernelTransaction transaction = kernel.newTransaction(Type.implicit, AUTH_DISABLED)) {
        try (Statement statement = transaction.acquireStatement()) {
            int id = createKey(statement, name);
            transaction.success();
            return id;
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) KernelAPI(org.neo4j.kernel.api.KernelAPI)

Aggregations

KernelTransaction (org.neo4j.kernel.api.KernelTransaction)77 Test (org.junit.Test)37 Statement (org.neo4j.kernel.api.Statement)30 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)14 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)14 KernelAPI (org.neo4j.kernel.api.KernelAPI)9 TopLevelTransaction (org.neo4j.kernel.impl.coreapi.TopLevelTransaction)8 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)7 TransactionTerminatedException (org.neo4j.graphdb.TransactionTerminatedException)6 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)6 QueryRegistryOperations (org.neo4j.kernel.api.QueryRegistryOperations)4 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)4 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)4 RemoteException (java.rmi.RemoteException)3 ExpectedException (org.junit.rules.ExpectedException)3 DependencyResolver (org.neo4j.graphdb.DependencyResolver)3 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)3 ShellException (org.neo4j.shell.ShellException)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2