本文整理汇总了Java中io.ebean.Query类的典型用法代码示例。如果您正苦于以下问题:Java Query类的具体用法?Java Query怎么用?Java Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Query类属于io.ebean包,在下文中一共展示了Query类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getActiveExams
import io.ebean.Query; //导入依赖的package包/类
@SubjectNotPresent
public Result getActiveExams(Optional<String> date) {
PathProperties pp = PathProperties.parse("(course(name, code, credits, " +
"gradeScale(description, externalRef, displayName), organisation(code, name, nameAbbreviation)) " +
"name, examActiveStartDate, examActiveEndDate, duration, enrollInstruction, examLanguages(code, name) " +
"gradeScale(description, externalRef, displayName), examOwners(firstName, lastName, email), " +
"examType(type)" +
")");
DateTime dateTime = date.isPresent() ?
ISODateTimeFormat.dateTimeParser().parseDateTime(date.get()) :
DateTime.now();
Query<Exam> query = Ebean.find(Exam.class);
query.apply(pp);
List<Exam> exams = query.where()
.eq("state", Exam.State.PUBLISHED)
.lt("examActiveStartDate", dateTime)
.ge("examActiveEndDate", dateTime)
.eq("executionType.type", ExamExecutionType.Type.PUBLIC.toString())
.findList();
return ok(exams, pp);
}
开发者ID:CSCfi,项目名称:exam,代码行数:23,代码来源:ExamAPIController.java
示例2: getReservations
import io.ebean.Query; //导入依赖的package包/类
@SubjectNotPresent
public Result getReservations(Optional<String> start, Optional<String> end, Optional<Long> roomId) {
PathProperties pp = PathProperties.parse("(startAt, endAt, noShow, " +
"user(firstName, lastName, email, userIdentifier), " +
"enrolment(exam(name, examOwners(firstName, lastName, email), parent(examOwners(firstName, lastName, email)))), " +
"machine(name, ipAddress, otherIdentifier, room(name, roomCode)))");
Query<Reservation> query = Ebean.find(Reservation.class);
pp.apply(query);
ExpressionList<Reservation> el = query.where()
.isNotNull("enrolment")
.ne("enrolment.exam.state", Exam.State.DELETED);
if (start.isPresent()) {
DateTime startDate = ISODateTimeFormat.dateTimeParser().parseDateTime(start.get());
el = el.ge("startAt", startDate.toDate());
}
if (end.isPresent()) {
DateTime endDate = ISODateTimeFormat.dateTimeParser().parseDateTime(end.get());
el = el.lt("endAt", endDate.toDate());
}
if (roomId.isPresent()) {
el = el.eq("machine.room.id", roomId.get());
}
Set<Reservation> reservations = el.orderBy("startAt").findSet();
return ok(reservations, pp);
}
开发者ID:CSCfi,项目名称:exam,代码行数:27,代码来源:ReservationAPIController.java
示例3: getRoomOpeningHours
import io.ebean.Query; //导入依赖的package包/类
@SubjectNotPresent
public Result getRoomOpeningHours(Long roomId, Optional<String> date) {
if (!date.isPresent()) {
return badRequest("no search date given");
}
LocalDate searchDate = ISODateTimeFormat.dateParser().parseLocalDate(date.get());
PathProperties pp = PathProperties.parse("(*, defaultWorkingHours(*), calendarExceptionEvents(*))");
Query<ExamRoom> query = Ebean.find(ExamRoom.class);
pp.apply(query);
ExamRoom room = query.where().idEq(roomId).findUnique();
if (room == null) {
return notFound("room not found");
}
room.setCalendarExceptionEvents(room.getCalendarExceptionEvents().stream().filter(ee -> {
LocalDate start = new LocalDate(ee.getStartDate()).withDayOfMonth(1);
LocalDate end = new LocalDate(ee.getEndDate()).dayOfMonth().withMaximumValue();
return !start.isAfter(searchDate) && !end.isBefore(searchDate);
}).collect(Collectors.toList()));
return ok(room, pp);
}
开发者ID:CSCfi,项目名称:exam,代码行数:22,代码来源:ReservationAPIController.java
示例4: findUsers
import io.ebean.Query; //导入依赖的package包/类
@Restrict({@Group("ADMIN")})
public Result findUsers(Optional<String> filter) {
Query<User> query = Ebean.find(User.class).fetch("roles").fetch("permissions");
List<User> results;
if (filter.isPresent()) {
ExpressionList<User> el = query.where().disjunction();
el = applyUserFilter(null, el, filter.get());
String condition = String.format("%%%s%%", filter.get());
results = el.ilike("email", condition)
.ilike("userIdentifier", condition)
.ilike("employeeNumber", condition)
.endJunction()
.orderBy("lastName, firstName")
.findList();
} else {
results = query.orderBy("lastName, firstName").findList();
}
return ok(Json.toJson(results));
}
开发者ID:CSCfi,项目名称:exam,代码行数:20,代码来源:UserController.java
示例5: listExams
import io.ebean.Query; //导入依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result listExams(Optional<List<Long>> courseIds, Optional<List<Long>> sectionIds, Optional<List<Long>> tagIds) {
User user = getLoggedUser();
List<Long> courses = courseIds.orElse(Collections.emptyList());
List<Long> sections = sectionIds.orElse(Collections.emptyList());
List<Long> tags = tagIds.orElse(Collections.emptyList());
PathProperties pp = PathProperties.parse("(id, name, course(id, code), examSections(id, name))");
Query<Exam> query = Ebean.find(Exam.class);
pp.apply(query);
ExpressionList<Exam> el = query.where().isNotNull("name").isNotNull("course");
if (!user.hasRole("ADMIN", getSession())) {
el = el.eq("examOwners", user);
}
if (!courses.isEmpty()) {
el = el.in("course.id", courses);
}
if (!sections.isEmpty()) {
el = el.in("examSections.id", sections);
}
if (!tags.isEmpty()) {
el = el.in("examSections.sectionQuestions.question.parent.tags.id", tags);
}
return ok(el.findList(), pp);
}
开发者ID:CSCfi,项目名称:exam,代码行数:25,代码来源:ExamController.java
示例6: getTeachersExams
import io.ebean.Query; //导入依赖的package包/类
@Restrict(@Group("TEACHER"))
public Result getTeachersExams() {
// Get list of exams that user is assigned to inspect or is creator of
PathProperties props = PathProperties.parse("(*, course(id, code), " +
"children(id, state, examInspections(user(id, firstName, lastName))), " +
"examinationDates(*), " +
"examOwners(id, firstName, lastName), executionType(type), " +
"examInspections(id, user(id, firstName, lastName)), " +
"examEnrolments(id, user(id), reservation(id, endAt)))");
Query<Exam> query = Ebean.createQuery(Exam.class);
props.apply(query);
User user = getLoggedUser();
List<Exam> exams = query
.where()
.in("state", Exam.State.PUBLISHED, Exam.State.SAVED, Exam.State.DRAFT)
.disjunction()
.eq("examInspections.user", user)
.eq("examOwners", user)
.endJunction()
.isNull("parent")
.orderBy("created").findList();
return ok(exams, props);
}
开发者ID:CSCfi,项目名称:exam,代码行数:24,代码来源:ExamController.java
示例7: getExams
import io.ebean.Query; //导入依赖的package包/类
@Restrict({@Group("ADMIN"), @Group("TEACHER")})
public Result getExams() {
User user = getLoggedUser();
PathProperties props = PathProperties.parse("(id, name)");
Query<Exam> q = Ebean.createQuery(Exam.class);
props.apply(q);
ExpressionList<Exam> el = q.where()
.isNull("parent") // only Exam prototypes
.eq("state", Exam.State.PUBLISHED);
if (user.hasRole("TEACHER", getSession())) {
el = el.gt("examActiveEndDate", new Date())
.disjunction()
.eq("creator", user)
.eq("examOwners", user)
.eq("examInspections.user", user)
.eq("shared", true)
.endJunction();
}
return ok(el.findList(), props);
}
开发者ID:CSCfi,项目名称:exam,代码行数:21,代码来源:ReservationController.java
示例8: getQuestion
import io.ebean.Query; //导入依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result getQuestion(Long id) {
User user = getLoggedUser();
Query<Question> query = Ebean.find(Question.class);
PathProperties pp = PathProperties.parse("(*, questionOwners(id, firstName, lastName, userIdentifier, email), " +
"attachment(id, fileName), options(id, correctOption, defaultScore, option), tags(id, name), " +
"examSectionQuestions(id, examSection(name, exam(name, state))))");
pp.apply(query);
ExpressionList<Question> expr = query.where().idEq(id);
if (user.hasRole("TEACHER", getSession())) {
expr = expr.disjunction()
.eq("shared", true)
.eq("questionOwners", user)
.eq("examSectionQuestions.examSection.exam.examOwners", user)
.endJunction();
}
Question question = expr.findUnique();
if (question == null) {
return forbidden("sitnet_error_access_forbidden");
}
Collections.sort(question.getOptions());
return ok(question, pp);
}
开发者ID:CSCfi,项目名称:exam,代码行数:24,代码来源:QuestionController.java
示例9: restrictMaxResultsIfNecessary
import io.ebean.Query; //导入依赖的package包/类
/**
* Restricts the max results of the given {@link Query} if the current {@code tree} marks this {@code query} as
* limited.
*
* @param query
* @return
*/
private Query restrictMaxResultsIfNecessary(Query query) {
if (tree.isLimiting()) {
if (query.getMaxRows() != Integer.MAX_VALUE) {
/*
* In order to return the correct results, we have to adjust the first result offset to be returned if:
* - a Pageable parameter is present
* - AND the requested page number > 0
* - AND the requested page size was bigger than the derived result limitation via the First/Top keyword.
*/
if (query.getMaxRows() > tree.getMaxResults() && query.getFirstRow() > 0) {
query.setFirstRow(query.getFirstRow() - (query.getMaxRows() - tree.getMaxResults()));
}
}
query.setMaxRows(tree.getMaxResults());
}
if (tree.isExistsProjection()) {
query.setMaxRows(1);
}
return query;
}
开发者ID:hexagonframework,项目名称:spring-data-ebean,代码行数:32,代码来源:PartTreeEbeanQuery.java
示例10: doExecute
import io.ebean.Query; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected Object doExecute(final AbstractEbeanQuery repositoryQuery, final Object[] values) {
ParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
Object createQuery = repositoryQuery.createQuery(values);
if (createQuery instanceof Query) {
Query ormQuery = (Query) createQuery;
PagedList pagedList = ormQuery.findPagedList();
return PageableExecutionUtils.getPage(pagedList.getList(), accessor.getPageable(), () -> pagedList.getTotalCount());
} else if (createQuery instanceof SqlQuery) {
SqlQuery sqlQuery = (SqlQuery) createQuery;
// TODO page
return sqlQuery.findList();
} else {
throw new InvalidEbeanQueryMethodException("query must be Query or SqlQuery");
}
}
开发者ID:hexagonframework,项目名称:spring-data-ebean,代码行数:19,代码来源:AbstractEbeanQueryExecution.java
示例11: bindAndPrepare
import io.ebean.Query; //导入依赖的package包/类
private Object bindAndPrepare(Object query, Parameters<?, ?> parameters) {
Object result = bind(query);
if (!parameters.hasPageableParameter()) {
return result;
}
if (query instanceof Query) {
Query ormQuery = (Query) query;
ormQuery.setFirstRow((int) getPageable().getOffset());
ormQuery.setMaxRows(getPageable().getPageSize());
} else if (query instanceof SqlQuery) {
SqlQuery sqlQuery = (SqlQuery) query;
sqlQuery.setFirstRow((int) getPageable().getOffset());
sqlQuery.setMaxRows(getPageable().getPageSize());
}
return result;
}
开发者ID:hexagonframework,项目名称:spring-data-ebean,代码行数:20,代码来源:ParameterBinder.java
示例12: createSqlQueryMappingColumns
import io.ebean.Query; //导入依赖的package包/类
/**
* Return a query using native SQL and column mapping.
*
* @param sql native SQL
* @param columnMapping column mapping,key is dbColumn, value is propertyName.
* @return the created Query using native SQL and column mapping config.
*/
public <T> Query<T> createSqlQueryMappingColumns(Class<T> entityType,
String sql,
Map<String, String> columnMapping) {
Assert.notNull(entityType, "entityType must not null");
Assert.hasText(sql, "sql must has text");
Assert.notEmpty(columnMapping, "columnMapping must not empty");
RawSqlBuilder rawSqlBuilder = RawSqlBuilder.parse(sql);
columnMapping.entrySet().forEach(entry -> {
rawSqlBuilder.columnMapping(entry.getKey(), entry.getValue());
});
return ebeanServer.find(entityType).setRawSql(rawSqlBuilder.create());
}
开发者ID:hexagonframework,项目名称:spring-data-ebean,代码行数:20,代码来源:EbeanQueryChannelService.java
示例13: processGroup
import io.ebean.Query; //导入依赖的package包/类
private long processGroup() throws IOException {
List<Object> deleteIds = group.getDeleteIds();
for (Object id : deleteIds) {
txn.send(new DocStoreDeleteEvent(desc, id));
}
count += deleteIds.size();
List<Object> indexIds = group.getIndexIds();
if (!indexIds.isEmpty()) {
Query<T> query = server.find(desc.getBeanType());
query.where().idIn(indexIds);
indexUsingQuery(query, txn);
}
Collection<UpdateNested> values = group.getNestedPathIds().values();
for (UpdateNested nested : values) {
ProcessNested<T> nestedDocUpdate = new ProcessNested<>(server, desc, txn, nested);
count += nestedDocUpdate.process();
}
return count;
}
开发者ID:ebean-orm,项目名称:ebean-elastic,代码行数:25,代码来源:ProcessGroup.java
示例14: fetchEmbeddedAssocMany
import io.ebean.Query; //导入依赖的package包/类
/**
* Load the json map given the embedded document has cardinality many (ElasticSearch nested).
*/
private void fetchEmbeddedAssocMany(List<Object> nestedIds) {
Query<T> query = server.createQuery(desc.getBeanType());
query.apply(manyRootDoc);
query.where().in(fullNestedPath, nestedIds);
// hit the database and build the embedded JSON documents
List<T> list = query.findList();
for (T bean : list) {
Object manyList = nestedProperty.getVal(bean);
String embedJson = server.json().toJson(manyList, nestedDoc);
Object beanId = desc.beanId(bean);
jsonMap.put(beanId, embedJson);
}
}
开发者ID:ebean-orm,项目名称:ebean-elastic,代码行数:19,代码来源:ProcessNested.java
示例15: allOptions
import io.ebean.Query; //导入依赖的package包/类
@Test
public void allOptions() {
TextSimple options = new TextSimple()
.analyzer("whitespace")
.analyzeWildcard(true)
.fields("name")
.lenient(true)
.locale("EN")
.lowercaseExpandedTerms(false)
.minShouldMatch("1")
.opAnd();
Query<Customer> query = server.find(Customer.class)
.text()
.textSimple("quick brown", options)
.query();
List<Customer> list = query.findList();
assertThat(list).hasSize(0);
assertEquals(query.getGeneratedSql(), "{\"query\":{\"simple_query_string\":{\"query\":\"quick brown\",\"analyzer\":\"whitespace\",\"fields\":[\"name\"],\"default_operator\":\"and\",\"lowercase_expanded_terms\":false,\"analyze_wildcard\":true,\"locale\":\"EN\",\"lenient\":true,\"minimum_should_match\":\"1\"}}}");
}
开发者ID:ebean-orm,项目名称:ebean-elastic,代码行数:23,代码来源:QueryTextSimpleTest.java
示例16: allEquals
import io.ebean.Query; //导入依赖的package包/类
@Test
public void allEquals() {
Map<String, Object> allEq = new HashMap<String,Object>();
allEq.put("status", "COMPLETE");
allEq.put("customer.id", 1);
Query<Order> query = Ebean.find(Order.class)
.setUseDocStore(true)
.where()
.allEq(allEq)
.query();
List<Order> list = query.findList();
assertThat(list).hasSize(1);
}
开发者ID:ebean-orm,项目名称:ebean-elastic,代码行数:17,代码来源:ElasticDocumentStoreTest.java
示例17: matchAllPhraseOptions
import io.ebean.Query; //导入依赖的package包/类
@Test
public void matchAllPhraseOptions() {
Match options = new Match().opAnd().phrase()
.analyzer("whitespace")
.boost(2)
.cutoffFrequency(1)
.minShouldMatch("50%")
.zeroTerms("all")
.maxExpansions(3) // maxExpansions is for phrasePrefix only
.phrase();
Query<Customer> query = server.find(Customer.class)
.text()
.match("name", "Cust DoesNotExist", options)
.query();
List<Customer> list = query.findList();
assertEquals(query.getGeneratedSql(), "{\"query\":{\"match\":{\"name\":{\"query\":\"Cust DoesNotExist\",\"operator\":\"and\",\"boost\":2.0,\"cutoff_frequency\":1.0,\"minimum_should_match\":\"50%\",\"zero_terms_query\":\"all\",\"analyzer\":\"whitespace\",\"type\":\"phrase\"}}}}");
assertThat(list).hasSize(0);
}
开发者ID:ebean-orm,项目名称:ebean-elastic,代码行数:22,代码来源:QueryMatchOptionTest.java
示例18: matchAllPhrasePrefixOptions
import io.ebean.Query; //导入依赖的package包/类
@Test
public void matchAllPhrasePrefixOptions() {
Match options = new Match().opAnd().phrase()
.analyzer("whitespace")
.boost(2)
.cutoffFrequency(1)
.minShouldMatch("50%")
.maxExpansions(3)
.phrasePrefix();
Query<Customer> query = server.find(Customer.class)
.text()
.match("name", "Cust NoAdd", options)
.query();
List<Customer> list = query.findList();
assertEquals(query.getGeneratedSql(), "{\"query\":{\"match\":{\"name\":{\"query\":\"Cust NoAdd\",\"operator\":\"and\",\"boost\":2.0,\"cutoff_frequency\":1.0,\"minimum_should_match\":\"50%\",\"analyzer\":\"whitespace\",\"type\":\"phrase_prefix\",\"max_expansions\":3}}}}");
assertThat(list).hasSize(0);
}
开发者ID:ebean-orm,项目名称:ebean-elastic,代码行数:21,代码来源:QueryMatchOptionTest.java
示例19: findEach_startsWith_product
import io.ebean.Query; //导入依赖的package包/类
@Test
public void findEach_startsWith_product() {
Query<Product> query = server.find(Product.class)
.setUseDocStore(true)
.where().startsWith("sku", "C00")
.query();
final LinkedHashSet<String> skuSet = new LinkedHashSet<String>();
final AtomicInteger count = new AtomicInteger();
query.findEach(bean -> {
count.incrementAndGet();
skuSet.add(bean.getSku());
});
assertEquals(count.get(), 3);
assertEquals(skuSet.size(), 3);
assertEquals(query.getGeneratedSql(), "{\"query\":{\"bool\":{\"filter\":{\"prefix\":{\"sku\":\"c00\"}}}}}");
}
开发者ID:ebean-orm,项目名称:ebean-elastic,代码行数:21,代码来源:QueryEachTest.java
示例20: findEach_join
import io.ebean.Query; //导入依赖的package包/类
@Test
public void findEach_join() {
Query<Order> query = server.find(Order.class)
.setUseDocStore(true)
.setMaxRows(2)
.select("id, customer.id")
//.fetch("customer", new FetchConfig().query())
//.fetch("shipments", new FetchConfig().query())
.orderBy().asc("whenCreated");
final List<Order> collect = new ArrayList<Order>();
query.findEach(bean -> collect.add(bean));
String json = Ebean.json().toJson(collect);
System.out.println(json);
for (Order order : collect) {
System.out.println("order id:"+order.getId()+" shipments:"+order.getShipments().size());
}
}
开发者ID:ebean-orm,项目名称:ebean-elastic,代码行数:24,代码来源:QueryEachTest.java
注:本文中的io.ebean.Query类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论