01: /*
02: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package org.mandarax.jdbc.client;
20:
21: import java.sql.Connection;
22: import java.sql.DriverManager;
23: import java.sql.SQLException;
24: import java.util.Properties;
25: import org.mandarax.jdbc.*;
26: import org.mandarax.jdbc.rpc.*;
27:
28: /**
29: * A mandarax jdbc driver. Only SELECT statements are supported, this driver
30: * is not jdbc compliant!
31: * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
32: * @version 3.3.2 <29 December 2004>
33: * @since 3.0
34: */
35:
36: public class ClientDriverImpl extends AbstractDriverImpl {
37: /**
38: * Constructor.
39: */
40: public ClientDriverImpl() {
41: super ();
42: try {
43: DriverManager.registerDriver(this );
44: } catch (SQLException x) {
45:
46: }
47: }
48:
49: /**
50: * Get a connection.
51: * @param url the url
52: * @param info additional connect info
53: */
54: public Connection connect(String url, Properties info)
55: throws SQLException {
56: if (this .acceptsURL(url)) {
57: Transport transport = null;
58: try {
59: if (url.indexOf("@") > -1)
60: transport = new org.mandarax.jdbc.client.http.HttpTransport(
61: url);
62: else
63: transport = new org.mandarax.jdbc.client.local.LocalTransport();
64: return new ConnectionImpl(url, transport);
65: } catch (Exception x) {
66: String server = JDBCUtils.getServerPart(url);
67: throw new SQLException(
68: "Cannot create connection for url + " + url
69: + " details from server " + server
70: + ": " + x.getMessage());
71: }
72: } else
73: return null;
74: }
75:
76: /**
77: * Indicates whether the driver accepts the url.
78: * @param url the url to be tested
79: * @return true or false
80: */
81: public boolean acceptsURL(String url) throws SQLException {
82: return this.isClientUrl(url);
83: }
84:
85: }
|