Content starts here Static Mediator API Code Reference
This page last changed on Jun 10, 2008.

edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2 Documentation > ALDSP 3.2 New Features Documentation

Static Mediator API Code Reference

This topic describes the advanced sample project that uses the Static Mediator API to call data service operations from client applications using a variety of argument and return types.

Source:

DSPClientSamplesStatic1/JavaResources/client.java_and_ws.static0

Topic Map

Using a Complex Argument

You can call ALDSP data service operations using a complex argument type. The example in this section creates a profileService object and populates the object with customer information using type-safe setter methods.

The sample then calls the getServiceCase method using the complex argument, which retrieves the CASE information through the identically-named ALDSP operation.

Source:

DSPClientSamplesStatic1/Java Resources/src/client.java_and_ws.static0/ClientComplexArg.java

Calling an Operation Using a Complex Argument
retailer.PROFILE_SERVICE profileService =(retailer.PROFILE_SERVICE)factory.create(retailer.PROFILE_SERVICE.class );

com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE");
retailertype.PROFILE_TYPE profile = profileService.createPROFILE();
profile.setCustomerID("CUSTOMER4");
profile.setFirstName("dummyFirstName");
profile.setLastName("dummyLastName");
profile.setCustomerSince( "2001-01-01");
profile.setEmailAddress( "dummyEmailAddress");
profile.setTelephoneNumber("8885551212");

if(isWebServiceClient()){
   dasResult = wsDas.getServiceCase(profileService);
} else {
   dasResult = ejbDas.getServiceCase(profileService);
}

Using a Complex Argument List

You can call data service operations using an argument consisting of a list of complex types. The example in this section creates two profileService objects and populates the objects with customer information using type-safe setter methods.

The sample then calls the getServiceCase method using the argument consisting of the list of complex objects, retrieving the CASE information through the identically-named ALDSP operation.

Source:

DSPClientSamplesStatic1/Java Resources/src/client.java_and_ws.static0/ClientComplexArgList.java

Calling an Operation Using a List of Complex Arguments
retailer.PROFILE_SERVICES profileService =(retailer.PROFILE_SERVICES)factory.create("urn:retailer", "PROFILE_SERVICES");
com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILES");
retailertype.PROFILE_TYPE profile = profileService.createPROFILE();
profile.setCustomerID("CUSTOMER4");
profile.setFirstName("dummyFirstName");
profile.setLastName("dummyLastName");
profile.setCustomerSince( "2001-01-01");
profile.setEmailAddress( "dummyEmailAddress");
profile.setTelephoneNumber("8885551212");

profile = profileService.createPROFILE();
profile.setCustomerID("CUSTOMER6");
profile.setFirstName("dummyFirstName");
profile.setLastName("dummyLastName");
profile.setCustomerSince( "2001-01-01");
profile.setEmailAddress( "dummyEmailAddress");
profile.setTelephoneNumber("8885551212");

if(isWebServiceClient()){
   dasResult = wsDas.getServiceCases(profileService);
} else {
   dasResult = ejbDas.getServiceCases(profileService);
}

Using a Complex Argument with Create-Read-Update-Delete Operations

You can call multiple ALDSP data service operations, each with a complex argument type, to perform a series of tasks including invoking create, read, update, and delete operations in the data service. The example in this section creates two profileService objects and populates the objects with "dummy" customer information using type-safe setter methods.

The sample then calls the getCustomerByCustID method using a complex argument and checks whether the customer information is already stored. If not, the sample calls the createPROFILE method to create the customer profile.

If a record already exists for the customer, the sample calls the updatePROFILE method to store the new information in the profileService object. If an existing record does not match, the sample calls the deletePROFILE method to remove the customer profile.

Source:

DSPClientSamplesStatic1/Java Resources/src/client.java_and_ws.static0/ClientComplexArgs_andCRUD.java

