KickJava   Java API By Example, From Geeks To Geeks.

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


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.Name;
22 import org.apache.juddi.datatype.business.BusinessEntity;
23 import org.apache.juddi.datatype.service.BusinessService;
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 TestServiceNameTable
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         String JavaDoc serviceKey = uuidgen.uuidgen();
68         BusinessService service = new BusinessService();
69         service.setServiceKey(serviceKey);
70         service.setBusinessKey(businessKey);
71
72         Vector JavaDoc nameList = new Vector JavaDoc();
73         nameList.add(new Name("SteveViens.com", "en"));
74         nameList.add(new Name("EsephanoViens.com", "it"));
75         nameList.add(new Name("AsdfJkl.com", "cy"));
76
77         String JavaDoc authorizedUserID = "sviens";
78
79         // begin a new transaction
80
txn.begin(connection);
81
82         // insert a new BusinessEntity
83
BusinessEntityTable.insert(business, authorizedUserID, connection);
84
85         // insert a new BusinessService
86
BusinessServiceTable.insert(service, connection);
87
88         // insert a Collection of Name objects
89
ServiceNameTable.insert(serviceKey, nameList, connection);
90
91         // select the Collection of Name objects
92
nameList = ServiceNameTable.select(serviceKey, connection);
93
94         // delete the Collection of Name objects
95
ServiceNameTable.delete(serviceKey, connection);
96
97         // re-select the Collection of Name objects
98
nameList = ServiceNameTable.select(serviceKey, connection);
99
100         // commit the transaction
101
txn.commit();
102       }
103       catch (Exception JavaDoc ex)
104       {
105         try
106         {
107           txn.rollback();
108         }
109         catch (java.sql.SQLException JavaDoc sqlex)
110         {
111           sqlex.printStackTrace();
112         }
113         throw ex;
114       }
115     }
116   }
117 }
118
Popular Tags