use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.
the class DataStatementArgumentVerificationTest method shouldAlwaysReturnFalseFromNodeHasLabelForNoSuchLabelConstant.
@Test
public void shouldAlwaysReturnFalseFromNodeHasLabelForNoSuchLabelConstant() throws Exception {
// given
ReadOperations statement = stubStatement();
// when
boolean hasLabel = statement.nodeHasLabel(17, StatementConstants.NO_SUCH_LABEL);
// then
assertFalse("should not contain any ids", hasLabel);
}
use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.
the class IndexCRUDIT method addingANodeWithPropertyShouldGetIndexed.
@Test
public void addingANodeWithPropertyShouldGetIndexed() throws Exception {
// Given
String indexProperty = "indexProperty";
GatheringIndexWriter writer = newWriter();
createIndex(db, myLabel, indexProperty);
// When
int value1 = 12;
String otherProperty = "otherProperty";
int otherValue = 17;
Node node = createNode(map(indexProperty, value1, otherProperty, otherValue), myLabel);
// Then, for now, this should trigger two NodePropertyUpdates
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, value1))));
tx.success();
}
// We get two updates because we both add a label and a property to be indexed
// in the same transaction, in the future, we should optimize this down to
// one NodePropertyUpdate.
}
use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.
the class IndexIT method addIndexRuleInATransaction.
@Test
public void addIndexRuleInATransaction() throws Exception {
// GIVEN
SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction();
// WHEN
NewIndexDescriptor expectedRule = schemaWriteOperations.indexCreate(SchemaBoundary.map(descriptor));
commit();
// THEN
ReadOperations readOperations = readOperationsInNewTransaction();
assertEquals(asSet(expectedRule), asSet(readOperations.indexesGetForLabel(labelId)));
assertEquals(expectedRule, readOperations.indexGetForLabelAndPropertyKey(descriptor));
commit();
}
use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.
the class RelationshipIT method askingForNonExistantReltypeOnDenseNodeShouldNotCorruptState.
@Test
public void askingForNonExistantReltypeOnDenseNodeShouldNotCorruptState() throws Exception {
// Given a dense node with one type of rels
long[] rels = new long[200];
long refNode;
int relTypeTheNodeDoesUse, relTypeTheNodeDoesNotUse;
{
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
relTypeTheNodeDoesUse = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName("Type1");
relTypeTheNodeDoesNotUse = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName("Type2");
refNode = statement.dataWriteOperations().nodeCreate();
long otherNode = statement.dataWriteOperations().nodeCreate();
for (int i = 0; i < rels.length; i++) {
rels[i] = statement.dataWriteOperations().relationshipCreate(relTypeTheNodeDoesUse, refNode, otherNode);
}
commit();
}
ReadOperations stmt = readOperationsInNewTransaction();
// When I've asked for rels that the node does not have
assertRels(stmt.nodeGetRelationships(refNode, Direction.INCOMING, new int[] { relTypeTheNodeDoesNotUse }));
// Then the node should still load the real rels
assertRels(stmt.nodeGetRelationships(refNode, Direction.BOTH, new int[] { relTypeTheNodeDoesUse }), rels);
}
use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.
the class RelationshipIT method shouldListRelationshipsInCurrentAndSubsequentTx.
@Test
public void shouldListRelationshipsInCurrentAndSubsequentTx() throws Exception {
// given
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
int relType1 = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName("Type1");
int relType2 = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName("Type2");
long refNode = statement.dataWriteOperations().nodeCreate();
long otherNode = statement.dataWriteOperations().nodeCreate();
long fromRefToOther1 = statement.dataWriteOperations().relationshipCreate(relType1, refNode, otherNode);
long fromRefToOther2 = statement.dataWriteOperations().relationshipCreate(relType2, refNode, otherNode);
long fromOtherToRef = statement.dataWriteOperations().relationshipCreate(relType1, otherNode, refNode);
long fromRefToRef = statement.dataWriteOperations().relationshipCreate(relType2, refNode, refNode);
long endNode = statement.dataWriteOperations().nodeCreate();
long fromRefToThird = statement.dataWriteOperations().relationshipCreate(relType2, refNode, endNode);
// when & then
assertRels(statement.readOperations().nodeGetRelationships(refNode, BOTH), fromRefToOther1, fromRefToOther2, fromRefToRef, fromRefToThird, fromOtherToRef);
assertRels(statement.readOperations().nodeGetRelationships(refNode, BOTH, new int[] { relType1 }), fromRefToOther1, fromOtherToRef);
assertRels(statement.readOperations().nodeGetRelationships(refNode, BOTH, new int[] { relType1, relType2 }), fromRefToOther1, fromRefToOther2, fromRefToRef, fromRefToThird, fromOtherToRef);
assertRels(statement.readOperations().nodeGetRelationships(refNode, INCOMING), fromOtherToRef);
assertRels(statement.readOperations().nodeGetRelationships(refNode, INCOMING, new int[] { relType1 }));
assertRels(statement.readOperations().nodeGetRelationships(refNode, OUTGOING, new int[] { relType1, relType2 }), fromRefToOther1, fromRefToOther2, fromRefToThird, fromRefToRef);
// when
commit();
ReadOperations readOperations = readOperationsInNewTransaction();
// when & then
assertRels(readOperations.nodeGetRelationships(refNode, BOTH), fromRefToOther1, fromRefToOther2, fromRefToRef, fromRefToThird, fromOtherToRef);
assertRels(readOperations.nodeGetRelationships(refNode, BOTH, new int[] { relType1 }), fromRefToOther1, fromOtherToRef);
assertRels(readOperations.nodeGetRelationships(refNode, BOTH, new int[] { relType1, relType2 }), fromRefToOther1, fromRefToOther2, fromRefToRef, fromRefToThird, fromOtherToRef);
assertRels(readOperations.nodeGetRelationships(refNode, INCOMING), fromOtherToRef);
assertRels(readOperations.nodeGetRelationships(refNode, INCOMING, new int[] { relType1 }));
assertRels(readOperations.nodeGetRelationships(refNode, OUTGOING, new int[] { relType1, relType2 }), fromRefToOther1, fromRefToOther2, fromRefToThird, fromRefToRef);
}
Aggregations