KickJava   Java API By Example, From Geeks To Geeks.

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


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.KeyedReference;
22 import org.apache.juddi.datatype.OverviewDoc;
23 import org.apache.juddi.datatype.tmodel.TModel;
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 TestTModelCategoryTable
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         OverviewDoc overviewDoc = new OverviewDoc();
62         overviewDoc.setOverviewURL(
63           "http://www.steveviens.com/overviewdoc.html");
64
65         String JavaDoc tModelKey = uuidgen.uuidgen();
66         TModel tModel = new TModel();
67         tModel.setTModelKey(tModelKey);
68         tModel.setAuthorizedName("sviens");
69         tModel.setOperator("WebServiceRegistry.com");
70         tModel.setName("Tuscany Web Service Company");
71         tModel.setOverviewDoc(overviewDoc);
72
73         Vector JavaDoc keyRefs = new Vector JavaDoc();
74         keyRefs.add(new KeyedReference(uuidgen.uuidgen(), "blah, blah, blah"));
75         keyRefs.add(
76           new KeyedReference(uuidgen.uuidgen(), "Yadda, Yadda, Yadda"));
77         keyRefs.add(
78           new KeyedReference(uuidgen.uuidgen(), "WhoobWhoobWhoobWhoob"));
79         keyRefs.add(new KeyedReference(uuidgen.uuidgen(), "Haachachachacha"));
80
81         String JavaDoc authorizedUserID = "sviens";
82
83         // begin a new transaction
84
txn.begin(connection);
85
86         // insert a new TModel
87
TModelTable.insert(tModel, authorizedUserID, connection);
88
89         // insert a Collection of new Category KeyedReference objects
90
TModelCategoryTable.insert(tModelKey, keyRefs, connection);
91
92         // insert another new TModel
93
tModel.setTModelKey(uuidgen.uuidgen());
94         TModelTable.insert(tModel, authorizedUserID, connection);
95
96         // insert another Collection of new Category KeyedReference objects
97
TModelCategoryTable.insert(tModel.getTModelKey(), keyRefs, connection);
98
99         // select a Collection of Category KeyedReference objects
100
keyRefs = TModelCategoryTable.select(tModelKey, connection);
101
102         // delete a Collection of Category KeyedReference objects
103
TModelCategoryTable.delete(tModelKey, connection);
104
105         // re-select a Collection of Category KeyedReference objects
106
keyRefs = TModelCategoryTable.select(tModelKey, connection);
107
108         // commit the transaction
109
txn.commit();
110       }
111       catch (Exception JavaDoc ex)
112       {
113         try
114         {
115           txn.rollback();
116         }
117         catch (java.sql.SQLException JavaDoc sqlex)
118         {
119           sqlex.printStackTrace();
120         }
121         throw ex;
122       }
123     }
124   }
125 }
126
Popular Tags