KickJava   Java API By Example, From Geeks To Geeks.

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


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

29 class TestBusinessEntityTable
30 {
31   public static void main(String JavaDoc[] args)
32     throws Exception JavaDoc
33   {
34     // make sure we're using a DBCP DataSource and
35
// not trying to use JNDI to aquire one.
36
Config.setStringProperty("juddi.useConnectionPool","true");
37
38     Connection JavaDoc conn = null;
39     try {
40       conn = Database.aquireConnection();
41       test(conn);
42     }
43     finally {
44       if (conn != null)
45         conn.close();
46     }
47   }
48
49   public static void test(Connection JavaDoc connection)
50     throws Exception JavaDoc
51   {
52     Transaction txn = new Transaction();
53     UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
54
55     try
56     {
57       String JavaDoc businessKey = uuidgen.uuidgen();
58       BusinessEntity business = new BusinessEntity();
59       business.setBusinessKey(businessKey);
60       business.setAuthorizedName("Steve Viens");
61       business.setOperator("www.jUDDI.org");
62
63       String JavaDoc publisherID = "sviens";
64
65       // begin a new transaction
66
txn.begin(connection);
67
68       // insert a new BusinessEntity
69
BusinessEntityTable.insert(business,publisherID,connection);
70
71       // select one of the BusinessEntity objects
72
business = BusinessEntityTable.select(businessKey,connection);
73
74       // delete that BusinessEntity object
75
//BusinessEntityTable.delete(businessKey,connection);
76

77       // re-select that BusinessEntity object
78
business = BusinessEntityTable.select(businessKey,connection);
79
80       // commit the transaction
81
txn.commit();
82     }
83     catch(Exception JavaDoc ex)
84     {
85       try { txn.rollback(); }
86       catch(java.sql.SQLException JavaDoc sqlex) { sqlex.printStackTrace(); }
87       throw ex;
88     }
89   }
90 }
91
Popular Tags