Search in sources :

Example 16 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class GraphDatabaseFacade method nodesByLabelAndProperty.

private ResourceIterator<Node> nodesByLabelAndProperty(Label myLabel, String key, Object value) {
    Statement statement = spi.currentStatement();
    ReadOperations readOps = statement.readOperations();
    int propertyId = readOps.propertyKeyGetForName(key);
    int labelId = readOps.labelGetForName(myLabel.name());
    if (propertyId == NO_SUCH_PROPERTY_KEY || labelId == NO_SUCH_LABEL) {
        statement.close();
        return emptyIterator();
    }
    NewIndexDescriptor descriptor = findAnyIndexByLabelAndProperty(readOps, propertyId, labelId);
    try {
        if (null != descriptor) {
            // Ha! We found an index - let's use it to find matching nodes
            IndexQuery.ExactPredicate query = IndexQuery.exact(descriptor.schema().getPropertyId(), value);
            return map2nodes(readOps.indexQuery(descriptor, query), statement);
        }
    } catch (KernelException e) {
    // weird at this point but ignore and fallback to a label scan
    }
    return getNodesByLabelAndPropertyWithoutIndex(propertyId, value, statement, labelId);
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) Statement(org.neo4j.kernel.api.Statement) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) InvalidTransactionTypeKernelException(org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) SchemaKernelException(org.neo4j.kernel.api.exceptions.schema.SchemaKernelException)

Example 17 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class SchemaRuleDeserializer2_0to3_1 method readIndexRule.

// === INDEX RULES ===
private static IndexRule readIndexRule(long id, boolean constraintIndex, int label, ByteBuffer serialized) {
    SchemaIndexProvider.Descriptor providerDescriptor = readIndexProviderDescriptor(serialized);
    int[] propertyKeyIds = readIndexPropertyKeys(serialized);
    NewIndexDescriptor descriptor = constraintIndex ? NewIndexDescriptorFactory.uniqueForLabel(label, propertyKeyIds) : NewIndexDescriptorFactory.forLabel(label, propertyKeyIds);
    long owningConstraint = constraintIndex ? readOwningConstraint(serialized) : NO_OWNING_CONSTRAINT;
    return new IndexRule(id, providerDescriptor, descriptor, owningConstraint);
}
Also used : SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)

Example 18 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class SchemaTransactionStateTest method shouldNotReturnExistentRuleDroppedInTransaction.

@Test
public void shouldNotReturnExistentRuleDroppedInTransaction() throws Exception {
    // GIVEN
    // -- a rule that exists in the store
    NewIndexDescriptor index = NewIndexDescriptorFactory.forLabel(labelId1, key1);
    when(store.indexesGetForLabel(labelId1)).thenReturn(option(index).iterator());
    // -- that same rule dropped in the transaction
    txContext.indexDrop(state, index);
    // WHEN
    assertNull(indexGetForLabelAndPropertyKey(txContext, state, labelId1, key1));
    Iterator<NewIndexDescriptor> rulesByLabel = txContext.indexesGetForLabel(state, labelId1);
    // THEN
    assertEquals(emptySetOf(NewIndexDescriptor.class), asSet(rulesByLabel));
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Test(org.junit.Test)

Example 19 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class SchemaTransactionStateTest method creatingAnIndexShouldBePopulatingStateWithinTX.

@Test
public void creatingAnIndexShouldBePopulatingStateWithinTX() throws Exception {
    // GIVEN
    commitLabels(labelId1);
    NewIndexDescriptor rule = indexCreate(txContext, state, labelId1, key1);
    // THEN
    assertEquals(InternalIndexState.POPULATING, txContext.indexGetState(state, rule));
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Test(org.junit.Test)

Example 20 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class SchemaTransactionStateTest method shouldReturnNonExistentRuleAddedInTransaction.

@Test
public void shouldReturnNonExistentRuleAddedInTransaction() throws Exception {
    // GIVEN
    // -- non-existent rule added in the transaction
    indexCreate(txContext, state, labelId1, key1);
    // WHEN
    NewIndexDescriptor index = indexGetForLabelAndPropertyKey(txContext, state, labelId1, key1);
    Iterator<NewIndexDescriptor> labelRules = txContext.indexesGetForLabel(state, labelId1);
    // THEN
    NewIndexDescriptor expectedRule = NewIndexDescriptorFactory.forLabel(labelId1, key1);
    assertEquals(expectedRule, index);
    assertEquals(asSet(expectedRule), asSet(labelRules));
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Test(org.junit.Test)

Aggregations

NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)99 Test (org.junit.Test)55 Statement (org.neo4j.kernel.api.Statement)24 ReadOperations (org.neo4j.kernel.api.ReadOperations)17 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)10 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)9 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)9 InternalIndexState (org.neo4j.kernel.api.index.InternalIndexState)7 Transaction (org.neo4j.graphdb.Transaction)6 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)5 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)5 SchemaRuleNotFoundException (org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException)5 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Label (org.neo4j.graphdb.Label)4 NotFoundException (org.neo4j.graphdb.NotFoundException)4 KernelException (org.neo4j.kernel.api.exceptions.KernelException)4 NodePropertyDescriptor (org.neo4j.kernel.api.schema.NodePropertyDescriptor)4