Samples Tutorial

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Creating Data Services from Java Functions

A Java function is another form of metadata that ALDSP can use as a data source. This is perhaps the most powerful metadata, because it allows ALDSP to utilize any data source that can be accessed from Java, such as Enterprise Java Beans, JMS/messaging applications, LDAP and other directory services, text/binary files that can be read through Java I/O, and even DCOM-based applications like Microsoft Excel.

In this lesson, you will access three data sources through Java functions:

 


Objectives

After completing this lesson, you will be able to:

 


Overview

When you use ALDSP's Import Source Metadata feature to import user-defined Java functions, the functions are introspected to create the necessary method signatures and parameter metadata. At the same time, a prologue is created that defines the function's signatures and relevant schema type for complex elements such as Java classes and arrays.

In ALDSP, user-defined functions are treated as Java classes. The following are supported:

The Metadata Import Wizard supports marshalling and unmarshalling that converts Java token iterators into XML, and vice versa. For example, you start with a Java function, getListGivenMixed, defined as follows:

public static float[] getListGivenMixed(float[] fpList, int size) {
int listLen = ((fpList.length > size) ? size : fpList.length);
float fpListop = new float[listLen];
for (int i =0; i < listLen; i++)
fpListop[i]=fpList[i];
return fpListop;
}

After the function is processed through the Metadata Import Wizard, the following XML-based metadata is generated:

(::pragma xds <x:xds xmlns:x="urn:annotations.ld.bea.com"
targetType="t:float" xmlns:t="http://www.w3.org/2001/XMLSchema">
<javaFunction
classpath="D:\jf\build\jar\jfTest.jar;D:\jf\xbeanTests\xbeangen\
Customer.jar;D:\wls82\weblogic81\server\lib\xbean.jar"
class="jfTest.Customer"/>
</x:xds>::)
declare namespace f1 = "ld:javaFunc/float";
(::pragma function <f:function xmlns:f="urn:annotations.ld.bea.com"
kind="datasource" access="public">
<params>
<param nativeType="[F"/>
<param nativeType="int"/>
</params>
</f:function>::)
declare function f1:getListGivenMixed($x1 as xsd:float*, $x2 as xsd:int)
as xsd:float* external;

The corresponding XQuery for the imported Java function would be as follows:

declare namespace f1 = "ld:javaFunc/float";
let $y := (2.0, 4.0, 6.0, 8.0, 10.0)
let $x := f1:getListGivenMixed($y, 2)
return $x
Note: To ensure successful importation and usage within ALDSP, the Java function should be static functions and its package and class names should be defined in its namespace. ALDSP recognizes the Java method name as the XQuery function name qualified with the Java function namespace.

For detailed information about using Java functions within ALDSP see the Data Services Developer's Guide.

 


32.1 Accessing Data Using WebLogic's Embedded LDAP Function

ALDSP enables access to data services, using WebLogic's embedded LDAP function. You will learn how to use this functionality by importing a Directory Service Markup Language (DSML)-based Java application as a Java function.

Objectives

In this exercise, you will:

