KickJava   Java API By Example, From Geeks To Geeks.

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


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.OverviewDoc;
21 import org.apache.juddi.datatype.tmodel.TModel;
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 TestTModelTable
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         OverviewDoc overviewDoc = new OverviewDoc();
61         overviewDoc.setOverviewURL("http://www.sviens.com/jtruss.html");
62
63         String JavaDoc tModelKey = uuidgen.uuidgen();
64         TModel tModel = new TModel();
65         tModel.setTModelKey(tModelKey);
66         tModel.setAuthorizedName("Steve Viens");
67         tModel.setOperator("WebServiceRegistry.com");
68         tModel.setName("Tuscany Web Service Company");
69         tModel.setOverviewDoc(overviewDoc);
70
71         String JavaDoc publisherID = "sviens";
72
73         // begin a new transaction
74
txn.begin(connection);
75
76         // insert a new TModel
77
TModelTable.insert(tModel,publisherID,connection);
78
79         // select one of the TModel objects
80
tModel = TModelTable.select(tModelKey,connection);
81
82         // select a Collection of TModel keys by PublisherID
83
TModelTable.selectByPublisherID(publisherID,connection);
84
85         TModelTable.verifyOwnership(tModelKey,"mviens",connection);
86         TModelTable.verifyOwnership(tModelKey,"sviens",connection);
87
88         // delete that TModel object
89
TModelTable.delete(tModelKey,connection);
90         //TModelTable.markAsDeleted(tModelKey,connection);
91

92         // re-select that TModel object
93
tModel = TModelTable.select(tModelKey,connection);
94
95         // re-select a Collection of TModel keys by PublisherID
96
TModelTable.selectByPublisherID(publisherID,connection);
97
98         // commit the transaction
99
txn.commit();
100       }
101       catch(Exception JavaDoc ex)
102       {
103         try { txn.rollback(); }
104         catch(java.sql.SQLException JavaDoc sqlex) { sqlex.printStackTrace(); }
105         throw ex;
106       }
107     }
108   }
109 }
110
Popular Tags