use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.
the class RelationshipCountsTest method countsForRelationship.
/**
* @param start the label of the start node of relationships to get the number of, or {@code null} for "any".
* @param type the type of the relationships to get the number of, or {@code null} for "any".
* @param end the label of the end node of relationships to get the number of, or {@code null} for "any".
*/
private long countsForRelationship(Transaction tx, Label start, RelationshipType type, Label end) {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
TokenRead tokenRead = ktx.tokenRead();
int startId;
int typeId;
int endId;
// start
if (start == null) {
startId = TokenRead.ANY_LABEL;
} else {
if (TokenRead.NO_TOKEN == (startId = tokenRead.nodeLabel(start.name()))) {
return 0;
}
}
// type
if (type == null) {
typeId = TokenRead.ANY_RELATIONSHIP_TYPE;
} else {
if (TokenRead.NO_TOKEN == (typeId = tokenRead.relationshipType(type.name()))) {
return 0;
}
}
// end
if (end == null) {
endId = TokenRead.ANY_LABEL;
} else {
if (TokenRead.NO_TOKEN == (endId = tokenRead.nodeLabel(end.name()))) {
return 0;
}
}
return ktx.dataRead().countsForRelationship(startId, typeId, endId);
}
use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.
the class DefaultValueMapperTest method shouldMapDirectRelationship.
@Test
void shouldMapDirectRelationship() {
// Given
Node start, end;
Relationship relationship;
try (Transaction tx = db.beginTx()) {
start = tx.createNode();
end = tx.createNode();
relationship = start.createRelationshipTo(end, RelationshipType.withName("R"));
tx.commit();
}
RelationshipValue relationshipValue = VirtualValues.relationshipValue(relationship.getId(), nodeValue(start.getId(), Values.EMPTY_TEXT_ARRAY, EMPTY_MAP), nodeValue(start.getId(), Values.EMPTY_TEXT_ARRAY, EMPTY_MAP), stringValue("R"), EMPTY_MAP);
// Then
try (Transaction tx = db.beginTx()) {
var mapper = new DefaultValueMapper((InternalTransaction) tx);
Relationship coreAPIRelationship = mapper.mapRelationship(relationshipValue);
assertThat(coreAPIRelationship.getId()).isEqualTo(relationship.getId());
assertThat(coreAPIRelationship.getStartNode()).isEqualTo(start);
assertThat(coreAPIRelationship.getEndNode()).isEqualTo(end);
}
}
use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.
the class DefaultValueMapperTest method shouldHandleLongPath.
@Test
void shouldHandleLongPath() {
// Given
Node a, b, c, d, e;
Relationship r1, r2, r3, r4;
try (Transaction tx = db.beginTx()) {
a = tx.createNode();
b = tx.createNode();
c = tx.createNode();
d = tx.createNode();
e = tx.createNode();
r1 = a.createRelationshipTo(b, RelationshipType.withName("R"));
r2 = b.createRelationshipTo(c, RelationshipType.withName("R"));
r3 = c.createRelationshipTo(d, RelationshipType.withName("R"));
r4 = d.createRelationshipTo(e, RelationshipType.withName("R"));
tx.commit();
}
// Then
try (Transaction tx = db.beginTx()) {
var mapper = new DefaultValueMapper((InternalTransaction) tx);
Path mapped = mapper.mapPath(path(asNodeValues(a, b, c, d, e), asRelationshipsValues(r1, r2, r3, r4)));
assertThat(mapped.length()).isEqualTo(4);
assertThat(mapped.startNode()).isEqualTo(a);
assertThat(mapped.endNode()).isEqualTo(e);
assertThat(Iterables.asList(mapped.relationships())).isEqualTo(Arrays.asList(r1, r2, r3, r4));
assertThat(Iterables.asList(mapped.reverseRelationships())).isEqualTo(Arrays.asList(r4, r3, r2, r1));
assertThat(Iterables.asList(mapped.nodes())).isEqualTo(Arrays.asList(a, b, c, d, e));
assertThat(Iterables.asList(mapped.reverseNodes())).isEqualTo(Arrays.asList(e, d, c, b, a));
assertThat(mapped.lastRelationship()).isEqualTo(r4);
assertThat(Iterators.asList(mapped.iterator())).isEqualTo(Arrays.asList(a, r1, b, r2, c, r3, d, r4, e));
}
}
use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.
the class GraphDbStructureGuide method accept.
@Override
public void accept(DbStructureVisitor visitor) {
try (Transaction tx = db.beginTx()) {
showStructure((InternalTransaction) tx, visitor);
tx.commit();
}
}
use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.
the class IndexRecoveryIT method createSomeBananas.
private Set<IndexEntryUpdate<?>> createSomeBananas(Label label) {
Set<IndexEntryUpdate<?>> updates = new HashSet<>();
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
int labelId = ktx.tokenRead().nodeLabel(label.name());
int propertyKeyId = ktx.tokenRead().propertyKey(key);
LabelSchemaDescriptor schemaDescriptor = SchemaDescriptor.forLabel(labelId, propertyKeyId);
for (int number : new int[] { 4, 10 }) {
Node node = tx.createNode(label);
node.setProperty(key, number);
updates.add(IndexEntryUpdate.add(node.getId(), schemaDescriptor, Values.of(number)));
}
tx.commit();
return updates;
}
}
Aggregations