Search in sources :

Example 1 with SchemaKernelException

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;
    }
}
Also used : 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) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)

Example 2 with SchemaKernelException

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();
}
Also used : SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 3 with SchemaKernelException

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();
}
Also used : SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) IndexBackedConstraintDescriptor(org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 4 with SchemaKernelException

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();
}
Also used : SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 5 with SchemaKernelException

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));
    }
}
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)

Aggregations

SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)8 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)5 Test (org.junit.jupiter.api.Test)4 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)4 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)3 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)3 IndexBackedConstraintDescriptor (org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor)3 NodeKeyConstraintDescriptor (org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor)3 KernelException (org.neo4j.exceptions.KernelException)2 Write (org.neo4j.internal.kernel.api.Write)2 ConstraintValidationException (org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException)2 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)2 UniquenessConstraintDescriptor (org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)2 String.format (java.lang.String.format)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Optional (java.util.Optional)1 ArrayUtils (org.apache.commons.lang3.ArrayUtils)1