use of org.neo4j.internal.kernel.api.TokenRead 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);
}
use of org.neo4j.internal.kernel.api.TokenRead 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.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class GraphDbStructureGuide method showRelCounts.
private static void showRelCounts(InternalTransaction transaction, DbStructureVisitor visitor) {
// all wildcards
KernelTransaction ktx = transaction.kernelTransaction();
noSide(ktx, visitor, WILDCARD_REL_TYPE, ANY_RELATIONSHIP_TYPE);
TokenRead tokenRead = ktx.tokenRead();
// one label only
for (Label label : transaction.getAllLabels()) {
int labelId = tokenRead.nodeLabel(label.name());
leftSide(ktx, visitor, label, labelId, WILDCARD_REL_TYPE, ANY_RELATIONSHIP_TYPE);
rightSide(ktx, visitor, label, labelId, WILDCARD_REL_TYPE, ANY_RELATIONSHIP_TYPE);
}
// fixed rel type
for (RelationshipType relType : transaction.getAllRelationshipTypes()) {
int relTypeId = tokenRead.relationshipType(relType.name());
noSide(ktx, visitor, relType, relTypeId);
for (Label label : transaction.getAllLabels()) {
int labelId = tokenRead.nodeLabel(label.name());
// wildcard on right
leftSide(ktx, visitor, label, labelId, relType, relTypeId);
// wildcard on left
rightSide(ktx, visitor, label, labelId, relType, relTypeId);
}
}
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class GraphCountsSection method retrieve.
static Stream<RetrieveResult> retrieve(Kernel kernel, Anonymizer anonymizer) throws TransactionFailureException, IndexNotFoundKernelException {
try (KernelTransaction tx = kernel.beginTransaction(KernelTransaction.Type.EXPLICIT, LoginContext.AUTH_DISABLED)) {
TokenRead tokens = tx.tokenRead();
Read read = tx.dataRead();
Map<String, Object> data = new HashMap<>();
data.put("nodes", nodeCounts(tokens, read, anonymizer));
data.put("relationships", relationshipCounts(tokens, read, anonymizer));
data.put("indexes", indexes(tokens, tx.schemaRead(), anonymizer));
data.put("constraints", constraints(tokens, tx.schemaRead(), anonymizer));
return Stream.of(new RetrieveResult(Sections.GRAPH_COUNTS, data));
}
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class GraphCountsSection method constraints.
private static List<Map<String, Object>> constraints(TokenRead tokens, SchemaRead schemaRead, Anonymizer anonymizer) {
List<Map<String, Object>> constraints = new ArrayList<>();
Iterator<ConstraintDescriptor> iterator = schemaRead.constraintsGetAll();
while (iterator.hasNext()) {
ConstraintDescriptor constraint = iterator.next();
EntityType entityType = constraint.schema().entityType();
Map<String, Object> data = new HashMap<>();
data.put("properties", map(constraint.schema().getPropertyIds(), id -> anonymizer.propertyKey(tokens.propertyKeyGetName(id), id)));
data.put("type", constraintType(constraint));
int entityTokenId = constraint.schema().getEntityTokenIds()[0];
switch(entityType) {
case NODE:
data.put("label", anonymizer.label(tokens.labelGetName(entityTokenId), entityTokenId));
constraints.add(data);
break;
case RELATIONSHIP:
data.put("relationshipType", anonymizer.relationshipType(tokens.relationshipTypeGetName(entityTokenId), entityTokenId));
constraints.add(data);
break;
default:
}
}
return constraints;
}
Aggregations