use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class UniquenessConstraintValidationIT method createConstraint.
private ConstraintDescriptor createConstraint(String label, String propertyKey) throws KernelException {
int labelId;
int propertyKeyId;
TokenWrite tokenWrite = tokenWriteInNewTransaction();
labelId = tokenWrite.labelGetOrCreateForName(label);
propertyKeyId = tokenWrite.propertyKeyGetOrCreateForName(propertyKey);
commit();
SchemaWrite schemaWrite = schemaWriteInNewTransaction();
ConstraintDescriptor constraint = schemaWrite.uniquePropertyConstraintCreate(uniqueForSchema(forLabel(labelId, propertyKeyId)));
commit();
return constraint;
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class NodeGetUniqueFromIndexSeekIT method createUniquenessConstraint.
private IndexDescriptor createUniquenessConstraint(int labelId, int... propertyIds) throws Exception {
KernelTransaction transaction = newTransaction(LoginContext.AUTH_DISABLED);
LabelSchemaDescriptor schema = SchemaDescriptor.forLabel(labelId, propertyIds);
ConstraintDescriptor constraint = transaction.schemaWrite().uniquePropertyConstraintCreate(IndexPrototype.uniqueForSchema(schema));
IndexDescriptor index = transaction.schemaRead().indexGetForName(constraint.getName());
commit();
return index;
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaRuleSerialization35Test method assertParseUniqueConstraintRule.
private static void assertParseUniqueConstraintRule(String serialized, String name) throws MalformedSchemaRuleException {
// GIVEN
long ruleId = 1;
int propertyKey = 3;
int labelId = 55;
long ownedIndexId = 2;
UniquenessConstraintDescriptor constraint = uniqueForLabel(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.ConstraintDescriptor 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.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaRuleException method describe.
public static String describe(SchemaDescriptorSupplier schemaThing) {
SchemaDescriptor schema = schemaThing.schema();
String tagType;
switch(schema.entityType()) {
case NODE:
tagType = "label";
break;
case RELATIONSHIP:
tagType = "relationship type";
break;
default:
throw new AssertionError("Unknown entity type: " + schema.entityType());
}
if (schemaThing instanceof ConstraintDescriptor) {
ConstraintDescriptor constraint = (ConstraintDescriptor) schemaThing;
switch(constraint.type()) {
case UNIQUE:
return tagType + " uniqueness constraint";
case EXISTS:
return tagType + " property existence constraint";
case UNIQUE_EXISTS:
return schema.entityType().name().toLowerCase() + " key constraint";
default:
throw new AssertionError("Unknown constraint type: " + constraint.type());
}
} else {
IndexDescriptor index = (IndexDescriptor) schemaThing;
IndexType indexType = index.getIndexType();
if (indexType != IndexType.BTREE) {
String indexTypeName = indexType.name().toLowerCase();
return indexTypeName + " " + tagType + " index";
} else {
return tagType + " index";
}
}
}
Aggregations