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