KickJava   Java API By Example, From Geeks To Geeks.

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


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.Email;
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 TestEmailTable
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("Billy Bob");
69         contact.setUseType("server");
70         contactList.add(contact);
71         int contactID = 0;
72
73         Vector JavaDoc emailList = new Vector JavaDoc();
74         Email email = null;
75
76         email = new Email("support@steveviens.com");
77         email.setUseType("Support");
78         emailList.add(email);
79
80         email = new Email("marketing@steveviens.com");
81         email.setUseType("Advertising");
82         emailList.add(email);
83
84         email = new Email("info@steveviens.com");
85         email.setUseType("Information");
86         emailList.add(email);
87
88         email = new Email("admin@steveviens.com");
89         email.setUseType("Administration");
90         emailList.add(email);
91
92         email = new Email("webmaster@steveviens.com");
93         email.setUseType("Web Master");
94         emailList.add(email);
95
96         String JavaDoc authorizedUserID = "sviens";
97
98         // begin a new transaction
99
txn.begin(connection);
100
101         // insert a new BusinessEntity
102
BusinessEntityTable.insert(business, authorizedUserID, connection);
103
104         // insert a new Contact
105
ContactTable.insert(businessKey, contactList, connection);
106
107         // insert a Collection of Email objects
108
EmailTable.insert(businessKey, contactID, emailList, connection);
109
110         // select a Collection of Email objects by BusinessKey
111
emailList = EmailTable.select(businessKey, contactID, connection);
112
113         // delete a Collection of Email objects by BusinessKey
114
EmailTable.delete(businessKey, connection);
115
116         // re-select a Collection of Email objects by BusinessKey
117
emailList = EmailTable.select(businessKey, contactID, connection);
118
119         // commit the transaction
120
txn.commit();
121       }
122       catch (Exception JavaDoc ex)
123       {
124         try
125         {
126           txn.rollback();
127         }
128         catch (java.sql.SQLException JavaDoc sqlex)
129         {
130           sqlex.printStackTrace();
131         }
132         throw ex;
133       }
134     }
135   }
136 }
137
Popular Tags