CustomerDB_XMLBean.jcx Sample

This topic inludes the source code for the CustomerDB_XMLBean.jcx Sample.

Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebServices/database/xmlBean/

Sample Source Code


01 package database.xmlBean; 
02 
03 import databaseCustomerDb.XCustomerDocument;
04 import databaseCustomerDb.XCustomerDocument.XCustomer;
05 import databaseCustomerDb.XCustomerDocument.Factory;
06 import com.bea.control.DatabaseControl;
07 import databaseCustomerDb.XCustomerDocument.XCustomer.XCustomerRow; 
08 import java.sql.SQLException; 
09 
10 
11 /** 
12  *<p> A sample Database Control that demonstrates how to
13  * load database data into XMLBean types.</p>
14  *
15  <p>This Database Control uses the JDBC Data Source 
16  * "cgSampleSataSource" which is configured automatically
17  * when WebLogic Workshop is installed.</p>
18  *
19  <p>The data source is configured with the JNDI
20  * name "cgSampleDataSource".</p>
21  
22  <p>The SQL queries refer to the CUSTOMER table,
23  * which is pre-loaded in the Pointbase database.</p>
24  
25  <p>The CUSTOMER table contains the following fields:
26  *      <ul>
27  *          <li>CUSTID (INT, Primary Key)</li>
28  *          <li>NAME (VARCHAR)</li>
29  *          <li>ADDRESS (VARCHAR)</li>
30  *          <li>CITY (VARCHAR)</li>
31  *          <li>STATE (CHAR(2))</li>
32  *          <li>ZIP (VARCHAR)</li>
33  *          <li>AREA_CODE (CHAR(3))</li>
34  *          <li>PHONE CHAR(9)</li>
35  *      </ul>
36  </p>
37  *
38  * @jc:connection data-source-jndi-name="cgSampleDataSource" 
39  */ 
40 
41 public interface CustomerDB_XMLBean extends com.bea.control.ControlExtension, DatabaseControl 
42 {
43     /**
44      * @jc:sql statement="SELECT * FROM customer" 
45      */
46      public XCustomerDocument findAllCustomersDoc()
47 
48     /**
49      * @jc:sql statement="SELECT name FROM customer" 
50      *      array-max-length=100
51      */
52      public XCustomerDocument getAllCustomerNames()
53 
54     /**
55      * @jc:sql statement="SELECT custid, name, address, city, state, zip, area_code, phone FROM customer WHERE custid = {key}"
56      */
57     public XCustomerDocument getCustomerByID(int key)
58 
59     /**
60      * @jc:sql statement="SELECT city FROM customer WHERE custid = {key}"
61      */
62     public XCustomerDocument getCustomerCityByID(int key)
63 
64     /**
65      * This method takes an XCustomerRow object
66      
67      *      <XCustomerRow> 
68      *          <CUSTID>1111</CUSTID> 
69      *          <NAME>Some Name</NAME> 
70      *          <ADDRESS>Some Address</ADDRESS> 
71      *          <CITY>Some City</CITY> 
72      *          <STATE>Some State</STATE> 
73      *          <ZIP>00000</ZIP> 
74      *          <AREA_CODE>111</AREA_CODE> 
75      *          <PHONE>123-4567</PHONE> 
76      *      </XCustomerRow>
77      *      
78      *  and parses it into a SQL INSERT statement before passing the statement onto the database.
79      *  Note that the substitution syntax uses the XML document's elements names: {cust.CUSTID}, {cust.NAME}, etc.
80      *   
81      * @jc:sql statement::
82      *     INSERT INTO customer (custid,name,address,city,state,zip,area_code,phone)
83      *     VALUES ({cust.CUSTID},{cust.NAME},{cust.ADDRESS},{cust.CITY},{cust.STATE}, 
84      *              {cust.ZIP},{cust.AREACODE},{cust.PHONE})
85      * ::
86      */
87     public int insertCustomerBean(XCustomerRow cust)
88 }