Search in sources :

Example 1 with ConstraintCreator

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."));
    }
}
Also used : HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ConstraintCreator(org.neo4j.graphdb.schema.ConstraintCreator) InvalidTransactionTypeException(org.neo4j.graphdb.InvalidTransactionTypeException) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Test(org.junit.Test)

Example 2 with ConstraintCreator

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;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ConstraintCreator(org.neo4j.graphdb.schema.ConstraintCreator) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition)

Example 3 with ConstraintCreator

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);
}
Also used : ConstraintCreator(org.neo4j.graphdb.schema.ConstraintCreator) ConstraintDefinitionRepresentation(org.neo4j.server.rest.repr.ConstraintDefinitionRepresentation) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition)

Aggregations

ConstraintCreator (org.neo4j.graphdb.schema.ConstraintCreator)3 ConstraintDefinition (org.neo4j.graphdb.schema.ConstraintDefinition)2 Test (org.junit.Test)1 InvalidTransactionTypeException (org.neo4j.graphdb.InvalidTransactionTypeException)1 Transaction (org.neo4j.graphdb.Transaction)1 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)1 HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)1 ClusterManager (org.neo4j.kernel.impl.ha.ClusterManager)1 ConstraintDefinitionRepresentation (org.neo4j.server.rest.repr.ConstraintDefinitionRepresentation)1