Search in sources :

Example 6 with LabelSchemaDescriptor

use of org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor in project neo4j by neo4j.

the class IndexStatisticsTest method createIndex.

private NewIndexDescriptor createIndex(String labelName, String propertyKeyName) throws KernelException {
    try (Transaction tx = db.beginTx()) {
        Statement statement = bridge.get();
        int labelId = statement.tokenWriteOperations().labelGetOrCreateForName(labelName);
        int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName(propertyKeyName);
        LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(labelId, propertyKeyId);
        NewIndexDescriptor index = statement.schemaWriteOperations().indexCreate(descriptor);
        tx.success();
        return index;
    }
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Transaction(org.neo4j.graphdb.Transaction) Statement(org.neo4j.kernel.api.Statement) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)

Example 7 with LabelSchemaDescriptor

use of org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor in project neo4j by neo4j.

the class IndexCRUDIT method addingALabelToPreExistingNodeShouldGetIndexed.

@Test
public 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(), equalTo(0));
    // AND WHEN
    try (Transaction tx = db.beginTx()) {
        node.addLabel(myLabel);
        tx.success();
    }
    // THEN
    try (Transaction tx = db.beginTx()) {
        ReadOperations readOperations = ctxSupplier.get().readOperations();
        int propertyKey1 = readOperations.propertyKeyGetForName(indexProperty);
        int label = readOperations.labelGetForName(myLabel.name());
        LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(label, propertyKey1);
        assertThat(writer.updatesCommitted, equalTo(asSet(IndexEntryUpdate.add(node.getId(), descriptor, value))));
        tx.success();
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) Test(org.junit.Test)

Example 8 with LabelSchemaDescriptor

use of org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor in project neo4j by neo4j.

the class IndexEntryConflictExceptionTest method shouldMakeEntryConflictsForOneNode.

@Test
public void shouldMakeEntryConflictsForOneNode() {
    LabelSchemaDescriptor schema = SchemaDescriptorFactory.forLabel(labelId, 2);
    IndexEntryConflictException e = new IndexEntryConflictException(0L, StatementConstants.NO_SUCH_NODE, "hi");
    assertThat(e.evidenceMessage(SchemaUtil.idTokenNameLookup, schema), equalTo("Node(0) already exists with label `label[1]` and property `property[2]` = 'hi'"));
}
Also used : LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) Test(org.junit.Test)

Example 9 with LabelSchemaDescriptor

use of org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor in project neo4j by neo4j.

the class MultipleIndexPopulator method newPopulatingUpdater.

@Override
public MultipleIndexUpdater newPopulatingUpdater(PropertyAccessor accessor) {
    Map<LabelSchemaDescriptor, Pair<IndexPopulation, IndexUpdater>> updaters = new HashMap<>();
    forEachPopulation(population -> {
        IndexUpdater updater = population.populator.newPopulatingUpdater(accessor);
        updaters.put(population.descriptor.schema(), Pair.of(population, updater));
    });
    return new MultipleIndexUpdater(this, updaters, logProvider);
}
Also used : HashMap(java.util.HashMap) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Pair(org.neo4j.helpers.collection.Pair)

Example 10 with LabelSchemaDescriptor

use of org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor in project neo4j by neo4j.

the class NodeSchemaMatcher method onMatchingSchema.

/**
     * Iterate over some schema suppliers, and invoke an action for every supplier that matches the node. To match the
     * node N the supplier must supply a LabelSchemaDescriptor D, such that N has the label of D, and values for all
     * the properties of D.
     *
     * To avoid unnecessary store lookups, this implementation only gets propertyKeyIds for the node if some
     * descriptor has a valid label.
     *
     * @param state The current statement
     * @param schemaSuppliers The suppliers to match
     * @param node The node
     * @param specialPropertyId This property id will always count as a match for the descriptor, regardless of
     *                          whether the node has this property or not
     * @param action The action to take on match
     * @param <EXCEPTION> The type of exception that can be thrown when taking the action
     * @throws EXCEPTION This exception is propagated from the action
     */
public <EXCEPTION extends Exception> void onMatchingSchema(KernelStatement state, Iterator<SUPPLIER> schemaSuppliers, NodeItem node, int specialPropertyId, SchemaMatchAction<SUPPLIER, EXCEPTION> action) throws EXCEPTION {
    PrimitiveIntSet nodePropertyIds = null;
    while (schemaSuppliers.hasNext()) {
        SUPPLIER schemaSupplier = schemaSuppliers.next();
        LabelSchemaDescriptor schema = schemaSupplier.schema();
        if (node.labels().contains(schema.getLabelId())) {
            if (nodePropertyIds == null) {
                nodePropertyIds = Primitive.intSet();
                nodePropertyIds.addAll(readOps.nodeGetPropertyKeys(state, node).iterator());
            }
            if (nodeHasSchemaProperties(nodePropertyIds, schema.getPropertyIds(), specialPropertyId)) {
                action.act(schemaSupplier);
            }
        }
    }
}
Also used : PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)

Aggregations

LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)23 Test (org.junit.Test)12 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)5 Transaction (org.neo4j.graphdb.Transaction)4 Statement (org.neo4j.kernel.api.Statement)4 IndexEntryUpdate (org.neo4j.kernel.api.index.IndexEntryUpdate)4 Node (org.neo4j.graphdb.Node)3 Pair (org.neo4j.helpers.collection.Pair)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 PrimitiveIntSet (org.neo4j.collection.primitive.PrimitiveIntSet)2 ReadOperations (org.neo4j.kernel.api.ReadOperations)2 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)2 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)2 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)2 NodeItem (org.neo4j.storageengine.api.NodeItem)2 IOException (java.io.IOException)1 Map (java.util.Map)1 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)1 SchemaWriteOperations (org.neo4j.kernel.api.SchemaWriteOperations)1