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);
}
}
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
}
}
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
}
}
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());
}
}
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);
}
}
Aggregations