use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class SchemaMatcher method onMatchingSchema.
/**
* Iterate over some schema suppliers, and invoke a callback for every supplier that matches the entity. To match the
* entity E the supplier must supply a {@link SchemaDescriptor} D, such that E has values for all the properties of D.
* The supplied schemas are all assumed to match E on token (label or relationship).
* <p>
* To avoid unnecessary store lookups, this implementation only gets propertyKeyIds for the entity if some
* descriptor has a valid token.
*
* @param <SUPPLIER> the type to match. Must implement SchemaDescriptorSupplier
* @param <EXCEPTION> The type of exception that can be thrown when taking the action
* @param schemaSuppliers The suppliers to match
* @param specialPropertyId This property id will always count as a match for the descriptor, regardless of
* whether the entity has this property or not
* @param callback The action to take on match
* @throws EXCEPTION This exception is propagated from the action
*/
static <SUPPLIER extends SchemaDescriptorSupplier, EXCEPTION extends Exception> void onMatchingSchema(Iterator<SUPPLIER> schemaSuppliers, int specialPropertyId, int[] existingPropertyIds, ThrowingConsumer<SUPPLIER, EXCEPTION> callback) throws EXCEPTION {
while (schemaSuppliers.hasNext()) {
SUPPLIER schemaSupplier = schemaSuppliers.next();
SchemaDescriptor schema = schemaSupplier.schema();
if (entityHasSchemaProperties(existingPropertyIds, schema.getPropertyIds(), specialPropertyId)) {
callback.accept(schemaSupplier);
}
}
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class SchemaComplianceChecker method checkCorrectlyIndexed.
<ENTITY extends PrimitiveRecord> void checkCorrectlyIndexed(ENTITY entity, long[] entityTokens, IntObjectMap<Value> values, Function<ENTITY, ConsistencyReport.PrimitiveConsistencyReport> reportSupplier) {
for (IndexDescriptor indexRule : indexes) {
SchemaDescriptor schema = indexRule.schema();
Value[] valueArray = RecordLoading.entityIntersectionWithSchema(entityTokens, values, schema);
if (valueArray == null) {
continue;
}
var reader = indexReaders.reader(indexRule);
if (indexRule.isUnique()) {
verifyIndexedUniquely(entity, valueArray, indexRule, reader, reportSupplier);
} else {
long count = reader.countIndexedEntities(entity.getId(), cursorContext, schema.getPropertyIds(), valueArray);
reportIncorrectIndexCount(entity, valueArray, indexRule, count, reportSupplier);
}
}
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class UniquePropertyValueValidationException method getUserMessage.
@Override
public String getUserMessage(TokenNameLookup tokenNameLookup) {
SchemaDescriptor schema = constraint.schema();
StringBuilder message = new StringBuilder();
for (Iterator<IndexEntryConflictException> iterator = conflicts.iterator(); iterator.hasNext(); ) {
IndexEntryConflictException conflict = iterator.next();
message.append(conflict.evidenceMessage(tokenNameLookup, schema));
if (iterator.hasNext()) {
message.append(System.lineSeparator());
}
}
return message.toString();
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class TxStateTest method addNodesToIndex.
private IndexUpdater addNodesToIndex(final IndexDescriptor descriptor) {
return new IndexUpdater() {
@Override
public void withDefaultStringProperties(long... nodeIds) {
Collection<Pair<Long, String>> entries = new ArrayList<>(nodeIds.length);
for (long nodeId : nodeIds) {
entries.add(of(nodeId, "value" + nodeId));
}
withProperties(entries);
}
private <T> void withProperties(Collection<Pair<Long, T>> nodesWithValues) {
SchemaDescriptor schema = descriptor.schema();
int[] labelIds = schema.getEntityTokenIds();
int[] propertyKeyIds = schema.getPropertyIds();
assertEquals(1, labelIds.length);
assertEquals(1, propertyKeyIds.length);
for (Pair<Long, T> entry : nodesWithValues) {
long nodeId = entry.first();
state.nodeDoCreate(nodeId);
state.nodeDoAddLabel(labelIds[0], nodeId);
Value valueAfter = Values.of(entry.other());
state.nodeDoAddProperty(nodeId, propertyKeyIds[0], valueAfter);
state.indexDoUpdateEntry(schema, nodeId, null, ValueTuple.of(valueAfter));
}
}
};
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class BuiltInProceduresTest method setup.
@BeforeEach
void setup() throws Exception {
procs.registerComponent(KernelTransaction.class, ctx -> ctx.internalTransaction().kernelTransaction(), false);
procs.registerComponent(DependencyResolver.class, Context::dependencyResolver, false);
procs.registerComponent(GraphDatabaseAPI.class, Context::graphDatabaseAPI, false);
procs.registerComponent(Transaction.class, Context::internalTransaction, true);
procs.registerComponent(SecurityContext.class, Context::securityContext, true);
procs.registerComponent(ProcedureCallContext.class, Context::procedureCallContext, true);
procs.registerComponent(SystemGraphComponents.class, ctx -> systemGraphComponents, false);
procs.registerComponent(Log.class, ctx -> log, false);
procs.registerType(Node.class, NTNode);
procs.registerType(Relationship.class, NTRelationship);
procs.registerType(Path.class, NTPath);
new SpecialBuiltInProcedures("1.3.37", Edition.COMMUNITY.toString()).accept(procs);
procs.registerProcedure(BuiltInProcedures.class);
procs.registerProcedure(BuiltInDbmsProcedures.class);
when(transaction.kernelTransaction()).thenReturn(tx);
when(tx.tokenRead()).thenReturn(tokens);
when(tx.dataRead()).thenReturn(read);
when(tx.schemaRead()).thenReturn(schemaRead);
when(tx.securityContext()).thenReturn(SecurityContext.AUTH_DISABLED);
when(callContext.isCalledFromCypher()).thenReturn(false);
when(schemaRead.snapshot()).thenReturn(schemaReadCore);
when(tokens.propertyKeyGetAllTokens()).thenAnswer(asTokens(propKeys));
when(tokens.labelsGetAllTokens()).thenAnswer(asTokens(labels));
when(tokens.relationshipTypesGetAllTokens()).thenAnswer(asTokens(relTypes));
when(schemaReadCore.indexesGetAll()).thenAnswer(i -> Iterators.concat(indexes.iterator(), uniqueIndexes.iterator()));
when(schemaReadCore.index(any(SchemaDescriptor.class))).thenAnswer((Answer<IndexDescriptor>) invocationOnMock -> {
SchemaDescriptor schema = invocationOnMock.getArgument(0);
return getIndexReference(schema);
});
when(schemaReadCore.constraintsGetAll()).thenAnswer(i -> constraints.iterator());
when(tokens.propertyKeyName(anyInt())).thenAnswer(invocation -> propKeys.get(invocation.getArgument(0)));
when(tokens.nodeLabelName(anyInt())).thenAnswer(invocation -> labels.get(invocation.getArgument(0)));
when(tokens.relationshipTypeName(anyInt())).thenAnswer(invocation -> relTypes.get(invocation.getArgument(0)));
when(tokens.propertyKeyGetName(anyInt())).thenAnswer(invocation -> propKeys.get(invocation.getArgument(0)));
when(tokens.labelGetName(anyInt())).thenAnswer(invocation -> labels.get(invocation.getArgument(0)));
when(tokens.relationshipTypeGetName(anyInt())).thenAnswer(invocation -> relTypes.get(invocation.getArgument(0)));
when(tokens.entityTokensGetNames(any(), any())).then(invocation -> {
EntityType type = invocation.getArgument(0);
int[] ids = invocation.getArgument(1);
Map<Integer, String> mapping = type == EntityType.NODE ? labels : relTypes;
return Arrays.stream(ids).mapToObj(mapping::get).toArray(String[]::new);
});
when(schemaReadCore.constraintsGetForRelationshipType(anyInt())).thenReturn(emptyIterator());
when(schemaReadCore.indexesGetForLabel(anyInt())).thenReturn(emptyIterator());
when(schemaReadCore.indexesGetForRelationshipType(anyInt())).thenReturn(emptyIterator());
when(schemaReadCore.constraintsGetForLabel(anyInt())).thenReturn(emptyIterator());
when(read.countsForNode(anyInt())).thenReturn(1L);
when(read.countsForRelationship(anyInt(), anyInt(), anyInt())).thenReturn(1L);
when(schemaReadCore.indexGetState(any(IndexDescriptor.class))).thenReturn(InternalIndexState.ONLINE);
}
Aggregations