use of org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor in project neo4j by neo4j.
the class TxStateTest method shouldAddUniquenessConstraint.
@Test
public void shouldAddUniquenessConstraint() throws Exception {
// when
UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel(1, 17);
state.constraintDoAdd(constraint, 7);
// then
ReadableDiffSets<ConstraintDescriptor> diff = state.constraintsChangesForLabel(1);
assertEquals(singleton(constraint), diff.getAdded());
assertTrue(diff.getRemoved().isEmpty());
}
use of org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor in project neo4j by neo4j.
the class TxStateTest method addingUniquenessConstraintShouldBeIdempotent.
@Test
public void addingUniquenessConstraintShouldBeIdempotent() throws Exception {
// given
UniquenessConstraintDescriptor constraint1 = ConstraintDescriptorFactory.uniqueForLabel(1, 17);
state.constraintDoAdd(constraint1, 7);
// when
UniquenessConstraintDescriptor constraint2 = ConstraintDescriptorFactory.uniqueForLabel(1, 17);
state.constraintDoAdd(constraint2, 19);
// then
assertEquals(constraint1, constraint2);
assertEquals(singleton(constraint1), state.constraintsChangesForLabel(1).getAdded());
}
use of org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor in project neo4j by neo4j.
the class IntegrityValidatorTest method shouldValidateUniquenessIndexes.
@Test
public void shouldValidateUniquenessIndexes() throws Exception {
// Given
NeoStores store = mock(NeoStores.class);
IndexingService indexes = mock(IndexingService.class);
IntegrityValidator validator = new IntegrityValidator(store, indexes);
UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel(1, 1);
doThrow(new UniquePropertyValueValidationException(constraint, ConstraintValidationException.Phase.VERIFICATION, new RuntimeException())).when(indexes).validateIndex(2L);
ConstraintRule record = ConstraintRule.constraintRule(1L, constraint, 2L);
// When
try {
validator.validateSchemaRule(record);
fail("Should have thrown integrity error.");
} catch (Exception e) {
// good
}
}
use of org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor in project neo4j by neo4j.
the class DataIntegrityValidatingStatementOperations method uniquePropertyConstraintCreate.
@Override
public UniquenessConstraintDescriptor uniquePropertyConstraintCreate(KernelStatement state, LabelSchemaDescriptor descriptor) throws AlreadyConstrainedException, CreateConstraintFailureException, AlreadyIndexedException, RepeatedPropertyInCompositeSchemaException {
assertValidDescriptor(descriptor, OperationContext.CONSTRAINT_CREATION);
ConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(descriptor);
assertConstraintDoesNotExist(state, constraint);
// It is not allowed to create uniqueness constraints on indexed label/property pairs
assertIndexDoesNotExist(state, OperationContext.CONSTRAINT_CREATION, SchemaBoundary.map(descriptor));
return schemaWriteDelegate.uniquePropertyConstraintCreate(state, descriptor);
}
use of org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor in project neo4j by neo4j.
the class ConstraintEnforcingEntityOperations method nodeAddLabel.
@Override
public boolean nodeAddLabel(KernelStatement state, long nodeId, int labelId) throws EntityNotFoundException, ConstraintValidationException {
try (Cursor<NodeItem> cursor = nodeCursorById(state, nodeId)) {
NodeItem node = cursor.get();
Iterator<ConstraintDescriptor> constraints = schemaReadOperations.constraintsGetForLabel(state, labelId);
while (constraints.hasNext()) {
ConstraintDescriptor constraint = constraints.next();
if (constraint.type() == UNIQUE) {
UniquenessConstraintDescriptor uniqueConstraint = (UniquenessConstraintDescriptor) constraint;
ExactPredicate[] propertyValues = getAllPropertyValues(state, uniqueConstraint.schema(), node);
if (propertyValues != null) {
validateNoExistingNodeWithExactValues(state, uniqueConstraint, propertyValues, node.id());
}
}
}
}
return entityWriteOperations.nodeAddLabel(state, nodeId, labelId);
}
Aggregations