use of org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor in project neo4j by neo4j.
the class TransactionToRecordStateVisitor method visitAddedNodeKeyConstraint.
private void visitAddedNodeKeyConstraint(NodeKeyConstraintDescriptor uniqueConstraint, long constraintId) throws KernelException {
IndexDescriptor indexRule = (IndexDescriptor) schemaStorage.loadSingleSchemaRule(uniqueConstraint.ownedIndexId(), cursorContext);
ConstraintDescriptor constraint = constraintSemantics.createNodeKeyConstraintRule(constraintId, uniqueConstraint, indexRule.getId());
schemaStateChanger.createSchemaRule(recordState, constraint);
schemaStateChanger.setConstraintIndexOwner(recordState, indexRule, constraintId);
}
use of org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor in project neo4j by neo4j.
the class SchemaRuleSerialization35Test method assertParseNodeKeyConstraintRule.
private static void assertParseNodeKeyConstraintRule(String serialized, String name) throws MalformedSchemaRuleException {
// GIVEN
long ruleId = 1;
int propertyKey = 3;
int labelId = 55;
long ownedIndexId = 2;
NodeKeyConstraintDescriptor constraint = nodeKeyForLabel(labelId, propertyKey);
byte[] bytes = decodeBase64(serialized);
// WHEN
ConstraintDescriptor deserialized = assertConstraintRule(SchemaRuleSerialization35.deserialize(ruleId, ByteBuffer.wrap(bytes)));
// THEN
assertThat(deserialized.getId()).isEqualTo(ruleId);
assertThat(deserialized).isEqualTo(constraint);
assertThat(deserialized.schema()).isEqualTo(constraint.schema());
assertThat(deserialized.asIndexBackedConstraint().ownedIndexId()).isEqualTo(ownedIndexId);
assertThat(deserialized.getName()).isEqualTo(name);
}
use of org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor in project neo4j by neo4j.
the class Operations method nodeKeyConstraintCreate.
@Override
public ConstraintDescriptor nodeKeyConstraintCreate(IndexPrototype prototype) throws KernelException {
SchemaDescriptor schema = prototype.schema();
exclusiveSchemaLock(schema);
ktx.assertOpen();
prototype = ensureIndexPrototypeHasIndexProvider(prototype);
NodeKeyConstraintDescriptor constraint = ConstraintDescriptorFactory.nodeKeyForSchema(schema);
try {
// Check data integrity
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 (SchemaKernelException e) {
exclusiveSchemaUnlock(schema);
throw e;
}
// enforce constraints
enforceNodeKeyConstraint(schema);
// create constraint
indexBackedConstraintCreate(constraint, prototype);
return constraint;
}
use of org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor in project neo4j by neo4j.
the class BuiltInProceduresTest method givenNodeKeys.
private void givenNodeKeys(String label, String... props) {
int labelId = token(label, labels);
int[] propIds = new int[props.length];
for (int i = 0; i < propIds.length; i++) {
propIds[i] = token(props[i], propKeys);
}
final NodeKeyConstraintDescriptor constraint = ConstraintDescriptorFactory.nodeKeyForLabel(labelId, propIds).withName("MyNodeKeyConstraint");
constraints.add(constraint);
}
Aggregations