KickJava   Java API By Example, From Geeks To Geeks.

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


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

28 class TestFindBusinessByNameQuery
29 {
30   public static void main(String JavaDoc[] args)
31     throws Exception JavaDoc
32   {
33     // make sure we're using a DBCP DataSource and
34
// not trying to use JNDI to aquire one.
35
Config.setStringProperty("juddi.useConnectionPool","true");
36
37     Connection JavaDoc conn = null;
38     try {
39       conn = Database.aquireConnection();
40       test(conn);
41     }
42     finally {
43       if (conn != null)
44         conn.close();
45     }
46   }
47
48   public static void test(Connection JavaDoc connection)
49     throws Exception JavaDoc
50   {
51     Vector JavaDoc names = new Vector JavaDoc();
52     names.add(new Name("St"));
53     names.add(new Name("X"));
54     names.add(new Name("Select","en"));
55     names.add(new Name("Inflex","en"));
56
57     Vector JavaDoc keysIn = null;
58     keysIn = new Vector JavaDoc();
59     keysIn.add("0e70128c-f7c6-4854-b292-d2f13b638acf");
60     keysIn.add("b405450a-64f5-4f95-8131-450429d0ae8c");
61     keysIn.add("3009f336-98c1-4193-a22f-fea73e79c909");
62     keysIn.add("45994713-d3c3-40d6-87b5-6ce51f36001c");
63     keysIn.add("901b15c5-799c-4387-8337-a1a35fceb791");
64     keysIn.add("80fdae14-0e5d-4ea6-8eb8-50fde422056d");
65     keysIn.add("e1996c33-c436-4004-9e3e-14de191bcc6b");
66     keysIn.add("3ef4772f-e04b-46ed-8065-c5a4e167b5ba");
67
68     Transaction txn = new Transaction();
69
70     if (connection != null)
71     {
72       try
73       {
74         // begin a new transaction
75
txn.begin(connection);
76
77         FindBusinessByNameQuery.select(names,keysIn,null,connection);
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