Search in sources :

Example 1 with StateHandlingStatementOperations

use of org.neo4j.kernel.impl.api.StateHandlingStatementOperations in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexScanWithIndexQuery.

@Test
public void shouldConsiderTransactionStateDuringIndexScanWithIndexQuery() throws Exception {
    // Given
    TransactionState txState = mock(TransactionState.class);
    KernelStatement statement = mock(KernelStatement.class);
    when(statement.hasTxStateWithChanges()).thenReturn(true);
    when(statement.txState()).thenReturn(txState);
    when(txState.indexUpdatesForScan(index)).thenReturn(new DiffSets<>(Collections.singleton(42L), Collections.singleton(44L)));
    when(txState.addedAndRemovedNodes()).thenReturn(new DiffSets<>(Collections.singleton(45L), Collections.singleton(46L)));
    StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
    IndexReader indexReader = addMockedIndexReader(statement);
    IndexQuery query = IndexQuery.exists(index.schema().getPropertyId());
    when(indexReader.query(query)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
    StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
    // When
    PrimitiveLongIterator results = context.indexQuery(statement, index, query);
    // Then
    assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Test(org.junit.Test)

Example 2 with StateHandlingStatementOperations

use of org.neo4j.kernel.impl.api.StateHandlingStatementOperations in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexRangeSeekByPrefix.

@Test
public void shouldConsiderTransactionStateDuringIndexRangeSeekByPrefix() throws Exception {
    // Given
    TransactionState txState = mock(TransactionState.class);
    KernelStatement statement = mock(KernelStatement.class);
    when(statement.hasTxStateWithChanges()).thenReturn(true);
    when(statement.txState()).thenReturn(txState);
    when(txState.indexUpdatesForRangeSeekByPrefix(index, "prefix")).thenReturn(new DiffSets<>(Collections.singleton(42L), Collections.singleton(44L)));
    when(txState.addedAndRemovedNodes()).thenReturn(new DiffSets<>(Collections.singleton(45L), Collections.singleton(46L)));
    StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
    IndexReader indexReader = addMockedIndexReader(statement);
    IndexQuery.StringPrefixPredicate query = IndexQuery.stringPrefix(index.schema().getPropertyId(), "prefix");
    when(indexReader.query(query)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
    StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
    // When
    PrimitiveLongIterator results = context.indexQuery(statement, index, query);
    // Then
    assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Test(org.junit.Test)

Example 3 with StateHandlingStatementOperations

use of org.neo4j.kernel.impl.api.StateHandlingStatementOperations in project neo4j by neo4j.

the class NeoStoreDataSource method buildStatementOperations.

private StatementOperationContainer buildStatementOperations(StoreReadLayer storeReadLayer, AutoIndexing autoIndexing, ConstraintIndexCreator constraintIndexCreator, UpdateableSchemaState updateableSchemaState, Guard guard, LegacyIndexStore legacyIndexStore) {
    // The passed in StoreReadLayer is the bottom most layer: Read-access to committed data.
    // To it we add:
    // + Transaction state handling
    StateHandlingStatementOperations stateHandlingContext = new StateHandlingStatementOperations(storeReadLayer, autoIndexing, constraintIndexCreator, legacyIndexStore);
    QueryRegistrationOperations queryRegistrationOperations = new StackingQueryRegistrationOperations(clock);
    StatementOperationParts parts = new StatementOperationParts(stateHandlingContext, stateHandlingContext, stateHandlingContext, stateHandlingContext, stateHandlingContext, stateHandlingContext, new SchemaStateConcern(updateableSchemaState), null, stateHandlingContext, stateHandlingContext, stateHandlingContext, queryRegistrationOperations);
    // + Constraints
    ConstraintEnforcingEntityOperations constraintEnforcingEntityOperations = new ConstraintEnforcingEntityOperations(constraintSemantics, parts.entityWriteOperations(), parts.entityReadOperations(), parts.schemaWriteOperations(), parts.schemaReadOperations());
    // + Data integrity
    DataIntegrityValidatingStatementOperations dataIntegrityContext = new DataIntegrityValidatingStatementOperations(parts.keyWriteOperations(), parts.schemaReadOperations(), constraintEnforcingEntityOperations);
    parts = parts.override(null, dataIntegrityContext, constraintEnforcingEntityOperations, constraintEnforcingEntityOperations, null, dataIntegrityContext, null, null, null, null, null, null);
    // + Locking
    LockingStatementOperations lockingContext = new LockingStatementOperations(parts.entityReadOperations(), parts.entityWriteOperations(), parts.schemaReadOperations(), parts.schemaWriteOperations(), parts.schemaStateOperations());
    parts = parts.override(null, null, null, lockingContext, lockingContext, lockingContext, lockingContext, lockingContext, null, null, null, null);
    // + Guard
    GuardingStatementOperations guardingOperations = new GuardingStatementOperations(parts.entityWriteOperations(), parts.entityReadOperations(), guard);
    StatementOperationParts guardedParts = parts.override(null, null, guardingOperations, guardingOperations, null, null, null, null, null, null, null, null);
    return new StatementOperationContainer(guardedParts, parts);
}
Also used : StackingQueryRegistrationOperations(org.neo4j.kernel.impl.api.StackingQueryRegistrationOperations) QueryRegistrationOperations(org.neo4j.kernel.impl.api.operations.QueryRegistrationOperations) SchemaStateConcern(org.neo4j.kernel.impl.api.SchemaStateConcern) StatementOperationParts(org.neo4j.kernel.impl.api.StatementOperationParts) LockingStatementOperations(org.neo4j.kernel.impl.api.LockingStatementOperations) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) ConstraintEnforcingEntityOperations(org.neo4j.kernel.impl.api.ConstraintEnforcingEntityOperations) StackingQueryRegistrationOperations(org.neo4j.kernel.impl.api.StackingQueryRegistrationOperations) GuardingStatementOperations(org.neo4j.kernel.impl.api.GuardingStatementOperations) StatementOperationContainer(org.neo4j.kernel.impl.api.StatementOperationContainer) DataIntegrityValidatingStatementOperations(org.neo4j.kernel.impl.api.DataIntegrityValidatingStatementOperations)

Example 4 with StateHandlingStatementOperations

use of org.neo4j.kernel.impl.api.StateHandlingStatementOperations in project neo4j by neo4j.

the class LabelTransactionStateTest method before.

@Before
public void before() throws Exception {
    store = mock(StoreReadLayer.class);
    when(store.indexesGetForLabel(anyInt())).then(answerAsIteratorFrom(Collections.emptyList()));
    when(store.indexesGetAll()).then(answerAsIteratorFrom(Collections.emptyList()));
    txState = new TxState();
    state = StatementOperationsTestHelper.mockedState(txState);
    txContext = new StateHandlingStatementOperations(store, mock(InternalAutoIndexing.class), mock(ConstraintIndexCreator.class), mock(LegacyIndexStore.class));
    storeStatement = mock(StoreStatement.class);
    when(state.getStoreStatement()).thenReturn(storeStatement);
}
Also used : StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) StoreStatement(org.neo4j.kernel.impl.api.store.StoreStatement) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Before(org.junit.Before)

Example 5 with StateHandlingStatementOperations

use of org.neo4j.kernel.impl.api.StateHandlingStatementOperations in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method shouldGetConstraintsByLabelAndProperty.

@Test
public void shouldGetConstraintsByLabelAndProperty() throws Exception {
    // given
    ConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(descriptor);
    TransactionState txState = new TxState();
    KernelStatement state = mockedState(txState);
    when(inner.constraintsGetForSchema(constraint.schema())).thenAnswer(invocation -> Iterators.emptyIterator());
    StateHandlingStatementOperations context = newTxStateOps(inner);
    context.uniquePropertyConstraintCreate(state, descriptor);
    // when
    Set<ConstraintDescriptor> result = Iterables.asSet(asIterable(context.constraintsGetForSchema(state, constraint.schema())));
    // then
    assertEquals(asSet(constraint), result);
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Test(org.junit.Test)

Aggregations

StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)18 Test (org.junit.Test)14 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)14 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)13 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)12 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)10 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)8 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)8 StoreStatement (org.neo4j.kernel.impl.api.store.StoreStatement)5 UniquenessConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor)4 Before (org.junit.Before)3 ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)3 ConstraintEnforcingEntityOperations (org.neo4j.kernel.impl.api.ConstraintEnforcingEntityOperations)2 NodeItem (org.neo4j.storageengine.api.NodeItem)2 Matchers.anyLong (org.mockito.Matchers.anyLong)1 Cursor (org.neo4j.cursor.Cursor)1 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)1 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)1 DataIntegrityValidatingStatementOperations (org.neo4j.kernel.impl.api.DataIntegrityValidatingStatementOperations)1 GuardingStatementOperations (org.neo4j.kernel.impl.api.GuardingStatementOperations)1