use of org.neo4j.ogm.cypher.query.DefaultGraphRowListModelRequest in project neo4j-ogm by neo4j.
the class LoadByTypeDelegate method loadAll.
/**
* Loads all objects of a given {@code type}. The {@code type} is used to determine the Neo4j label. If no such label
* can be determined, a warning is logged and an immutable, empty list is returned to prevent queries without label
* that potentially can retrieve all objects in the database if no {@link Filters filters} are given.
*
* @param type The type of objects to load.
* @param filters Additional filters to reduce the number of objects loaded, may be null or empty.
* @param sortOrder Sort order to be passed on to the database
* @param pagination Pagination if required
* @param depth Depth of relationships to load
* @param <T> Returned type
* @return A list of objects with the requested type
*/
public <T> Collection<T> loadAll(Class<T> type, Filters filters, SortOrder sortOrder, Pagination pagination, int depth) {
Optional<String> labelsOrType = session.determineLabelsOrTypeForLoading(type);
if (!labelsOrType.isPresent()) {
LOG.warn("Unable to find database label for entity " + type.getName() + " : no results will be returned. Make sure the class is registered, " + "and not abstract without @NodeEntity annotation");
return Collections.emptyList();
}
QueryStatements queryStatements = session.queryStatementsFor(type, depth);
SortOrder sortOrderWithResolvedProperties = sortOrderWithResolvedProperties(type, sortOrder);
PagingAndSortingQuery query;
if (filters == null || filters.isEmpty()) {
query = queryStatements.findByType(labelsOrType.get(), depth);
} else {
resolvePropertyAnnotations(type, filters);
query = queryStatements.findByType(labelsOrType.get(), filters, depth);
}
query.setSortOrder(sortOrderWithResolvedProperties).setPagination(pagination);
return session.doInTransaction(() -> {
if (query.needsRowResult()) {
DefaultGraphRowListModelRequest graphRowListModelRequest = new DefaultGraphRowListModelRequest(query.getStatement(), query.getParameters());
try (Response<GraphRowListModel> response = session.requestHandler().execute(graphRowListModelRequest)) {
return (Collection<T>) new GraphRowListModelMapper(session.metaData(), session.context(), session.getEntityInstantiator()).map(type, response);
}
} else {
GraphModelRequest request = new DefaultGraphModelRequest(query.getStatement(), query.getParameters());
try (Response<GraphModel> response = session.requestHandler().execute(request)) {
return (Collection<T>) new GraphRowModelMapper(session.metaData(), session.context(), session.getEntityInstantiator()).map(type, response);
}
}
}, Transaction.Type.READ_WRITE);
}
Aggregations