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.LearningElementDAO.java

public boolean demoteLE(LearningElement le) throws UnknownHostException {
    boolean ok = false;
    Query query = new Query();
    query.addCriteria(where("_id").is(le.getId()));
    LearningElement obj = this.mongoOps.findOne(query, LearningElement.class);
    obj.setId(le.getId());// ww w  . j  a v a2 s  . c  o m
    if (obj.getRev() == null)
        obj.setStatus(0);
    else
        obj.setStatus(1);
    this.mongoOps.save(obj);
    return ok;
}

From source file:things.mongo.MongoConnector.java

private Optional<Thing<?>> findThingForIdQuery(String id) {
    if (id == null) {
        throw new IllegalArgumentException("Id can't be null");
    }/*w  ww.j av  a2 s.c  om*/

    Query q = new Query();
    try {
        q.addCriteria(Criteria.where("_id").is(new ObjectId(id)));
    } catch (IllegalArgumentException iae) {
        throw new NoSuchThingException(id);
    }

    Thing thing = mongoTemplate.findOne(q, Thing.class);

    if (thing == null) {
        return Optional.empty();
    }
    return Optional.of(thing);
}

From source file:it.f2informatica.core.gateway.mongodb.ConsultantRepositoryGatewayMongoDB.java

@Override
public Page<ConsultantModel> paginateConsultants(final ConsultantSearchCriteria searchCriteria,
        Pageable pageable) {//from w w w . j  a  v  a  2 s .c o  m
    MongoQueryPredicate<Consultant> queryPredicate = new MongoQueryPredicate<Consultant>(Consultant.class) {
        @Override
        public Query queryPredicate() {
            final Query query = new Query();
            if (StringUtils.hasText(searchCriteria.getName())) {
                query.addCriteria(where("firstName").regex(searchCriteria.getName(), "i"));
            }
            if (StringUtils.hasText(searchCriteria.getLastName())) {
                query.addCriteria(where("lastName").regex(searchCriteria.getLastName(), "i"));
            }
            if (StringUtils.hasText(searchCriteria.getSkills())) {
                query.addCriteria(where("skills").in(searchCriteria.getSkills().split(",")));
            }
            return query;
        }
    };
    Page<Consultant> consultantPage = consultantRepository.findAll(queryPredicate, pageable);
    return new PageImpl<>(consultantToModelConverter.convertList(consultantPage.getContent()), pageable,
            consultantPage.getTotalElements());
}

From source file:things.mongo.MongoConnector.java

@Override
public boolean deleteThing(String id, Optional<String> type, Optional<String> key) {

    Optional<Thing<?>> thing = findThingForIdQuery(id);

    if (!thing.isPresent()) {
        return false;
    } else {//w ww. ja v a2 s .  c  o m
        Query q = new Query();
        try {
            q.addCriteria(Criteria.where("_id").is(new ObjectId(id)));
        } catch (IllegalArgumentException iae) {
            throw new NoSuchThingException(id);
        }
        mongoTemplate.remove(thing.get());
        return true;
    }
}

From source file:com.appleframework.monitor.model.Project.java

public List<MetricValue> findMetricData(String metricName) {

    Query query = fetchTimeQuery();
    query.addCriteria(Criteria.where("name").is(metricName));
    //query.sort().on(Constants.TIME_STAMP_FIELD_NAME, Order.ASCENDING);
    query.with(new Sort(Direction.ASC, Constants.TIME_STAMP_FIELD_NAME));
    logger.debug("find metric value by {} ,mongo={}", query.getQueryObject(), mongoUri);
    return fetchMongoTemplate().find(query, MetricValue.class, metricCollection);
}

From source file:com.skymobi.monitor.model.Project.java

public List<MetricValue> findMetricData(String metricName) {

    Query query = fetchTimeQuery();
    query.addCriteria(Criteria.where("name").is(metricName));
    query.sort().on(Constants.TIME_STAMP_FIELD_NAME, Order.ASCENDING);
    logger.debug("find metric value by {} ,mongo={}", query.getQueryObject(), mongoUri);
    return fetchMongoTemplate().find(query, MetricValue.class, metricCollection);
}

From source file:net.cit.tetrad.dao.management.impl.MainDaoImpl.java

public List<String> getExsitGlobalVariable(List<String> essentialGlobalVariableList) {
    Query query = new Query();
    query.addCriteria(Criteria.where("uid").in(essentialGlobalVariableList));
    query.fields().exclude("_id").include("uid");
    List<Object> globalList = monadService.getList(query, Global.class);

    List<String> exsitGlobalVariable = new ArrayList<String>();
    for (Object obj : globalList) {
        Global g = (Global) obj;//from   ww  w  .j av a2 s . c  o  m
        exsitGlobalVariable.add(g.getUid());
    }
    return exsitGlobalVariable;
}

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

/**
 * {@link RepositoryOperations#findAll}//from  ww  w . ja  v  a 2s  . com
 */
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, model);
}

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

/**
 * {@link RepositoryOperations#findAll}/*from ww w  .j a  v a2s.  co  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), model);
}

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

/**
 * {@link RepositoryOperations#count}//from  w w  w .  j  a  v a2  s.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, model);
}