KickJava   Java API By Example, From Geeks To Geeks.

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


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.request.FindQualifiers;
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 TestFindPublisherByNameQuery
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     String JavaDoc name = new String JavaDoc("Steve");
52
53     Vector JavaDoc idsIn = null;
54     idsIn = new Vector JavaDoc();
55     idsIn.add(new String JavaDoc("sviens"));
56     idsIn.add(new String JavaDoc("jdoe"));
57     idsIn.add(new String JavaDoc("steveviens"));
58
59     Transaction txn = new Transaction();
60
61     if (connection != null)
62     {
63       try
64       {
65         // begin a new transaction
66
txn.begin(connection);
67
68         Vector JavaDoc results = FindPublisherByNameQuery.select(name,idsIn,null,connection);
69         if (results != null)
70         {
71           for (int i=0; i<results.size(); i++)
72             System.out.println(i+": "+(String JavaDoc)results.elementAt(i));
73         }
74
75         FindQualifiers fqs = new FindQualifiers();
76         fqs.sortByNameAsc = true;
77
78         Vector JavaDoc resutls2 = FindPublisherByNameQuery.select(name,null,fqs,connection);
79         if (results != null)
80         {
81           for (int i=0; i<resutls2.size(); i++)
82             System.out.println(i+": "+(String JavaDoc)resutls2.elementAt(i));
83         }
84
85         fqs.exactNameMatch = true;
86
87         Vector JavaDoc resutls3 = FindPublisherByNameQuery.select(name,null,fqs,connection);
88         if (results != null)
89         {
90           for (int i=0; i<resutls3.size(); i++)
91             System.out.println(i+": "+(String JavaDoc)resutls3.elementAt(i));
92         }
93
94         // commit the transaction
95
txn.commit();
96       }
97       catch(Exception JavaDoc ex)
98       {
99         try { txn.rollback(); }
100         catch(java.sql.SQLException JavaDoc sqlex) { sqlex.printStackTrace(); }
101         throw ex;
102       }
103     }
104   }
105 }
Popular Tags