如何在seam应用程序中订购EntityQuery查询?

时间:2022-05-25 20:01:04

My project was originally generated by seam-gen and the action "List" bean, OfficeViewList looks pretty much like it did when first generated.

我的项目最初是由seam-gen和动作“List”bean生成的,OfficeViewList看起来非常像第一次生成时那样。

The bean extends EntityQuery.

该bean扩展了EntityQuery。

Now I want to order the results. What is the best way to do this?

现在我想订购结果。做这个的最好方式是什么?

Do I want to add some kind of "order by" class to my EJBQL? Or do I want to set the select order via

我想在EJBQL中添加某种“order by”类吗?或者我想通过设置选择顺序

Here is the code that seam-gen generated (I have changed the RESTRICTIONS, but otherwise it's the same):

这是seam-gen生成的代码(我更改了RESTRICTIONS,但是否则它是相同的):

private static final String EJBQL = 
        "select officeView from OfficeView officeView";

private static final String[] RESTRICTIONS = {
  "lower(officeView.addr1) like concat(lower(#{officeViewList.officeView.addr1}),'%')",
  "lower(officeView.buildingId) like  
     concat(lower({officeViewList.officeView.buildingId}),'%')",
  "lower(officeView.circuitId) like 
     concat('%',lower({officeViewList.officeView.circuitId}),'%')",};


public OfficeViewList() {
  setEjbql(EJBQL);
  setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
  setMaxResults(25);
}

The SQL translation is roughly

SQL翻译粗略

select * from office_view where order by office_id

select * from office_view where office_id

I was thinking to use setOrder or setOrderColumn, like this

我正在考虑使用setOrder或setOrderColumn,就像这样

public OfficeViewList() {
  setEjbql(EJBQL);
  setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
  setOrderColumn("office_id"); 
  setMaxResults(25);
}

but I can't quite figure out how to do it or whether either of these are appropriate. I can't find any documentation that really explains how to use these.

但我无法弄清楚如何做到这些或其中任何一个是否合适。我找不到任何真正解释如何使用这些文档的文档。

Or do I add some kind of "order by" clause to by EJBQL statement?

或者我是否通过EJBQL语句添加某种“order by”子句?

Or is there an annotation to add to my entity bean? or to the constructor?

或者是否有一个注释要添加到我的实体bean?还是构造函数?

Too many choices, not enough knowledge.

选择太多,知识不够。

Thank you in advance.

先感谢您。

TDR

2 个解决方案

#1


I ended up adding

我最后补充道

setOrderColumn("officeView.officeId");

to the constructor and that did exactly what I wanted.

到构造函数,这完全符合我的要求。

#2


EntityQuery load the restrictions array only the first time, then he doesn't call restrictions anymore. So if you want to use the same EntityQuery object and change the restrictions use your second solution, I use it too. Or initialize another EntityQuery object and and set differents restrictions.

EntityQuery只在第一次加载限制数组,然后他不再调用限制。因此,如果您想使用相同的EntityQuery对象并使用第二个解决方案更改限制,我也会使用它。或者初始化另一个EntityQuery对象并设置不同的限制。

#1


I ended up adding

我最后补充道

setOrderColumn("officeView.officeId");

to the constructor and that did exactly what I wanted.

到构造函数,这完全符合我的要求。

#2


EntityQuery load the restrictions array only the first time, then he doesn't call restrictions anymore. So if you want to use the same EntityQuery object and change the restrictions use your second solution, I use it too. Or initialize another EntityQuery object and and set differents restrictions.

EntityQuery只在第一次加载限制数组,然后他不再调用限制。因此,如果您想使用相同的EntityQuery对象并使用第二个解决方案更改限制,我也会使用它。或者初始化另一个EntityQuery对象并设置不同的限制。