KickJava   Java API By Example, From Geeks To Geeks.

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


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

27 public class TestPublisherTable
28 {
29   public static void main(String JavaDoc[] args)
30     throws Exception JavaDoc
31   {
32     // make sure we're using a DBCP DataSource and
33
// not trying to use JNDI to aquire one.
34
Config.setStringProperty("juddi.useConnectionPool","true");
35
36     Connection JavaDoc conn = null;
37     try {
38       conn = Database.aquireConnection();
39       test(conn);
40     }
41     finally {
42       if (conn != null)
43         conn.close();
44     }
45   }
46
47   public static void test(Connection JavaDoc connection)
48     throws Exception JavaDoc
49   {
50     Transaction txn = new Transaction();
51
52     if (connection != null)
53     {
54       try
55       {
56         // begin a new transaction
57
txn.begin(connection);
58
59         // insert a few new publishers
60
Publisher publisher = new Publisher();
61         publisher.setPublisherID("bcrosby");
62         publisher.setName("Bing Crosby");
63         publisher.setEmailAddress("bcrosby@juddi.org");
64         publisher.setAdmin(false);
65         publisher.setEnabled(false);
66         PublisherTable.insert(publisher,connection);
67
68         // select each inserted publisher
69
System.out.println(PublisherTable.select("bcrosby",connection));
70
71         publisher.setName("Barthalomue Crosby");
72         publisher.setEnabled(true);
73         PublisherTable.update(publisher,connection);
74
75         // select each inserted publisher
76
System.out.println(PublisherTable.select("bcrosby",connection));
77
78         // delete two of the inserted publishers
79
PublisherTable.delete("bcrosby",connection);
80
81         // select each inserted publisher
82
System.out.println(PublisherTable.select("bcrosby",connection));
83         System.out.println("");
84
85         // commit the transaction
86
txn.commit();
87       }
88       catch(Exception JavaDoc ex)
89       {
90         try { txn.rollback(); }
91         catch(java.sql.SQLException JavaDoc sqlex) { sqlex.printStackTrace(); }
92         throw ex;
93       }
94     }
95   }
96 }
Popular Tags