Calling Multiple Operations Using Complex Arguments
com.bea.dsp.sdo.SDOUtil.setElementName(profileService1,	"urn:retailer", "PROFILE");

profileServices[0]=profileService1;

retailertype.PROFILE_TYPE profile1 = profileService1.createPROFILE();
profile1.setCustomerID("CUSTOMER44");
profile1.setFirstName("dummyFirstName");
profile1.setLastName("dummyLastName44");
profile1.setCustomerSince( "2001-01-01");
profile1.setEmailAddress( "dummyEmailAddress");
profile1.setTelephoneNumber("8885551212");

retailer.PROFILE_SERVICE profileService2 =(retailer.PROFILE_SERVICE)factory.create("urn:retailer", "PROFILE_SERVICE");
com.bea.dsp.sdo.SDOUtil.setElementName(profileService2, "urn:retailer", "PROFILE");

profileServices[1]=profileService2;
retailertype.PROFILE_TYPE profile2 = profileService2.createPROFILE();
profile2.setCustomerID("CUSTOMER55");
profile2.setFirstName("dummyFirstName");
profile2.setLastName("dummyLastName55");
profile2.setCustomerSince( "2001-01-01");
profile2.setEmailAddress( "dummyEmailAddress");
profile2.setTelephoneNumber("8885551212");

if(isWebServiceClient()){
   dasResult = wsDas.getCustomerByCustID("CUSTOMER44");
} else {
   dasResult = ejbDas.getCustomerByCustID("CUSTOMER44");
}

if(!dasResult.hasNext()) {
   out("ADDING: ");

   if(isWebServiceClient()) {
      dasKey = wsDas.createPROFILE(profileServices);
   } else {
      dasKey = ejbDas.createPROFILE(profileServices);
   }

   while( dasKey.hasNext()){
      out("DataObject : " + dataObjectToString(xh, dasKey.next()));
   }

} else {
   retailer.PROFILE_SERVICE dObj= dasResult.next();

   if("dummyLastName44".equals(dObj.get("PROFILE/LastName"))){
      out("UPDATING: ");
      out("DataObject : " + dataObjectToString(xh,dObj));
      com.bea.dsp.sdo.SDOUtil.enableChanges(dObj);
      dObj.set("PROFILE/LastName", "Smith");
      if(isWebServiceClient()){
         wsDas.updatePROFILE(new retailer.PROFILE_SERVICE[]{dObj});
      } else {
         ejbDas.updatePROFILE(new retailer.PROFILE_SERVICE[]{dObj});
      }
   } else {
      out("DELETING: ");
      out("DataObject : " + dataObjectToString(xh,dObj));

      if(isWebServiceClient()){
         wsDas.deletePROFILE(new retailer.PROFILE_SERVICE[]{dObj});
      } else {
         ejbDas.deletePROFILE(new retailer.PROFILE_SERVICE[]{dObj});
      }

      if(isWebServiceClient()){
         dasResult = wsDas.getCustomerByCustID("CUSTOMER55");
      } else {
         dasResult = ejbDas.getCustomerByCustID("CUSTOMER55");
      }

      if(dasResult.hasNext()){
         dObj=dasResult.next();
         out("DataObject : " + dataObjectToString(xh,dObj));
         if(isWebServiceClient()){
            wsDas.deletePROFILE(new retailer.PROFILE_SERVICE[]{dObj});
         } else {
         ejbDas.deletePROFILE(new retailer.PROFILE_SERVICE[]{dObj});
         }
      }
   }
}

Returning a Simple Element

You can call ALDSP data service operations that return simple types. The example in this section determines the number of orders by calling the getOrderCount and getOrderCounts methods and assigning the results to variables of type java.math.BigInteger.

Source:
DSPClientSamplesStatic1/Java Resources/src/client.java_and_ws.static0/ClientSimpleReturn.java
Calling an Operation that Returns a Simple Type
java.math.BigInteger count;
if(isWebServiceClient()){
   count = wsDas.getOrderCount("CUSTOMER4");
} else {
   count = ejbDas.getOrderCount("CUSTOMER4");
}

