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

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

Introduction

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

Prototype

public Criteria(String key) 

Source Link

Usage

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  va2 s .  c  o m*/
        return null;
    }
}

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

@Override
public void insertOrUpdate(SensorDataset value) throws DaoException {
    Update update = new Update();
    Query existingQuery = new Query(new Criteria("timestamp").is(value.getTimestamp()));

    if (mongoOperation.exists(existingQuery, SensorDataset.class, collectionName)) {
        TreeMap<Integer, MinuteValues> minuteValues = value.getValues();
        for (Integer minuteTs : minuteValues.keySet()) {
            Query existingMinute = new Query(
                    new Criteria().andOperator(Criteria.where("timestamp").is(value.getTimestamp()),
                            Criteria.where("values." + minuteTs)));
            MinuteValues minute;/*from   w ww  .  j a v  a2  s . com*/
            if (mongoOperation.exists(existingMinute, MinuteValues.class, collectionName)) {
                minute = mongoOperation.findOne(existingMinute, MinuteValues.class, collectionName);
                minute.merge(minuteValues.get(minuteTs));
            } else {
                minute = minuteValues.get(minuteTs);
            }
            update.set("values." + minuteTs, minute);
        }
        mongoOperation.updateFirst(existingQuery, update, collectionName);
    } else {
        mongoOperation.save(value, collectionName);
    }
}

From source file:eu.cloudwave.wp5.feedbackhandler.repositories.MetricRepositoryImpl.java

/**
 * {@inheritDoc}// w  ww  .  ja  v a 2s  .  c  o  m
 */
@Override
public List<? extends ProcedureExecutionMetric> find(final DbApplication application, final String className,
        final String procedureName, final String[] procedureArguments) {
    final Criteria criteria = new Criteria(APPLICATION).is(application).and(PROC__CLASS_NAME).is(className)
            .and(PROC__NAME).is(procedureName).and(PROC__ARGUMENTS).is(procedureArguments);
    final Sort sort = new Sort(Sort.Direction.ASC, TIMESTAMP);
    final Query query = new Query(criteria).with(sort);
    return mongoTemplate.find(query, DbProcedureExecutionMetricImpl.class, DbTableNames.METRICS);
}

From source file:com.comcast.video.dawg.service.pound.DawgPoundMongoService.java

@SuppressWarnings("unchecked")
@Override//from w  w w . j a  va  2  s .  co m
public Map<String, Object>[] getByReserver(String token) {
    List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
    Criteria c = new Criteria("reserver").is(token);
    Query q = new Query(c);
    Collection<? extends DawgDevice> col = mongoTemplate.find(q, PersistableDevice.class, COLLECTION_NAME);
    for (DawgDevice device : col) {
        list.add(device.getData());
    }
    return list.toArray(new Map[list.size()]);
}

From source file:com.comcast.video.dawg.service.park.MongoParkService.java

/**
 * {@inheritDoc}//  w w  w  .j  a v a 2s . c om
 */
@Override
public List<DawgModel> getModelsByIds(String... modelNames) {
    Object[] vals = new Object[modelNames.length];
    for (int i = 0; i < modelNames.length; i++) {
        vals[i] = modelNames[i];
    }
    Criteria crit = new Criteria("name").in(vals);
    return template.find(new Query(crit), DawgModel.class, DawgModel.class.getSimpleName());
}

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

@Override
public boolean deleteUser(String name) {
    if (!userExists(name)) {
        return false;
    }//from   w  w  w . j av a 2  s. c  o  m
    mongoOperation.remove(new Query(new Criteria("name").is(name)), COLLECTION_NAME);
    mongoOperation.dropCollection("user_" + name);
    return true;
}

From source file:eu.cloudwave.wp5.feedbackhandler.repositories.AbstractRepository.java

protected Criteria appCriteria(final DbApplication application) {
    // Hint: Fields of DBRefs cannot be accessed directly in a query:
    // http://stackoverflow.com/questions/17973321/querying-mongodb-dbref-inner-field
    return new Criteria(APPLICATION__ID).is(application.getId());
}

From source file:lodsve.mongodb.core.GenericMongoRepository.java

public Iterable<T> findAll(Iterable<ID> ids) {
    Set<ID> parameters = new HashSet<>(tryDetermineRealSizeOrReturn(ids, 10));
    for (ID id : ids) {
        parameters.add(id);//  w  w  w.  j  av  a  2  s . com
    }

    return findAll(new Query(new Criteria(entityInformation.getIdAttribute()).in(parameters)));
}

From source file:eu.cloudwave.wp5.feedbackhandler.repositories.ProcedureExecutionRepositoryImpl.java

/**
 * {@inheritDoc}/*from  w w  w.j  a v a  2  s. c o  m*/
 */
@Override
public Optional<AggregatedInvocation> getCallersOfInvokedMethod(String invokedClassName,
        String invokedMethodName, String callerClassName, String callerMethodName) {
    // objects have to have the same method name + class name
    final MatchOperation matchOperation = match(
            new Criteria(PROC__NAME).is(invokedMethodName).and(PROC__CLASS_NAME).is(invokedClassName));

    /*
     * add all distinct callers of the given invoked method to set
     * 
     * Fields.from(Fields.field(<NEW ATTRIBUTE NAME>, <ORIGINAL ATTRIBUTE NAME>))
     */
    final GroupOperation groupOperation = group(
            Fields.from(Fields.field(INVOKED_METHOD_NAME_PROJECTION, PROC__NAME))
                    .and(INVOKED_CLASS_NAME_PROJECTION, PROC__CLASS_NAME)).addToSet("$" + CALLER)
                            .as(CALLER_AGGREGATION_ATTRIBUTE);

    List<AggregatedInvocation> aggregationResults = aggregateProcedureExecution(
            newAggregation(matchOperation, groupOperation), AggregatedInvocation.class).getMappedResults();
    if (!aggregationResults.isEmpty()) {
        return Optional.of(aggregationResults.get(0));
    }
    return Optional.absent();
}

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

/**
 * deletes a {@link UserAccount}/*from www  .  j a  v  a 2  s.  co m*/
 * 
 * @param id
 *            id of the user storage account to delete
 */
public void delete(String id) {
    db.remove(Query.query(new Criteria("id").is(id)), UserAccount.class);
}