Search in sources :

Example 6 with PagingAndSortingQuery

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());
}
Also used : SortOrder(org.neo4j.ogm.cypher.query.SortOrder) PagingAndSortingQuery(org.neo4j.ogm.cypher.query.PagingAndSortingQuery) Test(org.junit.Test)

Example 7 with PagingAndSortingQuery

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);
}
Also used : PagingAndSortingQuery(org.neo4j.ogm.cypher.query.PagingAndSortingQuery) Test(org.junit.Test)

Example 8 with PagingAndSortingQuery

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);
}
Also used : PagingAndSortingQuery(org.neo4j.ogm.cypher.query.PagingAndSortingQuery) Test(org.junit.Test)

Example 9 with PagingAndSortingQuery

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);
}
Also used : DefaultGraphModelRequest(org.neo4j.ogm.cypher.query.DefaultGraphModelRequest) GraphRowModelMapper(org.neo4j.ogm.context.GraphRowModelMapper) GraphModelRequest(org.neo4j.ogm.request.GraphModelRequest) DefaultGraphModelRequest(org.neo4j.ogm.cypher.query.DefaultGraphModelRequest) GraphModel(org.neo4j.ogm.model.GraphModel) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) PagingAndSortingQuery(org.neo4j.ogm.cypher.query.PagingAndSortingQuery) ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 10 with PagingAndSortingQuery

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);
}
Also used : FilteredQuery(org.neo4j.ogm.session.request.FilteredQuery) PagingAndSortingQuery(org.neo4j.ogm.cypher.query.PagingAndSortingQuery)

Aggregations

PagingAndSortingQuery (org.neo4j.ogm.cypher.query.PagingAndSortingQuery)19 Test (org.junit.Test)14 DefaultGraphModelRequest (org.neo4j.ogm.cypher.query.DefaultGraphModelRequest)4 GraphRowModelMapper (org.neo4j.ogm.context.GraphRowModelMapper)3 SortOrder (org.neo4j.ogm.cypher.query.SortOrder)3 GraphModel (org.neo4j.ogm.model.GraphModel)3 GraphModelRequest (org.neo4j.ogm.request.GraphModelRequest)3 ClassInfo (org.neo4j.ogm.metadata.ClassInfo)2 FilteredQuery (org.neo4j.ogm.session.request.FilteredQuery)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 GraphRowListModelMapper (org.neo4j.ogm.context.GraphRowListModelMapper)1 Filter (org.neo4j.ogm.cypher.Filter)1 Filters (org.neo4j.ogm.cypher.Filters)1 DefaultGraphRowListModelRequest (org.neo4j.ogm.cypher.query.DefaultGraphRowListModelRequest)1 Pagination (org.neo4j.ogm.cypher.query.Pagination)1 InvalidDepthException (org.neo4j.ogm.exception.core.InvalidDepthException)1 FieldInfo (org.neo4j.ogm.metadata.FieldInfo)1 GraphRowListModel (org.neo4j.ogm.model.GraphRowListModel)1