Richfaces と toplink を使用している単純な CRUD プロジェクトがあります。一部のページの読み込みがかなり遅いことに気付いたので、toplink のログ レベルを FINE に変更しました。rich:datatable 内のすべてのコース オブジェクトを一覧表示するページをロードすると、toplink が同じ select all クエリを 9 回実行しているように見えます。rich:datascroller を使用して次の 50 項目のセットに移動するか、列を並べ替えると、同じ select all クエリがさらに 18 回実行されます。
データテーブルは次のとおりです。
<rich:dataTable value="#{CourseController.courses}"
id="table"
var="dataTableItem"
rendered="#{CourseController.courses.rowCount>0}"
rows="50"
onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
onRowMouseOver="this.style.backgroundColor='#dcdcdc'">
<f:facet name="header">
<h:outputText value="Courses"/>
</f:facet>
<rich:column sortBy="#{dataTableItem.id}">
<f:facet name="header">
<h:outputText value="ID"/>
</f:facet>
<h:commandLink action="#{CourseController.viewCourse}">
<h:outputText value="#{dataTableItem.id}" />
<f:param name="id" value="#{dataTableItem.id}" />
</h:commandLink>
</rich:column>
<rich:column sortBy="#{dataTableItem.name}">
<f:facet name="header">
<h:outputText value="Name"/>
</f:facet>
<h:outputText value="#{dataTableItem.name}" />
</rich:column>
<rich:column sortBy="#{dataTableItem.owner}">
<f:facet name="header">
<h:outputText value="Owner"/>
</f:facet>
<h:outputText value="#{dataTableItem.owner}" />
</rich:column>
<rich:column rendered="#{LoginController.inSystemAdminGroup || LoginController.inOperationsManagerGroup || LoginController.inLogisticsCoordinatorGroup}">
<f:facet name="header">
<h:outputText value=""/>
</f:facet>
<h:commandLink action="#{CourseController.editCourse}">
<h:outputText value="Edit/Delete"/>
<f:param name="id" value="#{dataTableItem.id}" />
</h:commandLink>
</rich:column>
<f:facet name="footer">
<rich:datascroller id="datascroller" />
</f:facet>
</rich:dataTable>
テーブルによって呼び出されるコントローラーの関数:
public DataModel getCourses() {
System.out.println("Im in getCourses. Fun Fun Fun.");
model = new ListDataModel(courseFacade.findAll());
return model;
}
getCourses() 関数によって呼び出される私の Bean の関数:
public List<Course> findAll() {
System.out.println("Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!");
Query q = em.createQuery("select object(o) from Course as o WHERE o.deleted = FALSE ORDER BY o.name");
List<Course> courses = q.getResultList();
return courses;
}
そして、テーブルを含むページをロードしたときのコンソール出力:
Im in getCourses. Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
bind => [false]
Im in getCourses. Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
bind => [false]
Im in getCourses. Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
bind => [false]
Im in getCourses. Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
bind => [false]
Im in getCourses. Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
bind => [false]
Im in getCourses. Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
bind => [false]
Im in getCourses. Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
bind => [false]
Im in getCourses. Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
bind => [false]
Im in getCourses. Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
bind => [false]