use of org.springframework.data.mongodb.core.query.Query in project main by JohnPeng739.
the class GeneralAccessorImpl method find.
/**
* {@inheritDoc}
*
* @see GeneralAccessor#find(List, Class)
*/
@Override
public <T extends Base> List<T> find(List<ConditionTuple> tuples, Class<T> clazz) throws UserInterfaceDalErrorException {
try {
if (clazz.isInterface()) {
clazz = EntityFactory.getEntityClass(clazz);
}
Query query;
Criteria cd;
switch(tuples.size()) {
case 0:
query = new Query();
break;
case 1:
ConditionTuple tuple = tuples.get(0);
cd = where(tuple.field).is(tuple.value);
query = query(cd);
break;
default:
cd = where(tuples.get(0).field).is(tuples.get(0).value);
for (int index = 1; index < tuples.size(); index++) {
tuple = tuples.get(index);
cd.and(tuple.field).is(tuple.value);
}
query = query(cd);
break;
}
return template.find(query, clazz);
} catch (ClassNotFoundException ex) {
if (logger.isErrorEnabled()) {
logger.error(String.format("Condition find entity[%s] fail, condition: %s.", clazz.getName(), StringUtils.merge(tuples, ",")), ex);
}
throw new UserInterfaceDalErrorException(UserInterfaceDalErrorException.DalErrors.ENTITY_INSTANCE_FAIL);
}
}
use of org.springframework.data.mongodb.core.query.Query in project main by JohnPeng739.
the class GeneralAccessorImpl method list.
/**
* {@inheritDoc}
*
* @see GeneralAccessor#list(Pagination, Class, boolean)
*/
@Override
public <T extends Base> List<T> list(Pagination pagination, Class<T> clazz, boolean isValid) {
if (pagination == null) {
pagination = new Pagination();
}
try {
if (clazz.isInterface()) {
clazz = EntityFactory.getEntityClass(clazz);
}
pagination.setTotal((int) count(clazz, isValid));
int skip = (pagination.getPage() - 1) * pagination.getSize();
int limit = pagination.getSize();
if (isValid) {
return template.find(query(where("valid").is(true)).skip(skip).limit(limit), clazz);
} else {
return template.find(new Query().skip(skip).limit(limit), clazz);
}
} catch (ClassNotFoundException ex) {
throw new UserInterfaceDalErrorException(UserInterfaceDalErrorException.DalErrors.ENTITY_INSTANCE_FAIL);
}
}
use of org.springframework.data.mongodb.core.query.Query in project newton by muoncore.
the class MongoSagaRepository method clearInterests.
private void clearInterests(Saga saga) {
Query ops = new Query();
ops.addCriteria(Criteria.where("sagaId").is(saga.getId()));
BulkWriteResult execute = mongoTemplate.bulkOps(BulkOperations.BulkMode.ORDERED, SagaInterest.class).remove(ops).execute();
log.debug("Saga is complete, removed {} interests", execute.getRemovedCount());
}
use of org.springframework.data.mongodb.core.query.Query in project newton by muoncore.
the class MongoSagaRepository method updateSagaCreated.
private void updateSagaCreated(Saga saga, NewtonEvent event) {
Query query = new Query();
query.addCriteria(Criteria.where("sagaId").is(saga.getId()));
Update update = new Update();
update.set("sagaClassName", saga.getClass().getName());
update.set("sagaId", saga.getId());
update.set("eventId", event.getId());
mongoTemplate.upsert(query, update, SagaCreated.class);
}
use of org.springframework.data.mongodb.core.query.Query in project spring-data-document-examples by spring-projects.
the class AlbumsIntegrationTest method lookupAlbumsByTrackNameUsingJson.
@Test
public void lookupAlbumsByTrackNameUsingJson() throws Exception {
Query query = parseQuery("{'tracks.name' : 'Wheels'}");
assertSinglePursuitAlbum(query);
}
Aggregations