Search in sources :

Example 1 with DropConstraintFailureException

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);
}
Also used : NoSuchConstraintException(org.neo4j.kernel.api.exceptions.schema.NoSuchConstraintException) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexBackedConstraintDescriptor(org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor) DropConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException)

Example 2 with DropConstraintFailureException

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);
        }
    }
}
Also used : NoSuchConstraintException(org.neo4j.kernel.api.exceptions.schema.NoSuchConstraintException) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) DropConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 3 with DropConstraintFailureException

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));
    }
}
Also used : StatementConstants(org.neo4j.kernel.api.StatementConstants) Arrays(java.util.Arrays) CreateConstraintFailureException(org.neo4j.internal.kernel.api.exceptions.schema.CreateConstraintFailureException) ThrowingIntFunction(org.neo4j.function.ThrowingIntFunction) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Status(org.neo4j.kernel.api.exceptions.Status) IndexType(org.neo4j.internal.schema.IndexType) Config(org.neo4j.configuration.Config) Value(org.neo4j.values.storable.Value) IndexingProvidersService(org.neo4j.kernel.impl.api.index.IndexingProvidersService) NO_SUCH_LABEL(org.neo4j.kernel.api.StatementConstants.NO_SUCH_LABEL) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) DEGREES(org.neo4j.lock.ResourceTypes.DEGREES) GraphDatabaseInternalSettings.additional_lock_verification(org.neo4j.configuration.GraphDatabaseInternalSettings.additional_lock_verification) IndexWithNameAlreadyExistsException(org.neo4j.kernel.api.exceptions.schema.IndexWithNameAlreadyExistsException) ConstraintType(org.neo4j.internal.schema.ConstraintType) ConstraintWithNameAlreadyExistsException(org.neo4j.kernel.api.exceptions.schema.ConstraintWithNameAlreadyExistsException) NoSuchConstraintException(org.neo4j.kernel.api.exceptions.schema.NoSuchConstraintException) EquivalentSchemaRuleAlreadyExistsException(org.neo4j.kernel.api.exceptions.schema.EquivalentSchemaRuleAlreadyExistsException) AlreadyIndexedException(org.neo4j.kernel.api.exceptions.schema.AlreadyIndexedException) IndexQueryConstraints.unconstrained(org.neo4j.internal.kernel.api.IndexQueryConstraints.unconstrained) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Locks(org.neo4j.internal.kernel.api.Locks) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) RepeatedSchemaComponentException(org.neo4j.kernel.api.exceptions.schema.RepeatedSchemaComponentException) ConstraintSemantics(org.neo4j.kernel.impl.constraints.ConstraintSemantics) KernelVersion(org.neo4j.kernel.KernelVersion) ResourceType(org.neo4j.lock.ResourceType) DropConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException) KernelVersionRepository(org.neo4j.storageengine.api.KernelVersionRepository) TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) StorageReader(org.neo4j.storageengine.api.StorageReader) MemoryTracker(org.neo4j.memory.MemoryTracker) Read(org.neo4j.internal.kernel.api.Read) Iterators(org.neo4j.internal.helpers.collection.Iterators) NO_SUCH_PROPERTY_KEY(org.neo4j.kernel.api.StatementConstants.NO_SUCH_PROPERTY_KEY) VALIDATION(org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException.Phase.VALIDATION) RepeatedRelationshipTypeInSchemaException(org.neo4j.kernel.api.exceptions.schema.RepeatedRelationshipTypeInSchemaException) INDEX_CREATION(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException.OperationContext.INDEX_CREATION) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) KernelException(org.neo4j.exceptions.KernelException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) AlreadyConstrainedException(org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException) LongSet(org.eclipse.collections.api.set.primitive.LongSet) UnspecifiedKernelException(org.neo4j.exceptions.UnspecifiedKernelException) TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException) DbmsRuntimeRepository(org.neo4j.dbms.database.DbmsRuntimeRepository) SchemaRule(org.neo4j.internal.schema.SchemaRule) UnableToValidateConstraintException(org.neo4j.kernel.api.exceptions.schema.UnableToValidateConstraintException) ResourceTypes(org.neo4j.lock.ResourceTypes) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) ADDED_LABEL(org.neo4j.kernel.impl.newapi.IndexTxStateUpdater.LabelChangeType.ADDED_LABEL) ConstraintValidationException(org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) RelationshipSelections(org.neo4j.internal.kernel.api.helpers.RelationshipSelections) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexBrokenKernelException(org.neo4j.kernel.api.exceptions.schema.IndexBrokenKernelException) NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor) NO_VALUE(org.neo4j.values.storable.Values.NO_VALUE) Procedures(org.neo4j.internal.kernel.api.Procedures) RepeatedPropertyInSchemaException(org.neo4j.kernel.api.exceptions.schema.RepeatedPropertyInSchemaException) Collection(java.util.Collection) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) String.format(java.lang.String.format) NO_SUCH_NODE(org.neo4j.kernel.api.StatementConstants.NO_SUCH_NODE) List(java.util.List) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) RepeatedLabelInSchemaException(org.neo4j.kernel.api.exceptions.schema.RepeatedLabelInSchemaException) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) IndexNotApplicableKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException) Optional(java.util.Optional) NODE(org.neo4j.common.EntityType.NODE) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) ArrayUtils(org.apache.commons.lang3.ArrayUtils) DropIndexFailureException(org.neo4j.kernel.api.exceptions.schema.DropIndexFailureException) ConstraintDescriptorFactory(org.neo4j.internal.schema.constraints.ConstraintDescriptorFactory) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) Values(org.neo4j.values.storable.Values) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) Write(org.neo4j.internal.kernel.api.Write) SchemaDescriptorImplementation(org.neo4j.internal.schema.SchemaDescriptorImplementation) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) CONSTRAINT_CREATION(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException.OperationContext.CONSTRAINT_CREATION) REMOVED_LABEL(org.neo4j.kernel.impl.newapi.IndexTxStateUpdater.LabelChangeType.REMOVED_LABEL) IndexConfig(org.neo4j.internal.schema.IndexConfig) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) Iterator(java.util.Iterator) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) ResourceIds.indexEntryResourceId(org.neo4j.kernel.impl.locking.ResourceIds.indexEntryResourceId) ResourceIds(org.neo4j.kernel.impl.locking.ResourceIds) RELATIONSHIP(org.neo4j.common.EntityType.RELATIONSHIP) INDEX_ENTRY(org.neo4j.lock.ResourceTypes.INDEX_ENTRY) IndexBackedConstraintDescriptor(org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor) IndexBelongsToConstraintException(org.neo4j.kernel.api.exceptions.schema.IndexBelongsToConstraintException) SCHEMA_NAME(org.neo4j.lock.ResourceTypes.SCHEMA_NAME) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) Token(org.neo4j.internal.kernel.api.Token) NoSuchConstraintException(org.neo4j.kernel.api.exceptions.schema.NoSuchConstraintException) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexBackedConstraintDescriptor(org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor) DropConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException)

Example 4 with DropConstraintFailureException

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));
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) ResourceIterator(org.neo4j.graphdb.ResourceIterator) Iterator(java.util.Iterator) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) DropConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException) Test(org.junit.Test)

Example 5 with DropConstraintFailureException

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));
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) ResourceIterator(org.neo4j.graphdb.ResourceIterator) Iterator(java.util.Iterator) DropConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException) Test(org.junit.Test)

Aggregations

DropConstraintFailureException (org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException)5 Iterator (java.util.Iterator)3 NoSuchConstraintException (org.neo4j.kernel.api.exceptions.schema.NoSuchConstraintException)3 Test (org.junit.Test)2 ResourceIterator (org.neo4j.graphdb.ResourceIterator)2 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)2 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)2 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)2 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)2 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)2 IndexBackedConstraintDescriptor (org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor)2 NodeKeyConstraintDescriptor (org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor)2 UniquenessConstraintDescriptor (org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)2 ReadOperations (org.neo4j.kernel.api.ReadOperations)2 SchemaWriteOperations (org.neo4j.kernel.api.SchemaWriteOperations)2 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)2 String.format (java.lang.String.format)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1