KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > datastore > jdbc > TestAddressTable


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.juddi.datastore.jdbc;
17
18 import java.sql.Connection JavaDoc;
19 import java.util.Vector JavaDoc;
20
21 import org.apache.juddi.datatype.Address;
22 import org.apache.juddi.datatype.business.BusinessEntity;
23 import org.apache.juddi.datatype.business.Contact;
24 import org.apache.juddi.util.Config;
25 import org.apache.juddi.util.jdbc.Transaction;
26 import org.apache.juddi.uuidgen.UUIDGen;
27 import org.apache.juddi.uuidgen.UUIDGenFactory;
28
29 /**
30  * @author Steve Viens (sviens@apache.org)
31  */

32 class TestAddressTable
33 {
34   public static void main(String JavaDoc[] args)
35     throws Exception JavaDoc
36   {
37     // make sure we're using a DBCP DataSource and
38
// not trying to use JNDI to aquire one.
39
Config.setStringProperty("juddi.useConnectionPool","true");
40
41     Connection JavaDoc conn = null;
42     try {
43       conn = Database.aquireConnection();
44       test(conn);
45     }
46     finally {
47       if (conn != null)
48         conn.close();
49     }
50   }
51
52   public static void test(Connection JavaDoc connection) throws Exception JavaDoc
53   {
54     Transaction txn = new Transaction();
55     UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
56
57     if (connection != null)
58     {
59       try
60       {
61         String JavaDoc authorizedUserID = "sviens";
62
63         String JavaDoc businessKey = uuidgen.uuidgen();
64         BusinessEntity business = new BusinessEntity();
65         business.setBusinessKey(businessKey);
66         business.setAuthorizedName("sviens");
67         business.setOperator("WebServiceRegistry.com");
68
69         Vector JavaDoc contactList = new Vector JavaDoc();
70         Contact contact = new Contact("Bill Bob");
71         contact.setUseType("server");
72         contactList.add(contact);
73         int contactID = 0;
74
75         Vector JavaDoc addrList = new Vector JavaDoc();
76         Address address = null;
77
78         address = new Address();
79         address.setUseType("Mailing");
80         address.setSortCode("a");
81         addrList.add(address);
82
83         address = new Address();
84         address.setUseType("Shipping");
85         address.setSortCode("b");
86         addrList.add(address);
87
88         address = new Address();
89         address.setUseType("Marketing");
90         address.setSortCode("c");
91         addrList.add(address);
92
93         address = new Address();
94         address.setUseType("Sales");
95         address.setSortCode("d");
96         addrList.add(address);
97
98         address = new Address();
99         address.setUseType("Engineering");
100         address.setSortCode("e");
101         addrList.add(address);
102
103         // begin a new transaction
104
txn.begin(connection);
105
106         // insert a new BusinessEntity
107
BusinessEntityTable.insert(business, authorizedUserID, connection);
108
109         // insert a new Contact
110
ContactTable.insert(businessKey, contactList, connection);
111
112         // insert a Collection of Address objects
113
AddressTable.insert(businessKey, contactID, addrList, connection);
114
115         // select the Collection of Address objects
116
addrList = AddressTable.select(businessKey, contactID, connection);
117
118         // delete the Collection of Address objects
119
AddressTable.delete(businessKey, connection);
120
121         // re-select the Collection of Address objects
122
addrList = AddressTable.select(businessKey, contactID, connection);
123
124         // commit the transaction
125
txn.commit();
126       }
127       catch (Exception JavaDoc ex)
128       {
129         try {
130           txn.rollback();
131         }
132         catch (java.sql.SQLException JavaDoc sqlex) {
133           sqlex.printStackTrace();
134         }
135
136         throw ex;
137       }
138     }
139   }
140 }
Popular Tags