use of org.neo4j.internal.schema.SchemaDescriptor 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));
}
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class IndexTxStateUpdater method onDeleteUncreated.
// PROPERTY CHANGES
/**
* Creating an entity with its data in a transaction adds also adds that state to index transaction state (for matching indexes).
* When deleting an entity this method will delete this state from the index transaction state.
*
* @param entity entity that was deleted.
* @param propertyCursor property cursor for accessing the properties of the entity.
* @param tokens the entity tokens this entity has.
*/
private void onDeleteUncreated(EntityCursor entity, PropertyCursor propertyCursor, long[] tokens) {
assert noSchemaChangedInTx();
entity.properties(propertyCursor);
MutableIntList propertyKeyList = IntLists.mutable.empty();
while (propertyCursor.next()) {
propertyKeyList.add(propertyCursor.propertyKey());
}
// Make sure to sort the propertyKeyIds since SchemaMatcher.onMatchingSchema requires it.
int[] propertyKeyIds = propertyKeyList.toSortedArray();
Collection<IndexDescriptor> indexes = storageReader.valueIndexesGetRelated(tokens, propertyKeyIds, entity.entityType());
if (!indexes.isEmpty()) {
MutableIntObjectMap<Value> materializedProperties = IntObjectMaps.mutable.empty();
SchemaMatcher.onMatchingSchema(indexes.iterator(), ANY_PROPERTY_KEY, propertyKeyIds, index -> {
MemoryTracker memoryTracker = read.txState().memoryTracker();
SchemaDescriptor schema = index.schema();
Value[] values = getValueTuple(entity, propertyCursor, ANY_PROPERTY_KEY, NO_VALUE, schema.getPropertyIds(), materializedProperties, memoryTracker);
ValueTuple valueTuple = ValueTuple.of(values);
memoryTracker.allocateHeap(valueTuple.getShallowSize());
read.txState().indexDoUpdateEntry(schema, entity.reference(), valueTuple, null);
});
}
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class IndexTxStateUpdater method onPropertyChange.
private void onPropertyChange(EntityCursor entity, PropertyCursor propertyCursor, long[] tokens, int propertyKeyId, int[] existingPropertyKeyIds, Value beforeValue, Value afterValue) {
assert noSchemaChangedInTx();
Collection<IndexDescriptor> indexes = storageReader.valueIndexesGetRelated(tokens, propertyKeyId, entity.entityType());
if (!indexes.isEmpty()) {
MutableIntObjectMap<Value> materializedProperties = IntObjectMaps.mutable.empty();
SchemaMatcher.onMatchingSchema(indexes.iterator(), propertyKeyId, existingPropertyKeyIds, index -> {
MemoryTracker memoryTracker = read.txState().memoryTracker();
SchemaDescriptor schema = index.schema();
int[] propertyIds = schema.getPropertyIds();
Value[] valuesAfter = getValueTuple(entity, propertyCursor, propertyKeyId, afterValue, propertyIds, materializedProperties, memoryTracker);
// The valuesBefore tuple is just like valuesAfter, except is has the afterValue instead of the beforeValue
Value[] valuesBefore = Arrays.copyOf(valuesAfter, valuesAfter.length);
int k = ArrayUtils.indexOf(propertyIds, propertyKeyId);
valuesBefore[k] = beforeValue;
indexingService.validateBeforeCommit(index, valuesAfter, entity.reference());
ValueTuple valuesTupleBefore = ValueTuple.of(valuesBefore);
ValueTuple valuesTupleAfter = ValueTuple.of(valuesAfter);
// They are copies and same shallow size
memoryTracker.allocateHeap(valuesTupleBefore.getShallowSize() * 2);
read.txState().indexDoUpdateEntry(schema, entity.reference(), valuesTupleBefore, valuesTupleAfter);
});
}
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class IndexTxStateUpdater method onPropertyAdd.
private void onPropertyAdd(EntityCursor entity, PropertyCursor propertyCursor, long[] tokens, int propertyKeyId, int[] existingPropertyKeyIds, Value value) {
assert noSchemaChangedInTx();
Collection<IndexDescriptor> indexes = storageReader.valueIndexesGetRelated(tokens, propertyKeyId, entity.entityType());
if (!indexes.isEmpty()) {
MutableIntObjectMap<Value> materializedProperties = IntObjectMaps.mutable.empty();
SchemaMatcher.onMatchingSchema(indexes.iterator(), propertyKeyId, existingPropertyKeyIds, index -> {
MemoryTracker memoryTracker = read.txState().memoryTracker();
SchemaDescriptor schema = index.schema();
Value[] values = getValueTuple(entity, propertyCursor, propertyKeyId, value, schema.getPropertyIds(), materializedProperties, memoryTracker);
indexingService.validateBeforeCommit(index, values, entity.reference());
ValueTuple valueTuple = ValueTuple.of(values);
memoryTracker.allocateHeap(valueTuple.getShallowSize());
read.txState().indexDoUpdateEntry(schema, entity.reference(), null, valueTuple);
});
}
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class IndexTxStateUpdater method onPropertyRemove.
private void onPropertyRemove(EntityCursor entity, PropertyCursor propertyCursor, long[] tokens, int propertyKeyId, int[] existingPropertyKeyIds, Value value) {
assert noSchemaChangedInTx();
Collection<IndexDescriptor> indexes = storageReader.valueIndexesGetRelated(tokens, propertyKeyId, entity.entityType());
if (!indexes.isEmpty()) {
MutableIntObjectMap<Value> materializedProperties = IntObjectMaps.mutable.empty();
SchemaMatcher.onMatchingSchema(indexes.iterator(), propertyKeyId, existingPropertyKeyIds, index -> {
MemoryTracker memoryTracker = read.txState().memoryTracker();
SchemaDescriptor schema = index.schema();
Value[] values = getValueTuple(entity, propertyCursor, propertyKeyId, value, schema.getPropertyIds(), materializedProperties, memoryTracker);
ValueTuple valueTuple = ValueTuple.of(values);
memoryTracker.allocateHeap(valueTuple.getShallowSize());
read.txState().indexDoUpdateEntry(schema, entity.reference(), valueTuple, null);
});
}
}
Aggregations