org.mongodb.morphia.query.Query Java Examples
The following examples show how to use
org.mongodb.morphia.query.Query.
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 |
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: FlightServiceImpl.java From acmeair with Apache License 2.0 | 6 votes |
@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 #3
Source File: DynamicBuildRepository.java From DotCi with MIT License | 6 votes |
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 #4
Source File: MongoRepeatJobQueue.java From light-task-scheduler with Apache License 2.0 | 6 votes |
@Override public int incRepeatedCount(String jobId) { while (true) { JobPo jobPo = getJob(jobId); if (jobPo == null) { return -1; } Query<JobPo> query = template.createQuery(JobPo.class); query.field("jobId").equal(jobId); query.field("repeatedCount").equal(jobPo.getRepeatedCount()); UpdateOperations<JobPo> opts = template.createUpdateOperations(JobPo.class); opts.set("repeatedCount", jobPo.getRepeatedCount() + 1); UpdateResults ur = template.update(query, opts); if (ur.getUpdatedCount() == 1) { return jobPo.getRepeatedCount() + 1; } } }
Example #5
Source File: DBMockImpl.java From heimdall with Apache License 2.0 | 6 votes |
private <T> Query<T> prepareQuery(Object criteria, Datastore dataStore) { Query<T> query = (Query<T>) dataStore.createQuery(criteria.getClass()); List<Field> fields = this.getAllModelFields(criteria.getClass()); for (Field field : fields) { field.setAccessible(true); Object value = null; try { value = field.get(criteria); } catch (IllegalArgumentException | IllegalAccessException ignored) {} if (value != null) { query.criteria(field.getName()).equal(value); } } return query; }
Example #6
Source File: DBMockImpl.java From heimdall with Apache License 2.0 | 6 votes |
@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 #7
Source File: MongoLogConnector.java From heimdall with Apache License 2.0 | 6 votes |
/** * Creates a descending list of metrics for a specified period of time. * * @param id * Trace field wanted * @param size * max number of elements to return * @param period * period of time wanted * @return List of metrics */ public List<Metric> findByTop(String id, int size, Periods period) { final AdvancedDatastore datastore = this.datastore(); Query<LogTrace> query = prepareRange(datastore.createQuery(this.collection, LogTrace.class), period); query.field(id).notEqual(null); final AggregationPipeline pipeline = datastore.createAggregation(this.collection, LogTrace.class).match(query) .group(id, Group.grouping(METRIC, Group.last(id)), Group.grouping(VALUE, Accumulator.accumulator("$sum", 1))) .sort(Sort.descending(VALUE)).limit(size); final Iterator<Metric> aggregate = pipeline.aggregate(Metric.class); List<Metric> list = new ArrayList<>(); aggregate.forEachRemaining(list::add); return list; }
Example #8
Source File: DBMongoImpl.java From heimdall with Apache License 2.0 | 6 votes |
private <T> Query<T> prepareQuery(Object criteria, Datastore dataStore) { Query<T> query = (Query<T>) dataStore.createQuery(criteria.getClass()); List<Field> fields = this.getAllModelFields(criteria.getClass()); for (Field field : fields) { field.setAccessible(true); Object value = null; try { value = field.get(criteria); } catch (IllegalArgumentException | IllegalAccessException e) { log.error(e.getMessage(), e); } if (value != null) { query.criteria(field.getName()).equal(value); } } return query; }
Example #9
Source File: MongoNodeGroupStore.java From light-task-scheduler with Apache License 2.0 | 6 votes |
@Override public PaginationRsp<NodeGroupPo> getNodeGroup(NodeGroupGetReq request) { Query<NodeGroupPo> query = template.createQuery(NodeGroupPo.class); if (request.getNodeType() != null) { query.field("nodeType").equal(request.getNodeType()); } if (StringUtils.isNotEmpty(request.getNodeGroup())) { query.field("name").equal(request.getNodeGroup()); } PaginationRsp<NodeGroupPo> response = new PaginationRsp<NodeGroupPo>(); Long results = template.getCount(query); response.setResults(results.intValue()); if (results == 0) { return response; } query.order("-gmtCreated").offset(request.getStart()).limit(request.getLimit()); response.setRows(query.asList()); return response; }
Example #10
Source File: CustomerServiceImpl.java From acmeair with Apache License 2.0 | 5 votes |
@Override public Customer getCustomerByUsername(String username) { Query<CustomerImpl> q = datastore.find(CustomerImpl.class).field("_id").equal(username); Customer customer = q.get(); if (customer != null) { customer.setPassword(null); } return customer; }
Example #11
Source File: MongoExecutableJobQueue.java From light-task-scheduler with Apache License 2.0 | 5 votes |
@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 |
@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: MongoExecutableJobQueue.java From light-task-scheduler with Apache License 2.0 | 5 votes |
@Override public boolean removeBatch(String realTaskId, String taskTrackerNodeGroup) { String tableName = JobQueueUtils.getExecutableQueueName(taskTrackerNodeGroup); Query<JobPo> query = template.createQuery(tableName, JobPo.class); query.field("realTaskId").equal(realTaskId); query.field("taskTrackerNodeGroup").equal(taskTrackerNodeGroup); template.delete(query); return true; }
Example #14
Source File: MongoExecutableJobQueue.java From light-task-scheduler with Apache License 2.0 | 5 votes |
@Override public long countJob(String realTaskId, String taskTrackerNodeGroup) { String tableName = JobQueueUtils.getExecutableQueueName(taskTrackerNodeGroup); Query<JobPo> query = template.createQuery(tableName, JobPo.class); query.field("realTaskId").equal(realTaskId); query.field("taskTrackerNodeGroup").equal(taskTrackerNodeGroup); return query.countAll(); }
Example #15
Source File: BookingServiceImpl.java From acmeair with Apache License 2.0 | 5 votes |
@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 #16
Source File: MongoSuspendJobQueue.java From light-task-scheduler with Apache License 2.0 | 5 votes |
@Override public JobPo getJob(String taskTrackerNodeGroup, String taskId) { String tableName = JobQueueUtils.getExecutableQueueName(taskTrackerNodeGroup); Query<JobPo> query = template.createQuery(tableName, JobPo.class); query.field("taskId").equal(taskId). field("taskTrackerNodeGroup").equal(taskTrackerNodeGroup); return query.get(); }
Example #17
Source File: DynamicBuildRepository.java From DotCi with MIT License | 5 votes |
public <T extends DbBackedBuild> T getLastBuild(final DbBackedProject project, final String branch) { final Query<DbBackedBuild> query = getQuery(project); filterExpression(branch, query); final DbBackedBuild build = query .order("-number").get(); associateProject(project, build); return (T) build; }
Example #18
Source File: CommentRepository.java From RestExpress-Examples with Apache License 2.0 | 5 votes |
public void deleteByBlogEntryIds(Iterable<Identifier> blogEntryIds) { if (blogEntryIds.iterator().hasNext()) { Query<Comment> comments = getDataStore().createQuery(Comment.class).field("blogEntryId").in(blogEntryIds); getDataStore().delete(comments); } }
Example #19
Source File: JobMetric.java From DotCi with MIT License | 5 votes |
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 #20
Source File: MongodbRepository.java From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @param q * @param range */ private void configureQueryRange(Query<T> q, QueryRange range) { if (range == null) return; if (range.isInitialized()) { q.offset((int) range.getStart()); q.limit(range.getLimit()); } }
Example #21
Source File: MongoSuspendJobQueue.java From light-task-scheduler with Apache License 2.0 | 5 votes |
@Override public boolean remove(String jobId) { Query<JobPo> query = template.createQuery(JobPo.class); query.field("jobId").equal(jobId); WriteResult wr = template.delete(query); return wr.getN() == 1; }
Example #22
Source File: MongoExecutingJobQueue.java From light-task-scheduler with Apache License 2.0 | 5 votes |
@Override public JobPo getJob(String taskTrackerNodeGroup, String taskId) { Query<JobPo> query = template.createQuery(JobPo.class); query.field("taskId").equal(taskId). field("taskTrackerNodeGroup").equal(taskTrackerNodeGroup); return query.get(); }
Example #23
Source File: MongoPreLoader.java From light-task-scheduler with Apache License 2.0 | 5 votes |
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 #24
Source File: MongoPreLoader.java From light-task-scheduler with Apache License 2.0 | 5 votes |
@Override protected JobPo getJob(String taskTrackerNodeGroup, String jobId) { String tableName = JobQueueUtils.getExecutableQueueName(taskTrackerNodeGroup); Query<JobPo> query = template.createQuery(tableName, JobPo.class); query.field("jobId").equal(jobId). field("taskTrackerNodeGroup").equal(taskTrackerNodeGroup); return query.get(); }
Example #25
Source File: DynamicBuildRepository.java From DotCi with MIT License | 5 votes |
public DbBackedBuild getPreviousFinishedBuildOfSameBranch(final DbBackedBuild build, final String branch) { final DbBackedProject project = (DbBackedProject) build.getProject(); final Query<DbBackedBuild> query = getQuery(project); if (branch != null) filterExpression(branch, query); final DbBackedBuild previousBuild = query. limit(1). order("-number"). field("state").equal("COMPLETED").field("number").lessThan(build.getNumber()). get(); associateProject(project, previousBuild); return previousBuild; }
Example #26
Source File: MongoRepeatJobQueue.java From light-task-scheduler with Apache License 2.0 | 5 votes |
@Override public JobPo getJob(String taskTrackerNodeGroup, String taskId) { Query<JobPo> query = template.createQuery(JobPo.class); query.field("taskId").equal(taskId). field("taskTrackerNodeGroup").equal(taskTrackerNodeGroup); return query.get(); }
Example #27
Source File: MongoRepeatJobQueue.java From light-task-scheduler with Apache License 2.0 | 5 votes |
@Override public boolean remove(String jobId) { Query<JobPo> query = template.createQuery(JobPo.class); query.field("jobId").equal(jobId); WriteResult wr = template.delete(query); return wr.getN() == 1; }
Example #28
Source File: MongoJobFeedbackQueue.java From light-task-scheduler with Apache License 2.0 | 5 votes |
@Override public boolean remove(String jobClientNodeGroup, String id) { Query<JobFeedbackPo> query = createQuery(jobClientNodeGroup); query.field("id").equal(id); WriteResult wr = template.delete(query); return wr.getN() == 1; }
Example #29
Source File: MongoCronJobQueue.java From light-task-scheduler with Apache License 2.0 | 5 votes |
@Override public JobPo getJob(String taskTrackerNodeGroup, String taskId) { Query<JobPo> query = template.createQuery(JobPo.class); query.field("taskId").equal(taskId). field("taskTrackerNodeGroup").equal(taskTrackerNodeGroup); return query.get(); }
Example #30
Source File: MongoCronJobQueue.java From light-task-scheduler with Apache License 2.0 | 5 votes |
@Override public boolean remove(String jobId) { Query<JobPo> query = template.createQuery(JobPo.class); query.field("jobId").equal(jobId); WriteResult wr = template.delete(query); return wr.getN() == 1; }