Search in sources :

Example 6 with StorageStatement

use of org.neo4j.storageengine.api.StorageStatement in project neo4j by neo4j.

the class KernelStatementTest method assertStatementIsNotOpenWhileAcquireIsNotInvoked.

@Test(expected = NotInTransactionException.class)
public void assertStatementIsNotOpenWhileAcquireIsNotInvoked() {
    KernelTransactionImplementation transaction = mock(KernelTransactionImplementation.class);
    TxStateHolder txStateHolder = mock(TxStateHolder.class);
    StorageStatement storeStatement = mock(StorageStatement.class);
    AccessCapability accessCapability = mock(AccessCapability.class);
    Procedures procedures = mock(Procedures.class);
    KernelStatement statement = new KernelStatement(transaction, txStateHolder, storeStatement, procedures, accessCapability, LockTracer.NONE);
    statement.assertOpen();
}
Also used : TxStateHolder(org.neo4j.kernel.api.txstate.TxStateHolder) AccessCapability(org.neo4j.kernel.impl.factory.AccessCapability) StorageStatement(org.neo4j.storageengine.api.StorageStatement) Procedures(org.neo4j.kernel.impl.proc.Procedures) Test(org.junit.Test)

Example 7 with StorageStatement

use of org.neo4j.storageengine.api.StorageStatement in project neo4j by neo4j.

the class KernelStatementTest method shouldReleaseStorageStatementWhenForceClosed.

@Test
public void shouldReleaseStorageStatementWhenForceClosed() throws Exception {
    // given
    StorageStatement storeStatement = mock(StorageStatement.class);
    KernelStatement statement = new KernelStatement(mock(KernelTransactionImplementation.class), null, storeStatement, new Procedures(), new CanWrite(), LockTracer.NONE);
    statement.acquire();
    // when
    statement.forceClose();
    // then
    verify(storeStatement).release();
}
Also used : CanWrite(org.neo4j.kernel.impl.factory.CanWrite) StorageStatement(org.neo4j.storageengine.api.StorageStatement) Procedures(org.neo4j.kernel.impl.proc.Procedures) Test(org.junit.Test)

Example 8 with StorageStatement

use of org.neo4j.storageengine.api.StorageStatement in project neo4j by neo4j.

the class StateHandlingStatementOperations method indexQuery.

@Override
public PrimitiveLongIterator indexQuery(KernelStatement state, NewIndexDescriptor index, IndexQuery... predicates) throws IndexNotFoundKernelException, IndexNotApplicableKernelException {
    StorageStatement storeStatement = state.getStoreStatement();
    IndexReader reader = storeStatement.getIndexReader(index);
    PrimitiveLongIterator committed = reader.query(predicates);
    PrimitiveLongIterator exactMatches = LookupFilter.exactIndexMatches(this, state, committed, predicates);
    IndexQuery firstPredicate = predicates[0];
    switch(firstPredicate.type()) {
        case exact:
            IndexQuery.ExactPredicate[] exactPreds = assertOnlyExactPredicates(predicates);
            return filterIndexStateChangesForSeek(state, exactMatches, index, OrderedPropertyValues.of(exactPreds));
        case stringSuffix:
        case stringContains:
        case exists:
            return filterIndexStateChangesForScan(state, exactMatches, index);
        case rangeNumeric:
            {
                assertSinglePredicate(predicates);
                IndexQuery.NumberRangePredicate numPred = (IndexQuery.NumberRangePredicate) firstPredicate;
                return filterIndexStateChangesForRangeSeekByNumber(state, index, numPred.from(), numPred.fromInclusive(), numPred.to(), numPred.toInclusive(), exactMatches);
            }
        case rangeString:
            {
                assertSinglePredicate(predicates);
                IndexQuery.StringRangePredicate strPred = (IndexQuery.StringRangePredicate) firstPredicate;
                return filterIndexStateChangesForRangeSeekByString(state, index, strPred.from(), strPred.fromInclusive(), strPred.to(), strPred.toInclusive(), committed);
            }
        case stringPrefix:
            {
                assertSinglePredicate(predicates);
                IndexQuery.StringPrefixPredicate strPred = (IndexQuery.StringPrefixPredicate) firstPredicate;
                return filterIndexStateChangesForRangeSeekByPrefix(state, index, strPred.prefix(), committed);
            }
        default:
            throw new UnsupportedOperationException("Query not supported: " + Arrays.toString(predicates));
    }
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) StorageStatement(org.neo4j.storageengine.api.StorageStatement) IndexReader(org.neo4j.storageengine.api.schema.IndexReader)

Example 9 with StorageStatement

use of org.neo4j.storageengine.api.StorageStatement in project neo4j by neo4j.

the class KernelTransactionFactory method kernelTransactionWithInternals.

