本文整理汇总了Java中com.haulmont.cuba.core.global.LoadContext.Query方法的典型用法代码示例。如果您正苦于以下问题:Java LoadContext.Query方法的具体用法?Java LoadContext.Query怎么用?Java LoadContext.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.haulmont.cuba.core.global.LoadContext
的用法示例。
在下文中一共展示了LoadContext.Query方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTimeEntriesForPeriod
import com.haulmont.cuba.core.global.LoadContext; //导入方法依赖的package包/类
@Override
public List<TimeEntry> getTimeEntriesForPeriod(Date start, Date end, User user, @Nullable TimeEntryStatus status, @Nullable String viewName) {
LoadContext<TimeEntry> loadContext = new LoadContext<>(TimeEntry.class);
if (viewName != null) {
loadContext.setView(viewName);
}
String queryStr = "select e from ts$TimeEntry e where e.user.id = :userId and (e.date between :start and :end)";
if (status != null) {
queryStr += " and e.status = :status";
}
LoadContext.Query query = loadContext.setQueryString(queryStr)
.setParameter("start", start)
.setParameter("end", end)
.setParameter("userId", user.getId());
if (status != null) {
query.setParameter("status", status.getId());
}
return dataManager.loadList(loadContext);
}
示例2: getApprovableTimeEntriesForPeriod
import com.haulmont.cuba.core.global.LoadContext; //导入方法依赖的package包/类
@Override
public List<TimeEntry> getApprovableTimeEntriesForPeriod(
Date start, Date end, User approver, User user, @Nullable TimeEntryStatus status, @Nullable String viewName
) {
LoadContext<TimeEntry> loadContext = new LoadContext<>(TimeEntry.class);
if (viewName != null) {
loadContext.setView(viewName);
}
String queryStr = "select e from ts$TimeEntry e join e.task t join t.project pr join pr.participants p " +
"where p.user.id = :approverId and (p.role.code = '" + MANAGER.getId() + "' or p.role.code = '" + APPROVER.getId() + "') " +
"and e.user.id = :userId and (e.date between :start and :end)";
if (status != null) {
queryStr += " and e.status = :status";
}
LoadContext.Query query = loadContext.setQueryString(queryStr)
.setParameter("start", start)
.setParameter("end", end)
.setParameter("approverId", approver.getId())
.setParameter("userId", user.getId());
if (status != null) {
query.setParameter("status", status.getId());
}
return dataManager.loadList(loadContext);
}
示例3: testSecondQuery
import com.haulmont.cuba.core.global.LoadContext; //导入方法依赖的package包/类
@Test
public void testSecondQuery() throws SQLException {
DataService dataService = AppBeans.get(DataService.class);
LoadContext context = new LoadContext(User.class).setView(View.LOCAL);
context.setQueryString("select u from sec$User u where u.email like :email").setParameter("email", "%aaa.com");
LoadContext.Query prevQuery = new LoadContext.Query("select u from sec$User u where u.name like :name")
.setParameter("name", "A-%");
context.getPrevQueries().add(prevQuery); context.setQueryKey(111);
List<Entity> entities = dataService.loadList(context);
assertEquals(10, entities.size());
List<Map<String, Object>> queryResults = getQueryResults();
assertEquals(20, queryResults.size());
}
示例4: getStatisticsByTasks
import com.haulmont.cuba.core.global.LoadContext; //导入方法依赖的package包/类
public Map<Task, BigDecimal> getStatisticsByTasks(Date start, Date end, @Nullable Project project) {
LoadContext.Query query = LoadContext.createQuery(
"select t from ts$TimeEntry t where t.date >= :start and t.date <= :end")
.setParameter("start", start)
.setParameter("end", end);
if (project != null) {
query.setQueryString(query.getQueryString() + " and t.task.project.id = :project");
query.setParameter("project", project);
}
LoadContext<TimeEntry> loadContext = LoadContext.create(TimeEntry.class)
.setQuery(query)
.setView(new View(TimeEntry.class)
.addProperty("task",
new View(Task.class)
.addProperty("name")
.addProperty("project", viewRepository.getView(Project.class, View.MINIMAL)))
.addProperty("timeInMinutes")
);
List<TimeEntry> timeEntries = dataManager.loadList(loadContext);
Map<Task, BigDecimal> result = new HashMap<>();
for (TimeEntry timeEntry : timeEntries) {
BigDecimal sum = result.get(timeEntry.getTask());
if (sum == null) {
sum = BigDecimal.ZERO;
}
sum = sum.add(HoursAndMinutes.fromTimeEntry(timeEntry).toBigDecimal());
result.put(timeEntry.getTask(), sum);
}
return result;
}
示例5: getActiveProjectsForUser
import com.haulmont.cuba.core.global.LoadContext; //导入方法依赖的package包/类
public List<Project> getActiveProjectsForUser(User user, @Nullable String viewName) {
LoadContext<Project> loadContext = new LoadContext<>(Project.class);
if (viewName != null) {
loadContext.setView(viewName);
}
LoadContext.Query query =
new LoadContext.Query("select pr from ts$Project pr, in(pr.participants) p " +
"where p.user.id = :userId and pr.status = 'open' order by pr.name")
.setParameter("userId", user.getId());
loadContext.setQuery(query);
return dataManager.loadList(loadContext);
}
示例6: getActiveManagedProjectsForUser
import com.haulmont.cuba.core.global.LoadContext; //导入方法依赖的package包/类
public List<Project> getActiveManagedProjectsForUser(User user, @Nullable String viewName) {
LoadContext<Project> loadContext = new LoadContext<>(Project.class);
if (viewName != null) {
loadContext.setView(viewName);
}
LoadContext.Query query =
new LoadContext.Query("select pr from ts$Project pr, in(pr.participants) p " +
"where p.user.id = :userId " +
"and (p.role.code = '" + MANAGER.getId() + "' or p.role.code = '" + APPROVER.getId() + "') " +
"and pr.status = 'open'")
.setParameter("userId", user.getId());
loadContext.setQuery(query);
return dataManager.loadList(loadContext);
}
示例7: getTagsForTheProject
import com.haulmont.cuba.core.global.LoadContext; //导入方法依赖的package包/类
public List<Tag> getTagsForTheProject(@Nullable Project project, @Nullable String viewName) {
LoadContext<Tag> loadContext = new LoadContext<>(Tag.class);
if (viewName != null) {
loadContext.setView(viewName);
}
LoadContext.Query query =
new LoadContext.Query("select e from ts$Tag e left join e.tagType.projects pr where pr.id is null" +
" or (pr.id = :project)")
.setParameter("project", project);
loadContext.setQuery(query);
return dataManager.loadList(loadContext);
}
示例8: getTagsWithTheTagType
import com.haulmont.cuba.core.global.LoadContext; //导入方法依赖的package包/类
@Override
public List<Tag> getTagsWithTheTagType(TagType type, @Nullable String viewName) {
LoadContext<Tag> loadContext = new LoadContext<>(Tag.class);
if (viewName != null) {
loadContext.setView(viewName);
}
LoadContext.Query query =
new LoadContext.Query("select e from ts$Tag e where e.tagType.id = :type")
.setParameter("type", type);
loadContext.setQuery(query);
return dataManager.loadList(loadContext);
}
示例9: testThirdQuery
import com.haulmont.cuba.core.global.LoadContext; //导入方法依赖的package包/类
@Test
public void testThirdQuery() throws SQLException {
DataService dataService = AppBeans.get(DataService.class);
LoadContext context;
List<Entity> entities;
context = new LoadContext(User.class).setView(View.LOCAL);
LoadContext.Query query1 = context.setQueryString("select u from sec$User u where u.email like :email")
.setParameter("email", "%aaa.com");
entities = dataService.loadList(context);
assertEquals(20, entities.size());
context = new LoadContext(User.class).setView(View.LOCAL);
LoadContext.Query query2 = context.setQueryString("select u from sec$User u where u.name like :name")
.setParameter("name", "A-%");
context.getPrevQueries().add(query1);
context.setQueryKey(111);
entities = dataService.loadList(context);
assertEquals(10, entities.size());
context = new LoadContext(User.class).setView(View.LOCAL);
context.setQueryString("select u from sec$User u where u.firstName like :firstName")
.setParameter("firstName", "C-%");
context.getPrevQueries().add(query1);
context.getPrevQueries().add(query2);
context.setQueryKey(111);
entities = dataService.loadList(context);
assertEquals(5, entities.size());
}
示例10: load
import com.haulmont.cuba.core.global.LoadContext; //导入方法依赖的package包/类
private LinkedHashSet<User> load(int firstResult, int maxResults, String queryString) {
DataManager ds = AppBeans.get(DataManager.NAME);
LoadContext<User> lc = new LoadContext<>(User.class);
LoadContext.Query q = lc.setQueryString(queryString);
q.setParameter("groupId", groupId);
q.setFirstResult(firstResult);
q.setMaxResults(maxResults);
List<User> list = ds.loadList(lc);
return new LinkedHashSet<>(list);
}
示例11: QueryHolder
import com.haulmont.cuba.core.global.LoadContext; //导入方法依赖的package包/类
public QueryHolder(LoadContext.Query query) {
this.query = query;
}
示例12: createQueryLoadContext
import com.haulmont.cuba.core.global.LoadContext; //导入方法依赖的package包/类
protected LoadContext<Entity> createQueryLoadContext(String entityName,
String queryName,
@Nullable Integer limit,
@Nullable Integer offset,
Map<String, String> params) throws ClassNotFoundException, ParseException {
MetaClass metaClass = restControllerUtils.getMetaClass(entityName);
checkCanReadEntity(metaClass);
RestQueriesConfiguration.QueryInfo queryInfo = restQueriesConfiguration.getQuery(entityName, queryName);
if (queryInfo == null) {
throw new RestAPIException("Query not found",
String.format("Query with name %s for entity %s not found", queryName, entityName),
HttpStatus.NOT_FOUND);
}
LoadContext<Entity> ctx = new LoadContext<>(metaClass);
LoadContext.Query query = new LoadContext.Query(queryInfo.getJpql());
if (limit != null) {
query.setMaxResults(limit);
} else {
query.setMaxResults(persistenceManagerClient.getMaxFetchUI(entityName));
}
if (offset != null) {
query.setFirstResult(offset);
}
for (RestQueriesConfiguration.QueryParamInfo paramInfo : queryInfo.getParams()) {
String paramName = paramInfo.getName();
String requestParamValue = params.get(paramName);
if (requestParamValue == null) {
throw new RestAPIException("Query parameter not found",
String.format("Query parameter %s not found", paramName),
HttpStatus.BAD_REQUEST);
}
Class<?> clazz = ClassUtils.forName(paramInfo.getType(), getClass().getClassLoader());
Object objectParamValue = toObject(clazz, requestParamValue);
query.setParameter(paramName, objectParamValue);
}
ctx.setQuery(query);
ctx.setView(queryInfo.getViewName());
return ctx;
}