use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class SchemaImpl method descriptorToDefinition.
private IndexDefinition descriptorToDefinition(final TokenRead tokenRead, IndexDescriptor index) {
try {
SchemaDescriptor schema = index.schema();
int[] entityTokenIds = schema.getEntityTokenIds();
boolean constraintIndex = index.isUnique();
String[] propertyNames = PropertyNameUtils.getPropertyKeysOrThrow(tokenRead, index.schema().getPropertyIds());
switch(schema.entityType()) {
case NODE:
Label[] labels = new Label[entityTokenIds.length];
for (int i = 0; i < labels.length; i++) {
labels[i] = label(tokenRead.nodeLabelName(entityTokenIds[i]));
}
return new IndexDefinitionImpl(actions, index, labels, propertyNames, constraintIndex);
case RELATIONSHIP:
RelationshipType[] relTypes = new RelationshipType[entityTokenIds.length];
for (int i = 0; i < relTypes.length; i++) {
relTypes[i] = withName(tokenRead.relationshipTypeName(entityTokenIds[i]));
}
return new IndexDefinitionImpl(actions, index, relTypes, propertyNames, constraintIndex);
default:
throw new IllegalArgumentException("Cannot create IndexDefinition for " + schema.entityType() + " entity-typed schema.");
}
} catch (KernelException e) {
throw new RuntimeException(e);
}
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class PlainOperationsTest method indexedBackedConstraintCreateMustThrowOnFulltextSchemas.
@Test
void indexedBackedConstraintCreateMustThrowOnFulltextSchemas() throws Exception {
// given
when(tokenHolders.labelTokens().getTokenById(anyInt())).thenReturn(new NamedToken("Label", 123));
when(tokenHolders.propertyKeyTokens().getTokenById(anyInt())).thenReturn(new NamedToken("prop", 456));
SchemaDescriptor schema = SchemaDescriptor.fulltext(NODE, this.schema.getEntityTokenIds(), this.schema.getPropertyIds());
IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema).withName("constraint name").withIndexProvider(GenericNativeIndexProvider.DESCRIPTOR);
IndexDescriptor constraintIndex = prototype.materialise(42);
when(constraintIndexCreator.createUniquenessConstraintIndex(any(), any(), eq(prototype))).thenReturn(constraintIndex);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexProxy.getDescriptor()).thenReturn(constraintIndex);
when(indexingService.getIndexProxy(constraintIndex)).thenReturn(indexProxy);
when(storageReader.constraintsGetForSchema(schema)).thenReturn(Collections.emptyIterator());
when(storageReader.indexGetForSchema(schema)).thenReturn(Collections.emptyIterator());
// when
var e = assertThrows(KernelException.class, () -> operations.uniquePropertyConstraintCreate(prototype));
assertThat(e.getUserMessage(tokenHolders)).contains("full-text schema");
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class IndexTxStateUpdaterTestBase method setUp.
void setUp(List<IndexDescriptor> indexes) throws IndexNotFoundKernelException {
txState = mock(TransactionState.class);
when(txState.memoryTracker()).thenReturn(EmptyMemoryTracker.INSTANCE);
StorageReader storageReader = mock(StorageReader.class);
when(storageReader.valueIndexesGetRelated(any(), anyInt(), any())).thenAnswer(invocationOnMock -> {
long[] tokens = invocationOnMock.getArgument(0);
int propertyKeyId = invocationOnMock.getArgument(1);
Set<IndexDescriptor> descriptors = new HashSet<>();
for (IndexDescriptor index : indexes) {
SchemaDescriptor schema = index.schema();
if (schema.isAffected(tokens) && contains(schema.getPropertyIds(), propertyKeyId)) {
if (schema.propertySchemaType() == PropertySchemaType.COMPLETE_ALL_TOKENS) {
descriptors.add(index);
}
}
}
return descriptors;
});
when(storageReader.valueIndexesGetRelated(any(), any(int[].class), any())).thenAnswer(invocationOnMock -> {
long[] tokens = invocationOnMock.getArgument(0);
int[] propertyKeyIds = invocationOnMock.getArgument(1);
Set<IndexDescriptor> descriptors = new HashSet<>();
for (IndexDescriptor index : indexes) {
if (index.schema().isAffected(tokens)) {
boolean containsAll = true;
for (int propertyId : index.schema().getPropertyIds()) {
containsAll &= contains(propertyKeyIds, propertyId);
}
if (containsAll) {
descriptors.add(index);
}
}
}
return descriptors;
});
Read readOps = mock(Read.class);
when(readOps.txState()).thenReturn(txState);
IndexingService indexingService = mock(IndexingService.class);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(any(IndexDescriptor.class))).thenReturn(indexProxy);
indexTxUpdater = new IndexTxStateUpdater(storageReader, readOps, indexingService);
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class LockVerificationMonitor method assertSchemaLocked.
static void assertSchemaLocked(ResourceLocker locks, SchemaRule schemaRule, AbstractBaseRecord record) {
if (schemaRule instanceof IndexDescriptor && ((IndexDescriptor) schemaRule).isUnique()) {
// Current lock abstraction does not let us check if anyone (parent) has those locks so there is nothing we can check here unfortunately
return;
}
Objects.requireNonNull(schemaRule);
assertLocked(locks, schemaNameResourceId(schemaRule.getName()), SCHEMA_NAME, EXCLUSIVE, record);
SchemaDescriptor schema = schemaRule.schema();
for (long key : schema.lockingKeys()) {
assertLocked(locks, key, schema.keyType(), EXCLUSIVE, record);
}
}
use of org.neo4j.internal.schema.SchemaDescriptor in project neo4j by neo4j.
the class MultipleIndexPopulator method newPopulatingUpdater.
@VisibleForTesting
MultipleIndexUpdater newPopulatingUpdater(NodePropertyAccessor accessor, CursorContext cursorContext) {
Map<SchemaDescriptor, Pair<IndexPopulation, IndexUpdater>> updaters = new HashMap<>();
forEachPopulation(population -> {
IndexUpdater updater = population.populator.newPopulatingUpdater(accessor, cursorContext);
updaters.put(population.schema(), Pair.of(population, updater));
}, cursorContext);
return new MultipleIndexUpdater(this, updaters, logProvider, cursorContext);
}
Aggregations