Search in sources :

Example 1 with DropIndexFailureException

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);
    }
}
Also used : UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) NodeExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.NodeExistenceConstraintDescriptor) RelExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.RelExistenceConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) DropIndexFailureException(org.neo4j.kernel.api.exceptions.schema.DropIndexFailureException) CreateConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException)

Aggregations

TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)1 CreateConstraintFailureException (org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException)1 DropIndexFailureException (org.neo4j.kernel.api.exceptions.schema.DropIndexFailureException)1 UniquePropertyValueValidationException (org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException)1 ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)1 NodeExistenceConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.NodeExistenceConstraintDescriptor)1 RelExistenceConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.RelExistenceConstraintDescriptor)1 UniquenessConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor)1