Example usage for org.springframework.data.mongodb.core.query Query addCriteria

List of usage examples for org.springframework.data.mongodb.core.query Query addCriteria

Introduction

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

Prototype

public Query addCriteria(CriteriaDefinition criteriaDefinition) 

Source Link

Document

Adds the given CriteriaDefinition to the current Query .

Usage

From source file:com.card.loop.xyz.dao.UserDAO.java

public boolean acceptUser(User user) throws UnknownHostException {
    boolean ok = false;
    Query query = new Query();
    query.addCriteria(where("_id").is(user.getId()));
    User obj = this.user.findOne(query, User.class);
    obj.setId(user.getId());//from   ww  w.  j ava2 s .co m
    obj.setNewAccount(false);
    this.user.save(obj);
    return ok;
}

From source file:com.card.loop.xyz.dao.UserDAO.java

public User getUser(String username, String password, String type) throws UnknownHostException {
    Query query = new Query();
    query.addCriteria(Criteria.where("username").is(username).and("password").is(password).and("userType")
            .is(type).and("newAccount").is(false));
    User p = null;//from  w  w w.j a va2  s.  c o  m
    p = user.findOne(query, User.class);
    System.out.println(p);

    return p;
}

From source file:com.card.loop.xyz.dao.LearningObjectDAO.java

public boolean demoteLO(LearningObject lo) throws UnknownHostException {
    boolean ok = false;
    Query query = new Query();
    query.addCriteria(where("_id").is(lo.getId()));
    LearningObject obj = this.mongoOps.findOne(query, LearningObject.class);
    obj.setId(lo.getId());// ww  w . j a v  a  2 s. co  m
    obj.setStatus(0);
    obj.setRating(1);

    this.mongoOps.save(obj);
    return ok;
}

From source file:com.card.loop.xyz.dao.LearningObjectDAO.java

public void updateLO(LearningObjectDto lo) throws UnknownHostException {
    Query query = new Query();
    query.addCriteria(where("_id").is(lo.getId()));
    LearningObject obj = mongoOps.findOne(query, LearningObject.class);
    obj.setId(lo.getId());/*from  w w w. ja v  a  2  s  .co m*/
    obj.setUploadDate(lo.getUploadDate());
    obj.setDownloads(lo.getDownloads());
    obj.setStatus(lo.getStatus());
    obj.setSubject(lo.getSubject());
    obj.setDescription(lo.getDescription());
    obj.setUploadedBy(lo.getUploadedBy());
    obj.setRating(lo.getRating());
    obj.setComments(lo.getComments());
    mongoOps.save(obj);
}

From source file:org.oncoblocks.centromere.mongodb.CentromereMongoRepository.java

/**
 * {@link RepositoryOperations#findAll}//from w w  w.  jav  a2  s .c o  m
 */
public List<T> find(Iterable<QueryCriteria> queryCriterias) {
    Criteria criteria = MongoQueryUtils.getQueryFromQueryCriteria(queryCriterias);
    Query query = new Query();
    if (criteria != null) {
        query.addCriteria(criteria);
    }
    return mongoOperations.find(query, metadata.getJavaType());
}

From source file:org.oncoblocks.centromere.mongodb.CentromereMongoRepository.java

/**
 * {@link RepositoryOperations#findAll}//from   w ww .  ja v a 2  s. c o  m
 */
public List<T> find(Iterable<QueryCriteria> queryCriterias, Sort sort) {
    Criteria criteria = MongoQueryUtils.getQueryFromQueryCriteria(queryCriterias);
    Query query = new Query();
    if (criteria != null) {
        query.addCriteria(criteria);
    }
    return mongoOperations.find(query.with(sort), metadata.getJavaType());
}

From source file:org.oncoblocks.centromere.mongodb.CentromereMongoRepository.java

/**
 * {@link RepositoryOperations#count}/*from   ww  w .  j av  a  2s. c  o m*/
 */
public long count(Iterable<QueryCriteria> queryCriterias) {
    Criteria criteria = MongoQueryUtils.getQueryFromQueryCriteria(queryCriterias);
    Query query = new Query();
    if (criteria != null) {
        query.addCriteria(criteria);
    }
    return mongoOperations.count(query, metadata.getJavaType());
}

From source file:org.oncoblocks.centromere.mongodb.CentromereMongoRepository.java

/**
 * {@link RepositoryOperations#distinct(String, Iterable)}
 *//*w  w  w .j  a  v a  2  s  .  co  m*/
public List<Object> distinct(String field, Iterable<QueryCriteria> queryCriterias) {
    Criteria criteria = MongoQueryUtils.getQueryFromQueryCriteria(queryCriterias);
    Query query = new Query();
    if (criteria != null) {
        query.addCriteria(criteria);
    }
    return mongoOperations.getCollection(mongoOperations.getCollectionName(metadata.getJavaType()))
            .distinct(field, query.getQueryObject());
}

From source file:org.oncoblocks.centromere.mongodb.CentromereMongoRepository.java

/**
 * {@link RepositoryOperations#findAll}/*  w w  w .j  a  v a  2  s .c  o m*/
 */
public Page<T> find(Iterable<QueryCriteria> queryCriterias, Pageable pageable) {
    Criteria criteria = MongoQueryUtils.getQueryFromQueryCriteria(queryCriterias);
    Query query = new Query();
    if (criteria != null) {
        query.addCriteria(criteria);
    }
    List<T> entities = mongoOperations.find(query.with(pageable), metadata.getJavaType());
    long count = count(queryCriterias);
    return new PageImpl<>(entities, pageable, count);
}

From source file:io.gravitee.repository.mongodb.management.internal.event.EventMongoRepositoryImpl.java

@Override
public Page<EventMongo> search(Map<String, Object> values, long from, long to, int page, int size) {
    Query query = new Query();

    // set criteria query
    values.forEach((k, v) -> {/* w  w  w  . ja v  a 2 s .  c  om*/
        if (v instanceof Collection) {
            query.addCriteria(Criteria.where(k).in((Collection) v));
        } else {
            query.addCriteria(Criteria.where(k).is(v));
        }
    });

    // set range query
    query.addCriteria(Criteria.where("updatedAt").gte(new Date(from)).lt(new Date(to)));

    // set sort by updated at
    query.with(new Sort(Sort.Direction.DESC, "updatedAt"));

    // set pageable
    query.with(new PageRequest(page, size));

    List<EventMongo> events = mongoTemplate.find(query, EventMongo.class);
    long total = mongoTemplate.count(query, EventMongo.class);

    Page<EventMongo> eventsPage = new Page<>(events, page, size, total);

    return eventsPage;
}