KickJava   Java API By Example, From Geeks To Geeks.

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


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

27 class TestFindBindingByServiceKeyQuery
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     String JavaDoc serviceKey = "5E2D4E60-9876-11D8-AE77-AC68422E7D92";
51
52     Vector JavaDoc keysIn = new Vector JavaDoc();
53     keysIn.add("5E305BA0-9876-11D8-AE77-D080179B6DB4");
54     keysIn.add("c311085b-3277-470d-8ce9-07b81c484e4b");
55     keysIn.add("6b368a5a-6a62-4f23-a002-f11e22780a91");
56     keysIn.add("45994713-d3c3-40d6-87b5-6ce51f36001c");
57     keysIn.add("901b15c5-799c-4387-8337-a1a35fceb791");
58     keysIn.add("80fdae14-0e5d-4ea6-8eb8-50fde422056d");
59     keysIn.add("e1996c33-c436-4004-9e3e-14de191bcc6b");
60     keysIn.add("3ef4772f-e04b-46ed-8065-c5a4e167b5ba");
61
62     Transaction txn = new Transaction();
63
64     if (connection != null)
65     {
66       try
67       {
68         // begin a new transaction
69
txn.begin(connection);
70
71         Vector JavaDoc keys = null;
72
73         keys = FindBindingByServiceKeyQuery.select(serviceKey,keysIn,null,connection);
74         System.out.println(keys.size());
75
76         keys = FindBindingByServiceKeyQuery.select(serviceKey,null,null,connection);
77         System.out.println(keys.size());
78
79         // commit the transaction
80
txn.commit();
81       }
82       catch(Exception JavaDoc ex)
83       {
84         try { txn.rollback(); }
85         catch(java.sql.SQLException JavaDoc sqlex) { sqlex.printStackTrace(); }
86         throw ex;
87       }
88     }
89   }
90 }
91
Popular Tags