![]() ![]() ![]() ![]() ![]() ![]() |
After a Data Services Platform (ALDSP) application is deployed to a WebLogic Server, clients can use it to access real-time data. ALDSP supports a services-oriented approach to data access, using several technologies:
In this lesson, you will enable ALDSP to consume data through the SDO Mediator API.
After completing this lesson, you will be able to:
SDO is a joint specification of BEA and IBM that defines a Java-based programming architecture and API for data access. A central goal of SDO is to provide client applications with a unified interface for accessing and updating data, regardless of its physical source or format.
SDO has similarities with other data access technologies, such as JDBC, Java Data Objects (JDO), and XMLBeans. However, what distinguishes SDO from other technologies is that SDO gives applications both static programming and a dynamic API for accessing data, along with a disconnected model for accessing externally persisted data. Disconnected data access means that when ALDSP gets data from a source, such as a database, it opens a connection to the source only long enough to retrieve the data. The connection is closed while the client operates on the data locally. When the client submits changes to apply to the source, the connection is reopened.
ALDSP implements the SDO specification as its client programming model. In concrete terms, this means that when a client application invokes a read function on a data service residing on a server, any data is returned as a data object. A data object is a fundamental component of the SDO programming model. It represents a unit of structured information, with static and dynamic interfaces for getting and setting its properties.
In addition to static calls, SDO, like RowSets in JDBC, has a dynamic Mediator API for accessing data through untyped calls (for example, getString("CUSTOMER_NAME")). An untyped Mediator API is useful if you do not know the data service to run at development time.
The Mediator API gives client applications full access to data services deployed on a WebLogic server. The application can invoke read functions, get the results as Service Data Objects, and pass changes back to the source. To use the Mediator API, a client program must first establish an initial context with the server that hosts the data services. The client can then invoke data service queries and operate on the results as Service Data Objects.
An untyped Mediator API is useful if, at development time, you do not know the data service to run.
<beahome>\weblogic81\samples\liquiddata\EvalGuide
The Java project is added to the application, in the DataServiceClient folder. To use the Mediator API, you need to add the method calls to instantiate the data service, invoke the getCustomerProfile() method and assign the return value of the function to the CustomerProfileDocument SDO/XML bean.
import com.bea.dsp.dsmediator.client.DataService;
import com.bea.dsp.dsmediator.client.DataServiceFactory;
String params[] = {customer_id};
DataService ds = DataServiceFactory.newDataService(
getInitialContext(), // Initial Context
"Evaluation", // Application Name
"ld:DataServices/CustomerManagement/CustomerProfile" // Data Service Name
);
CustomerProfileDocument[] doc = (CustomerProfileDocument[]) ds.invoke("getCustomerProfile",params);
Customer customer = doc.getCustomerProfile().getCustomerArray(0);
Customer customer = doc[0].getCustomerProfile().getCustomerArray(0);
Note: | WebLogic Server must be running. Confirm that the program returns the specified results by viewing the results in the Output window (if the Output window is not open, choose View ![]() ![]() |
Note: | To use the Mediator API outside of WebLogic Workshop, you need to add the following files to your classpath: |
%\bea\weblogic81\server\lib\weblogic.jar
%\bea\weblogic81\server\lib\xbean.jar
%\bea\user_projects\applications\Evaluation\APP-INF\lib\DataServices.jar
%\bea\weblogic81\liquiddata\lib\ld-server-core.jar
%\bea\weblogic81\liquiddata\lib\ld-client.jar
%\bea\weblogic81\liquiddata\lib\wlsdo.jar
With the typed mediator interface, you instantiate a typed data service proxy in the client, instead of using the generic data service interface. The typed data service interface may be easier to program and it improves code readability.
In this exercise, you will access data services from a Java client, using the typed SDO Mediator API. You will be provided with a generated API for your data service, which lets you directly invoke the actual functions as methods (for example, ds.getCustomerProfile(customer_id)).
Note: | This confirmation box appears only the first time you build the SDO Mediator Client. However, to ensure that the latest EAR file is used while building the SDO Mediator Client, you must build the EAR before you build the SDO Mediator Client. |
Generating SDO client API jar...
clean:
de-ear:
build:
[delete] Deleting: C:\bea\user_projects\applications\Evaluation\Evaluation-ld-client.jar
[mkdir] Created dir: C:\Documents and Settings\jsmith\Local Settings\Temp\wlw-temp-53911\sdo_compile42918\client\src
[java] May 2, 2006 6:41:26 PM com.bea.ld.context.MetadataContext getRepositoryRoot
[java] INFO: 30 (ms)
[java] May 2, 2006 6:41:27 PM com.bea.ld.wrappers.ws.JAXRPCWebserviceAdapter <clinit>
[java] WARNING: Unable to instantiate ServiceFactory. Please ensure that javax.xml.rpc.ServiceFactory property has been properly set.
[mkdir] Created dir: C:\Documents and Settings\jsmith\Local Settings\Temp\wlw-temp-53911\sdo_compile42918\client\classes
[javac] Compiling 12 source files to C:\Documents and Settings\jsmith\Local Settings\Temp\wlw-temp-53911\sdo_compile42918\client\classes
[jar] Updating jar: C:\bea\user_projects\applications\Evaluation\Evaluation-ld-client.jar
all:
Importing SDO client API jar into application...
SDO client API jar available as C:\bea\user_projects\applications\Evaluation\Evaluation-ld-client.jar
Note: | The drive information may be different for your application. |
CustomerProfile ds = CustomerProfile.getInstance(
getInitialContext(), // Initial Context
"Evaluation" // Application Name
);
CustomerProfileDocument doc = ds.getCustomerProfile(customer_id);
Note: | In the case of typed mediator APIs, you specify whether you are retrieving a single object or an array based on the data service function declaration. In the preceding example, to retrieve a single object in the output, the doc object is used instead of doc[0]. |
After Excercise 7.2 Running a Java Program Using the Typed Mediator API, you must remove the Evaluation_ld-client.jar file from your Libraries folder because this JAR file will create inconsistencies in future lessons. You must also revert the method calls to use the Untyped Mediator API.
DataService ds = DataServiceFactory.newDataService(
getInitialContext(), // Initial Context
"Evaluation", // Application Name
"ld:DataServices/CustomerManagement/CustomerProfile" // Data Service Name
);
CustomerProfileDocument[] doc = (CustomerProfileDocument[])
ds.invoke("getCustomerProfile", params);
System.out.println("Connected to DSP 2.x : CustomerProfile Data Service...");
Note: | If your application name is different from Evaluation, locate "Evaluation" in the newDataService() call and rename it to reflect the name of your application. |
In this lesson, you learned how to:
![]() ![]() ![]() |