use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.
the class IndexStatisticsTest method createSomePersons.
private void createSomePersons() throws KernelException {
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
createPersonNode(ktx, "Davide");
createPersonNode(ktx, "Stefan");
createPersonNode(ktx, "John");
createPersonNode(ktx, "John");
tx.commit();
}
}
use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.
the class IndexCRUDIT method addingALabelToPreExistingNodeShouldGetIndexed.
@Test
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()).isEqualTo(0);
// AND WHEN
try (Transaction tx = db.beginTx()) {
node = tx.getNodeById(node.getId());
node.addLabel(myLabel);
tx.commit();
}
// THEN
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
TokenRead tokenRead = ktx.tokenRead();
int propertyKey1 = tokenRead.propertyKey(indexProperty);
int label = tokenRead.nodeLabel(myLabel.name());
LabelSchemaDescriptor descriptor = SchemaDescriptor.forLabel(label, propertyKey1);
assertThat(writer.updatesCommitted).isEqualTo(asSet(IndexEntryUpdate.add(node.getId(), descriptor, Values.of(value))));
tx.commit();
}
}
use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.
the class IndexStatisticsTest method createPersonNameIndex.
private IndexDescriptor createPersonNameIndex() throws KernelException {
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
int labelId = ktx.tokenWrite().labelGetOrCreateForName(PERSON_LABEL);
int propertyKeyId = ktx.tokenWrite().propertyKeyGetOrCreateForName(NAME_PROPERTY);
LabelSchemaDescriptor schema = forLabel(labelId, propertyKeyId);
var index = ktx.schemaWrite().indexCreate(schema, "my index");
tx.commit();
return index;
}
}
use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.
the class LabelCountsTest method countsForNode.
/**
* @param label the label to get the number of nodes of, or {@code null} to get the total number of nodes.
*/
private long countsForNode(Transaction tx, Label label) {
KernelTransaction transaction = ((InternalTransaction) tx).kernelTransaction();
Read read = transaction.dataRead();
int labelId;
if (label == null) {
labelId = ANY_LABEL;
} else {
if (TokenRead.NO_TOKEN == (labelId = transaction.tokenRead().nodeLabel(label.name()))) {
return 0;
}
}
return read.countsForNode(labelId);
}
use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.
the class CompositeCountsTest 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 transaction = ((InternalTransaction) tx).kernelTransaction();
TokenRead tokenRead = transaction.tokenRead();
int startId;
int typeId;
int endId;
// start
if (start == null) {
startId = ANY_LABEL;
} else {
if (TokenRead.NO_TOKEN == (startId = tokenRead.nodeLabel(start.name()))) {
return 0;
}
}
// type
if (type == null) {
typeId = TokenRead.NO_TOKEN;
} else {
if (TokenRead.NO_TOKEN == (typeId = tokenRead.relationshipType(type.name()))) {
return 0;
}
}
// end
if (end == null) {
endId = ANY_LABEL;
} else {
if (TokenRead.NO_TOKEN == (endId = tokenRead.nodeLabel(end.name()))) {
return 0;
}
}
return transaction.dataRead().countsForRelationship(startId, typeId, endId);
}
Aggregations