out("DataObject : " + count);

if(isWebServiceClient()){
   dasResult = wsDas.getOrderCounts("CUSTOMER4");
} else {
   dasResult = ejbDas.getOrderCounts("CUSTOMER4");
}

while( dasResult.hasNext()){
   java.math.BigInteger theCount = (java.math.BigInteger) dasResult.next();
   out("DataObject : " + theCount);
}

Including Auditing

You can audit calls to ALDSP data service operations and later retrieve the audit information for further processing. The example in this section creates a RequestConfig object and enables the data service audit feature (RETURN_DATA_SERVICE_AUDIT).

After enabling audit, the example includes the instance of the RequestConfig object as an argument when calling methods corresponding to data service operations. The example then retrieves the audit records and iterates through the results to output for display.

Source:

DSPClientSamplesStatic1/Java Resources/src/client.java_and_ws.static0/ClientWithAudit.java

Auditing Operations
com.bea.dsp.RequestConfig reqConfig = new com.bea.dsp.RequestConfig();
reqConfig.enableFeature(com.bea.dsp.RequestConfig.RETURN_DATA_SERVICE_AUDIT);
reqConfig.setStringArrayAttribute(com.bea.dsp.RequestConfig.RETURN_AUDIT_PROPERTIES, attributes);

if(isWebServiceClient()){
   dasResult = wsDas.getCustomerByLoginID("Steve", reqConfig);
} else {
   dasResult = ejbDas.getCustomerByLoginID("Steve", reqConfig);
}

com.bea.ld.DataServiceAudit dsAudit = reqConfig.retrieveDataServiceAudit();
if (dsAudit != null) {
   List l = dsAudit.getAllRecords();
   for (Iterator it = l.iterator(); it.hasNext();) {
      com.bea.ld.DSPAuditRecord auditRec = (com.bea.ld.DSPAuditRecord) it.next();
      Map propMap = auditRec.getAuditProperties();
      for (Iterator pit = propMap.keySet().iterator(); pit.hasNext();) {
         String key = (String) pit.next();
         out("Audit Information: " + key + " = " + propMap.get(key));
      }
   }
}

while( dasResult.hasNext()){
   out("DataObject : " + dataObjectToString(xh,(retailer.PROFILE_SERVICE)dasResult.next()));
}

Using Filters

You can filter the results of calls to data service operations using the ALDSP RequestConfig. The example in this section creates an instance of the RequestConfig object and then defines a filter based on the customer ID.

After defining the filter, the example sets the filter on the RequestConfig object and passes the instance of RequestConfig as an argument when calling the method corresponding to data service operation.

You can find the source code for this sample project in the DSPClientSamplesStatic1/Java Resources/src/client.java_and_ws.static0/ClientWithAudit.java file.

Filtering Based on an Identifier
reqConfig = new com.bea.dsp.RequestConfig();
com.bea.ld.filter.FilterXQuery filter=new com.bea.ld.filter.FilterXQuery();

filter.addFilter("PROFILE","PROFILE/PROFILE/CustomerID","=","$customerID");
com.bea.ld.ExternalVariables externalVariables=new com.bea.ld.ExternalVariables();
externalVariables.setString(new javax.xml.namespace.QName("customerID"), "CUSTOMER5");
filter.setExternalVariables(externalVariables);

/* Alteratively, filter with a hard-coded value */

// filter.addFilter("PROFILE", "PROFILE/PROFILE/CustomerID","=","CUSTOMER5");

reqConfig.setFilter(filter);
try {
   if(isWebServiceClient()){
      dasResult = wsDas.getProfile(reqConfig);
   } else {
      dasResult = ejbDas.getProfile(reqConfig);
   }
}

Related Topics

Concepts
How Tos
Reference
Document generated by Confluence on Jul 03, 2008 12:11