use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class Operations method ensureIndexPrototypeHasName.
private IndexPrototype ensureIndexPrototypeHasName(IndexPrototype prototype) throws KernelException {
if (prototype.getName().isEmpty()) {
SchemaDescriptor schema = prototype.schema();
int[] entityTokenIds = schema.getEntityTokenIds();
String[] entityTokenNames;
switch(schema.entityType()) {
case NODE:
entityTokenNames = resolveTokenNames(token::nodeLabelName, entityTokenIds);
break;
case RELATIONSHIP:
entityTokenNames = resolveTokenNames(token::relationshipTypeName, entityTokenIds);
break;
default:
throw new UnspecifiedKernelException(Status.General.UnknownError, "Cannot create index for entity type %s in the schema %s.", schema.entityType(), schema);
}
int[] propertyIds = schema.getPropertyIds();
String[] propertyNames = resolveTokenNames(token::propertyKeyName, propertyIds);
prototype = prototype.withName(SchemaRule.generateName(prototype, entityTokenNames, propertyNames));
}
return prototype;
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class Operations method ensureConstraintHasName.
@SuppressWarnings("unchecked")
private <T extends ConstraintDescriptor> T ensureConstraintHasName(T constraint) throws KernelException {
if (constraint.getName() == null) {
SchemaDescriptor schema = constraint.schema();
int[] entityTokenIds = schema.getEntityTokenIds();
String[] entityTokenNames;
switch(schema.entityType()) {
case NODE:
entityTokenNames = resolveTokenNames(token::nodeLabelName, entityTokenIds);
break;
case RELATIONSHIP:
entityTokenNames = resolveTokenNames(token::relationshipTypeName, entityTokenIds);
break;
default:
throw new UnspecifiedKernelException(Status.General.UnknownError, "Cannot create constraint for entity type %s in the schema %s.", schema.entityType(), schema);
}
int[] propertyIds = schema.getPropertyIds();
String[] propertyNames = resolveTokenNames(token::propertyKeyName, propertyIds);
constraint = (T) constraint.withName(SchemaRule.generateName(constraint, entityTokenNames, propertyNames));
}
return constraint;
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class Operations method validateNoExistingNodeWithExactValues.
/**
* Check so that there is not an existing node with the exact match of label and property
*/
private void validateNoExistingNodeWithExactValues(IndexBackedConstraintDescriptor constraint, PropertyIndexQuery.ExactPredicate[] propertyValues, long modifiedNode) throws UniquePropertyValueValidationException, UnableToValidateConstraintException {
IndexDescriptor index = allStoreHolder.indexGetForName(constraint.getName());
try (FullAccessNodeValueIndexCursor valueCursor = cursors.allocateFullAccessNodeValueIndexCursor(ktx.cursorContext(), memoryTracker);
IndexReaders indexReaders = new IndexReaders(index, allStoreHolder)) {
assertIndexOnline(index);
SchemaDescriptor schema = index.schema();
long[] labelIds = schema.lockingKeys();
if (labelIds.length != 1) {
throw new UnableToValidateConstraintException(constraint, new AssertionError(format("Constraint indexes are not expected to be multi-token indexes, " + "but the constraint %s was referencing an index with the following schema: %s.", constraint.userDescription(token), schema.userDescription(token))), token);
}
// Take a big fat lock, and check for existing node in index
ktx.lockClient().acquireExclusive(ktx.lockTracer(), INDEX_ENTRY, indexEntryResourceId(labelIds[0], propertyValues));
allStoreHolder.nodeIndexSeekWithFreshIndexReader(valueCursor, indexReaders.createReader(), propertyValues);
if (valueCursor.next() && valueCursor.nodeReference() != modifiedNode) {
throw new UniquePropertyValueValidationException(constraint, VALIDATION, new IndexEntryConflictException(valueCursor.nodeReference(), NO_SUCH_NODE, PropertyIndexQuery.asValueTuple(propertyValues)), token);
}
} catch (IndexNotFoundKernelException | IndexBrokenKernelException | IndexNotApplicableKernelException e) {
throw new UnableToValidateConstraintException(constraint, e, token);
}
}
use of org.neo4j.internal.schema.SchemaDescriptor 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);
}
}
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class Read method acquireSharedSchemaLock.
<T extends SchemaDescriptorSupplier> T acquireSharedSchemaLock(T schemaLike) {
SchemaDescriptor schema = schemaLike.schema();
long[] lockingKeys = schema.lockingKeys();
ktx.lockClient().acquireShared(ktx.lockTracer(), schema.keyType(), lockingKeys);
return schemaLike;
}
Aggregations