Example usage for org.springframework.data.mongodb.core.query BasicQuery with

List of usage examples for org.springframework.data.mongodb.core.query BasicQuery with

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.query BasicQuery with.

Prototype

public Query with(Pageable pageable) 

Source Link

Document

Sets the given pagination information on the Query instance.

Usage

From source file:com.traffitruck.service.MongoDAO.java

public List<Load> getLoadsWithoutTruckByFilter(Double sourceLat, Double sourceLng, Integer source_radius,
        Double destinationLat, Double destinationLng, Integer destination_radius) {
    // The criteria API isn't good enough
    String query = "{";

    query += "weight: { $exists: true } "; // dummy for handling commas
    if (sourceLat != null && sourceLng != null && source_radius != null) {
        query += ", sourceLocation : { $geoWithin : { $centerSphere: [ [" + sourceLng + ", " + sourceLat + "], "
                + source_radius / EARTH_RADIUS_IN_RADIANS + "] } }";
    }// w  w  w . ja v a2 s .co  m
    if (destinationLat != null && destinationLng != null && destination_radius != null) {
        query += ", destinationLocation : { $geoWithin : { $centerSphere: [ [" + destinationLng + ", "
                + destinationLat + "], " + destination_radius / EARTH_RADIUS_IN_RADIANS + "] } }";
    }
    // no need for the photo here
    query += "} , {loadPhoto:0}";
    BasicQuery queryobj = new BasicQuery(query);
    // sort results
    queryobj.with(new Sort(Direction.DESC, "driveDate"));

    List<Load> coll = mongoTemplate.find(queryobj, Load.class);
    coll.stream().forEach(load -> load.setLoadPhoto(null));

    return coll;
}

From source file:com.traffitruck.service.MongoDAO.java

public List<Load> getLoadsForTruckByFilter(Truck truck, Double sourceLat, Double sourceLng,
        Integer source_radius, Double destinationLat, Double destinationLng, Integer destination_radius) {
    // The criteria API isn't good enough
    String query = "{";

    query += "weight: { $exists: true, $lte: " + truck.getMaxWeight() + " } ";
    if (truck.getMaxVolume() != null) {
        query += ", volume: { $exists: true, $lte: " + truck.getMaxVolume() + " } ";
    }//ww w .  j a  va2s  .  co m
    query += ", type: { $exists: true, $in: [" + convertToInClause(truck.getAcceptableLoadTypes()) + "] } ";
    query += ", loadingType: { $exists: true, $in: [" + convertToInClause(truck.getAcceptableLiftTypes())
            + "] } ";
    query += ", downloadingType: { $exists: true, $in: [" + convertToInClause(truck.getAcceptableLiftTypes())
            + "] } ";
    if (sourceLat != null && sourceLng != null && source_radius != null) {
        query += ", sourceLocation : { $geoWithin : { $centerSphere: [ [" + sourceLng + ", " + sourceLat + "], "
                + source_radius / EARTH_RADIUS_IN_RADIANS + "] } }";
    }
    if (destinationLat != null && destinationLng != null && destination_radius != null) {
        query += ", destinationLocation : { $geoWithin : { $centerSphere: [ [" + destinationLng + ", "
                + destinationLat + "], " + destination_radius / EARTH_RADIUS_IN_RADIANS + "] } }";
    }
    // no need for the photo here
    query += "} , {loadPhoto:0}";
    BasicQuery queryobj = new BasicQuery(query);
    // sort results
    queryobj.with(new Sort(Direction.DESC, "driveDate"));

    List<Load> coll = mongoTemplate.find(queryobj, Load.class);
    coll.stream().forEach(load -> load.setLoadPhoto(null));

    return coll;
}