use of org.neo4j.internal.schema.ConstraintType in project neo4j by neo4j.
the class ConstraintsProcedureUtil method prettyPrint.
static String prettyPrint(ConstraintDescriptor constraintDescriptor, TokenNameLookup tokenNameLookup) {
SchemaDescriptor schema = constraintDescriptor.schema();
int[] entityTokenIds = schema.getEntityTokenIds();
if (entityTokenIds.length != 1) {
throw new IllegalArgumentException("Cannot pretty-print multi-token constraints: " + constraintDescriptor.userDescription(tokenNameLookup));
}
String entityTypeName = schema.entityType() == EntityType.NODE ? tokenNameLookup.labelGetName(entityTokenIds[0]) : tokenNameLookup.relationshipTypeGetName(entityTokenIds[0]);
entityTypeName = escapeLabelOrRelTyp(entityTypeName);
String entityName = entityTypeName.toLowerCase();
String properties = formatProperties(schema.getPropertyIds(), tokenNameLookup, entityName);
ConstraintType type = constraintDescriptor.type();
switch(type) {
case EXISTS:
switch(schema.entityType()) {
case NODE:
return "CONSTRAINT ON ( " + entityName + ":" + entityTypeName + " ) ASSERT " + properties + " IS NOT NULL";
case RELATIONSHIP:
return "CONSTRAINT ON ()-[ " + entityName + ":" + entityTypeName + " ]-() ASSERT " + properties + " IS NOT NULL";
default:
throw new IllegalStateException("Unknown schema entity type: " + schema.entityType() + ".");
}
case UNIQUE:
return "CONSTRAINT ON ( " + entityName + ":" + entityTypeName + " ) ASSERT " + properties + " IS UNIQUE";
case UNIQUE_EXISTS:
return "CONSTRAINT ON ( " + entityName + ":" + entityTypeName + " ) ASSERT " + properties + " IS NODE KEY";
default:
throw new IllegalStateException("Unknown constraint type: " + type + ".");
}
}
use of org.neo4j.internal.schema.ConstraintType in project neo4j by neo4j.
the class SchemaStore method schemaConstraintToMap.
private static void schemaConstraintToMap(ConstraintDescriptor rule, Map<String, Value> map) {
// Rule
putStringProperty(map, PROP_SCHEMA_RULE_TYPE, "CONSTRAINT");
ConstraintType type = rule.type();
switch(type) {
case UNIQUE:
putStringProperty(map, PROP_CONSTRAINT_RULE_TYPE, "UNIQUE");
if (rule.asIndexBackedConstraint().hasOwnedIndexId()) {
putLongProperty(map, PROP_OWNED_INDEX, rule.asIndexBackedConstraint().ownedIndexId());
}
break;
case EXISTS:
putStringProperty(map, PROP_CONSTRAINT_RULE_TYPE, "EXISTS");
break;
case UNIQUE_EXISTS:
putStringProperty(map, PROP_CONSTRAINT_RULE_TYPE, "UNIQUE_EXISTS");
if (rule.asIndexBackedConstraint().hasOwnedIndexId()) {
putLongProperty(map, PROP_OWNED_INDEX, rule.asIndexBackedConstraint().ownedIndexId());
}
break;
default:
throw new UnsupportedOperationException("Unrecognized constraint type: " + type);
}
}
use of org.neo4j.internal.schema.ConstraintType in project neo4j by neo4j.
the class Operations method constraintDrop.
@Override
public void constraintDrop(SchemaDescriptor schema, ConstraintType type) throws SchemaKernelException {
ktx.assertOpen();
Iterator<ConstraintDescriptor> constraints = ktx.schemaRead().constraintsGetForSchema(schema);
constraints = Iterators.filter(constraint -> constraint.type() == type, constraints);
if (constraints.hasNext()) {
ConstraintDescriptor constraint = constraints.next();
if (!constraints.hasNext()) {
constraintDrop(constraint);
} else {
String schemaDescription = schema.userDescription(token);
String constraintDescription = constraints.next().userDescription(token);
throw new DropConstraintFailureException(constraint, new IllegalArgumentException("More than one " + type + " constraint was found with the '" + schemaDescription + "' schema: " + constraintDescription + ", please drop constraint by name instead."));
}
} else {
throw new DropConstraintFailureException(schema, new NoSuchConstraintException(schema, token));
}
}
Aggregations