use of org.neo4j.internal.schema.RelationTypeSchemaDescriptor in project neo4j by neo4j.
the class SchemaProcessorTest method shouldHandleCorrectDescriptorVersions.
@Test
void shouldHandleCorrectDescriptorVersions() {
List<String> callHistory = new ArrayList<>();
SchemaProcessor processor = new SchemaProcessor() {
@Override
public void processSpecific(LabelSchemaDescriptor schema) {
callHistory.add("LabelSchemaDescriptor");
}
@Override
public void processSpecific(RelationTypeSchemaDescriptor schema) {
callHistory.add("RelationTypeSchemaDescriptor");
}
@Override
public void processSpecific(SchemaDescriptor schemaDescriptor) {
callHistory.add("SchemaDescriptor");
}
};
disguisedLabel().processWith(processor);
disguisedLabel().processWith(processor);
disguisedRelType().processWith(processor);
disguisedLabel().processWith(processor);
disguisedRelType().processWith(processor);
disguisedRelType().processWith(processor);
assertThat(callHistory).containsExactly("LabelSchemaDescriptor", "LabelSchemaDescriptor", "RelationTypeSchemaDescriptor", "LabelSchemaDescriptor", "RelationTypeSchemaDescriptor", "RelationTypeSchemaDescriptor");
}
use of org.neo4j.internal.schema.RelationTypeSchemaDescriptor in project neo4j by neo4j.
the class SchemaDescriptorTest method shouldCreateEqualRelTypes.
@Test
void shouldCreateEqualRelTypes() {
RelationTypeSchemaDescriptor desc1 = SchemaDescriptor.forRelType(REL_TYPE_ID, 1);
RelationTypeSchemaDescriptor desc2 = SchemaDescriptor.forRelType(REL_TYPE_ID, 1);
SchemaTestUtil.assertEquality(desc1, desc2);
}
use of org.neo4j.internal.schema.RelationTypeSchemaDescriptor in project neo4j by neo4j.
the class PlainOperationsTest method shouldReleaseAcquiredSchemaWriteLockIfRelationshipPropertyExistenceConstraintCreationFails.
@Test
void shouldReleaseAcquiredSchemaWriteLockIfRelationshipPropertyExistenceConstraintCreationFails() throws Exception {
// given
RelationTypeSchemaDescriptor descriptor = SchemaDescriptor.forRelType(11, 13);
RelExistenceConstraintDescriptor constraint = existsForSchema(descriptor);
storageReaderWithConstraints(constraint);
int relTypeId = descriptor.getRelTypeId();
int propertyId = descriptor.getPropertyId();
when(tokenHolders.relationshipTypeTokens().getTokenById(relTypeId)).thenReturn(new NamedToken("Label", relTypeId));
when(tokenHolders.propertyKeyTokens().getTokenById(propertyId)).thenReturn(new NamedToken("prop", relTypeId));
// when
try {
operations.relationshipPropertyExistenceConstraintCreate(descriptor, "constraint name");
fail("Expected an exception because this schema should already be constrained.");
} catch (AlreadyConstrainedException ignore) {
// Good.
}
// then
order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.RELATIONSHIP_TYPE, relTypeId);
order.verify(storageReader).constraintsGetForSchema(descriptor);
order.verify(locks).releaseExclusive(ResourceTypes.RELATIONSHIP_TYPE, relTypeId);
}
use of org.neo4j.internal.schema.RelationTypeSchemaDescriptor in project neo4j by neo4j.
the class IndexingServiceIntegrationTest method testManualRelationshipIndexPopulation.
@ParameterizedTest
@MethodSource("parameters")
void testManualRelationshipIndexPopulation(GraphDatabaseSettings.SchemaIndex schemaIndex) throws Exception {
setUp(schemaIndex);
IndexDescriptor index;
Kernel kernel = ((GraphDatabaseAPI) database).getDependencyResolver().resolveDependency(Kernel.class);
try (KernelTransaction tx = kernel.beginTransaction(EXPLICIT, AUTH_DISABLED)) {
int foodId = tx.tokenWrite().relationshipTypeGetOrCreateForName(FOOD_LABEL);
int propertyId = tx.tokenWrite().propertyKeyGetOrCreateForName(PROPERTY_NAME);
RelationTypeSchemaDescriptor schema = forRelType(foodId, propertyId);
index = tx.schemaWrite().indexCreate(schema, "food names");
tx.commit();
}
IndexingService indexingService = getIndexingService(database);
IndexProxy indexProxy = indexingService.getIndexProxy(index);
waitIndexOnline(indexProxy);
assertEquals(InternalIndexState.ONLINE, indexProxy.getState());
PopulationProgress progress = indexProxy.getIndexPopulationProgress();
assertEquals(progress.getCompleted(), progress.getTotal());
}
use of org.neo4j.internal.schema.RelationTypeSchemaDescriptor in project neo4j by neo4j.
the class SchemaImpl method asConstraintDefinition.
private ConstraintDefinition asConstraintDefinition(ConstraintDescriptor constraint, TokenRead tokenRead) {
// internal storage engine API.
if (constraint.isNodePropertyExistenceConstraint() || constraint.isNodeKeyConstraint() || constraint.isUniquenessConstraint()) {
SchemaDescriptor schemaDescriptor = constraint.schema();
int[] entityTokenIds = schemaDescriptor.getEntityTokenIds();
Label[] labels = new Label[entityTokenIds.length];
for (int i = 0; i < entityTokenIds.length; i++) {
labels[i] = label(tokenRead.labelGetName(entityTokenIds[i]));
}
String[] propertyKeys = Arrays.stream(schemaDescriptor.getPropertyIds()).mapToObj(tokenRead::propertyKeyGetName).toArray(String[]::new);
if (constraint.isNodePropertyExistenceConstraint()) {
return new NodePropertyExistenceConstraintDefinition(actions, constraint, labels[0], propertyKeys);
} else if (constraint.isUniquenessConstraint()) {
return new UniquenessConstraintDefinition(actions, constraint, new IndexDefinitionImpl(actions, null, labels, propertyKeys, true));
} else {
return new NodeKeyConstraintDefinition(actions, constraint, new IndexDefinitionImpl(actions, null, labels, propertyKeys, true));
}
} else if (constraint.isRelationshipPropertyExistenceConstraint()) {
RelationTypeSchemaDescriptor descriptor = constraint.schema().asRelationshipTypeSchemaDescriptor();
return new RelationshipPropertyExistenceConstraintDefinition(actions, constraint, withName(tokenRead.relationshipTypeGetName(descriptor.getRelTypeId())), tokenRead.propertyKeyGetName(descriptor.getPropertyId()));
}
throw new IllegalArgumentException("Unknown constraint " + constraint);
}
Aggregations