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:org.starfishrespect.myconsumption.server.business.repositories.repositoriesimpl.SensorRepositoryImpl.java

@Override
public Sensor insertSensor(Sensor sensor) {
    Criteria criteria = new Criteria("type").is(sensor.getType());
    Criteria settingsCriterias = null;//from   w w w  .  java 2  s . c o m
    for (String key : sensor.getSensorSettings().getKeys()) {
        if (settingsCriterias == null) {
            settingsCriterias = new Criteria("sensorSettings." + key)
                    .is(sensor.getSensorSettings().getValue(key));
        } else {
            settingsCriterias = new Criteria("sensorSettings." + key)
                    .is(sensor.getSensorSettings().getValue(key)).andOperator(settingsCriterias);
        }
    }
    if (settingsCriterias != null) {
        criteria.andOperator(settingsCriterias);
    }
    Query existingQuery = new Query(criteria);
    if (mongoOperation.exists(existingQuery, Sensor.class, COLLECTION_NAME)) {
        return mongoOperation.findOne(existingQuery, Sensor.class, COLLECTION_NAME);
    }
    mongoOperation.save(sensor, COLLECTION_NAME);
    return sensor;
}

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

public DiemDTO getDiemById(String id) {
    Query query = Query.query(Criteria.where("id").is(id));
    return mongoOperation.findOne(query, DiemDTO.class);
}

From source file:org.starfishrespect.myconsumption.server.business.repositories.repositoriesimpl.UserRepositoryImpl.java

@Override
public User getUser(String name) {
    Query existingQuery = new Query(new Criteria("name").is(name));
    if (mongoOperation.exists(existingQuery, User.class, COLLECTION_NAME)) {
        return mongoOperation.findOne(existingQuery, User.class, COLLECTION_NAME);
    } else {/*from   w  w  w  .  j a va 2s .  com*/
        return null;
    }
}

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

@Override
public PersonalAccessToken getToken(final String tokenId) {
    final OpenScienceFrameworkPersonalToken token = this.mongoTemplate
            .findOne(//from www .  ja va2s .  c  o m
                    new Query(new Criteria().andOperator(Criteria.where("tokenId").is(tokenId),
                            Criteria.where("isActive").is(Boolean.TRUE))),
                    OpenScienceFrameworkPersonalToken.class);

    if (token == null) {
        return null;
    }

    final String scopes = token.scopes == null ? "" : token.scopes;
    return new PersonalAccessToken(token.tokenId, token.owner, new HashSet<>(Arrays.asList(scopes.split(" "))));
}

From source file:org.ingini.mongodb.spring.example.read.TestFindOne.java

@Test
public void shouldFindOneEntryBasedOnGenderAndFirstName() {
    //GIVEN/*from   w  w w.  j a  v a 2s . co m*/
    CollectionManager.cleanAndFill(mongoTemplate.getDb(), "characters.json", HumanCharacter.COLLECTION_NAME);

    //WHEN
    Heroine heroine = mongoTemplate.findOne(
            Query.query(Criteria.where("gender").is(Gender.FEMALE).and("first_name").is("Arya")),
            Heroine.class);

    //THEN
    assertThat(heroine).isNotNull();

}

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

@Override
public GlobalStats getGlobalStats(Date time) {
    Query query = new Query(Criteria.where("refreshTime").is(time));
    query.with(new Sort(Sort.Direction.ASC, "refreshTime"));
    return mongoOperation.findOne(query, GlobalStats.class);
}

From source file:com.telefonica.euro_iaas.sdc.puppetwrapper.services.impl.CatalogManagerMongoImpl.java

public void removeNode(String nodeName) {
    Query searchNodeQuery = new Query(Criteria.where("id").is(nodeName));
    mongoTemplate.remove(searchNodeQuery, Node.class);

}

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

@Override
public AddressStats getLastAddressStats(Integer addressId) {
    Query query = new Query(Criteria.where("addressId").is(addressId));
    query.with(new Sort(Sort.Direction.DESC, "refreshTime"));
    return mongoOperation.findOne(query, AddressStats.class);
}

From source file:eu.trentorise.smartcampus.profileservice.storage.ProfileStorage.java

public List<ExtendedProfile> findExtendedProfiles(String profileId, Map<String, Object> profileAttrs) {
    Criteria criteria = new Criteria();
    criteria = Criteria.where("content.profileId").is(profileId);
    for (String key : profileAttrs.keySet()) {
        criteria.and("content.content." + key).is(profileAttrs.get(key));
    }//w  w  w.  jav  a 2 s . c  o m
    criteria.and("type").is(ExtendedProfile.class.getCanonicalName());
    criteria.and("deleted").is(false);

    List<ExtendedProfile> profiles = find(Query.query(criteria), ExtendedProfile.class);
    return profiles;
}

From source file:org.cbioportal.session_service.domain.internal.SessionRepositoryImpl.java

public Session findOneBySourceAndTypeAndData(String source, String type, Object data) {
    Query query = new Query(Criteria.where("source").is(source).and("type").is(type).and("data").is(data));
    return this.mongoTemplate.findOne(query, Session.class, type);
}