Using Cayenne Remote Object persistence (Cayenne ROP)
ROP (remote object persistence) remote object persistence is a unique feature of Cayenne, which provides a lightweight remote object persistence and querying capability by using WEB service technology. By using this feature, the client program can access a remote database using a Cayenne API similar to accessing the local database (the remote database can be any database that can be accessed over a network connection). Figure 1 is a schematic diagram of the Cayenne Remote Object persistence. When a client program performs an access operation on a remote data object, the Cayenne Connection object in the client program automatically invokes the Cayenne Web Service (CWS) running on the remote server, and CWS uses the Cayenne DataContext performs the appropriate database operations and returns the results of the operation to the client program through a Web Service.
Figure 1. The principle structure diagram of Cayenne Remote Object persistence
The concept and configuration of the Cayenne Web Service (CWS)
CWS is a core component of Cayenne Remote Object Persistence, a regular Java Web application that uses Hessian as the Web Service engine. The Java classes used by Cayenne mapping files and persisted objects are included in this application. When you deploy this program to a Java EE application server that supports servlet functionality, you can support the use of remote object persistence through the Web Service provided by Hessian.
The CWS configuration is simple, just place the Java class of the Cayenne mapping file and the persisted object on the Java classPath of the CWS Web program, and configure a web.xml in Hessianservlet. Listing 1 is a typical file structure for a CWS Web application.
Listing 1. CWS WEB Application Typical file structure
CayenneCWSServer/
WEB-INF/
web.xml
lib/
cayenne.jar
hessian-3.0.13.jar
databaseb-driver.jar
otherJars......
classes/
cayenne.xml
DataMap.map.xml
DataNode.driver.xml
// 服务器端持久化对象
com/cn/ibm/PersistentObject.class
com/cn/ibm/auto/_PersistentObject.class
......
// 客户端远程访问持久化对象
com/cn/ibm/client/PersistentObject.class
com/cn/ibm/client/auto/_PersistentObject.class
......