KickJava   Java API By Example, From Geeks To Geeks.

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


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.AddressLine;
23 import org.apache.juddi.datatype.business.BusinessEntity;
24 import org.apache.juddi.datatype.business.Contact;
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 TestAddressLineTable
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)
54     throws Exception JavaDoc
55   {
56     Transaction txn = new Transaction();
57     UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
58
59     if (connection != null)
60     {
61       try
62       {
63         String JavaDoc authorizedUserID = "sviens";
64
65         String JavaDoc businessKey = uuidgen.uuidgen();
66         BusinessEntity business = new BusinessEntity();
67         business.setBusinessKey(businessKey);
68         business.setAuthorizedName("sviens");
69         business.setOperator("WebServiceRegistry.com");
70
71         Contact contact = new Contact();
72         contact.setPersonNameValue("Bill Bob");
73         contact.setUseType("server");
74
75         Vector JavaDoc contactList = new Vector JavaDoc();
76         contactList.add(contact);
77         int contactID = 0;
78
79         Address address = new Address();
80         address.setUseType("Mailing");
81         address.setSortCode("a");
82
83         Vector JavaDoc addrList = new Vector JavaDoc();
84         addrList.add(address);
85         int addressID = 0;
86
87         AddressLine addrLine1 = new AddressLine();
88         addrLine1.setLineValue("SteveViens.com, Inc.");
89
90         AddressLine addrLine2 = new AddressLine();
91         addrLine2.setLineValue("PO BOX 6856");
92
93         AddressLine addrLine3 = new AddressLine();
94         addrLine3.setLineValue("78 Marne Avenue");
95
96         AddressLine addrLine4 = new AddressLine();
97         addrLine4.setLineValue("Portsmouth");
98
99         AddressLine addrLine5 = new AddressLine();
100         addrLine5.setLineValue("New Hampshire");
101
102         Vector JavaDoc lineList = new Vector JavaDoc();
103         lineList.add(addrLine1);
104         lineList.add(addrLine2);
105         lineList.add(addrLine3);
106         lineList.add(addrLine4);
107         lineList.add(addrLine5);
108
109         // begin a new transaction
110
txn.begin(connection);
111
112         // insert a new BusinessEntity
113
BusinessEntityTable.insert(business,authorizedUserID,connection);
114
115         // insert a new Contact
116
ContactTable.insert(businessKey,contactList,connection);
117
118         // insert a new Address
119
AddressTable.insert(businessKey,contactID,addrList,connection);
120
121         // insert a Collection of AddressLine objects
122
AddressLineTable.insert(businessKey,contactID,addressID,lineList,connection);
123
124         // select the Collection of AddressLine objects
125
lineList = AddressLineTable.select(businessKey,contactID,addressID,connection);
126
127         // delete the Collection of AddressLine objects
128
//AddressLineTable.delete(businessKey,connection);
129

130         // re-select the Collection of AddressLine objects
131
lineList = AddressLineTable.select(businessKey,contactID,addressID,connection);
132
133         // commit the transaction
134
txn.commit();
135       }
136       catch(Exception JavaDoc ex)
137       {
138         try { txn.rollback(); }
139         catch(java.sql.SQLException JavaDoc sqlex) { sqlex.printStackTrace(); }
140         throw ex;
141       }
142     }
143   }
144 }
145
Popular Tags