2012年6月29日星期五

ADF_154:AM使用指南之四:把AM中的方法发布为WebService

开发环境:JDeveloper 11.1.2.1.0 + Oracle XE Database 10gR2。

实际应用中,我们经常需要在AM中添加自己的方法,这些方法可以以Data Control的方式暴露出来,供ADF Faces使用。
但那些使用了非ADF技术开发的应用如何使用AM中的方法呢?
这里介绍最简便的一种方法:把AM中的方法暴露成WebService。

重要步骤说明:
1. 创建应用时选择General Application,为Project1增加ADF BC Components。


2. Create Entities from Table: 选择Employee表。

3. 生成 AM Impl类。



增加如下方法:

/* 更新员工的工资 */
public void updateSalary(Number employeeId, Number salary) {
Key key = new Key(new Object[] { employeeId });
Row row = this.getEmployeesView1().getRow(key);
row.setAttribute("Salary", salary);

try {
this.getDBTransaction().commit();
} catch (Exception ex) {
ex.printStackTrace();
}
}

/* 获取员工的工作的总时间(多少个月) */
public Number emplWorkLoad(Number employeeId) {
this.getJobHistoryView1().setNamedWhereClauseParam("bv_employeeId", employeeId);
this.getJobHistoryView1().executeQuery();

if (this.getJobHistoryView1().first() != null) {
return (Number)this.getJobHistoryView1().first().getAttribute("WorkLoad");
}

return null;
}

4. 手工创建JobHistory VO,选择Read-Only through SQL query。

别忘了在AM的Data Model中,手工加入JobHistoryView。

5. 修改AM的Java和Service Interface选项。
在Client Interface中加入updateSalary和emplWorkLoad方法,这两个方法将会在Data Control中显示出来。
在Service Interface中加入updateSalary和emplWorkLoad方法,这两个方法将会被发布为WebService。


6. 修改AM的Configuration选项。
因为要发布到独立的WLS上,所以默认的Configuration要选择AppModuleService,以及JDBC DataSource形式的数据库连接。


要事先在WLS Console中配置该DataSouce。


7. 访问EM,找到发布的应用,测试两个方法。
http://localhost:7001/Application7-Project1-context-root/AppModuleService?wsdl。

Project下载:AM_WebService.7z

参考文献:
1. http://andrejusb.blogspot.com/2009/08/web-service-interface-for-adf-bc.html。

没有评论: