Search in sources :

Example 1 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 2 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)

Example 3 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 4 with LabelSchemaDescriptor

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

the class BatchInserterImpl method verifyIndexOrUniquenessConstraintCanBeCreated.

private void verifyIndexOrUniquenessConstraintCanBeCreated(int labelId, int[] propertyKeyIds, String errorMessage) {
    LabelSchemaDescriptor schemaDescriptor = SchemaDescriptorFactory.forLabel(labelId, propertyKeyIds);
    ConstraintDescriptor constraintDescriptor = ConstraintDescriptorFactory.uniqueForLabel(labelId, propertyKeyIds);
    if (schemaCache.hasIndexRule(schemaDescriptor) || schemaCache.hasConstraintRule(constraintDescriptor)) {
        throw new ConstraintViolationException(errorMessage);
    }
}
Also used : ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)

Example 5 with LabelSchemaDescriptor

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

the class SchemaRuleSerialization method readIndexRule.

// PRIVATE
// READ INDEX
private static IndexRule readIndexRule(long id, ByteBuffer source) throws MalformedSchemaRuleException {
    SchemaIndexProvider.Descriptor indexProvider = readIndexProviderDescriptor(source);
    LabelSchemaDescriptor schema;
    byte indexRuleType = source.get();
    String name;
    switch(indexRuleType) {
        case GENERAL_INDEX:
            schema = readLabelSchema(source);
            name = readRuleName(id, IndexRule.class, source);
            return IndexRule.indexRule(id, NewIndexDescriptorFactory.forSchema(schema), indexProvider, name);
        case UNIQUE_INDEX:
            long owningConstraint = source.getLong();
            schema = readLabelSchema(source);
            NewIndexDescriptor descriptor = NewIndexDescriptorFactory.uniqueForSchema(schema);
            name = readRuleName(id, IndexRule.class, source);
            return IndexRule.constraintIndexRule(id, descriptor, indexProvider, owningConstraint == NO_OWNING_CONSTRAINT_YET ? null : owningConstraint, name);
        default:
            throw new MalformedSchemaRuleException(format("Got unknown index rule type '%d'.", indexRuleType));
    }
}
Also used : SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) MalformedSchemaRuleException(org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)

Aggregations

LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)10 Test (org.junit.Test)4 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)4 PrimitiveIntSet (org.neo4j.collection.primitive.PrimitiveIntSet)2 Statement (org.neo4j.kernel.api.Statement)2 NodeItem (org.neo4j.storageengine.api.NodeItem)2 HashMap (java.util.HashMap)1 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)1 Transaction (org.neo4j.graphdb.Transaction)1 Pair (org.neo4j.helpers.collection.Pair)1 SchemaWriteOperations (org.neo4j.kernel.api.SchemaWriteOperations)1 ConstraintValidationException (org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException)1 CreateConstraintFailureException (org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException)1 MalformedSchemaRuleException (org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException)1 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)1 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)1 ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)1 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)1 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)1 StoreStatement (org.neo4j.kernel.impl.api.store.StoreStatement)1