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

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

Introduction

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

Prototype

public Query(CriteriaDefinition criteriaDefinition) 

Source Link

Document

Creates a new Query using the given CriteriaDefinition .

Usage

From source file:com.springsource.html5expense.mongodb.services.ExpenseRepository.java

@Override
public Expense changeExpenseStatus(Long expenseId, String state) {
    Update update = new Update();
    update.set("state", State.valueOf(state));
    Expense exp = getExpense(expenseId);
    logger.debug("Get Expense " + exp.getDescription());
    mongoTemplate.updateFirst(new Query(Criteria.where("_id").is(expenseId)), update, EXPENSE_COLLECTION_NAME);
    return getExpense(expenseId);
}

From source file:com.enitalk.configs.DateCache.java

@Bean(name = "skipCache")
public LoadingCache<String, ConcurrentSkipListSet<DateTime>> datesMap() {
    CacheBuilder<Object, Object> ccc = CacheBuilder.newBuilder();
    ccc.expireAfterWrite(2, TimeUnit.MINUTES);

    LoadingCache<String, ConcurrentSkipListSet<DateTime>> cache = ccc
            .build(new CacheLoader<String, ConcurrentSkipListSet<DateTime>>() {

                @Override/*  w ww  .  j a  v  a 2  s.  co  m*/
                public ConcurrentSkipListSet<DateTime> load(String key) throws Exception {
                    try {
                        HashMap teachers = mongo.findOne(Query.query(Criteria.where("i").is(key)),
                                HashMap.class, "teachers");
                        ObjectNode teacherJson = jackson.convertValue(teachers, ObjectNode.class);
                        String timeZone = teacherJson.at("/calendar/timeZone").asText();

                        NavigableSet<DateTime> set = days(teacherJson.path("schedule"), timeZone, teacherJson);

                        DateTimeZone dzz = DateTimeZone.forID(timeZone);
                        DateTimeFormatter df = ISODateTimeFormat.dateTimeNoMillis().withZone(dzz);

                        byte[] events = calendar.busyEvents(jackson.createObjectNode().put("id", key));
                        JsonNode evs = jackson.readTree(events);
                        Iterator<JsonNode> its = evs.iterator();
                        TreeSet<DateTime> dates = new TreeSet<>();
                        while (its.hasNext()) {
                            String date = its.next().asText();
                            DateTime av = df.parseDateTime(date).toDateTime(DateTimeZone.UTC);
                            dates.add(av);
                        }

                        set.removeAll(dates);

                        logger.info("Dates for i {} {}", key, set);

                        return new ConcurrentSkipListSet<>(set);

                    } catch (Exception e) {
                        logger.error(ExceptionUtils.getFullStackTrace(e));
                    }
                    return null;
                }

            });

    return cache;
}

From source file:io.cos.cas.adaptors.mongodb.OpenScienceFrameworkLogoutHandler.java

/**
 * Find the Institution by Id./*from  w  w w.  j av  a  2s  .co m*/
 * @param institutionId The Institution Id
 * @return OpenScienceFrameworkInstitution
 */
public OpenScienceFrameworkInstitution findInstitutionById(final String institutionId) {
    if (institutionId == null) {
        return null;
    }
    final OpenScienceFrameworkInstitution institution = this.mongoTemplate.findOne(
            new Query(Criteria.where("institution_id").is(institutionId).and("is_deleted").is(Boolean.FALSE)),
            OpenScienceFrameworkInstitution.class);
    return institution;
}

From source file:com.epam.ta.reportportal.database.dao.ProjectRepositoryCustomImpl.java

@Override
public void removeUserFromProjects(String userId) {
    StringBuilder builder = new StringBuilder("users.");
    builder.append(userId);//ww w . j av  a2s . c  o m
    Query query = Query.query(Criteria.where(builder.toString()).exists(true));
    mongoTemplate.updateMulti(query, new Update().unset(builder.toString()), Project.class);
}

From source file:eu.trentorise.smartcampus.communicatorservice.manager.UserAccountManager.java

public List<UserAccount> findUserAccounts(String appId) {
    Criteria criteria = new Criteria();
    criteria = criteria.and("appId").is(appId);
    return db.find(Query.query(criteria), UserAccount.class);
}

From source file:com.enitalk.opentok.CheckAvailabilityRunnable.java

@Override
@Scheduled(fixedDelay = 10000L)/*  ww w .  j a  v a2  s. com*/
public void run() {
    try {
        Query q = Query.query(Criteria.where("video").in(2, 3).andOperator(
                Criteria.where("checkDate").lt(DateTime.now().toDate()), Criteria.where("video").exists(true)));
        List<HashMap> evs = mongo.find(q, HashMap.class, "events");
        if (evs.isEmpty()) {
            return;
        }

        ArrayNode events = jackson.convertValue(evs, ArrayNode.class);
        Iterator<JsonNode> it = events.elements();
        mongo.updateMulti(q, new Update().set("video", 3), "events");

        while (it.hasNext()) {
            JsonNode en = it.next();
            rabbit.send("youtube_check", MessageBuilder.withBody(jackson.writeValueAsBytes(en)).build());
        }

    } catch (Exception e) {
        logger.info(ExceptionUtils.getFullStackTrace(e));
    }
}

From source file:strat.mining.multipool.stats.persistence.dao.coinshift.impl.GlobalStatsDAOMongo.java

@Override
public List<GlobalStats> getGlobalStatsSince(Date time) {
    Query query = new Query(Criteria.where("refreshTime").gt(time));
    query.with(new Sort(Sort.Direction.ASC, "refreshTime"));
    return mongoOperation.find(query, GlobalStats.class);
}

From source file:quanlyhocvu.api.mongodb.DAO.HocSinhDAO.java

public HocSinhDTO getHocSinhById(String idHocSinh) {
    Query query = Query.query(Criteria.where("id").is(idHocSinh));
    return mongoOperations.findOne(query, HocSinhDTO.class);
}

From source file:se.inera.axel.shs.broker.messagestore.internal.MongoMessageLogAdminService.java

@Override
public Iterable<ShsMessageEntry> findMessages(Filter filter) {

    Criteria criteria = buildCriteria(filter);
    Query query = Query.query(criteria);

    query.with(new Sort(Sort.Direction.DESC, "arrivalTimeStamp"));

    query = query.limit(filter.getLimit());
    query = query.skip(filter.getSkip());

    return mongoTemplate.find(query, ShsMessageEntry.class);

}

From source file:strat.mining.multipool.stats.persistence.dao.coinshift.impl.AddressStatsDAOMongo.java

@Override
public List<AddressStats> getAddressStats(Integer addressId) {
    Query query = new Query(Criteria.where("addressId").is(addressId));
    query.with(new Sort(Sort.Direction.ASC, "refreshTime"));
    return mongoOperation.find(query, AddressStats.class);
}