Search in sources :

Example 16 with LabelSchemaDescriptor

use of org.neo4j.internal.schema.LabelSchemaDescriptor 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 17 with LabelSchemaDescriptor

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

the class SchemaDescriptorTest method shouldCreateEqualLabels.

@Test
void shouldCreateEqualLabels() {
    LabelSchemaDescriptor desc1 = SchemaDescriptor.forLabel(LABEL_ID, 1);
    LabelSchemaDescriptor desc2 = SchemaDescriptor.forLabel(LABEL_ID, 1);
    SchemaTestUtil.assertEquality(desc1, desc2);
}
Also used : LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with LabelSchemaDescriptor

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

the class SchemaRuleDeserializer2_0to3_1 method readIndexRule.

// === INDEX RULES ===
private static IndexDescriptor readIndexRule(long id, boolean constraintIndex, int label, ByteBuffer serialized) {
    String providerKey = getDecodedStringFrom(serialized);
    String providerVersion = getDecodedStringFrom(serialized);
    IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor(providerKey, providerVersion);
    int[] propertyKeyIds = readIndexPropertyKeys(serialized);
    LabelSchemaDescriptor schema = SchemaDescriptor.forLabel(label, propertyKeyIds);
    String name = defaultIndexName(id);
    if (constraintIndex) {
        return IndexPrototype.uniqueForSchema(schema, providerDescriptor).withName(name).materialise(id).withOwningConstraintId(readOwningConstraint(serialized));
    } else {
        return IndexPrototype.forSchema(schema, providerDescriptor).withName(name).materialise(id);
    }
}
Also used : IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor)

Example 19 with LabelSchemaDescriptor

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

the class IndexRecoveryIT method createSomeBananas.

private Set<IndexEntryUpdate<?>> createSomeBananas(Label label) {
    Set<IndexEntryUpdate<?>> updates = new HashSet<>();
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        int labelId = ktx.tokenRead().nodeLabel(label.name());
        int propertyKeyId = ktx.tokenRead().propertyKey(key);
        LabelSchemaDescriptor schemaDescriptor = SchemaDescriptor.forLabel(labelId, propertyKeyId);
        for (int number : new int[] { 4, 10 }) {
            Node node = tx.createNode(label);
            node.setProperty(key, number);
            updates.add(IndexEntryUpdate.add(node.getId(), schemaDescriptor, Values.of(number)));
        }
        tx.commit();
        return updates;
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) 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) HashSet(java.util.HashSet)

Example 20 with LabelSchemaDescriptor

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

the class IndexIT method createIndexesForDifferentLabelsConcurrently.

@Test
@Timeout(10)
void createIndexesForDifferentLabelsConcurrently() throws Throwable {
    TokenWrite tokenWrite = tokenWriteInNewTransaction();
    int label2 = tokenWrite.labelGetOrCreateForName("Label2");
    commit();
    LabelSchemaDescriptor anotherLabelDescriptor = SchemaDescriptor.forLabel(label2, propertyKeyId);
    schemaWriteInNewTransaction().indexCreate(anotherLabelDescriptor, "my index");
    Future<?> indexFuture = executorService.submit(createIndex(db, label(LABEL), PROPERTY_KEY));
    indexFuture.get();
    commit();
}
Also used : TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest) Timeout(org.junit.jupiter.api.Timeout)

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