use of org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException in project neo4j by neo4j.
the class Operations method constraintDrop.
@Override
public void constraintDrop(String name) throws SchemaKernelException {
exclusiveSchemaNameLock(name);
ConstraintDescriptor constraint = allStoreHolder.constraintGetForName(name);
if (constraint == null) {
throw new DropConstraintFailureException(name, new NoSuchConstraintException(name));
}
constraintDrop(constraint);
}
use of org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException in project neo4j by neo4j.
the class Operations method constraintDrop.
@Override
public void constraintDrop(ConstraintDescriptor constraint) throws SchemaKernelException {
// Lock
SchemaDescriptor schema = constraint.schema();
exclusiveLock(schema.keyType(), schema.lockingKeys());
exclusiveSchemaNameLock(constraint.getName());
ktx.assertOpen();
// verify data integrity
try {
assertConstraintExists(constraint);
} catch (NoSuchConstraintException e) {
throw new DropConstraintFailureException(constraint, e);
}
// Drop it like it's hot
TransactionState txState = ktx.txState();
txState.constraintDoDrop(constraint);
if (constraint.enforcesUniqueness()) {
IndexDescriptor index = allStoreHolder.indexGetForName(constraint.getName());
if (index != IndexDescriptor.NO_INDEX) {
txState.indexDoDrop(index);
}
}
}
use of org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException 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));
}
}
use of org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException in project neo4j by neo4j.
the class NodePropertyExistenceConstraintCreationIT method shouldNotDropPropertyExistenceConstraintThatDoesNotExistWhenThereIsAUniquePropertyConstraint.
@Test
public void shouldNotDropPropertyExistenceConstraintThatDoesNotExistWhenThereIsAUniquePropertyConstraint() throws Exception {
// given
UniquenessConstraintDescriptor constraint;
{
SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
constraint = statement.uniquePropertyConstraintCreate(descriptor);
commit();
}
// when
try {
SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
statement.constraintDrop(ConstraintDescriptorFactory.existsForSchema(constraint.schema()));
fail("expected exception");
}// then
catch (DropConstraintFailureException e) {
assertThat(e.getCause(), instanceOf(NoSuchConstraintException.class));
} finally {
rollback();
}
// then
{
ReadOperations statement = readOperationsInNewTransaction();
Iterator<ConstraintDescriptor> constraints = statement.constraintsGetForSchema(descriptor);
assertEquals(constraint, single(constraints));
}
}
use of org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException in project neo4j by neo4j.
the class UniquenessConstraintCreationIT method shouldNotDropUniquePropertyConstraintThatDoesNotExistWhenThereIsAPropertyExistenceConstraint.
@Test
public void shouldNotDropUniquePropertyConstraintThatDoesNotExistWhenThereIsAPropertyExistenceConstraint() throws Exception {
// given
SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction();
schemaWriteOperations.nodePropertyExistenceConstraintCreate(descriptor);
commit();
// when
try {
SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
statement.constraintDrop(ConstraintDescriptorFactory.uniqueForSchema(descriptor));
fail("expected exception");
}// then
catch (DropConstraintFailureException e) {
assertThat(e.getCause(), instanceOf(NoSuchConstraintException.class));
} finally {
rollback();
}
// then
{
ReadOperations statement = readOperationsInNewTransaction();
Iterator<ConstraintDescriptor> constraints = statement.constraintsGetForSchema(descriptor);
assertEquals(ConstraintDescriptorFactory.existsForSchema(descriptor), single(constraints));
}
}
Aggregations