use of org.neo4j.graphdb.schema.ConstraintCreator in project neo4j by neo4j.
the class ConstraintsInHAIT method creatingConstraintOnSlaveIsNotAllowed.
@Test
public void creatingConstraintOnSlaveIsNotAllowed() throws Exception {
// given
ClusterManager.ManagedCluster cluster = clusterRule.startCluster();
HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
slave.beginTx();
try {
ConstraintCreator constraintCreator = slave.schema().constraintFor(Label.label("LabelName")).assertPropertyIsUnique("PropertyName");
// when
constraintCreator.create();
fail("should have thrown exception");
} catch (InvalidTransactionTypeException e) {
assertThat(e.getMessage(), equalTo("Modifying the database schema can only be done on the master server, " + "this server is a slave. Please issue schema modification commands directly to the master."));
}
}
use of org.neo4j.graphdb.schema.ConstraintCreator in project neo4j by neo4j.
the class GraphDbHelper method createPropertyUniquenessConstraint.
public ConstraintDefinition createPropertyUniquenessConstraint(String labelName, List<String> propertyKeys) {
try (Transaction tx = database.getGraph().beginTransaction(implicit, AUTH_DISABLED)) {
ConstraintCreator creator = database.getGraph().schema().constraintFor(label(labelName));
for (String propertyKey : propertyKeys) {
creator = creator.assertPropertyIsUnique(propertyKey);
}
ConstraintDefinition result = creator.create();
tx.success();
return result;
}
}
use of org.neo4j.graphdb.schema.ConstraintCreator in project neo4j by neo4j.
the class DatabaseActions method createPropertyUniquenessConstraint.
public ConstraintDefinitionRepresentation createPropertyUniquenessConstraint(String labelName, Iterable<String> propertyKeys) {
ConstraintCreator constraintCreator = graphDb.schema().constraintFor(label(labelName));
for (String key : propertyKeys) {
constraintCreator = constraintCreator.assertPropertyIsUnique(key);
}
ConstraintDefinition constraintDefinition = constraintCreator.create();
return new ConstraintDefinitionRepresentation(constraintDefinition);
}
Aggregations