use of org.neo4j.kernel.api.ReadOperations 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.ReadOperations 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.ReadOperations in project neo4j by neo4j.
the class LabelIT method shouldListAllLabels.
@Test
public void shouldListAllLabels() throws Exception {
// given
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
int label1Id = statement.tokenWriteOperations().labelGetOrCreateForName("label1");
int label2Id = statement.tokenWriteOperations().labelGetOrCreateForName("label2");
// when
Iterator<Token> labelIdsBeforeCommit = statement.readOperations().labelsGetAllTokens();
// then
assertThat(asCollection(labelIdsBeforeCommit), hasItems(new Token("label1", label1Id), new Token("label2", label2Id)));
// when
commit();
ReadOperations readOperations = readOperationsInNewTransaction();
Iterator<Token> labelIdsAfterCommit = readOperations.labelsGetAllTokens();
// then
assertThat(asCollection(labelIdsAfterCommit), hasItems(new Token("label1", label1Id), new Token("label2", label2Id)));
}
use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.
the class NodeGetUniqueFromIndexSeekIT method shouldNotCompositeFindNonMatchingNode.
@Test
public void shouldNotCompositeFindNonMatchingNode() throws Exception {
// given
NewIndexDescriptor index = createUniquenessConstraint(labelId, propertyId1, propertyId2);
String value1 = "value1";
String value2 = "value2";
createNodeWithValues("other_" + value1, "other_" + value2);
// when looking for it
ReadOperations readOperations = readOperationsInNewTransaction();
long foundId = readOperations.nodeGetFromUniqueIndexSeek(index, exact(propertyId1, value1), exact(propertyId2, value2));
commit();
// then
assertTrue("Non-matching created node was found", isNoSuchNode(foundId));
}
use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.
the class PropertyIT method nodeHasNotPropertyIfUnset.
@Test
public void nodeHasNotPropertyIfUnset() throws Exception {
// GIVEN
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
long nodeId = statement.dataWriteOperations().nodeCreate();
// WHEN
int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("clown");
// THEN
assertThat(statement.readOperations().nodeHasProperty(nodeId, propertyKeyId), is(false));
assertThat(statement.readOperations().nodeGetProperty(nodeId, propertyKeyId), nullValue());
// WHEN
commit();
ReadOperations readOperations = readOperationsInNewTransaction();
// THEN
assertThat(readOperations.nodeHasProperty(nodeId, propertyKeyId), is(false));
assertThat(readOperations.nodeGetProperty(nodeId, propertyKeyId), nullValue());
}
Aggregations