use of org.neo4j.internal.schema.constraints.NodeExistenceConstraintDescriptor in project neo4j by neo4j.
the class BuiltInProceduresTest method givenNodePropExistenceConstraint.
private void givenNodePropExistenceConstraint(String label, String propKey) {
int labelId = token(label, labels);
int propId = token(propKey, propKeys);
final NodeExistenceConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForLabel(labelId, propId).withName("MyExistenceConstraint");
constraints.add(constraint);
}
use of org.neo4j.internal.schema.constraints.NodeExistenceConstraintDescriptor in project neo4j by neo4j.
the class RecordStorageReaderTestBase method createNodePropertyExistenceConstraint.
protected void createNodePropertyExistenceConstraint(Label label, String propertyKey) throws Exception {
TxState txState = new TxState();
NodeExistenceConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForLabel(getOrCreateLabelId(label), getOrCreatePropertyKeyId(propertyKey));
long id = commitContext.reserveSchema();
txState.constraintDoAdd(constraint.withId(id).withName("constraint_" + id));
apply(txState);
}
use of org.neo4j.internal.schema.constraints.NodeExistenceConstraintDescriptor in project neo4j by neo4j.
the class GraphDbStructureGuide method showUniqueConstraints.
private static void showUniqueConstraints(DbStructureVisitor visitor, KernelTransaction ktx, TokenNameLookup nameLookup) {
Iterator<ConstraintDescriptor> constraints = ktx.schemaRead().constraintsGetAll();
while (constraints.hasNext()) {
ConstraintDescriptor constraint = constraints.next();
String userDescription = constraint.userDescription(nameLookup);
if (constraint.isUniquenessConstraint()) {
visitor.visitUniqueConstraint(constraint.asUniquenessConstraint(), userDescription);
} else if (constraint.isNodePropertyExistenceConstraint()) {
NodeExistenceConstraintDescriptor existenceConstraint = constraint.asNodePropertyExistenceConstraint();
visitor.visitNodePropertyExistenceConstraint(existenceConstraint, userDescription);
} else if (constraint.isRelationshipPropertyExistenceConstraint()) {
RelExistenceConstraintDescriptor existenceConstraint = constraint.asRelationshipPropertyExistenceConstraint();
visitor.visitRelationshipPropertyExistenceConstraint(existenceConstraint, userDescription);
} else if (constraint.isNodeKeyConstraint()) {
NodeKeyConstraintDescriptor nodeKeyConstraint = constraint.asNodeKeyConstraint();
visitor.visitNodeKeyConstraint(nodeKeyConstraint, userDescription);
} else {
throw new IllegalArgumentException("Unknown constraint type: " + constraint.getClass() + ", " + "constraint: " + constraint);
}
}
}
use of org.neo4j.internal.schema.constraints.NodeExistenceConstraintDescriptor in project neo4j by neo4j.
the class PlainOperationsTest method shouldReleaseAcquiredSchemaWriteLockIfNodePropertyExistenceConstraintCreationFails.
@Test
void shouldReleaseAcquiredSchemaWriteLockIfNodePropertyExistenceConstraintCreationFails() throws Exception {
// given
NodeExistenceConstraintDescriptor constraint = existsForSchema(schema);
storageReaderWithConstraints(constraint);
int labelId = schema.getLabelId();
int propertyId = schema.getPropertyId();
when(tokenHolders.labelTokens().getTokenById(labelId)).thenReturn(new NamedToken("Label", labelId));
when(tokenHolders.propertyKeyTokens().getTokenById(propertyId)).thenReturn(new NamedToken("prop", labelId));
// when
try {
operations.nodePropertyExistenceConstraintCreate(schema, "constraint name");
fail("Expected an exception because this schema should already be constrained.");
} catch (AlreadyConstrainedException ignore) {
// Good.
}
// then
order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.LABEL, labelId);
order.verify(storageReader).constraintsGetForSchema(schema);
order.verify(locks).releaseExclusive(ResourceTypes.LABEL, labelId);
}
use of org.neo4j.internal.schema.constraints.NodeExistenceConstraintDescriptor in project neo4j by neo4j.
the class SchemaCheckerTest method shouldPopulateMandatoryPropertiesMap.
@Test
void shouldPopulateMandatoryPropertiesMap() throws Exception {
// given
try (AutoCloseable ignored = tx()) {
var cursorContext = CursorContext.NULL;
NodeExistenceConstraintDescriptor constraint1 = ConstraintDescriptorFactory.existsForLabel(label1, propertyKey1).withId(schemaStore.nextId(cursorContext)).withName(NAME);
NodeExistenceConstraintDescriptor constraint2 = ConstraintDescriptorFactory.existsForLabel(label2, propertyKey1, propertyKey2).withId(schemaStore.nextId(cursorContext)).withName(NAME2);
RelExistenceConstraintDescriptor constraint3 = ConstraintDescriptorFactory.existsForRelType(relationshipType1, propertyKey2).withId(schemaStore.nextId(cursorContext)).withName(NAME);
RelExistenceConstraintDescriptor constraint4 = ConstraintDescriptorFactory.existsForRelType(relationshipType2, propertyKey1, propertyKey2).withId(schemaStore.nextId(cursorContext)).withName(NAME2);
schemaStorage.writeSchemaRule(constraint1, cursorContext, INSTANCE);
schemaStorage.writeSchemaRule(constraint2, cursorContext, INSTANCE);
schemaStorage.writeSchemaRule(constraint3, cursorContext, INSTANCE);
schemaStorage.writeSchemaRule(constraint4, cursorContext, INSTANCE);
}
// when
check();
// then
assertEquals(IntSets.mutable.of(propertyKey1), mandatoryNodeProperties.remove(label1));
assertEquals(IntSets.mutable.of(propertyKey1, propertyKey2), mandatoryNodeProperties.remove(label2));
assertTrue(mandatoryNodeProperties.isEmpty());
assertEquals(IntSets.mutable.of(propertyKey2), mandatoryRelationshipProperties.remove(relationshipType1));
assertEquals(IntSets.mutable.of(propertyKey1, propertyKey2), mandatoryRelationshipProperties.remove(relationshipType2));
assertTrue(mandatoryRelationshipProperties.isEmpty());
}
Aggregations