Search in sources :

Example 16 with SortOrder

use of org.neo4j.ogm.cypher.query.SortOrder in project neo4j-ogm by neo4j.

the class NodeEntityQuerySortingTest method testMultipleSortOrders.

@Test
public void testMultipleSortOrders() {
    String cypher = "MATCH (n:`Raptor`) WITH n ORDER BY n.age DESC,n.name DESC RETURN n";
    check(cypher, query.findByType("Raptor", 0).setSortOrder(sortOrder.add(DESC, "age", "name")).getStatement());
    check(cypher, query.findByType("Raptor", 0).setSortOrder(new SortOrder(DESC, "age", "name")).getStatement());
    check(cypher, query.findByType("Raptor", 0).setSortOrder(new SortOrder().desc("age", "name")).getStatement());
}
Also used : SortOrder(org.neo4j.ogm.cypher.query.SortOrder) Test(org.junit.Test)

Example 17 with SortOrder

use of org.neo4j.ogm.cypher.query.SortOrder in project framework by dynamiatools.

the class Neo4jCrudService method find.

@Override
public <T> List<T> find(Class<T> type, QueryParameters parameters) {
    parameters.setType(type);
    fireListeners(parameters, EventType.BEFORE_QUERY);
    Filters filters = buildFilters(parameters);
    SortOrder sortOrder = new SortOrder();
    Pagination pagination = null;
    int depth = getDepth(parameters);
    if (parameters.getPaginator() != null) {
        long totalSize = s().count(type, filters);
        parameters.getPaginator().setTotalSize(totalSize);
        pagination = buildPagination(parameters);
    }
    if (parameters.getSorter() != null) {
        BeanSorter s = parameters.getSorter();
        sortOrder.add(s.isAscending() ? SortOrder.Direction.ASC : SortOrder.Direction.DESC, s.getColumnName());
    }
    List<T> result = new ArrayList<>(s().loadAll(type, filters, sortOrder, pagination, depth));
    fireListeners(parameters, EventType.AFTER_QUERY);
    return result;
}
Also used : Pagination(org.neo4j.ogm.cypher.query.Pagination) Filters(org.neo4j.ogm.cypher.Filters) SortOrder(org.neo4j.ogm.cypher.query.SortOrder) BeanSorter(tools.dynamia.commons.BeanSorter)

Example 18 with SortOrder

use of org.neo4j.ogm.cypher.query.SortOrder in project framework by dynamiatools.

the class Neo4jCrudService method findSingle.

@Override
public <T> T findSingle(Class<T> entityClass, QueryParameters params) {
    Optional<T> result;
    if (params.size() == 1 && params.containsKey("id")) {
        result = Optional.of(s().load(entityClass, (Serializable) params.get("id"), params.getDepth()));
    } else {
        params.setType(entityClass);
        fireListeners(params, EventType.BEFORE_QUERY);
        Filters filters = buildFilters(params);
        SortOrder sortOrder = new SortOrder();
        Pagination pagination = new Pagination(0, 1);
        int depth = getDepth(params);
        Collection<T> data = s().loadAll(entityClass, filters, sortOrder, pagination, depth);
        result = data.stream().findFirst();
        fireListeners(params, EventType.AFTER_QUERY);
    }
    return result.orElse(null);
}
Also used : Pagination(org.neo4j.ogm.cypher.query.Pagination) Filters(org.neo4j.ogm.cypher.Filters) SortOrder(org.neo4j.ogm.cypher.query.SortOrder)

Example 19 with SortOrder

use of org.neo4j.ogm.cypher.query.SortOrder in project framework by dynamiatools.

the class Neo4jCrudService method findAll.

@Override
public <T> List<T> findAll(Class<T> type, String orderBy) {
    SortOrder order = new SortOrder();
    order.add(orderBy);
    return new ArrayList<>(s().loadAll(type, order));
}
Also used : SortOrder(org.neo4j.ogm.cypher.query.SortOrder)

Aggregations

SortOrder (org.neo4j.ogm.cypher.query.SortOrder)19 Test (org.junit.Test)13 Filters (org.neo4j.ogm.cypher.Filters)4 Pagination (org.neo4j.ogm.cypher.query.Pagination)4 PagingAndSortingQuery (org.neo4j.ogm.cypher.query.PagingAndSortingQuery)3 Before (org.junit.Before)2 Filter (org.neo4j.ogm.cypher.Filter)2 User (org.neo4j.ogm.domain.cineasts.annotated.User)2 Artist (org.neo4j.ogm.domain.music.Artist)2 Satellite (org.neo4j.ogm.domain.satellites.Satellite)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 GraphRowListModelMapper (org.neo4j.ogm.context.GraphRowListModelMapper)1 GraphRowModelMapper (org.neo4j.ogm.context.GraphRowModelMapper)1 DefaultGraphModelRequest (org.neo4j.ogm.cypher.query.DefaultGraphModelRequest)1 DefaultGraphRowListModelRequest (org.neo4j.ogm.cypher.query.DefaultGraphRowListModelRequest)1 Movie (org.neo4j.ogm.domain.cineasts.annotated.Movie)1 Rating (org.neo4j.ogm.domain.cineasts.annotated.Rating)1 User (org.neo4j.ogm.domain.gh368.User)1 Album (org.neo4j.ogm.domain.music.Album)1