use of org.neo4j.ogm.cypher.query.PagingAndSortingQuery in project neo4j-ogm by neo4j.
the class RelationshipEntityQuerySortingTest method testMultipleSortOrders.
@Test
public void testMultipleSortOrders() {
String cypher = "MATCH ()-[r0:`ORBITS`]-() WITH DISTINCT(r0) as r0,startnode(r0) AS n, " + "endnode(r0) AS m ORDER BY r0.distance DESC,r0.aphelion DESC " + "MATCH p1 = (n)-[*0..3]-() WITH r0, COLLECT(DISTINCT p1) AS startPaths, m " + "MATCH p2 = (m)-[*0..3]-() WITH r0, startPaths, COLLECT(DISTINCT p2) AS endPaths " + "WITH r0,startPaths + endPaths AS paths UNWIND paths AS p RETURN DISTINCT p, ID(r0)";
PagingAndSortingQuery orbitsQuery = query.findByType("ORBITS", 3);
check(cypher, orbitsQuery.setSortOrder(sortOrder.add(DESC, "distance", "aphelion")).getStatement());
check(cypher, orbitsQuery.setSortOrder(new SortOrder(DESC, "distance", "aphelion")).getStatement());
check(cypher, orbitsQuery.setSortOrder(new SortOrder().desc("distance", "aphelion")).getStatement());
}
use of org.neo4j.ogm.cypher.query.PagingAndSortingQuery in project neo4j-ogm by neo4j.
the class NodeQueryStatementsTest method testFindAllByLabelPrimaryIndex.
@Test
public void testFindAllByLabelPrimaryIndex() {
List<String> ids = Arrays.asList("uuid-1", "uuid-2");
PagingAndSortingQuery query = primaryQueryStatements.findAllByType("Orbit", ids, 0);
assertThat(query.getStatement()).isEqualTo("MATCH (n:`Orbit`) WHERE n.`uuid` IN $ids WITH n RETURN n");
assertThat(query.getParameters()).containsEntry("ids", ids);
}
use of org.neo4j.ogm.cypher.query.PagingAndSortingQuery in project neo4j-ogm by neo4j.
the class NodeQueryStatementsTest method testFindAllByLabelPrimaryIndexInfiniteDepth.
@Test
public void testFindAllByLabelPrimaryIndexInfiniteDepth() {
List<String> ids = Arrays.asList("uuid-1", "uuid-2");
PagingAndSortingQuery query = primaryQueryStatements.findAllByType("Orbit", ids, -1);
assertThat(query.getStatement()).isEqualTo("MATCH (n:`Orbit`) WHERE n.`uuid` IN $ids WITH n MATCH p=(n)-[*0..]-(m) RETURN p");
assertThat(query.getParameters()).containsEntry("ids", ids);
}
use of org.neo4j.ogm.cypher.query.PagingAndSortingQuery in project neo4j-ogm by neo4j.
the class LoadOneDelegate method load.
public <T, ID extends Serializable> T load(Class<T> type, ID id, int depth) {
ClassInfo classInfo = session.metaData().classInfo(type.getName());
if (classInfo == null) {
throw new IllegalArgumentException(type + " is not a managed entity.");
}
final FieldInfo primaryIndexField = classInfo.primaryIndexField();
if (primaryIndexField != null && !primaryIndexField.isTypeOf(id.getClass())) {
throw new IllegalArgumentException("Supplied id does not match primary index type on supplied class " + type.getName());
}
if (primaryIndexField == null && !(id instanceof Long)) {
throw new IllegalArgumentException("Supplied id must be of type Long (native graph id) when supplied class " + "does not have primary id " + type.getName());
}
Optional<String> labelsOrType = session.determineLabelsOrTypeForLoading(type);
if (!labelsOrType.isPresent()) {
logger.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 null;
}
QueryStatements<ID> queryStatements = session.queryStatementsFor(type, depth);
PagingAndSortingQuery qry = queryStatements.findOneByType(labelsOrType.get(), convertIfNeeded(classInfo, id), depth);
GraphModelRequest request = new DefaultGraphModelRequest(qry.getStatement(), qry.getParameters());
return session.doInTransaction(() -> {
try (Response<GraphModel> response = session.requestHandler().execute(request)) {
new GraphRowModelMapper(session.metaData(), session.context(), session.getEntityInstantiator()).map(type, response);
return lookup(type, id);
}
}, Transaction.Type.READ_ONLY);
}
use of org.neo4j.ogm.cypher.query.PagingAndSortingQuery in project neo4j-ogm by neo4j.
the class NodeQueryStatements method findByType.
@Override
public PagingAndSortingQuery findByType(String label, Filters parameters, int depth) {
FilteredQuery filteredQuery = FilteredQueryBuilder.buildNodeQuery(label, parameters);
String matchClause = filteredQuery.statement();
String returnClause = loadClauseBuilder.build(label, depth);
return new PagingAndSortingQuery(matchClause, returnClause, filteredQuery.parameters(), depth != 0, true);
}
Aggregations