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);
}
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);
}
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));
}
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));
}
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));
}
Aggregations