use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class BatchInsertTest method shouldCreateDeferredUniquenessConstraintInEmptyDatabase.
@Test
public void shouldCreateDeferredUniquenessConstraintInEmptyDatabase() throws Exception {
// GIVEN
BatchInserter inserter = newBatchInserter();
// WHEN
ConstraintDefinition definition = inserter.createDeferredConstraint(label("Hacker")).assertPropertyIsUnique("handle").create();
// THEN
assertEquals("Hacker", definition.getLabel().name());
assertEquals(ConstraintType.UNIQUENESS, definition.getConstraintType());
assertEquals(asSet("handle"), Iterables.asSet(definition.getPropertyKeys()));
inserter.shutdown();
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class DatabaseActionsTest method shouldCreatePropertyUniquenessConstraint.
@Test
public void shouldCreatePropertyUniquenessConstraint() throws Exception {
// GIVEN
String labelName = "person", propertyKey = "name";
// WHEN
actions.createPropertyUniquenessConstraint(labelName, asList(propertyKey));
// THEN
try (Transaction tx = graph.beginTx()) {
Iterable<ConstraintDefinition> defs = graphdbHelper.getPropertyUniquenessConstraints(labelName, propertyKey);
assertEquals(asSet(propertyKey), Iterables.asSet(single(defs).getPropertyKeys()));
tx.success();
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class DatabaseActionsTest method shouldDropPropertyUniquenessConstraint.
@Test
public void shouldDropPropertyUniquenessConstraint() throws Exception {
// GIVEN
String labelName = "user", propertyKey = "login";
ConstraintDefinition index = graphdbHelper.createPropertyUniquenessConstraint(labelName, asList(propertyKey));
// WHEN
actions.dropPropertyUniquenessConstraint(labelName, asList(propertyKey));
// THEN
assertFalse("Constraint should have been dropped", Iterables.asSet(graphdbHelper.getPropertyUniquenessConstraints(labelName, propertyKey)).contains(index));
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class DatabaseActionsTest method dropNonExistentConstraint.
@Test
public void dropNonExistentConstraint() throws Exception {
// GIVEN
String labelName = "user", propertyKey = "login";
ConstraintDefinition constraint = graphdbHelper.createPropertyUniquenessConstraint(labelName, asList(propertyKey));
// EXPECT
expectedException.expect(ConstraintViolationException.class);
// WHEN
try (Transaction tx = graph.beginTx()) {
constraint.drop();
constraint.drop();
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class CypherResultSubGraph method from.
public static SubGraph from(Result result, GraphDatabaseService gds, boolean addBetween) {
final CypherResultSubGraph graph = new CypherResultSubGraph();
final List<String> columns = result.columns();
for (Map<String, Object> row : loop(result)) {
for (String column : columns) {
final Object value = row.get(column);
graph.addToGraph(value);
}
}
for (IndexDefinition def : gds.schema().getIndexes()) {
if (graph.getLabels().contains(def.getLabel())) {
graph.addIndex(def);
}
}
for (ConstraintDefinition def : gds.schema().getConstraints()) {
if (graph.getLabels().contains(def.getLabel())) {
graph.addConstraint(def);
}
}
if (addBetween) {
graph.addRelationshipsBetweenNodes();
}
return graph;
}
Aggregations