KickJava   Java API By Example, From Geeks To Geeks.

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


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.Description;
22 import org.apache.juddi.datatype.business.BusinessEntity;
23 import org.apache.juddi.datatype.business.Contact;
24 import org.apache.juddi.datatype.business.Contacts;
25 import org.apache.juddi.util.Config;
26 import org.apache.juddi.util.jdbc.Transaction;
27 import org.apache.juddi.uuidgen.UUIDGen;
28 import org.apache.juddi.uuidgen.UUIDGenFactory;
29
30 /**
31  * @author Steve Viens (sviens@apache.org)
32  */

33 class TestContactDescTable
34 {
35   public static void main(String JavaDoc[] args)
36     throws Exception JavaDoc
37   {
38     // make sure we're using a DBCP DataSource and
39
// not trying to use JNDI to aquire one.
40
Config.setStringProperty("juddi.useConnectionPool","true");
41
42     Connection JavaDoc conn = null;
43     try {
44       conn = Database.aquireConnection();
45       test(conn);
46     }
47     finally {
48       if (conn != null)
49         conn.close();
50     }
51   }
52
53   public static void test(Connection JavaDoc connection) throws Exception JavaDoc
54   {
55     Transaction txn = new Transaction();
56     UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
57
58     if (connection != null)
59     {
60       try
61       {
62         // Description List
63
Vector JavaDoc descList = new Vector JavaDoc();
64         descList.add(new Description("blah, blah, blah", "en"));
65         descList.add(new Description("Yadda, Yadda, Yadda", "it"));
66         descList.add(new Description("WhoobWhoobWhoobWhoob", "cy"));
67         descList.add(new Description("Haachachachacha", "km"));
68
69         // Contact
70
Contact contact = new Contact("Anthony Michaels");
71         contact.setUseType("sales");
72         contact.setDescriptionVector(descList);
73
74         // Contact List
75
Vector JavaDoc contactList = new Vector JavaDoc();
76         contactList.add(contact);
77         Contacts contacts = new Contacts();
78         contacts.setContactVector(contactList);
79
80         // Business Entity
81
String JavaDoc businessKey = uuidgen.uuidgen();
82         BusinessEntity business = new BusinessEntity();
83         business.setBusinessKey(businessKey);
84         business.setAuthorizedName("sviens");
85         business.setOperator("WebServiceRegistry.com");
86         business.setContacts(contacts);
87
88         int contactID = 0;
89
90         // begin a new transaction
91
txn.begin(connection);
92
93         String JavaDoc authorizedUserID = "sviens";
94
95         // insert a new BusinessEntity
96
BusinessEntityTable.insert(business, authorizedUserID, connection);
97
98         // insert a new Contact
99
ContactTable.insert(businessKey, contactList, connection);
100
101         // insert a Collection of Description objects
102
ContactDescTable.insert(businessKey, contactID, descList, connection);
103
104         // select a Collection BusinessService objects by BusinessKey
105
descList = ContactDescTable.select(businessKey, contactID, connection);
106
107         // delete a Collection BusinessService objects by BusinessKey
108
ContactDescTable.delete(businessKey, connection);
109
110         // re-select a Collection Description objects by BusinessKey
111
descList = ContactDescTable.select(businessKey, contactID, connection);
112
113         // commit the transaction
114
txn.commit();
115       }
116       catch (Exception JavaDoc ex)
117       {
118         try
119         {
120           txn.rollback();
121         }
122         catch (java.sql.SQLException JavaDoc sqlex)
123         {
124           sqlex.printStackTrace();
125         }
126         throw ex;
127       }
128     }
129   }
130 }
131
Popular Tags