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

The following examples show how to use org.mongodb.morphia.query.Query#asList() . 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: MongoLogConnector.java    From heimdall with Apache License 2.0 6 votes vote down vote up
private Page<LogTrace> preparePage(Query<LogTrace> query, Integer page, Integer limit) {
	List<LogTrace> list;
	Long totalElements = query.count();

	query = query.order("-ts");

	page = page == null ? PAGE : page;
	limit = limit == null || limit > LIMIT ? LIMIT : limit;

	if (page >= 1 && limit > 0) {
		list = query.asList(new FindOptions().limit(limit).skip(page * limit));
	} else {
		list = query.asList(new FindOptions().limit(limit));
	}

	return buildPage(list, page, limit, totalElements);
}
 
Example 2
Source File: DBMockImpl.java    From heimdall with Apache License 2.0 6 votes vote down vote up
@Override
public <T> Page<T> find(Object criteria, Integer page, Integer limit) {

    Query<T> query = this.prepareQuery(criteria, this.datastore());

    List<T> list;
    Long totalElements = query.count();

    page = page == null ? PAGE : page;
    limit = limit == null || limit > LIMIT ? LIMIT : limit;

    if (page >= 1 && limit > 0) {
        list = query.asList(new FindOptions().limit(limit).skip(page * limit));
    } else {
        list = query.asList(new FindOptions().limit(limit));
    }

    return buildPage(list, page, limit, totalElements);
}
 
Example 3
Source File: DBMongoImpl.java    From heimdall with Apache License 2.0 6 votes vote down vote up
@Override
public <T> Page<T> find(Object criteria, Integer page, Integer limit) {

     Query<T> query = this.prepareQuery(criteria, this.datastore());

     List<T> list;
     Long totalElements = query.count();
     
     page = page == null ? PAGE : page;
     limit = limit == null || limit > LIMIT ? LIMIT : limit;
     
     if (page >= 1 && limit > 0) {
          list = query.asList(new FindOptions().limit(limit).skip(page * limit));  
     } else {
          list = query.asList(new FindOptions().limit(limit));
     }

     return buildPage(list, page, limit, totalElements);
}
 
Example 4
Source File: FlightServiceImpl.java    From acmeair with Apache License 2.0 6 votes vote down vote up
@Override
protected  List<Flight> getFlightBySegment(FlightSegment segment, Date deptDate){
	Query<FlightImpl> q2;
	if(deptDate != null) {
		q2 = datastore.find(FlightImpl.class).disableValidation().field("flightSegmentId").equal(segment.getFlightName()).field("scheduledDepartureTime").equal(deptDate);
	} else {
		q2 = datastore.find(FlightImpl.class).disableValidation().field("flightSegmentId").equal(segment.getFlightName());
	}
	List<FlightImpl> flightImpls = q2.asList();
	List<Flight> flights;
	if (flightImpls != null) {
		flights =  new ArrayList<Flight>(); 
		for (Flight flight : flightImpls) {
			flight.setFlightSegment(segment);
			flights.add(flight);
		}
	}
	else {
		flights = new ArrayList<Flight>(); // put an empty list into the cache in the cache in the case where no matching flights
	}
	return flights;
}
 
Example 5
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 6
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 7
Source File: DynamicBuildRepository.java    From DotCi with MIT License 6 votes vote down vote up
public <T extends DbBackedBuild> Iterable<T> getBuildGreaterThan(final DbBackedProject project, final int number, final String branch) {
    Query<DbBackedBuild> query = getQuery(project).order("number")
        .field("number").greaterThan(number)
        .order("-number");

    if (branch != null) {
        query = query.field("actions.causes.branch.branch").equal(branch);
    }

    final List<DbBackedBuild> builds = query.asList();

    for (final DbBackedBuild build : builds) {
        associateProject(project, build);
    }

    return (Iterable<T>) query.asList();
}
 
