Search in sources :

Example 1 with NewIndexDescriptor

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

the class IndexingAcceptanceTest method shouldSupportIndexSeekByPrefix.

@Test
public void shouldSupportIndexSeekByPrefix() throws SchemaRuleNotFoundException, IndexNotFoundKernelException, IndexNotApplicableKernelException {
    // GIVEN
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    IndexDefinition index = Neo4jMatchers.createIndex(db, LABEL1, "name");
    createNodes(db, LABEL1, "name", "Mattias", "Mats", "Carla");
    PrimitiveLongSet expected = createNodes(db, LABEL1, "name", "Karl", "Karlsson");
    // WHEN
    PrimitiveLongSet found = Primitive.longSet();
    try (Transaction tx = db.beginTx()) {
        Statement statement = getStatement((GraphDatabaseAPI) db);
        ReadOperations ops = statement.readOperations();
        NewIndexDescriptor descriptor = indexDescriptor(ops, index);
        int propertyKeyId = descriptor.schema().getPropertyId();
        found.addAll(ops.indexQuery(descriptor, stringPrefix(propertyKeyId, "Karl")));
    }
    // THEN
    assertThat(found, equalTo(expected));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 2 with NewIndexDescriptor

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

the class IndexingAcceptanceTest method shouldNotIncludeNodesDeletedInSameTxInIndexSeekByPrefix.

@Test
public void shouldNotIncludeNodesDeletedInSameTxInIndexSeekByPrefix() throws SchemaRuleNotFoundException, IndexNotFoundKernelException, IndexNotApplicableKernelException {
    // GIVEN
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    IndexDefinition index = Neo4jMatchers.createIndex(db, LABEL1, "name");
    createNodes(db, LABEL1, "name", "Mattias");
    PrimitiveLongSet toDelete = createNodes(db, LABEL1, "name", "Karlsson", "Mats");
    PrimitiveLongSet expected = createNodes(db, LABEL1, "name", "Karl");
    // WHEN
    PrimitiveLongSet found = Primitive.longSet();
    try (Transaction tx = db.beginTx()) {
        PrimitiveLongIterator deleting = toDelete.iterator();
        while (deleting.hasNext()) {
            long id = deleting.next();
            db.getNodeById(id).delete();
            expected.remove(id);
        }
        Statement statement = getStatement((GraphDatabaseAPI) db);
        ReadOperations readOperations = statement.readOperations();
        NewIndexDescriptor descriptor = indexDescriptor(readOperations, index);
        int propertyKeyId = descriptor.schema().getPropertyId();
        found.addAll(readOperations.indexQuery(descriptor, stringPrefix(propertyKeyId, "Karl")));
    }
    // THEN
    assertThat(found, equalTo(expected));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) ReadOperations(org.neo4j.kernel.api.ReadOperations) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 3 with NewIndexDescriptor

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

the class SchemaRuleSerializationTest method assertParseUniqueIndexRule.

private void assertParseUniqueIndexRule(String serialized, String name) throws MalformedSchemaRuleException {
    // GIVEN
    long ruleId = 33;
    long constraintId = 11;
    NewIndexDescriptor index = NewIndexDescriptorFactory.uniqueForLabel(61, 988);
    SchemaIndexProvider.Descriptor indexProvider = new SchemaIndexProvider.Descriptor("index-provider", "25.0");
    byte[] bytes = decodeBase64(serialized);
    //        System.out.println( encodeBase64( IndexRule.constraintIndexRule( ruleId, index, indexProvider, constraintId, "custom_name" ).serialize() ) );
    // WHEN
    IndexRule deserialized = assertIndexRule(SchemaRuleSerialization.deserialize(ruleId, ByteBuffer.wrap(bytes)));
    // THEN
    assertThat(deserialized.getId(), equalTo(ruleId));
    assertThat(deserialized.getIndexDescriptor(), equalTo(index));
    assertThat(deserialized.schema(), equalTo(index.schema()));
    assertThat(deserialized.getProviderDescriptor(), equalTo(indexProvider));
    assertThat(deserialized.getOwningConstraint(), equalTo(constraintId));
    assertThat(deserialized.getName(), is(name));
}
Also used : SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)

Example 4 with NewIndexDescriptor

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

the class DumpCountsStore method getAllIndexesFrom.

private static Map<Long, NewIndexDescriptor> getAllIndexesFrom(SchemaStorage storage) {
    HashMap<Long, NewIndexDescriptor> indexes = new HashMap<>();
    Iterator<IndexRule> indexRules = storage.indexesGetAll();
    while (indexRules.hasNext()) {
        IndexRule rule = indexRules.next();
        indexes.put(rule.getId(), rule.getIndexDescriptor());
    }
    return indexes;
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) HashMap(java.util.HashMap)

Example 5 with NewIndexDescriptor

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

the class HaCountsIT method createAnIndex.

private NewIndexDescriptor createAnIndex(HighlyAvailableGraphDatabase db, Label label, String propertyName) throws KernelException {
    try (Transaction tx = db.beginTx()) {
        Statement statement = statement(db);
        int labelId = statement.tokenWriteOperations().labelGetOrCreateForName(label.name());
        int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName(propertyName);
        NewIndexDescriptor index = statement.schemaWriteOperations().indexCreate(SchemaDescriptorFactory.forLabel(labelId, propertyKeyId));
        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)

Aggregations

NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)62 Test (org.junit.Test)25 Statement (org.neo4j.kernel.api.Statement)14 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)8 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 ReadOperations (org.neo4j.kernel.api.ReadOperations)7 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)5 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)5 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)4 ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Label (org.neo4j.graphdb.Label)3 RelationshipType (org.neo4j.graphdb.RelationshipType)3 UniquenessConstraint (org.neo4j.kernel.api.constraints.UniquenessConstraint)3 KernelException (org.neo4j.kernel.api.exceptions.KernelException)3 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)3 SchemaRuleNotFoundException (org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException)3 OrderedPropertyValues (org.neo4j.kernel.api.schema_new.OrderedPropertyValues)3