本文整理汇总了Java中org.mongodb.morphia.query.Query.filter方法的典型用法代码示例。如果您正苦于以下问题:Java Query.filter方法的具体用法?Java Query.filter怎么用?Java Query.filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mongodb.morphia.query.Query
的用法示例。
在下文中一共展示了Query.filter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enrichQuery
import org.mongodb.morphia.query.Query; //导入方法依赖的package包/类
private void enrichQuery(Query<?> mongoQuery, String field, Collection<Object> criteria) {
if (criteria.size() == 1) {
// range query
Object val = criteria.iterator().next();
// TODO: rather operatte on ParsedField and have a method to determine whether it's some operation
if (field.contains(">") || field.contains("<")) {
mongoQuery.filter(field, val);
} else if (val instanceof ServiceQueryReservedValue) {
adaptToReservedValue(mongoQuery, field, (ServiceQueryReservedValue) val);
} else {
mongoQuery.field(field).equal(val);
}
} else {
// TODO: deal nicely with other operations
if (field.contains("<>")) {
mongoQuery.field(ServiceQueryUtil.parseQueryField(field).getFieldName()).notIn(criteria);
} else {
mongoQuery.field(field).in(criteria);
}
}
}
示例2: filter
import org.mongodb.morphia.query.Query; //导入方法依赖的package包/类
/**
*
* @param queryCriteria - key is field and operator and value is RHS value
* eg: "Location in" => "Delhi"
* @param sortCriteria - comma separated field names. use - for descending
* order eg: "location, -status"
* @param pageInfo - contain limit and offset
* @return
*/
public List<T> filter(Map<String, Object> queryCriteria, String sortCriteria, PageInfo pageInfo) {
Query<T> query = datastore.createQuery(genericType);
for (Map.Entry<String, Object> entry : queryCriteria.entrySet()) {
query = query.filter(entry.getKey(), entry.getValue());
}
if (pageInfo == null) {
pageInfo = new PageInfo(100000, 0);
}
if (sortCriteria == null) {
sortCriteria = "_id";
}
query = query.limit(pageInfo.getLimit()).offset(pageInfo.getOffset());
query = query.order(sortCriteria);
return query.asList();
}
示例3: findBySalary
import org.mongodb.morphia.query.Query; //导入方法依赖的package包/类
public List<EmployeeEntity> findBySalary(final BigDecimal minimum, final BigDecimal maximum) {
/**
* Check that the minimum is not negative and that the maximum is not
* smaller than the minimum.
*/
if (((minimum != null) && (minimum.compareTo(BigDecimal.ZERO) < 0))
|| ((minimum != null) && (maximum != null) && (maximum.compareTo(minimum) < 0))) {
return new ArrayList<>();
}
Query<EmployeeEntity> query = mongoDatastore.find(EmployeeEntity.class);
if (minimum != null) {
BigDecimal minimumScale = minimum.setScale(2, BigDecimal.ROUND_HALF_UP);
query.filter("salaryString >=", minimumScale.toPlainString());
}
if (maximum != null) {
BigDecimal maximumScale = maximum.setScale(2, BigDecimal.ROUND_HALF_UP);
query.filter("salaryString <=", maximumScale.toPlainString());
}
return query.asList();
}
示例4: build
import org.mongodb.morphia.query.Query; //导入方法依赖的package包/类
@Override
public void build(
final Query<?> query,
final String field,
final String value
)
{
if (_isEmpty( value )) {
return;
}
if (_isList( value )) {
String[] value_elem = _asList( value );
List<OvalEnumeration> list = new ArrayList<OvalEnumeration>();
for (String v : value_elem) {
list.add( OvalEnumerationHelper.fromValue( _type, v ) );
}
query.filter( field + " in", list );
} else {
query.filter( field, OvalEnumerationHelper.fromValue( _type, value ) );
}
}
示例5: _findUniqueKey
import org.mongodb.morphia.query.Query; //导入方法依赖的package包/类
protected Key<OvalDefinitions> _findUniqueKey(
final OvalDefinitions oval_definitions
)
{
Query<OvalDefinitions> q = createQuery();
GeneratorType generator = oval_definitions.getGenerator();
q.filter( "generator.timestamp", generator.getTimestamp() );
q.filter( "generator.schema_version", generator.getSchemaVersion() );
String digest = oval_definitions.getDefinitionsDigest();
q.filter( "definitions_digest", digest );
_LOG_.debug( "find unique: query=" + q );
Key<OvalDefinitions> id = find( q ).getKey();
_LOG_.debug( "find unique: id=" + id );
return id;
}
示例6: _findExistingKey
import org.mongodb.morphia.query.Query; //导入方法依赖的package包/类
protected Key<OvalDefinitions> _findExistingKey(
final OvalDefinitions oval_definitions
)
{
Query<OvalDefinitions> q = createQuery();
String pid = oval_definitions.getPersistentID();
if (pid == null) {
GeneratorType generator = oval_definitions.getGenerator();
q.filter( "generator.timestamp", generator.getTimestamp() );
q.filter( "generator.schema_version", generator.getSchemaVersion() );
String digest = oval_definitions.getDefinitionsDigest();
q.filter( "definitions_digest", digest );
} else {
q.filter( "_id", oval_definitions.getPersistentID() );
}
_LOG_.debug( "find existing key: query=" + q );
Key<OvalDefinitions> key = find( q ).getKey();
_LOG_.debug( "find existing key: found key=" + key );
return key;
}
示例7: getLast
import org.mongodb.morphia.query.Query; //导入方法依赖的package包/类
public <T extends DbBackedBuild> Iterable<T> getLast(final DbBackedProject project, final int i, final String branch, final Result result) {
Query<DbBackedBuild> query = getQuery(project).limit(i).order("-number");
if (branch != null) {
query = filterExpression(branch, query);
}
if (result != null) {
query = query.filter("result", result.toString());
}
final List<DbBackedBuild> builds = query.asList();
for (final DbBackedBuild build : builds) {
associateProject(project, build);
}
return (Iterable<T>) builds;
}
示例8: getCurrentUserBuilds
import org.mongodb.morphia.query.Query; //导入方法依赖的package包/类
public <T extends DbBackedBuild> Iterable<T> getCurrentUserBuilds(final DbBackedProject project, final int i, final Result result) {
Query<DbBackedBuild> query = getQuery(project)
.limit(i)
.order("-number");
query.or(
query.criteria("actions.causes.user").equal(Jenkins.getAuthentication().getName()),
query.criteria("actions.causes.pusher").equal(Jenkins.getAuthentication().getName())
);
if (result != null) {
query = query.filter("result", result.toString());
}
final List<DbBackedBuild> builds = query.asList();
for (final DbBackedBuild build : builds) {
associateProject(project, build);
}
return (Iterable<T>) builds;
}
示例9: testVersionedUpsert
import org.mongodb.morphia.query.Query; //导入方法依赖的package包/类
@Test
public void testVersionedUpsert() {
final Datastore datastore = getDs();
Versioned entity = new Versioned();
entity.setName("Value 1");
Query<Versioned> query = datastore.find(Versioned.class);
query.filter("name", "Value 1");
UpdateOperations<Versioned> ops = datastore.createUpdateOperations(Versioned.class);
ops.set("name", "Value 3");
datastore.update(query, ops, new UpdateOptions().upsert(true));
entity = datastore.find(Versioned.class).get();
Assert.assertEquals("Value 3", entity.getName());
Assert.assertEquals(1, entity.getVersion().longValue());
}
示例10: filterPagination
import org.mongodb.morphia.query.Query; //导入方法依赖的package包/类
private Query<T> filterPagination(Map<String, Object> filters, Query<T> pagination) {
if (filters != null) {
for (String key : filters.keySet()) {
pagination = pagination.filter(key, filters.get(key));
}
}
return pagination;
}
示例11: search
import org.mongodb.morphia.query.Query; //导入方法依赖的package包/类
@Override
public PaginationRsp<JobLogPo> search(JobLoggerRequest request) {
Query<JobLogPo> query = template.createQuery(JobLogPo.class);
if(StringUtils.isNotEmpty(request.getTaskId())){
query.field("taskId").equal(request.getTaskId());
}
if(StringUtils.isNotEmpty(request.getTaskTrackerNodeGroup())){
query.field("taskTrackerNodeGroup").equal(request.getTaskTrackerNodeGroup());
}
if (request.getStartLogTime() != null) {
query.filter("logTime >= ", getTimestamp(request.getStartLogTime()));
}
if (request.getEndLogTime() != null) {
query.filter("logTime <= ", getTimestamp(request.getEndLogTime()));
}
PaginationRsp<JobLogPo> paginationRsp = new PaginationRsp<JobLogPo>();
Long results = template.getCount(query);
paginationRsp.setResults(results.intValue());
if (results == 0) {
return paginationRsp;
}
// 查询rows
query.order("-logTime").offset(request.getStart()).limit(request.getLimit());
paginationRsp.setRows(query.asList());
return paginationRsp;
}
示例12: pageSelect
import org.mongodb.morphia.query.Query; //导入方法依赖的package包/类
@Override
public PaginationRsp<JobPo> pageSelect(JobQueueReq request) {
Query<JobPo> query = template.createQuery(getTargetTable(request.getTaskTrackerNodeGroup()), JobPo.class);
addCondition(query, "jobId", request.getJobId());
addCondition(query, "taskId", request.getTaskId());
addCondition(query, "taskTrackerNodeGroup", request.getTaskTrackerNodeGroup());
addCondition(query, "submitNodeGroup", request.getSubmitNodeGroup());
addCondition(query, "needFeedback", request.getNeedFeedback());
if (request.getStartGmtCreated() != null) {
query.filter("gmtCreated >= ", request.getStartGmtCreated().getTime());
}
if (request.getEndGmtCreated() != null) {
query.filter("gmtCreated <= ", request.getEndGmtCreated().getTime());
}
if (request.getStartGmtModified() != null) {
query.filter("gmtModified <= ", request.getStartGmtModified().getTime());
}
if (request.getEndGmtModified() != null) {
query.filter("gmtModified >= ", request.getEndGmtModified().getTime());
}
PaginationRsp<JobPo> response = new PaginationRsp<JobPo>();
Long results = template.getCount(query);
response.setResults(results.intValue());
if (results == 0) {
return response;
}
if (StringUtils.isNotEmpty(request.getField()) && StringUtils.isNotEmpty(request.getDirection())) {
query.order(("ASC".equalsIgnoreCase(request.getDirection()) ? "" : "-") + request.getField());
}
query.offset(request.getStart()).limit(request.getLimit());
response.setRows(query.asList());
return response;
}
示例13: getBuildBySha
import org.mongodb.morphia.query.Query; //导入方法依赖的package包/类
public <T extends DbBackedBuild> T getBuildBySha(final DbBackedProject<?, ?> project, final String sha, final Result result) {
Query<DbBackedBuild> query = getQuery(project).
field("actions.causes.sha").equal(sha);
if (result != null) {
query = query.filter("result", result.toString());
}
final DbBackedBuild build = query.get();
associateProject(project, build);
return (T) build;
}
示例14: find
import org.mongodb.morphia.query.Query; //导入方法依赖的package包/类
@Override
@Deprecated
public <T, V> Query<T> find(final Class<T> clazz, final String property, final V value, final int offset, final int size) {
final Query<T> query = createQuery(clazz);
query.offset(offset);
query.limit(size);
return query.filter(property, value);
}
示例15: testBulkUpdate
import org.mongodb.morphia.query.Query; //导入方法依赖的package包/类
@Test
public void testBulkUpdate() {
final Datastore datastore = getDs();
Versioned entity = new Versioned();
entity.setName("Value 1");
datastore.save(entity);
entity = datastore.get(Versioned.class, entity.getId());
Assert.assertEquals("Value 1", entity.getName());
Assert.assertEquals(1, entity.getVersion().longValue());
entity.setName("Value 2");
datastore.save(entity);
entity = datastore.get(Versioned.class, entity.getId());
Assert.assertEquals("Value 2", entity.getName());
Assert.assertEquals(2, entity.getVersion().longValue());
Query<Versioned> query = datastore.find(Versioned.class);
query.filter("id", entity.getId());
UpdateOperations<Versioned> ops = datastore.createUpdateOperations(Versioned.class);
ops.set("name", "Value 3");
datastore.update(query, ops);
entity = datastore.get(Versioned.class, entity.getId());
Assert.assertEquals("Value 3", entity.getName());
Assert.assertEquals(3, entity.getVersion().longValue());
}