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));
}
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));
}
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);
}
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);
}
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);
}
Aggregations