Example 8
Source File: BookingServiceImpl.java    From acmeair with Apache License 2.0 5 votes vote down vote up
@Override
public List<Booking> getBookingsByUser(String user) {
	try{
		Query<BookingImpl> q = datastore.find(BookingImpl.class).disableValidation().field("customerId").equal(user);
		List<BookingImpl> bookingImpls = q.asList();
		List<Booking> bookings = new ArrayList<Booking>();
		for(Booking b: bookingImpls){
			bookings.add(b);
		}
		return bookings;
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example 9
Source File: DynamicBuildRepository.java    From DotCi with MIT License 5 votes vote down vote up
public Iterable<DynamicBuild> getLastBuildsForUser(final String user, final int numberOfBuilds) {

        final Query<DynamicBuild> query = getDynamicBuildsForUser(user, numberOfBuilds);

        final List<DynamicBuild> builds = query.asList();

        final DynamicProjectRepository repo = SetupConfig.get().getDynamicProjectRepository();
        for (final DbBackedBuild build : builds) {
            final DbBackedProject project = repo.getProjectById(build.getProjectId());
            associateProject(project, build);
        }

        return builds;
    }
 
Example 10
Source File: JobMetric.java    From DotCi with MIT License 5 votes vote down vote up
protected List<DynamicBuild> getBuilds(Query<DynamicBuild> query) {
    query = applyQueryFilters(query);

    final List<DynamicBuild> builds = query.asList();
    for (final DynamicBuild build : builds) {
        associateProject(getProject(), build);
    }
    return builds;
}
 
Example 11
Source File: MongoExecutableJobQueue.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
@Override
public List<JobPo> getDeadJob(String taskTrackerNodeGroup, long deadline) {
    String tableName = JobQueueUtils.getExecutableQueueName(taskTrackerNodeGroup);
    Query<JobPo> query = template.createQuery(tableName, JobPo.class);
    query.field("isRunning").equal(true).
            filter("gmtCreated < ", deadline);
    return query.asList();
}
 
Example 12
Source File: MongoSchedulerJobQueue.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
@Override
public List<JobPo> getNeedGenerateJobPos(Long checkTime, int topSize) {
    Query<JobPo> query = template.createQuery(JobPo.class);
    query.field("relyOnPrevCycle").equal(false);
    query.field("lastGenerateTriggerTime").equal(checkTime);
    query.offset(0).limit(topSize);
    return query.asList();
}
 
Example 13
Source File: MongoPreLoader.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
protected List<JobPo> load(String loadTaskTrackerNodeGroup, int loadSize) {
    // load
    String tableName = JobQueueUtils.getExecutableQueueName(loadTaskTrackerNodeGroup);
    Query<JobPo> query = template.createQuery(tableName, JobPo.class);
    query.field("isRunning").equal(false)
            .filter("triggerTime < ", SystemClock.now())
            .order(" priority, triggerTime , gmtCreated").offset(0).limit(loadSize);
    return query.asList();
}
 
Example 14
Source File: MongoJobFeedbackQueue.java    From light-task-scheduler with Apache License 2.0 4 votes vote down vote up
@Override
public List<JobFeedbackPo> fetchTop(String jobClientNodeGroup, int top) {
    Query<JobFeedbackPo> query = createQuery(jobClientNodeGroup);
    query.order("gmtCreated").limit(top);
    return query.asList();
}
 
Example 15
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();
}
 
Example 16
Source File: MongoExecutingJobQueue.java    From light-task-scheduler with Apache License 2.0 4 votes vote down vote up
@Override
public List<JobPo> getJobs(String taskTrackerIdentity) {
    Query<JobPo> query = template.createQuery(JobPo.class);
    query.field("taskTrackerIdentity").equal(taskTrackerIdentity);
    return query.asList();
}
 
Example 17
Source File: MongoNodeGroupStore.java    From light-task-scheduler with Apache License 2.0 4 votes vote down vote up
@Override
public List<NodeGroupPo> getNodeGroup(NodeType nodeType) {
    Query<NodeGroupPo> query = template.createQuery(NodeGroupPo.class);
    query.field("nodeType").equal(nodeType);
    return query.asList();
}
 
Example 18
Source File: DynamicBuildRepository.java    From DotCi with MIT License 3 votes vote down vote up
public <T extends DbBackedBuild> Iterable<T> getBuilds(final DbBackedProject project, final int offset) {
    final Query<DbBackedBuild> query = getQuery(project).order("-number")
        .offset(offset);


    final List<DbBackedBuild> builds = query.asList();

    for (final DbBackedBuild build : builds) {
        associateProject(project, build);
    }

    return (Iterable<T>) query.asList();
}