use of org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor in project neo4j by neo4j.
the class Operations method uniquePropertyConstraintCreate.
@Override
public ConstraintDescriptor uniquePropertyConstraintCreate(IndexPrototype prototype) throws KernelException {
SchemaDescriptor schema = prototype.schema();
exclusiveSchemaLock(schema);
ktx.assertOpen();
prototype = ensureIndexPrototypeHasIndexProvider(prototype);
UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(schema);
try {
assertValidDescriptor(schema, SchemaKernelException.OperationContext.CONSTRAINT_CREATION);
if (prototype.getName().isEmpty()) {
constraint = ensureConstraintHasName(constraint);
prototype = prototype.withName(constraint.getName());
} else {
constraint = constraint.withName(prototype.getName().get());
}
exclusiveSchemaNameLock(constraint.getName());
assertNoBlockingSchemaRulesExists(constraint);
} catch (KernelException e) {
// Try not to hold on to exclusive schema locks when we don't strictly need them.
exclusiveSchemaUnlock(schema);
throw e;
}
// Create constraints
constraint = indexBackedConstraintCreate(constraint, prototype);
return constraint;
}
use of org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor in project neo4j by neo4j.
the class TxStateTest method shouldAddUniquenessConstraint.
@Test
void shouldAddUniquenessConstraint() {
// when
LabelSchemaDescriptor schema = forLabel(1, 17);
UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(schema);
state.constraintDoAdd(constraint, IndexPrototype.uniqueForSchema(schema).withName("constraint_7").materialise(7));
// then
DiffSets<ConstraintDescriptor> diff = state.constraintsChangesForLabel(1);
assertEquals(singleton(constraint), diff.getAdded());
assertTrue(diff.getRemoved().isEmpty());
}
use of org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor in project neo4j by neo4j.
the class TxStateTest method addingUniquenessConstraintShouldBeIdempotent.
@Test
void addingUniquenessConstraintShouldBeIdempotent() {
// given
LabelSchemaDescriptor schema = forLabel(1, 17);
UniquenessConstraintDescriptor constraint1 = ConstraintDescriptorFactory.uniqueForSchema(schema);
state.constraintDoAdd(constraint1, IndexPrototype.uniqueForSchema(schema).withName("constraint_7").materialise(7));
// when
UniquenessConstraintDescriptor constraint2 = ConstraintDescriptorFactory.uniqueForSchema(schema);
state.constraintDoAdd(constraint2, IndexPrototype.uniqueForSchema(schema).withName("constraint_19").materialise(19));
// then
assertEquals(constraint1, constraint2);
assertEquals(singleton(constraint1), state.constraintsChangesForLabel(1).getAdded());
}
use of org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor in project neo4j by neo4j.
the class TxStateTest method dataRevisionMustNotChangeOnSchemaChanges.
@Test
void dataRevisionMustNotChangeOnSchemaChanges() {
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
state.indexDoAdd(indexOn_1_1);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
state.indexDoDrop(indexOn_1_1);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
state.indexDoUnRemove(indexOn_1_1);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
UniquenessConstraintDescriptor constraint1 = ConstraintDescriptorFactory.uniqueForLabel(1, 17);
state.constraintDoAdd(constraint1);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
state.constraintDoDrop(constraint1);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
state.constraintDoUnRemove(constraint1);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
IndexBackedConstraintDescriptor constraint2 = ConstraintDescriptorFactory.nodeKeyForLabel(0, 0);
state.constraintDoAdd(constraint2, IndexPrototype.uniqueForSchema(forLabel(0, 0)).withName("index").materialise(0));
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
state.labelDoCreateForName("Label", false, 0);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
state.relationshipTypeDoCreateForName("REL", false, 0);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
state.propertyKeyDoCreateForName("prop", false, 0);
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
// This is not strictly a schema-change, but it is a "non-data" change in that these will not transform into store updates.
// Or schema updates for that matter. We only do these to speed up the transaction state filtering of schema index query results.
state.indexDoUpdateEntry(indexOn_1_1.schema(), 0, ValueTuple.of(Values.booleanValue(true)), ValueTuple.of(Values.booleanValue(false)));
assertThat(state.getDataRevision()).isEqualTo(0L);
assertFalse(state.hasDataChanges());
}
use of org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor in project neo4j by neo4j.
the class BuiltInProceduresTest method givenUniqueConstraint.
private void givenUniqueConstraint(String label, String propKey) {
int labelId = token(label, labels);
int propId = token(propKey, propKeys);
LabelSchemaDescriptor schema = forLabel(labelId, propId);
int id = uniqueIndexes.size() + 1000;
final String name = "constraint_" + id;
IndexDescriptor index = IndexPrototype.uniqueForSchema(schema, EMPTY.getProviderDescriptor()).withName(name).materialise(id);
uniqueIndexes.add(index);
final UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel(labelId, propId).withName(name);
constraints.add(constraint);
}
Aggregations