KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xeus > bottomline > BottomlineConnection


1 /**
2  * Bottomline
3  * A JDBC Bridge API to load multiple database drivers from JAR files
4  *
5  * Copyright (C) 2006 Technology N
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  *
21  * @author Kamran Zafar
22  *
23  * Contact Info:
24  * Email: kamran@technology-n.com
25  * xeus.man@gmail.com
26  */

27
28 /*
29  * BottomlineConnection.java
30  * Created on Sep 9, 2006
31  */

32 package xeus.bottomline;
33
34 import java.net.MalformedURLException JavaDoc;
35 import java.net.URL JavaDoc;
36 import java.net.URLClassLoader JavaDoc;
37 import java.sql.CallableStatement JavaDoc;
38 import java.sql.Connection JavaDoc;
39 import java.sql.DatabaseMetaData JavaDoc;
40 import java.sql.Driver JavaDoc;
41 import java.sql.PreparedStatement JavaDoc;
42 import java.sql.SQLException JavaDoc;
43 import java.sql.SQLWarning JavaDoc;
44 import java.sql.Savepoint JavaDoc;
45 import java.sql.Statement JavaDoc;
46 import java.util.Map JavaDoc;
47 import java.util.Properties JavaDoc;
48
49 import xeus.bottomline.exception.BottomlineException;
50
51 /**
52  * @author Kamran Zafar
53  *
54  */

