use of org.neo4j.ogm.session.request.strategy.impl.CountStatements in project neo4j-ogm by neo4j.
the class ExecuteQueriesDelegate method count.
public long count(Class<?> clazz, Iterable<Filter> filters) {
ClassInfo classInfo = session.metaData().classInfo(clazz.getSimpleName());
if (classInfo != null) {
resolvePropertyAnnotations(clazz, filters);
CypherQuery query;
if (classInfo.isRelationshipEntity()) {
query = new CountStatements().countEdges(classInfo.neo4jName(), filters);
} else {
query = new CountStatements().countNodes(classInfo.neo4jName(), filters);
}
return count(query, classInfo.isRelationshipEntity());
}
throw new RuntimeException(clazz.getName() + " is not a persistable class");
}
use of org.neo4j.ogm.session.request.strategy.impl.CountStatements in project neo4j-ogm by neo4j.
the class ExecuteQueriesDelegate method countEntitiesOfType.
public long countEntitiesOfType(Class<?> entity) {
ClassInfo classInfo = session.metaData().classInfo(entity.getName());
if (classInfo == null) {
return 0;
}
CypherQuery countStatement;
if (classInfo.isRelationshipEntity()) {
ClassInfo startNodeInfo = null;
ClassInfo endNodeInfo = null;
for (FieldInfo fieldInfo : classInfo.fieldsInfo().fields()) {
if (fieldInfo.hasAnnotation(StartNode.class)) {
startNodeInfo = session.metaData().classInfo(DescriptorMappings.getType(fieldInfo.getTypeDescriptor()).getName());
} else if (fieldInfo.hasAnnotation(EndNode.class)) {
endNodeInfo = session.metaData().classInfo(DescriptorMappings.getType(fieldInfo.getTypeDescriptor()).getName());
}
if (endNodeInfo != null && startNodeInfo != null) {
break;
}
}
String start = startNodeInfo.neo4jName();
String end = endNodeInfo.neo4jName();
String type = classInfo.neo4jName();
countStatement = new CountStatements().countEdges(start, type, end);
} else {
Collection<String> labels = classInfo.staticLabels();
if (labels.isEmpty()) {
return 0;
}
countStatement = new CountStatements().countNodes(labels);
}
return session.doInTransaction(() -> {
try (Response<RowModel> response = session.requestHandler().execute((RowModelRequest) countStatement)) {
RowModel queryResult = response.next();
return queryResult == null ? 0 : ((Number) queryResult.getValues()[0]).longValue();
}
}, Transaction.Type.READ_ONLY);
}
Aggregations