static Instances kernelTransactionWithInternals(SecurityContext securityContext) {
    TransactionHeaderInformation headerInformation = new TransactionHeaderInformation(-1, -1, new byte[0]);
    TransactionHeaderInformationFactory headerInformationFactory = mock(TransactionHeaderInformationFactory.class);
    when(headerInformationFactory.create()).thenReturn(headerInformation);
    StorageEngine storageEngine = mock(StorageEngine.class);
    StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
    StorageStatement storageStatement = mock(StorageStatement.class);
    when(storeReadLayer.newStatement()).thenReturn(storageStatement);
    when(storageEngine.storeReadLayer()).thenReturn(storeReadLayer);
    KernelTransactionImplementation transaction = new KernelTransactionImplementation(mock(StatementOperationContainer.class), mock(SchemaWriteGuard.class), new TransactionHooks(), mock(ConstraintIndexCreator.class), new Procedures(), headerInformationFactory, mock(TransactionRepresentationCommitProcess.class), mock(TransactionMonitor.class), mock(Supplier.class), mock(Pool.class), Clocks.systemClock(), NULL, LockTracer.NONE, PageCursorTracerSupplier.NULL, storageEngine, new CanWrite());
    StatementLocks statementLocks = new SimpleStatementLocks(new NoOpClient());
    transaction.initialize(0, 0, statementLocks, KernelTransaction.Type.implicit, securityContext, 0L);
    return new Instances(transaction, storageEngine, storeReadLayer, storageStatement);
}
Also used : StorageStatement(org.neo4j.storageengine.api.StorageStatement) TransactionHeaderInformation(org.neo4j.kernel.impl.api.TransactionHeaderInformation) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) TransactionHooks(org.neo4j.kernel.impl.api.TransactionHooks) Procedures(org.neo4j.kernel.impl.proc.Procedures) TransactionHeaderInformationFactory(org.neo4j.kernel.impl.transaction.TransactionHeaderInformationFactory) StorageEngine(org.neo4j.storageengine.api.StorageEngine) StatementOperationContainer(org.neo4j.kernel.impl.api.StatementOperationContainer) CanWrite(org.neo4j.kernel.impl.factory.CanWrite) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) SchemaWriteGuard(org.neo4j.kernel.impl.api.SchemaWriteGuard) NoOpClient(org.neo4j.kernel.impl.locking.NoOpClient) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) TransactionRepresentationCommitProcess(org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) StatementLocks(org.neo4j.kernel.impl.locking.StatementLocks) PageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracerSupplier) Supplier(java.util.function.Supplier) Pool(org.neo4j.collection.pool.Pool) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) TransactionMonitor(org.neo4j.kernel.impl.transaction.TransactionMonitor)

Example 10 with StorageStatement

use of org.neo4j.storageengine.api.StorageStatement in project neo4j by neo4j.

the class KernelTransactionsTest method newKernelTransactions.

private static KernelTransactions newKernelTransactions(boolean testKernelTransactions, TransactionCommitProcess commitProcess, StorageStatement firstStoreStatements, StorageStatement... otherStorageStatements) throws Throwable {
    Locks locks = mock(Locks.class);
    when(locks.newClient()).thenReturn(mock(Locks.Client.class));
    StoreReadLayer readLayer = mock(StoreReadLayer.class);
    when(readLayer.newStatement()).thenReturn(firstStoreStatements, otherStorageStatements);
    StorageEngine storageEngine = mock(StorageEngine.class);
    when(storageEngine.storeReadLayer()).thenReturn(readLayer);
    doAnswer(invocation -> {
        invocation.getArgumentAt(0, Collection.class).add(mock(StorageCommand.class));
        return null;
    }).when(storageEngine).createCommands(anyCollection(), any(ReadableTransactionState.class), any(StorageStatement.class), any(ResourceLocker.class), anyLong());
    return newKernelTransactions(locks, storageEngine, commitProcess, testKernelTransactions);
}
Also used : StorageStatement(org.neo4j.storageengine.api.StorageStatement) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ResourceLocker(org.neo4j.storageengine.api.lock.ResourceLocker) Collection(java.util.Collection) Matchers.anyCollection(org.mockito.Matchers.anyCollection) ReadableTransactionState(org.neo4j.storageengine.api.txstate.ReadableTransactionState) Locks(org.neo4j.kernel.impl.locking.Locks) StorageEngine(org.neo4j.storageengine.api.StorageEngine)

Aggregations

StorageStatement (org.neo4j.storageengine.api.StorageStatement)15 Test (org.junit.Test)7 Procedures (org.neo4j.kernel.impl.proc.Procedures)3 NodeItem (org.neo4j.storageengine.api.NodeItem)3 StorageEngine (org.neo4j.storageengine.api.StorageEngine)3 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)3 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)3 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)2 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)2 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)2 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)2 CanWrite (org.neo4j.kernel.impl.factory.CanWrite)2 Locks (org.neo4j.kernel.impl.locking.Locks)2 SimpleStatementLocks (org.neo4j.kernel.impl.locking.SimpleStatementLocks)2 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Supplier (java.util.function.Supplier)1 Matchers.anyCollection (org.mockito.Matchers.anyCollection)1 Pool (org.neo4j.collection.pool.Pool)1