KickJava   Java API By Example, From Geeks To Geeks.

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


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

30 class TestBusinessServiceTable
31 {
32   public static void main(String JavaDoc[] args)
33     throws Exception JavaDoc
34   {
35     // make sure we're using a DBCP DataSource and
36
// not trying to use JNDI to aquire one.
37
Config.setStringProperty("juddi.useConnectionPool","true");
38
39     Connection JavaDoc conn = null;
40     try {
41       conn = Database.aquireConnection();
42       test(conn);
43     }
44     finally {
45       if (conn != null)
46         conn.close();
47     }
48   }
49
50   public static void test(Connection JavaDoc connection)
51     throws Exception JavaDoc
52   {
53     Transaction txn = new Transaction();
54     UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
55
56     if (connection != null)
57     {
58       try
59       {
60         String JavaDoc businessKey = uuidgen.uuidgen();
61         BusinessEntity business = new BusinessEntity();
62         business.setBusinessKey(businessKey);
63         business.setAuthorizedName("sviens");
64         business.setOperator("WebServiceRegistry.com");
65
66         String JavaDoc serviceKey = uuidgen.uuidgen();
67         BusinessService service = new BusinessService();
68         service.setBusinessKey(businessKey);
69         service.setServiceKey(serviceKey);
70
71         // begin a new transaction
72
txn.begin(connection);
73
74         String JavaDoc authorizedUserID = "sviens";
75
76         // insert a new BusinessEntity
77
BusinessEntityTable.insert(business,authorizedUserID,connection);
78
79         // insert a new BusinessService
80
BusinessServiceTable.insert(service,connection);
81
82         // insert another new BusinessService
83
service.setServiceKey(uuidgen.uuidgen());
84         BusinessServiceTable.insert(service,connection);
85
86         // insert one more new BusinessService
87
service.setServiceKey(uuidgen.uuidgen());
88         BusinessServiceTable.insert(service,connection);
89
90         // select a BusinessService object
91
service = BusinessServiceTable.select(serviceKey,connection);
92
93         // delete a BusinessService object
94
BusinessServiceTable.delete(serviceKey,connection);
95
96         // select a BusinessService object
97
service = BusinessServiceTable.select(serviceKey,connection);
98
99         // select a Collection BusinessService objects by BusinessKey
100
BusinessServiceTable.selectByBusinessKey(businessKey,connection);
101
102         // delete a Collection BusinessService objects by BusinessKey
103
BusinessServiceTable.deleteByBusinessKey(businessKey,connection);
104
105         // select a Collection BusinessService objects by BusinessKey
106
BusinessServiceTable.selectByBusinessKey(businessKey,connection);
107
108         // commit the transaction
109
txn.commit();
110       }
111       catch(Exception JavaDoc ex)
112       {
113         try { txn.rollback(); }
114         catch(java.sql.SQLException JavaDoc sqlex) { sqlex.printStackTrace(); }
115         throw ex;
116       }
117     }
118   }
119 }
120
Popular Tags