use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method shouldListAddedConstraints.
@Test
void shouldListAddedConstraints() {
// GIVEN
ConstraintDefinition constraint1 = createUniquenessConstraint(label, propertyKey);
ConstraintDefinition constraint2 = createUniquenessConstraint(otherLabel, propertyKey);
// WHEN THEN
try (Transaction tx = db.beginTx()) {
assertThat(tx.schema().getConstraints()).containsOnly(constraint1, constraint2);
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method cannotCreateIndexWithSameNameAsExistingConstraintWithGeneratedName.
@Test
void cannotCreateIndexWithSameNameAsExistingConstraintWithGeneratedName() {
ConstraintDefinition constraint = createUniquenessConstraint(label, propertyKey);
ConstraintViolationException exception = assertThrows(ConstraintViolationException.class, () -> createIndex(db, constraint.getName(), label, secondPropertyKey));
assertThat(exception).hasMessageContaining(constraint.getName());
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method uniquenessConstraintIndexesAreBtreeIndexTypeByDefault.
@Test
void uniquenessConstraintIndexesAreBtreeIndexTypeByDefault() {
String name;
try (Transaction tx = db.beginTx()) {
ConstraintDefinition constraint = tx.schema().constraintFor(label).assertPropertyIsUnique(propertyKey).create();
name = constraint.getName();
IndexDefinition index = getIndex(tx, name);
assertThat(index.getIndexType()).isEqualTo(BTREE);
tx.commit();
}
try (Transaction tx = db.beginTx()) {
IndexDefinition index = getIndex(tx, name);
assertThat(index.getIndexType()).isEqualTo(BTREE);
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaImpl method asConstraintDefinitions.
private Iterable<ConstraintDefinition> asConstraintDefinitions(Iterator<? extends ConstraintDescriptor> constraints, TokenRead tokenRead) {
// Intentionally create an eager list so that used statement can be closed
List<ConstraintDefinition> definitions = new ArrayList<>();
while (constraints.hasNext()) {
ConstraintDescriptor constraint = constraints.next();
definitions.add(asConstraintDefinition(constraint, tokenRead));
}
return definitions;
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaImpl method asConstraintDefinitions.
private Iterable<ConstraintDefinition> asConstraintDefinitions(Iterator<? extends ConstraintDescriptor> constraints, ReadOperations readOperations) {
// Intentionally create an eager list so that used statement can be closed
List<ConstraintDefinition> definitions = new ArrayList<>();
while (constraints.hasNext()) {
ConstraintDescriptor constraint = constraints.next();
definitions.add(asConstraintDefinition(ConstraintBoundary.map(constraint), readOperations));
}
return definitions;
}
Aggregations