use of org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException in project neo4j by neo4j.
the class Operations method lockAndValidatePropertyExistenceConstraint.
private ConstraintDescriptor lockAndValidatePropertyExistenceConstraint(SchemaDescriptor descriptor, String name) throws KernelException {
// Lock constraint schema.
exclusiveSchemaLock(descriptor);
ktx.assertOpen();
try {
// Verify data integrity.
assertValidDescriptor(descriptor, SchemaKernelException.OperationContext.CONSTRAINT_CREATION);
ConstraintDescriptor constraint = ConstraintDescriptorFactory.existsForSchema(descriptor).withName(name);
constraint = ensureConstraintHasName(constraint);
exclusiveSchemaNameLock(constraint.getName());
assertNoBlockingSchemaRulesExists(constraint);
return constraint;
} catch (SchemaKernelException e) {
exclusiveSchemaUnlock(descriptor);
throw e;
}
}
use of org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException in project neo4j by neo4j.
the class IndexIT method shouldDisallowDroppingIndexByNameThatDoesNotExist.
@Test
void shouldDisallowDroppingIndexByNameThatDoesNotExist() throws KernelException {
// given
String indexName = "My fancy index";
IndexDescriptor index;
{
SchemaWrite statement = schemaWriteInNewTransaction();
index = statement.indexCreate(schema, indexName);
commit();
}
{
SchemaWrite statement = schemaWriteInNewTransaction();
statement.indexDrop(index);
commit();
}
// when
SchemaWrite statement = schemaWriteInNewTransaction();
SchemaKernelException e = assertThrows(SchemaKernelException.class, () -> statement.indexDrop(indexName));
assertEquals(e.getMessage(), "Unable to drop index called `My fancy index`. There is no such index.");
rollback();
}
use of org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException in project neo4j by neo4j.
the class IndexIT method shouldDisallowDroppingConstraintByNameThatDoesNotExist.
@Test
void shouldDisallowDroppingConstraintByNameThatDoesNotExist() throws KernelException {
// given
String constraintName = "my constraint";
ConstraintDescriptor constraint;
{
SchemaWrite statement = schemaWriteInNewTransaction();
constraint = statement.uniquePropertyConstraintCreate(uniqueForSchema(schema).withName("constraint name"));
commit();
}
{
SchemaWrite statement = schemaWriteInNewTransaction();
statement.constraintDrop(constraint);
commit();
}
// when
SchemaWrite statement = schemaWriteInNewTransaction();
SchemaKernelException e = assertThrows(SchemaKernelException.class, () -> statement.constraintDrop(constraintName));
assertEquals("Unable to drop constraint `my constraint`: No such constraint my constraint.", e.getMessage());
rollback();
}
use of org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException in project neo4j by neo4j.
the class IndexIT method shouldDisallowDroppingIndexByNameThatBelongsToConstraint.
@Test
void shouldDisallowDroppingIndexByNameThatBelongsToConstraint() throws KernelException {
// given
String constraintName = "my constraint";
{
SchemaWrite statement = schemaWriteInNewTransaction();
statement.uniquePropertyConstraintCreate(uniqueForSchema(schema).withName("constraint name"));
commit();
}
// when
SchemaWrite statement = schemaWriteInNewTransaction();
SchemaKernelException e = assertThrows(SchemaKernelException.class, () -> statement.indexDrop(constraintName));
assertEquals("Unable to drop index called `my constraint`. There is no such index.", e.getMessage());
rollback();
}
use of org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException in project neo4j by neo4j.
the class Operations method constraintDrop.
@Override
public void constraintDrop(SchemaDescriptor schema, ConstraintType type) throws SchemaKernelException {
ktx.assertOpen();
Iterator<ConstraintDescriptor> constraints = ktx.schemaRead().constraintsGetForSchema(schema);
constraints = Iterators.filter(constraint -> constraint.type() == type, constraints);
if (constraints.hasNext()) {
ConstraintDescriptor constraint = constraints.next();
if (!constraints.hasNext()) {
constraintDrop(constraint);
} else {
String schemaDescription = schema.userDescription(token);
String constraintDescription = constraints.next().userDescription(token);
throw new DropConstraintFailureException(constraint, new IllegalArgumentException("More than one " + type + " constraint was found with the '" + schemaDescription + "' schema: " + constraintDescription + ", please drop constraint by name instead."));
}
} else {
throw new DropConstraintFailureException(schema, new NoSuchConstraintException(schema, token));
}
}
Aggregations