Instructions

  1. In the DataServices project, create a folder and name it Functions. This is where you will place the Java functions that you want to import.
  2. Set the LDAP security credential for WebLogic's Embedded LDAP, by completing the following steps:
    1. Open the WebLogic Server Console from your browser:
    2. http://localhost:7001/console.
    3. Login using the following credentials:
      • User Name = weblogic
      • Password = weblogic
    4. Select the Security folder, located under the ldplatform domain.
    5. Click Embedded LDAP.
    6. Enter security in the Credential and Confirm Credential fields.
    7. Click Apply. This allows access to the WebLogic Server LDAP.
    8. Figure 32-1 Setting LDAP Access Credentials


      Setting LDAP Access Credentials

  3. You will need to restart the WebLogic Server now as change to this property does not take effect until the Server is restarted.
  4. Create a new user, by completing the following steps:
    1. Expand the Security Arrow symbol Realms Arrow symbol myrealm Arrow symbol Users folders.
    2. Click Configure a New User, using your name and a password of your choice.
    3. Click Apply.
  5. In WebLogic Workshop right-click the Libraries folder and import all the JAR files located in the samples\liqiddata\EvalGuide\ldap\lib folder into the Libraries folder in Workshop.
  6. Right-click the Functions folder and import DSML.java from the samples\liquiddata\EvalGuide folder.
  7. Build the DataServices project.
  8. Import the Java function metadata for the DSML Java application into the Functions folder by completing the following steps:
    1. Right click the Functions folder and choose Import Source Metadata.
    2. Select Java Function for the Data Source Type and click Next.
    3. In the Class Name field, browse and select DataServices.jar\Functions\DSML.class and click Next.
    4. Select the callDSML() function, click Add, and then click Next.
    5. Note: Do not select the callDSML procedure as a side-effect procedure.
    6. Accept the default settings in the Summary window and click Finish.
    7. The dsml.ds file and schemas folder are added to the Functions folder.

  9. Build the DataServices project.
  10. Test the DSML data service by completing the following steps:
    1. Open dsml.ds in Test View.
    2. Select callDSML() from the Function drop-down list.
    3. Enter the following arguments (for more information on LDAP arguments and access, see http://dev2dev.bea.com/codelibrary/code/ld_ldap.jsp):
      Description
      Argument

      LDAP URL

      ldap://localhost:7001

      Principal (Directory Manager)

      cn=Admin

      Credentials (Password)

      security

      JNDI (true: use JNDI to access LDAP; false: use native LDAP connection

      jndi

      Base domain name to search

      dc=ldplatform

      Filter used to search

      cn=<your user name>

    4. Click Execute.
    5. View the results.
    6. Figure 32-2 Results for callDSML()


       Results for callDSML()

 


32.2 Accessing Excel Spreadsheet Data Using JCOM

Data in a Microsoft Excel spreadsheet can be accessed through JCOM.

Objectives

In this exercise, you will:

Instructions

  1. Right-click the Libraries folder and using the add Add to Library option, add all the JAR files located in the samples\liqiddata\EvalGuide\excel\lib folder.
  2. Right-click the Functions folder and import excel_jcom.java from <beahome>\weblogic81\samples\LiquidData\EvalGuide.
  3. Build the DataServices project.
  4. Import the Java function metadata for the Excel JCOM Java application into the Functions folder, by completing the following steps:
    1. Right-click the Functions project and choose Import Source Metadata.
    2. Select Java Function for the Data Source Type and click Next.
    3. In the Class Name field, browse and select DataServices\Functions\Functions.excel_jcom and then click Next.
    4. Select the getExcel() function, click Add, and then click Next.
    5. Accept the default setting in the Select Side Effect Procedures window and click Next.
    6. Accept the default settings in the Summary window and click Finish. The excel.ds and associated schema files are added to the Functions folder.
  5. Build the DataServices project.
  6. Test the Excel data service, by completing the following steps:
    1. Open excel.ds in Test View.
    2. Select getExcel(x1, x2) from the Function drop-down list.
    3. Enter the following arguments:
      Description
      Argument

      XLS File Name

      <beahome>\weblogic81\samples\LiquidData\EvalGuide\excel\test.xls

      Worksheet Name

      Customers

  7. Review the results.
  8. Figure 32-3 Results of the getExcel function


     Results of the getExcel function

Note: For more information on Excel access refer to a dev2dev sample illustrating accessing data in an MS-Excel spreadsheet. As of this writing the sample is located at:
http://codesamples.projects.dev2dev.bea.com/servlets/Scarab?id=S230

 


32.3 (Optional) Accessing Data Using an Enterprise Java Bean

Create an Enterprise Java Bean that returns customer credit card information using a Java function.

Objectives

In this exercise, you will:

Instructions

  1. Create a Schemas Project, by completing the following steps:
    1. Right-click the Evaluation application folder and import the Schemas folder as a Schema Project. The folder is located in:
    2. <beahome>\weblogic81\samples\LiquidData\EvalGuide\ejb

      This schema will be used for the EJB results, which returns an XML document containing credit card information for a customer.

    3. Build the Schemas project.
  2. Create an EJB Project, by completing the following steps:
    1. Right-click the Evaluation application folder and import the EJB folder as an EJB Project. The folder is located in:
    2. <beahome>\weblogic81\samples\LiquidData\EvalGuide\ejb. This contains:

      • A container-managed entity bean that maps to the credit card database table.
      • A stateless session bean that invokes the entity bean finder method returning a list of credit cards for a given customer in the shape of the CREDIT_CARDS XML schema.
    3. Build the EJB project.
  3. Create a Java project, by completing the following steps:
    1. Right-click the Evaluation application folder and import the EJBClient folder as a Java Project. The folder is located in:
    2. <beahome>\weblogic81\samples\LiquidData\EvalGuide\ejb 

      This project contains the Java client that connects remotely to the stateless session bean. This will be used as the custom function.

    3. Build the EJBClient project.
  4. Run CreditCardClient.java, which is located in the EJBClient project folder. A list of credit cards for CUSTOMER3 should display in the Output window
  5. Note: Click OK for the pop-up message. Drag and drop the CreditCardClient.java into the Functions folder.
  6. Build the DataServices project.
  7. Import the Java function metadata for the EJB Client into the DataServices project by completing the following steps.
    1. Right-click the Functions folder and select Import Source Metadata.
    2. Select Java Function as the Data Source Type and click Next.
    3. Browse and select DataServices\Functions.CreditCardClient as the Class Name and click Next.
    4. Select getCreditCards, click Add, and then click Next.
    5. Accept the default settings in the Select Side Effect Procedures window.
    6. Accept the default settings in the Summary window and click Finish. The CREDIT_CARDS.ds file is added to the Functions folder.
    7. Note: Do not confuse this data service with the CREDIT_CARD.ds created from the relationship database.
    8. Build the DataServices project.
  8. Test the getCreditCards() function within the CREDIT_CARDS data service. Use CUSTOMER3 as the argument. Confirm that you can retrieve credit card information for Britt Pierce.
  9. Figure 32-4 Results for the getCreditCards() function


    Results for the getCreditCards() function

 


Lesson Summary

In this lesson, you learned how to import the following sources as Java functions:


  Back to Top       Previous  Next