Search in sources :

Example 1 with ConstraintViolationException

use of org.neo4j.graphdb.ConstraintViolationException in project neo4j by neo4j.

the class BatchInserterImpl method verifyIndexOrUniquenessConstraintCanBeCreated.

private void verifyIndexOrUniquenessConstraintCanBeCreated(int labelId, int[] propertyKeyIds, String errorMessage) {
    LabelSchemaDescriptor schemaDescriptor = SchemaDescriptorFactory.forLabel(labelId, propertyKeyIds);
    ConstraintDescriptor constraintDescriptor = ConstraintDescriptorFactory.uniqueForLabel(labelId, propertyKeyIds);
    if (schemaCache.hasIndexRule(schemaDescriptor) || schemaCache.hasConstraintRule(constraintDescriptor)) {
        throw new ConstraintViolationException(errorMessage);
    }
}
Also used : ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)

Example 2 with ConstraintViolationException

use of org.neo4j.graphdb.ConstraintViolationException in project neo4j by neo4j.

the class BatchInsertTest method shouldNotAllowCreationOfDeferredSchemaIndexAfterConstraintOnSameKeys.

@Test
public void shouldNotAllowCreationOfDeferredSchemaIndexAfterConstraintOnSameKeys() throws Exception {
    // GIVEN
    BatchInserter inserter = globalInserter;
    String labelName = "Hacker4-" + denseNodeThreshold;
    // WHEN
    inserter.createDeferredConstraint(label(labelName)).assertPropertyIsUnique("handle").create();
    try {
        inserter.createDeferredSchemaIndex(label(labelName)).on("handle").create();
        fail("Should have thrown exception.");
    } catch (ConstraintViolationException e) {
    // THEN Good
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) Test(org.junit.Test)

Example 3 with ConstraintViolationException

use of org.neo4j.graphdb.ConstraintViolationException in project neo4j by neo4j.

the class BatchInsertTest method shouldNotAllowCreationOfDuplicateIndex.

@Test
public void shouldNotAllowCreationOfDuplicateIndex() throws Exception {
    // GIVEN
    BatchInserter inserter = globalInserter;
    String labelName = "Hacker1-" + denseNodeThreshold;
    // WHEN
    inserter.createDeferredSchemaIndex(label(labelName)).on("handle").create();
    try {
        inserter.createDeferredSchemaIndex(label(labelName)).on("handle").create();
        fail("Should have thrown exception.");
    } catch (ConstraintViolationException e) {
    // THEN Good
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) Test(org.junit.Test)

Example 4 with ConstraintViolationException

use of org.neo4j.graphdb.ConstraintViolationException in project neo4j by neo4j.

the class BatchInsertTest method shouldNotAllowDuplicatedUniquenessConstraints.

@Test
public void shouldNotAllowDuplicatedUniquenessConstraints() throws Exception {
    // Given
    Label label = label("Person2-" + denseNodeThreshold);
    String property = "name";
    BatchInserter inserter = globalInserter;
    // When
    inserter.createDeferredConstraint(label).assertPropertyIsUnique(property).create();
    try {
        inserter.createDeferredConstraint(label).assertPropertyIsUnique(property).create();
        fail("Exception expected");
    } catch (ConstraintViolationException e) {
        // Then
        assertEquals("It is not allowed to create uniqueness constraints and indexes on the same {label;property}", e.getMessage());
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) Label(org.neo4j.graphdb.Label) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) Test(org.junit.Test)

Example 5 with ConstraintViolationException

use of org.neo4j.graphdb.ConstraintViolationException in project neo4j by neo4j.

the class RelationshipProxy method setProperty.

@Override
public void setProperty(String key, Object value) {
    try (Statement statement = actions.statement()) {
        int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName(key);
        statement.dataWriteOperations().relationshipSetProperty(getId(), Property.property(propertyKeyId, value));
    } catch (IllegalArgumentException e) {
        // Trying to set an illegal value is a critical error - fail this transaction
        actions.failTransaction();
        throw e;
    } catch (EntityNotFoundException e) {
        throw new NotFoundException(e);
    } catch (IllegalTokenNameException e) {
        // TODO: Maybe throw more context-specific error than just IllegalArgument
        throw new IllegalArgumentException(e);
    } catch (InvalidTransactionTypeKernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    } catch (AutoIndexingKernelException e) {
        throw new IllegalStateException("Auto indexing encountered a failure while setting property: " + e.getMessage(), e);
    }
}
Also used : Statement(org.neo4j.kernel.api.Statement) InvalidTransactionTypeKernelException(org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) PropertyNotFoundException(org.neo4j.kernel.api.exceptions.PropertyNotFoundException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) IllegalTokenNameException(org.neo4j.kernel.api.exceptions.schema.IllegalTokenNameException) AutoIndexingKernelException(org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException)

Aggregations

ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)21 Test (org.junit.Test)14 BatchInserter (org.neo4j.unsafe.batchinsert.BatchInserter)8 Transaction (org.neo4j.graphdb.Transaction)6 Label (org.neo4j.graphdb.Label)4 File (java.io.File)3 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)3 Node (org.neo4j.graphdb.Node)3 NotFoundException (org.neo4j.graphdb.NotFoundException)3 Statement (org.neo4j.kernel.api.Statement)3 EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)3 InvalidTransactionTypeKernelException (org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException)3 PropertyNotFoundException (org.neo4j.kernel.api.exceptions.PropertyNotFoundException)2 IllegalTokenNameException (org.neo4j.kernel.api.exceptions.schema.IllegalTokenNameException)2 HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)2 IOException (java.io.IOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ComException (org.neo4j.com.ComException)1 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)1 TransientTransactionFailureException (org.neo4j.graphdb.TransientTransactionFailureException)1