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;
}
}
use of org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor in project neo4j by neo4j.
the class IndexCRUDIT method addingALabelToPreExistingNodeShouldGetIndexed.
@Test
public void addingALabelToPreExistingNodeShouldGetIndexed() throws Exception {
// GIVEN
String indexProperty = "indexProperty";
GatheringIndexWriter writer = newWriter();
createIndex(db, myLabel, indexProperty);
// WHEN
String otherProperty = "otherProperty";
int value = 12;
int otherValue = 17;
Node node = createNode(map(indexProperty, value, otherProperty, otherValue));
// THEN
assertThat(writer.updatesCommitted.size(), equalTo(0));
// AND WHEN
try (Transaction tx = db.beginTx()) {
node.addLabel(myLabel);
tx.success();
}
// THEN
try (Transaction tx = db.beginTx()) {
ReadOperations readOperations = ctxSupplier.get().readOperations();
int propertyKey1 = readOperations.propertyKeyGetForName(indexProperty);
int label = readOperations.labelGetForName(myLabel.name());
LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(label, propertyKey1);
assertThat(writer.updatesCommitted, equalTo(asSet(IndexEntryUpdate.add(node.getId(), descriptor, value))));
tx.success();
}
}
use of org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor in project neo4j by neo4j.
the class IndexEntryConflictExceptionTest method shouldMakeEntryConflictsForOneNode.
@Test
public void shouldMakeEntryConflictsForOneNode() {
LabelSchemaDescriptor schema = SchemaDescriptorFactory.forLabel(labelId, 2);
IndexEntryConflictException e = new IndexEntryConflictException(0L, StatementConstants.NO_SUCH_NODE, "hi");
assertThat(e.evidenceMessage(SchemaUtil.idTokenNameLookup, schema), equalTo("Node(0) already exists with label `label[1]` and property `property[2]` = 'hi'"));
}
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);
}
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);
}
}
}
}
Aggregations