use of org.neo4j.kernel.impl.api.StatementOperationParts 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.StatementOperationParts in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldCreateIndexInAnotherTransaction.
@Test
public void shouldCreateIndexInAnotherTransaction() throws Exception {
// given
StatementOperationParts constraintCreationContext = mockedParts();
StatementOperationParts indexCreationContext = mockedParts();
KernelStatement state = mockedState();
IndexingService indexingService = mock(IndexingService.class);
StubKernel kernel = new StubKernel();
when(constraintCreationContext.schemaReadOperations().indexGetCommittedId(state, index)).thenReturn(2468L);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(2468L)).thenReturn(indexProxy);
PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, false);
// when
long indexId = creator.createUniquenessConstraintIndex(state, constraintCreationContext.schemaReadOperations(), descriptor);
// then
assertEquals(2468L, indexId);
assertEquals(1, kernel.statements.size());
verify(kernel.statements.get(0).txState()).indexRuleDoAdd(eq(index));
verifyNoMoreInteractions(indexCreationContext.schemaWriteOperations());
verify(constraintCreationContext.schemaReadOperations()).indexGetCommittedId(state, index);
verifyNoMoreInteractions(constraintCreationContext.schemaReadOperations());
verify(indexProxy).awaitStoreScanCompleted();
}
use of org.neo4j.kernel.impl.api.StatementOperationParts in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldDropIndexIfPopulationFails.
@Test
public void shouldDropIndexIfPopulationFails() throws Exception {
// given
StatementOperationParts constraintCreationContext = mockedParts();
KernelStatement state = mockedState();
IndexingService indexingService = mock(IndexingService.class);
StubKernel kernel = new StubKernel();
when(constraintCreationContext.schemaReadOperations().indexGetCommittedId(state, index)).thenReturn(2468L);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(2468L)).thenReturn(indexProxy);
IndexEntryConflictException cause = new IndexEntryConflictException(2, 1, "a");
doThrow(new IndexPopulationFailedKernelException(SchemaBoundary.map(descriptor), "some index", cause)).when(indexProxy).awaitStoreScanCompleted();
PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, false);
// when
try {
creator.createUniquenessConstraintIndex(state, constraintCreationContext.schemaReadOperations(), descriptor);
fail("expected exception");
}// then
catch (UniquePropertyValueValidationException e) {
assertEquals("Existing data does not satisfy CONSTRAINT ON ( label[123]:label[123] ) ASSERT label[123].property[456] IS UNIQUE.", e.getMessage());
}
assertEquals(2, kernel.statements.size());
TransactionState tx1 = kernel.statements.get(0).txState();
NewIndexDescriptor newIndex = NewIndexDescriptorFactory.uniqueForLabel(123, 456);
verify(tx1).indexRuleDoAdd(newIndex);
verifyNoMoreInteractions(tx1);
verify(constraintCreationContext.schemaReadOperations()).indexGetCommittedId(state, index);
verifyNoMoreInteractions(constraintCreationContext.schemaReadOperations());
TransactionState tx2 = kernel.statements.get(1).txState();
verify(tx2).indexDoDrop(newIndex);
verifyNoMoreInteractions(tx2);
}
use of org.neo4j.kernel.impl.api.StatementOperationParts in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldReleaseSchemaLockWhileAwaitingIndexPopulation.
@Test
public void shouldReleaseSchemaLockWhileAwaitingIndexPopulation() throws Exception {
// given
StubKernel kernel = new StubKernel();
IndexingService indexingService = mock(IndexingService.class);
StatementOperationParts constraintCreationContext = mockedParts();
PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
KernelStatement state = mockedState();
when(constraintCreationContext.schemaReadOperations().indexGetCommittedId(state, index)).thenReturn(2468L);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(anyLong())).thenReturn(indexProxy);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, true);
// when
creator.createUniquenessConstraintIndex(state, constraintCreationContext.schemaReadOperations(), index.schema());
// then
verify(state.locks().pessimistic()).releaseExclusive(ResourceTypes.SCHEMA, ResourceTypes.schemaResource());
verify(state.locks().pessimistic()).acquireExclusive(state.lockTracer(), ResourceTypes.SCHEMA, ResourceTypes.schemaResource());
}
use of org.neo4j.kernel.impl.api.StatementOperationParts in project neo4j by neo4j.
the class GuardIT method notIncludeGuardingOperationLayerOnNonGuardingParts.
@Test
public void notIncludeGuardingOperationLayerOnNonGuardingParts() throws Exception {
GraphDatabaseAPI database = startDataBase();
DependencyResolver dependencyResolver = database.getDependencyResolver();
StatementOperationContainer operationParts = dependencyResolver.resolveDependency(StatementOperationContainer.class);
StatementOperationParts guardedParts = operationParts.nonGuarderParts();
assertThat(guardedParts.entityReadOperations(), not(instanceOf(GuardingStatementOperations.class)));
assertThat(guardedParts.entityWriteOperations(), not(instanceOf(GuardingStatementOperations.class)));
}
Aggregations