Information Integration Using the AquaLogic Data Services Platform
Pages: 1, 2, 3, 4

Developing a Client

Service Data Objects (SDO) form the basic interface for client interaction in AquaLogic DSP. As mentioned in my previous article, SDOs are disconnected data objects. SDO is built on top of the XMLBeans framework. Therefore, XMLBeans, which is quite handy, becomes the basic client interface. AquaLogic DSP provides two interfaces to SDO:

  1. SDO Client Mediator API
  2. AquaLogic DSP Control

Let's look at these in more detail.

The SDO Client Mediator API

AquaLogic DSP supports two types of mediators to the AquaLogic DSP application—typed and dynamic. These APIs help other applications to handshake with DSP applications and get the SDO objects that are references to your original data in the data source.

In the case of the typed API, WebLogic Workshop can help you in generating wrapper mediators for every data service in the application. For example, if you have Customer.ds with a getCustomer() function, then you can have a corresponding generated class Customer.java with a getCustomer() method. The Dynamic API follows the dynamic proxy pattern and is useful when you need dynamic behavior (when you don't know the DS name at design time).

Let's develop a Java project and see how we can use the Mediator API to build a client. Refer to the documentation for more details on the Mediator API.

  1. Right-click the application root (OrderManagement), and select Build SDO client Mediator. You can see the client jar formed under the root of the application, named OrderManagement-ld-client.jar. This will contain proxy classes for all the data services in the application.
  2. Create a new Java project and name it "DataServiceClient" (File->New->Project->Java Project).
  3. Add the OrderManagement-ld-client.jar to the CLASSPATH (Right-click Library in application view, and select the generated client JAR).
  4. Create a new Java class in the DataServiceClient project. Add the code given below to complete the Java client. Here we have used dynamic client, static client, and a prepared expression.
  5. Run the Java client.
1 import com.bea.ld.dsmediator.client.DataService;
2 import com.bea.ld.dsmediator.client.DataServiceFactory;
3 import com.bea.ld.dsmediator.client.PreparedExpression;
4 import java.util.Hashtable;
5 import javax.naming.Context;
6 import javax.naming.InitialContext;
7 import repository.CUSTOMERS;
8
9 public class DataServiceClient
10 {
12
13    public static void main(String [] args) {
14        try{
15       Hashtable h = new Hashtable();
16       h.put(Context.INITIAL_CONTEXT_FACTORY,
17            "weblogic.jndi.WLInitialContextFactory");
18        h.put(Context.PROVIDER_URL,"t3://localhost:7001");
19        h.put(Context.SECURITY_PRINCIPAL,"weblogic");
20        h.put(Context.SECURITY_CREDENTIALS,"weblogic");
21        InitialContext ctx=     new InitialContext(h);
22        System.out.println("========Dynamic Query=================");
23        DataService xds =     
           DataServiceFactory.newDataService(ctx,"OrderManagement","ld:repository/CUSTOMERS");
24        System.out.println(xds.invoke("CUSTOMERS",null));
25        System.out.println("========End of the Dynamic Query=================");
26       
27        System.out.println("========Static Query=================");
28        CUSTOMERS cust = CUSTOMERS.getInstance(ctx,"OrderManagement");
29        System.out.println(cust.CUSTOMERS());
30        System.out.println("========End of the Static Query=================");
31       
32        System.out.println("========Prepared Expression Query=================");
33        PreparedExpression prepareExpression = DataServiceFactory.prepareExpression(new
34        InitialContext(h),"OrderManagement", "<test>"+"OrderManagement"+"</test>");
35        System.out.println(prepareExpression.executeQuery());
36        System.out.println("========End of Prepared Expression Query=================");
37       
38        }catch(Exception exp){
39                   
40        }
41    }
42 }

Let's walk through this code. We use the DataServiceFactory factory class to get a reference to the data service.

Referring to Line 23, you'll see:

DataServiceFactory.newDataService(ctx,"OrderManagement","ld:repository/CUSTOMERS");

Here "OrderManagement" is the ADSP project name, and "ld:repository/CUSTOMERS" is the URI to the data service.

Referring to Line 24: The xds.invoke("CUSTOMERS",null) calls the function in the data service. Here we are passing "null" as the parameter since this is a no argument function. This function will return an array of CUSTOMERS as a result. (The same result can be viewed by executing the function from the test view in WebLogic Workshop.)

Line 28 shows how we can use the static API to call the same function. Here "CUSTOMERS" is the mediator client generated with the help of WebLogic Workshop.

Line 33 shows how to use PreparedExpression to execute the ad hoc queries. Refer to the product documentation for more details.

AquaLogic DSP also provides a Streaming API that you can use for large result sets. Chapter 13 of the Samples Tutorial (PDF) of the product documentation explains this technology.

AquaLogic DSP Control

WebLogic Workshop comes with a rich collection of controls. AquaLogic DSP controls can help in developing applications that can talk with LD applications. Refer to the product documentation for more details on building AquaLogic DSP controls.

Pages: 1, 2, 3, 4

Next Page »