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:uk.gov.nationalarchives.discovery.taxonomy.common.repository.mongo.impl.IAViewUpdateRepositoryImpl.java

@Override
public List<IAViewUpdate> findDocumentsCreatedFromDateAndCreatedBeforeDate(Date gtDate, Date ltDate,
        Integer limit) {//from   www  . java 2s  . com
    List<Criteria> listOfCriterias = new ArrayList<Criteria>();
    if (gtDate != null) {
        listOfCriterias.add(Criteria.where(IAViewUpdate.FIELD_CREATIONDATE).gte(gtDate));
    }
    if (ltDate != null) {
        listOfCriterias.add(Criteria.where(IAViewUpdate.FIELD_CREATIONDATE).lt(ltDate));
    }
    Query query = new Query(new Criteria().andOperator(listOfCriterias.toArray(new Criteria[0])));

    query.limit(limit + 1);
    query.with(new Sort(new Order(Sort.Direction.ASC, IAViewUpdate.FIELD_CREATIONDATE),
            new Order(Sort.Direction.ASC, IAViewUpdate.FIELD_DOCREFERENCE)));
    return mongoTemplate.find(query, IAViewUpdate.class);
}

From source file:strat.mining.multipool.stats.persistence.dao.donation.impl.TransactionDAOMongo.java

@Override
public void deleteTransactionBefore(Date date) {
    Query query = new Query(Criteria.where("date").lt(date));
    mongoOperation.remove(query, Transaction.class);
}

From source file:io.github.carlomicieli.springbooks.services.BookService.java

public List<Book> findByTag(String tag) {
    return mongoTemplate.find(new Query(where("tags").is(tag)), Book.class);
}

From source file:io.github.microcks.repository.DailyStatisticRepositoryImpl.java

@Override
public void incrementDailyStatistic(String day, String serviceName, String serviceVersion, String hourKey,
        String minuteKey) {//w  w  w.  j a  v a  2  s  .  com

    // Build a query to select specific object within collection.
    Query query = new Query(Criteria.where("day").is(day).and("serviceName").is(serviceName)
            .and("serviceVersion").is(serviceVersion));

    // Other way to build a query using statically imported methods.
    //Query queryShort = query(where("day").is(day).and("serviceName").is(serviceName).and("serviceVersion").is(serviceVersion));

    // Build update to increment the 3 fields.
    Update update = new Update().inc("dailyCount", 1).inc("hourlyCount." + hourKey, 1)
            .inc("minuteCount." + minuteKey, 1);

    // Do an upsert with find and modify.
    template.findAndModify(query, update, DailyStatistic.class);
}

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

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

From source file:com.ciphertool.zodiacengine.dao.SolutionDao.java

@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
public List<SolutionChromosome> findByCipherName(String cipherName) {
    // First find the Cipher by name
    Query selectByCipherNameQuery = new Query(Criteria.where("name").is(cipherName));

    Cipher cipher = mongoOperations.findOne(selectByCipherNameQuery, Cipher.class);

    // Then find the Solutions that correspond to this Cipher
    Query selectByCipherIdQuery = new Query(Criteria.where("cipherId").is(cipher.getId()));

    List<SolutionChromosome> solutions = mongoOperations.find(selectByCipherIdQuery, SolutionChromosome.class);

    return solutions;
}

From source file:com.monkeyk.sos.infrastructure.mongo.UserRepositoryMongo.java

@Override
public User findByUsername(String username) {
    LOG.debug("Call findByUsername, username = {}", username);
    Query query = new Query(new Criteria("username").is(username));
    return this.mongoTemplate().findOne(query, User.class);
}

From source file:demo.SpringNoChangeTest.java

@Test
public void testTwoWithoutMap() {
    Two two = new Two("two", "title two", "desc two", null);
    template.save(two);//from   w  w  w.j  a va 2s.  co m

    Two foundTwo = template.findOne(Query.query(Criteria.where("id").is(two.id)), Two.class);
    Assert.assertThat(foundTwo.title, Matchers.nullValue());
    Assert.assertThat(foundTwo.desc, Matchers.is("desc two"));
    Assert.assertThat(foundTwo.map.get("TITLE"), Matchers.nullValue());
    Assert.assertThat(foundTwo.map.get("DESC"), Matchers.is("desc two"));
}

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

@Override
public void deleteGlobalStats(Date time) {
    Query query = new Query(Criteria.where("refreshTime").is(time));
    mongoOperation.remove(query, GlobalStats.class);
}

From source file:persistence.mongodb.security.DocumentMetadataRepository.java

public DocumentAccessPermissionBean getAccessPermission(final String documentId) {
    Query searchUserQuery = new Query(Criteria.where("documentId").is(documentId));
    DocumentAccessPermissionBean permissionBean = mongoOperations.findOne(searchUserQuery,
            DocumentAccessPermissionBean.class);

    return permissionBean;
}