Search in sources :

Example 1 with RelationTypeSchemaDescriptor

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");
}
Also used : RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) ArrayList(java.util.ArrayList) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaProcessor(org.neo4j.internal.schema.SchemaProcessor) Test(org.junit.jupiter.api.Test)

Example 2 with 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);
}
Also used : RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with RelationTypeSchemaDescriptor

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);
}
Also used : RelExistenceConstraintDescriptor(org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor) AlreadyConstrainedException(org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) NamedToken(org.neo4j.token.api.NamedToken) Test(org.junit.jupiter.api.Test)

Example 4 with RelationTypeSchemaDescriptor

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());
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) PopulationProgress(org.neo4j.internal.kernel.api.PopulationProgress) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) Kernel(org.neo4j.kernel.api.Kernel) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with RelationTypeSchemaDescriptor

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);
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) Label(org.neo4j.graphdb.Label) SchemaDescriptor.forLabel(org.neo4j.internal.schema.SchemaDescriptor.forLabel) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor)

Aggregations

RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)6 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)2 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)2 ArrayList (java.util.ArrayList)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 Label (org.neo4j.graphdb.Label)1 PopulationProgress (org.neo4j.internal.kernel.api.PopulationProgress)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1 SchemaDescriptor.forLabel (org.neo4j.internal.schema.SchemaDescriptor.forLabel)1 SchemaProcessor (org.neo4j.internal.schema.SchemaProcessor)1 RelExistenceConstraintDescriptor (org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor)1 Kernel (org.neo4j.kernel.api.Kernel)1 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)1 AlreadyConstrainedException (org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException)1 NamedToken (org.neo4j.token.api.NamedToken)1