use of org.neo4j.kernel.api.exceptions.schema.DropIndexFailureException in project neo4j by neo4j.
the class StateHandlingStatementOperations method uniquePropertyConstraintCreate.
@Override
public UniquenessConstraintDescriptor uniquePropertyConstraintCreate(KernelStatement state, LabelSchemaDescriptor descriptor) throws CreateConstraintFailureException {
UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(descriptor);
try {
if (state.hasTxStateWithChanges() && // ..., DROP, *CREATE*
state.txState().indexDoUnRemove(constraint.ownedIndexDescriptor())) {
// creation is undoing a drop
if (// CREATE, ..., DROP, *CREATE*
!state.txState().constraintDoUnRemove(constraint)) {
// ... the drop we are undoing did itself undo a prior create...
state.txState().constraintDoAdd(constraint, state.txState().indexCreatedForConstraint(constraint));
}
} else // *CREATE*
{
// create from scratch
Iterator<ConstraintDescriptor> it = storeLayer.constraintsGetForSchema(descriptor);
while (it.hasNext()) {
if (it.next().equals(constraint)) {
return constraint;
}
}
long indexId = constraintIndexCreator.createUniquenessConstraintIndex(state, this, descriptor);
state.txState().constraintDoAdd(constraint, indexId);
}
return constraint;
} catch (UniquePropertyValueValidationException | DropIndexFailureException | TransactionFailureException e) {
throw new CreateConstraintFailureException(constraint, e);
}
}
Aggregations