KickJava   Java API By Example, From Geeks To Geeks.

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


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  * tModelBag: This is a list of tModel uuid_key values that represent the
28  * technical fingerprint of a bindingTemplate structure to find. All
29  * bindingTemplate structures within any businessService associated with the
30  * businessEntity specified by the businessKey argument will be searched.
31  *
32  * If more than one tModel key is specified in this structure, only
33  * businessService structures that contain bindingTemplate structures with
34  * fingerprint information that matches all of the tModel keys specified will
35  * be returned (logical AND only).
36  *
37  * @author Steve Viens (sviens@apache.org)
38  */

39 class TestFindServiceByTModelKeyQuery
40 {
41   public static void main(String JavaDoc[] args)
42     throws Exception JavaDoc
43   {
44     // make sure we're using a DBCP DataSource and
45
// not trying to use JNDI to aquire one.
46
Config.setStringProperty("juddi.useConnectionPool","true");
47
48     Connection JavaDoc conn = null;
49     try {
50       conn = Database.aquireConnection();
51       test(conn);
52     }
53     finally {
54       if (conn != null)
55         conn.close();
56     }
57   }
58
59   public static void test(Connection JavaDoc connection)
60     throws Exception JavaDoc
61   {
62     String JavaDoc businessKey = "13411e97-24cf-43d1-bee0-455e7ec5e9fc";
63
64     TModelBag tModelBag = new TModelBag();
65     Vector JavaDoc tModelKeyVector = new Vector JavaDoc();
66     tModelKeyVector.addElement(new TModelKey(""));
67     tModelKeyVector.addElement(new TModelKey(""));
68     tModelKeyVector.addElement(new TModelKey("2a33d7d7-2b73-4de9-99cd-d4c51c186bce"));
69     tModelKeyVector.addElement(new TModelKey("2a33d7d7-2b73-4de9-99cd-d4c51c186bce"));
70     tModelBag.setTModelKeyVector(tModelKeyVector);
71
72     Vector JavaDoc keysIn = new Vector JavaDoc();
73     keysIn.add("13411e97-24cf-43d1-bee0-455e7ec5e9fc");
74     keysIn.add("3f244f19-7ba7-4c3e-a93e-ae33e530794b");
75     keysIn.add("3009f336-98c1-4193-a22f-fea73e79c909");
76     keysIn.add("3ef4772f-e04b-46ed-8065-c5a4e167b5ba");
77
78     Transaction txn = new Transaction();
79
80     if (connection != null)
81     {
82       try
83       {
84         // begin a new transaction
85
txn.begin(connection);
86
87         FindServiceByTModelKeyQuery.select(businessKey,tModelBag,keysIn,null,connection);
88         FindServiceByTModelKeyQuery.select(businessKey,tModelBag,null,null,connection);
89
90         // commit the transaction
91
txn.commit();
92       }
93       catch(Exception JavaDoc ex)
94       {
95         try { txn.rollback(); }
96         catch(java.sql.SQLException JavaDoc sqlex) { sqlex.printStackTrace(); }
97         throw ex;
98       }
99     }
100   }
101 }
102
Popular Tags