实际使用中,经常需要在某个VO上增加一个Attribute,该Attribute的值来自于其它关联的的VO的Attribute值。
使用View Link有一个Accessor特性可以轻松地帮我们实现该功能。
重要步骤说明:
1. Accessor 是定义在View Link上的,默认情况下是没有定义的。
以Department和Employee为例,其一对多的关系是定义在EmpDepFkLink.xml上的。
默认情况下,Accessor是没有定义的,即Exposed in View Object没有定义。
3. 在EmployeesView中增加一个Attribute:DepartmentName,Expression 表达式:DepartmentsView1.DepartmentName。
4. 运行AM
点击EmployeesView1,
查看日志,会发现两条SELECT 语句,也就是说,使用Accessor关联要调用两次SQL查询。
不过,点击前后记录,会发现不是每次都执行查询,只有新的Employee才会执行。
访问过的记录,都是从内存中获取的。
[77] INFO: No app _def_ in BindingContext for: AppModule
[78] DCUtil, returning:oracle.jbo.uicli.binding.JUApplication, for AppModule
[79] Replacing: null with: AppModule_EmployeesView1_0PageDef
[80] INFO: No app _def_ in BindingContext for: AppModule
[81] DCUtil, returning:oracle.jbo.uicli.binding.JUApplication, for AppModule
[82] INFO: No app _def_ in BindingContext for: PROJECT_GLOBAL_VARIABLES
[83] INFO: mDCRefMap lookup failed. Does the cpx have a dataControlUsages 'dc' entry? PROJECT_GLOBAL_VARIABLES
[84] Resolving VO:AppModule.EmployeesView1 for iterator binding:oracle_jbo_uicli_binding_JUIteratorBinding_9
[85] DCUtil, RETURNING: for AppModule.EmployeesView1
[86] EmployeesView1 ViewRowSetImpl.execute caused params to be "un"changed
[87] Carrying over CappedRowCount:-1for ViewRowSet:EmployeesView1
[88] Column count: 15
[89] executeQueryForCollection ViewObject:EmployeesView1, RowSet:EmployeesView1
[90] EmployeesView1>#q computed SQLStmtBufLen: 494, actual=347, storing=377
[91] SELECT Employees.EMPLOYEE_ID, Employees.FIRST_NAME, Employees.LAST_NAME, Employees.EMAIL, Employees.PHONE_NUMBER, Employees.HIRE_DATE, Employees.JOB_ID, Employees.SALARY, Employees.COMMISSION_PCT, Employees.MANAGER_ID, Employees.DEPARTMENT_ID FROM EMPLOYEES Employees
[92] ViewObject: [model.EmployeesView]AppModule.EmployeesView1 Created new QUERY statement
[93] Bind params for ViewObject: [model.EmployeesView]AppModule.EmployeesView1
[94] DBTransactionImpl.mDefaultSparseArrayThreshold is 20
[95] Entity with key:oracle.jbo.Key[100 ] owned by row:oracle.jbo.Key[100 ]
[96] Employees_Departments1_EmpDeptFkLink_DepartmentsView_0 ViewRowSetImpl.setParamValues params changed
[97] Employees_Departments1_EmpDeptFkLink_DepartmentsView_0 ViewRowSetImpl.execute caused params to be "un"changed
[98] Carrying over CappedRowCount:-1for ViewRowSet:Employees_Departments1_EmpDeptFkLink_DepartmentsView_0
[99] Column count: 5
[100] executeQueryForCollection ViewObject:Employees_Departments1_EmpDeptFkLink_DepartmentsView, RowSet:Employees_Departments1_EmpDeptFkLink_DepartmentsView_0
[101] Employees_Departments1_EmpDeptFkLink_DepartmentsView>#q computed SQLStmtBufLen: 250, actual=216, storing=246
[102] SELECT Departments.DEPARTMENT_ID, Departments.DEPARTMENT_NAME, Departments.MANAGER_ID, Departments.LOCATION_ID FROM DEPARTMENTS Departments WHERE Departments.DEPARTMENT_ID = :Bind_DepartmentId
[103] ViewObject: [model.DepartmentsView]AppModule.Employees_Departments1_EmpDeptFkLink_DepartmentsView Created new QUERY statement
[104] Bind params for ViewObject: [model.DepartmentsView]AppModule.Employees_Departments1_EmpDeptFkLink_DepartmentsView
[105] For RowSet : Employees_Departments1_EmpDeptFkLink_DepartmentsView_0
[106] Binding param "Bind_DepartmentId": 90
[107] Entity with key:oracle.jbo.Key[90 ] owned by row:oracle.jbo.Key[90 ]
[108] RecalcExpression trueresovles to true
[109] Employees_Departments1_EmpDeptFkLink_DepartmentsView_1 ViewRowSetImpl.setParamValues params changed
[110] Employees_Departments1_EmpDeptFkLink_DepartmentsView_1 ViewRowSetImpl.execute caused params to be "un"changed
[111] executeQueryForCollection ViewObject:Employees_Departments1_EmpDeptFkLink_DepartmentsView, RowSet:Employees_Departments1_EmpDeptFkLink_DepartmentsView_1
[112] **** refreshControl() for BindingContainer :AppModule_EmployeesView1_0PageDef
[113] RecalcExpression trueresovles to true
[114] Employees_Departments1_EmpDeptFkLink_DepartmentsView_2 ViewRowSetImpl.setParamValues params changed
[115] Employees_Departments1_EmpDeptFkLink_DepartmentsView_2 ViewRowSetImpl.execute caused params to be "un"changed
[116] executeQueryForCollection ViewObject:Employees_Departments1_EmpDeptFkLink_DepartmentsView, RowSet:Employees_Departments1_EmpDeptFkLink_DepartmentsView_2
[117] RecalcExpression trueresovles to true
[118] Employees_Departments1_EmpDeptFkLink_DepartmentsView_3 ViewRowSetImpl.setParamValues params changed
[119] Employees_Departments1_EmpDeptFkLink_DepartmentsView_3 ViewRowSetImpl.execute caused params to be "un"changed
[120] executeQueryForCollection ViewObject:Employees_Departments1_EmpDeptFkLink_DepartmentsView, RowSet:Employees_Departments1_EmpDeptFkLink_DepartmentsView_3
[121] ##### QueryCollection.finl oracle.jbo.Key[90 ]
Project 下载:ADF_ViewLink_Accessor.7z
参考文献:
1. http://andrejusb.blogspot.jp/2011/12/groovy-with-view-link-accessor.html
没有评论:
发表评论