Search in sources :

Example 6 with SchemaKernelException

use of org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException in project neo4j by neo4j.

the class TransactionImpl method createNode.

@Override
public Node createNode(Label... labels) {
    var ktx = kernelTransaction();
    try {
        TokenWrite tokenWrite = ktx.tokenWrite();
        int[] labelIds = new int[labels.length];
        String[] labelNames = new String[labels.length];
        for (int i = 0; i < labelNames.length; i++) {
            labelNames[i] = labels[i].name();
        }
        tokenWrite.labelGetOrCreateForNames(labelNames, labelIds);
        Write write = ktx.dataWrite();
        long nodeId = write.nodeCreateWithLabels(labelIds);
        return newNodeEntity(nodeId);
    } catch (ConstraintValidationException e) {
        throw new ConstraintViolationException("Unable to add label.", e);
    } catch (SchemaKernelException e) {
        throw new IllegalArgumentException(e);
    } catch (KernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    }
}
Also used : TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) Write(org.neo4j.internal.kernel.api.Write) ConstraintValidationException(org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException)

Example 7 with SchemaKernelException

use of org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException in project neo4j by neo4j.

the class IndexIT method shouldDisallowDroppingIndexBySchemaThatDoesNotExist.

@Test
void shouldDisallowDroppingIndexBySchemaThatDoesNotExist() throws Exception {
    // given
    IndexDescriptor index;
    {
        SchemaWrite statement = schemaWriteInNewTransaction();
        index = statement.indexCreate(schema, "my index");
        commit();
    }
    {
        SchemaWrite statement = schemaWriteInNewTransaction();
        statement.indexDrop(index.schema());
        commit();
    }
    // when
    SchemaWrite statement = schemaWriteInNewTransaction();
    SchemaKernelException e = assertThrows(SchemaKernelException.class, () -> statement.indexDrop(index.schema()));
    assertEquals("Unable to drop index on (:" + LABEL + " {" + PROPERTY_KEY + "}). There is no such index.", e.getMessage());
    commit();
}
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 8 with SchemaKernelException

use of org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException in project neo4j by neo4j.

the class Operations method nodeKeyConstraintCreate.

@Override
public ConstraintDescriptor nodeKeyConstraintCreate(IndexPrototype prototype) throws KernelException {
    SchemaDescriptor schema = prototype.schema();
    exclusiveSchemaLock(schema);
    ktx.assertOpen();
    prototype = ensureIndexPrototypeHasIndexProvider(prototype);
    NodeKeyConstraintDescriptor constraint = ConstraintDescriptorFactory.nodeKeyForSchema(schema);
    try {
        // Check data integrity
        assertValidDescriptor(schema, SchemaKernelException.OperationContext.CONSTRAINT_CREATION);
        if (prototype.getName().isEmpty()) {
            constraint = ensureConstraintHasName(constraint);
            prototype = prototype.withName(constraint.getName());
        } else {
            constraint = constraint.withName(prototype.getName().get());
        }
        exclusiveSchemaNameLock(constraint.getName());
        assertNoBlockingSchemaRulesExists(constraint);
    } catch (SchemaKernelException e) {
        exclusiveSchemaUnlock(schema);
        throw e;
    }
    // enforce constraints
    enforceNodeKeyConstraint(schema);
    // create constraint
    indexBackedConstraintCreate(constraint, prototype);
    return constraint;
}
Also used : RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)

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