Search in sources :

Example 11 with LabelSchemaDescriptor

use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.

the class ConstraintTestBase method shouldFindConstraintsBySchema.

@Test
void shouldFindConstraintsBySchema() throws Exception {
    // GIVEN
    addConstraints("FOO", "prop");
    try (KernelTransaction tx = beginTransaction()) {
        int label = tx.tokenWrite().labelGetOrCreateForName("FOO");
        int prop = tx.tokenWrite().propertyKeyGetOrCreateForName("prop");
        LabelSchemaDescriptor descriptor = labelSchemaDescriptor(label, prop);
        // WHEN
        List<ConstraintDescriptor> constraints = asList(tx.schemaRead().constraintsGetForSchema(descriptor));
        // THEN
        assertThat(constraints).hasSize(1);
        assertThat(constraints.get(0).schema().getPropertyId()).isEqualTo(prop);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Example 12 with LabelSchemaDescriptor

use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.

the class IndexProcedures method createIndex.

private Stream<BuiltInProcedures.SchemaIndexInfo> createIndex(String name, List<String> labels, List<String> properties, IndexProviderDescriptor indexProviderDescriptor, Map<String, Object> configMap, String statusMessage, IndexCreator indexCreator) throws ProcedureException {
    IndexConfig indexConfig = IndexSettingUtil.toIndexConfigFromStringObjectMap(configMap);
    assertSingleLabel(labels);
    assertValidIndexProvider(indexProviderDescriptor);
    int labelId = getOrCreateLabelId(labels.get(0));
    int[] propertyKeyIds = getOrCreatePropertyIds(properties);
    try {
        SchemaWrite schemaWrite = ktx.schemaWrite();
        LabelSchemaDescriptor labelSchemaDescriptor = SchemaDescriptor.forLabel(labelId, propertyKeyIds);
        indexCreator.create(schemaWrite, name, labelSchemaDescriptor, indexProviderDescriptor, indexConfig);
        return Stream.of(new BuiltInProcedures.SchemaIndexInfo(name, labels, properties, indexProviderDescriptor.name(), statusMessage));
    } catch (KernelException e) {
        throw new ProcedureException(e.status(), e, e.getMessage());
    }
}
Also used : IndexConfig(org.neo4j.internal.schema.IndexConfig) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException)

Example 13 with LabelSchemaDescriptor

use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.

the class IndexCRUDIT method addingALabelToPreExistingNodeShouldGetIndexed.

@Test
void addingALabelToPreExistingNodeShouldGetIndexed() throws Exception {
    // GIVEN
    String indexProperty = "indexProperty";
    GatheringIndexWriter writer = newWriter();
    createIndex(db, myLabel, indexProperty);
    // WHEN
    String otherProperty = "otherProperty";
    int value = 12;
    int otherValue = 17;
    Node node = createNode(map(indexProperty, value, otherProperty, otherValue));
    // THEN
    assertThat(writer.updatesCommitted.size()).isEqualTo(0);
    // AND WHEN
    try (Transaction tx = db.beginTx()) {
        node = tx.getNodeById(node.getId());
        node.addLabel(myLabel);
        tx.commit();
    }
    // THEN
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        TokenRead tokenRead = ktx.tokenRead();
        int propertyKey1 = tokenRead.propertyKey(indexProperty);
        int label = tokenRead.nodeLabel(myLabel.name());
        LabelSchemaDescriptor descriptor = SchemaDescriptor.forLabel(label, propertyKey1);
        assertThat(writer.updatesCommitted).isEqualTo(asSet(IndexEntryUpdate.add(node.getId(), descriptor, Values.of(value))));
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Node(org.neo4j.graphdb.Node) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Test(org.junit.jupiter.api.Test)

Example 14 with LabelSchemaDescriptor

use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.

the class IndexStatisticsTest method createPersonNameIndex.

private IndexDescriptor createPersonNameIndex() throws KernelException {
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        int labelId = ktx.tokenWrite().labelGetOrCreateForName(PERSON_LABEL);
        int propertyKeyId = ktx.tokenWrite().propertyKeyGetOrCreateForName(NAME_PROPERTY);
        LabelSchemaDescriptor schema = forLabel(labelId, propertyKeyId);
        var index = ktx.schemaWrite().indexCreate(schema, "my index");
        tx.commit();
        return index;
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction)

Example 15 with LabelSchemaDescriptor

use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.

the class IndexEntryConflictExceptionTest method shouldMakeEntryConflictsForOneNode.

@Test
void shouldMakeEntryConflictsForOneNode() {
    LabelSchemaDescriptor schema = SchemaDescriptor.forLabel(labelId, 2);
    IndexEntryConflictException e = new IndexEntryConflictException(0L, StatementConstants.NO_SUCH_NODE, value);
    assertThat(e.evidenceMessage(tokens, schema)).isEqualTo("Node(0) already exists with label `label1` and property `p2` = 'hi'");
}
Also used : LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)63 Test (org.junit.jupiter.api.Test)41 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)24 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)16 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)5 UniquenessConstraintDescriptor (org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)5 Value (org.neo4j.values.storable.Value)5 Transaction (org.neo4j.graphdb.Transaction)4 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)4 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)4 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)4 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 RepeatedTest (org.junit.jupiter.api.RepeatedTest)3 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)3 Node (org.neo4j.graphdb.Node)3 TokenRead (org.neo4j.internal.kernel.api.TokenRead)3 TokenWrite (org.neo4j.internal.kernel.api.TokenWrite)3 IndexConfig (org.neo4j.internal.schema.IndexConfig)3