55 public class BottomlineConnection implements Connection JavaDoc {
56
57     private Connection JavaDoc conn;
58
59     /**
60      * @param url
61      * @param props
62      * @throws BottomlineException
63      * @throws SQLException
64      */

65     public BottomlineConnection(String JavaDoc url, Properties JavaDoc props)
66             throws BottomlineException, SQLException JavaDoc {
67         Driver JavaDoc driver = null;
68         try {
69             URL JavaDoc u = new URL JavaDoc("jar:file:/"+props
70                     .getProperty(BottomlineConstants.DRIVER_JAR)+"!/");
71             URLClassLoader JavaDoc ucl = new URLClassLoader JavaDoc(new URL JavaDoc[] { u });
72             driver = (Driver JavaDoc) Class.forName(
73                     props.getProperty(BottomlineConstants.DRIVER_CLASS), true,
74                     ucl).newInstance();
75         } catch (InstantiationException JavaDoc e) {
76             throw new BottomlineException(e);
77         } catch (IllegalAccessException JavaDoc e) {
78             throw new BottomlineException(e);
79         } catch (ClassNotFoundException JavaDoc e) {
80             throw new BottomlineException(e);
81         } catch (MalformedURLException JavaDoc e) {
82             throw new BottomlineException(e);
83         }
84
85         conn = driver.connect(url.replaceFirst("jdbc:bottomline:", "jdbc:"),
86                 props);
87     }
88
89     /**
90      * @return
91      */

92     public Connection JavaDoc getUnderlayingConnection() {
93         return conn;
94     }
95
96     /*
97      * (non-Javadoc)
98      *
99      * @see java.sql.Connection#createStatement()
100      */

101     public Statement JavaDoc createStatement() throws SQLException JavaDoc {
102         return conn.createStatement();
103     }
104
105     /*
106      * (non-Javadoc)
107      *
108      * @see java.sql.Connection#prepareStatement(java.lang.String)
109      */

110     public PreparedStatement JavaDoc prepareStatement(String JavaDoc arg0) throws SQLException JavaDoc {
111         return conn.prepareStatement(arg0);
112     }
113
114     /*
115      * (non-Javadoc)
116      *
117      * @see java.sql.Connection#prepareCall(java.lang.String)
118      */

119     public CallableStatement JavaDoc prepareCall(String JavaDoc arg0) throws SQLException JavaDoc {
120         return conn.prepareCall(arg0);
121     }
122
123     /*
124      * (non-Javadoc)
125      *
126      * @see java.sql.Connection#nativeSQL(java.lang.String)
127      */

128     public String JavaDoc nativeSQL(String JavaDoc arg0) throws SQLException JavaDoc {
129         return conn.nativeSQL(arg0);
130     }
131
132     /*
133      * (non-Javadoc)
134      *
135      * @see java.sql.Connection#setAutoCommit(boolean)
136      */

137     public void setAutoCommit(boolean arg0) throws SQLException JavaDoc {
138         conn.setAutoCommit(arg0);
139     }
140
141     /*
142      * (non-Javadoc)
143      *
144      * @see java.sql.Connection#getAutoCommit()
145      */

146     public boolean getAutoCommit() throws SQLException JavaDoc {
147         return conn.getAutoCommit();
148     }
149
150     /*
151      * (non-Javadoc)
152      *
153      * @see java.sql.Connection#commit()
154      */

155     public void commit() throws SQLException JavaDoc {
156         conn.commit();
157     }
158
159     /*
160      * (non-Javadoc)
161      *
162      * @see java.sql.Connection#rollback()
163      */

164     public void rollback() throws SQLException JavaDoc {
165         conn.rollback();
166     }
167
168     /*
169      * (non-Javadoc)
170      *
171      * @see java.sql.Connection#close()
172      */

173     public void close() throws SQLException JavaDoc {
174         conn.close();
175     }
176
177     /*
178      * (non-Javadoc)
179      *
180      * @see java.sql.Connection#isClosed()
181      */

182     public boolean isClosed() throws SQLException JavaDoc {
183         return conn.isClosed();
184     }
185
186     /*
187      * (non-Javadoc)
188      *
189      * @see java.sql.Connection#getMetaData()
190      */

191     public DatabaseMetaData JavaDoc getMetaData() throws SQLException JavaDoc {
192         return conn.getMetaData();
193     }
194
195     /*
196      * (non-Javadoc)
197      *
198      * @see java.sql.Connection#setReadOnly(boolean)
199      */

200     public void setReadOnly(boolean arg0) throws SQLException JavaDoc {
201         conn.setReadOnly(arg0);
202     }
203
204     /*
205      * (non-Javadoc)
206      *
207      * @see java.sql.Connection#isReadOnly()
208      */

209     public boolean isReadOnly() throws SQLException JavaDoc {
210         return conn.isReadOnly();
211     }
212
213     /*
214      * (non-Javadoc)
215      *
216      * @see java.sql.Connection#setCatalog(java.lang.String)
217      */

218     public void setCatalog(String JavaDoc arg0) throws SQLException JavaDoc {
219         conn.setCatalog(arg0);
220     }
221
222     /*
223      * (non-Javadoc)
224      *
225      * @see java.sql.Connection#getCatalog()
226      */

227     public String JavaDoc getCatalog() throws SQLException JavaDoc {
228         return conn.getCatalog();
229     }
230
231     /*
232      * (non-Javadoc)
233      *
234      * @see java.sql.Connection#setTransactionIsolation(int)
235      */

236     public void setTransactionIsolation(int arg0) throws SQLException JavaDoc {
237         conn.setTransactionIsolation(arg0);
238     }
239
240     /*
241      * (non-Javadoc)
242      *
243      * @see java.sql.Connection#getTransactionIsolation()
244      */

245     public int getTransactionIsolation() throws SQLException JavaDoc {
246         return conn.getTransactionIsolation();
247     }
248
249     /*
250      * (non-Javadoc)
251      *
252      * @see java.sql.Connection#getWarnings()
253      */

254     public SQLWarning JavaDoc getWarnings() throws SQLException JavaDoc {
255         return conn.getWarnings();
256     }
257
258     /*
259      * (non-Javadoc)
260      *
261      * @see java.sql.Connection#clearWarnings()
262      */

263     public void clearWarnings() throws SQLException JavaDoc {
264         conn.clearWarnings();
265     }
266
267     /*
268      * (non-Javadoc)
269      *
270      * @see java.sql.Connection#createStatement(int, int)
271      */

272     public Statement JavaDoc createStatement(int arg0, int arg1) throws SQLException JavaDoc {
273         return conn.createStatement(arg0, arg1);
274     }
275
276     /*
277      * (non-Javadoc)
278      *
279      * @see java.sql.Connection#prepareStatement(java.lang.String, int, int)
280      */

281     public PreparedStatement JavaDoc prepareStatement(String JavaDoc arg0, int arg1, int arg2)
282             throws SQLException JavaDoc {
283         return conn.prepareStatement(arg0, arg1, arg2);
284     }
285
286     /*
287      * (non-Javadoc)
288      *
289      * @see java.sql.Connection#prepareCall(java.lang.String, int, int)
290      */

291     public CallableStatement JavaDoc prepareCall(String JavaDoc arg0, int arg1, int arg2)
292             throws SQLException JavaDoc {
293         return conn.prepareCall(arg0, arg1, arg2);
294     }
295
296     /*
297      * (non-Javadoc)
298      *
299      * @see java.sql.Connection#getTypeMap()
300      */

301     public Map JavaDoc getTypeMap() throws SQLException JavaDoc {
302         return conn.getTypeMap();
303     }
304
305     /**
306      * @param arg0
307      * @throws SQLException
308      */

309     public void setTypeMap(Map JavaDoc arg0) throws SQLException JavaDoc {
310         conn.setTypeMap(arg0);
311     }
312
313     /*
314      * (non-Javadoc)
315      *
316      * @see java.sql.Connection#setHoldability(int)
317      */

318     public void setHoldability(int arg0) throws SQLException JavaDoc {
319         conn.setHoldability(arg0);
320     }
321
322     /*
323      * (non-Javadoc)
324      *
325      * @see java.sql.Connection#getHoldability()
326      */

327     public int getHoldability() throws SQLException JavaDoc {
328         return conn.getHoldability();
329     }
330
331     /*
332      * (non-Javadoc)
333      *
334      * @see java.sql.Connection#setSavepoint()
335      */

336     public Savepoint JavaDoc setSavepoint() throws SQLException JavaDoc {
337         return conn.setSavepoint();
338     }
339
340     /*
341      * (non-Javadoc)
342      *
343      * @see java.sql.Connection#setSavepoint(java.lang.String)
344      */

345     public Savepoint JavaDoc setSavepoint(String JavaDoc arg0) throws SQLException JavaDoc {
346         return conn.setSavepoint(arg0);
347     }
348
349     /*
350      * (non-Javadoc)
351      *
352      * @see java.sql.Connection#rollback(java.sql.Savepoint)
353      */

354     public void rollback(Savepoint JavaDoc arg0) throws SQLException JavaDoc {
355         conn.rollback(arg0);
356     }
357
358     /*
359      * (non-Javadoc)
360      *
361      * @see java.sql.Connection#releaseSavepoint(java.sql.Savepoint)
362      */

363     public void releaseSavepoint(Savepoint JavaDoc arg0) throws SQLException JavaDoc {
364         conn.releaseSavepoint(arg0);
365     }
366
367     /*
368      * (non-Javadoc)
369      *
370      * @see java.sql.Connection#createStatement(int, int, int)
371      */

372     public Statement JavaDoc createStatement(int arg0, int arg1, int arg2)
373             throws SQLException JavaDoc {
374         return conn.createStatement(arg0, arg1, arg2);
375     }
376
377     /*
378      * (non-Javadoc)
379      *
380      * @see java.sql.Connection#prepareStatement(java.lang.String, int, int,
381      * int)
382      */

383     public PreparedStatement JavaDoc prepareStatement(String JavaDoc arg0, int arg1, int arg2,
384             int arg3) throws SQLException JavaDoc {
385         return conn.prepareStatement(arg0, arg1, arg2, arg3);
386     }
387
388     /*
389      * (non-Javadoc)
390      *
391      * @see java.sql.Connection#prepareCall(java.lang.String, int, int, int)
392      */

393     public CallableStatement JavaDoc prepareCall(String JavaDoc arg0, int arg1, int arg2,
394             int arg3) throws SQLException JavaDoc {
395         return conn.prepareCall(arg0, arg1, arg2, arg3);
396     }
397
398     /*
399      * (non-Javadoc)
400      *
401      * @see java.sql.Connection#prepareStatement(java.lang.String, int)
402      */

403     public PreparedStatement JavaDoc prepareStatement(String JavaDoc arg0, int arg1)
404             throws SQLException JavaDoc {
405         return conn.prepareStatement(arg0, arg1);
406     }
407
408     /*
409      * (non-Javadoc)
410      *
411      * @see java.sql.Connection#prepareStatement(java.lang.String, int[])
412      */

413     public PreparedStatement JavaDoc prepareStatement(String JavaDoc arg0, int[] arg1)
414             throws SQLException JavaDoc {
415         return conn.prepareStatement(arg0, arg1);
416     }
417
418     /*
419      * (non-Javadoc)
420      *
421      * @see java.sql.Connection#prepareStatement(java.lang.String,
422      * java.lang.String[])
423      */

424     public PreparedStatement JavaDoc prepareStatement(String JavaDoc arg0, String JavaDoc[] arg1)
425             throws SQLException JavaDoc {
426         return conn.prepareStatement(arg0, arg1);
427     }
428 }
429
Popular Tags