Java Code Examples for org.mongodb.morphia.query.Query#filter()

The following examples show how to use org.mongodb.morphia.query.Query#filter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DynamicBuildRepository.java    From DotCi with MIT License 6 votes vote down vote up
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;
}
 
Example 2
Source File: DynamicBuildRepository.java    From DotCi with MIT License 6 votes vote down vote up
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;
}
 
Example 3
Source File: MongoJobLogger.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
@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(StringUtils.isNotEmpty(request.getLogType())){
        query.field("logType").equal(request.getLogType());
    }
    if(StringUtils.isNotEmpty(request.getLevel())){
        query.field("level").equal(request.getLevel());
    }
    if(StringUtils.isNotEmpty(request.getSuccess())){
        query.field("success").equal(request.getSuccess());
    }
    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;
}
 
Example 4
Source File: AbstractMongoJobQueue.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
@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, "realTaskId", request.getRealTaskId());
    addCondition(query, "taskTrackerNodeGroup", request.getTaskTrackerNodeGroup());
    addCondition(query, "jobType", request.getJobType());
    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;
}
 
Example 5
Source File: DynamicBuildRepository.java    From DotCi with MIT License 5 votes vote down vote up
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;
    }
 
Example 6
Source File: MongoExecutingJobQueue.java    From light-task-scheduler with Apache License 2.0 4 votes vote down vote up
@Override
public List<JobPo> getDeadJobs(long deadline) {
    Query<JobPo> query = template.createQuery(JobPo.class);
    query.filter("gmtModified < ", deadline);
    return query.asList();
}