KickJava   Java API By Example, From Geeks To Geeks.

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


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

29 class TestFindBusinessByTModelKeyQuery
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     TModelBag tModelBag = new TModelBag();
53     Vector JavaDoc tModelKeyVector = new Vector JavaDoc();
54     tModelKeyVector.addElement(new TModelKey(""));
55     tModelKeyVector.addElement(new TModelKey(""));
56     tModelKeyVector.addElement(new TModelKey("2a33d7d7-2b73-4de9-99cd-d4c51c186bce"));
57     tModelKeyVector.addElement(new TModelKey("2a33d7d7-2b73-4de9-99cd-d4c51c186bce"));
58     tModelBag.setTModelKeyVector(tModelKeyVector);
59
60     Vector JavaDoc keysIn = new Vector JavaDoc();
61     keysIn.add("13411e97-24cf-43d1-bee0-455e7ec5e9fc");
62     keysIn.add("3f244f19-7ba7-4c3e-a93e-ae33e530794b");
63     keysIn.add("3009f336-98c1-4193-a22f-fea73e79c909");
64     keysIn.add("3ef4772f-e04b-46ed-8065-c5a4e167b5ba");
65
66     Transaction txn = new Transaction();
67
68     if (connection != null)
69     {
70       try
71       {
72         // begin a new transaction
73
txn.begin(connection);
74
75         FindBusinessByTModelKeyQuery.select(tModelBag,keysIn,null,connection);
76         FindBusinessByTModelKeyQuery.select(tModelBag,null,null,connection);
77
78         // commit the transaction
79
txn.commit();
80       }
81       catch(Exception JavaDoc ex)
82       {
83         try { txn.rollback(); }
84         catch(java.sql.SQLException JavaDoc sqlex) { sqlex.printStackTrace(); }
85         throw ex;
86       }
87     }
88   }
89 }
90
Popular Tags