KickJava   Java API By Example, From Geeks To Geeks.

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


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.Phone;
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 TestPhoneTable
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 businessKey = uuidgen.uuidgen();
62         BusinessEntity business = new BusinessEntity();
63         business.setBusinessKey(businessKey);
64         business.setAuthorizedName("sviens");
65         business.setOperator("WebServiceRegistry.com");
66
67         Vector JavaDoc contactList = new Vector JavaDoc();
68         Contact contact = new Contact("John Smith");
69         contact.setUseType("tech support");
70         contactList.add(contact);
71         int contactID = 0;
72
73         Vector JavaDoc phoneList = new Vector JavaDoc();
74         Phone phone = null;
75
76         phone = new Phone("603.457.8110");
77         phone.setUseType("Voice Mailbox");
78         phoneList.add(phone);
79
80         phone = new Phone("603.457.8111");
81         phone.setUseType("Fax");
82         phoneList.add(phone);
83
84         phone = new Phone("603.457.8112");
85         phone.setUseType("Mobil");
86         phoneList.add(phone);
87
88         phone = new Phone("603.457.8113");
89         phone.setUseType("Pager");
90         phoneList.add(phone);
91
92         String JavaDoc authorizedUserID = "sviens";
93
94         // begin a new transaction
95
txn.begin(connection);
96
97         // insert a new BusinessEntity
98
BusinessEntityTable.insert(business, authorizedUserID, connection);
99
100         // insert a new Contact
101
ContactTable.insert(businessKey, contactList, connection);
102
103         // insert a Collection of Phone objects
104
PhoneTable.insert(businessKey, contactID, phoneList, connection);
105
106         // select a Collection of Phone objects by BusinessKey
107
phoneList = PhoneTable.select(businessKey, contactID, connection);
108
109         // delete a Collection of Phone objects by BusinessKey
110
PhoneTable.delete(businessKey, connection);
111
112         // re-select a Collection of Phone objects by BusinessKey
113
phoneList = PhoneTable.select(businessKey, contactID, connection);
114
115         // commit the transaction
116
txn.commit();
117       }
118       catch (Exception JavaDoc ex)
119       {
120         try
121         {
122           txn.rollback();
123         }
124         catch (java.sql.SQLException JavaDoc sqlex)
125         {
126           sqlex.printStackTrace();
127         }
128         throw ex;
129       }
130     }
131   }
132 }
133
Popular Tags