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