Search in sources :

Example 81 with Filters

use of org.neo4j.ogm.cypher.Filters 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 82 with Filters

use of org.neo4j.ogm.cypher.Filters 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)

Aggregations

Filters (org.neo4j.ogm.cypher.Filters)82 Filter (org.neo4j.ogm.cypher.Filter)78 Test (org.junit.Test)77 Restaurant (org.neo4j.ogm.domain.restaurant.Restaurant)10 Date (java.util.Date)6 CypherQuery (org.neo4j.ogm.cypher.query.CypherQuery)6 SortOrder (org.neo4j.ogm.cypher.query.SortOrder)4 Rating (org.neo4j.ogm.domain.cineasts.annotated.Rating)3 User (org.neo4j.ogm.domain.cineasts.annotated.User)3 Before (org.junit.Before)2 Pagination (org.neo4j.ogm.cypher.query.Pagination)2 Movie (org.neo4j.ogm.domain.cineasts.annotated.Movie)2 Pet (org.neo4j.ogm.domain.cineasts.annotated.Pet)2 Flight (org.neo4j.ogm.domain.gh851.Flight)2 Map (java.util.Map)1 UnaryOperator (java.util.function.UnaryOperator)1 PropertyValueTransformer (org.neo4j.ogm.cypher.PropertyValueTransformer)1 ContainsAnyComparison (org.neo4j.ogm.cypher.function.ContainsAnyComparison)1 DistanceComparison (org.neo4j.ogm.cypher.function.DistanceComparison)1 DistanceFromPoint (org.neo4j.ogm.cypher.function.DistanceFromPoint)1