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.server;
20:
21: import java.sql.Connection;
22: import java.sql.DriverManager;
23: import java.sql.SQLException;
24: import java.util.Properties;
25:
26: import org.mandarax.jdbc.*;
27: import org.mandarax.kernel.KnowledgeBase;
28:
29: /**
30: * A mandarax jdbc driver. Only SELECT statements are supported, this driver
31: * is not jdbc compliant!
32: * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
33: * @version 3.3.2 <29 December 2004>
34: * @since 3.0
35: */
36:
37: public class ServerDriverImpl extends AbstractDriverImpl {
38:
39: /**
40: * Constructor.
41: */
42: public ServerDriverImpl() {
43: super ();
44: try {
45: DriverManager.registerDriver(this );
46: } catch (SQLException x) {
47:
48: }
49: }
50:
51: /**
52: * Get a connection.
53: * @param url the url
54: * @param info additional connect info
55: */
56: public Connection connect(String url, Properties info)
57: throws SQLException {
58:
59: // this is necessary since the driver manager does not call acceptsURL when selecting a driver !!
60: if (!this .isServerUrl(url)) {
61: LOG_JDBC.warn("Unexpected URL " + url + ", cannot connect");
62: return null;
63: }
64:
65: KnowledgeBase kb = KnowledgeBaseServer.defaultInstance
66: .getKnowledgeBase(url);
67: return new ConnectionImpl(kb, url);
68: }
69:
70: /**
71: * Indicates whether the driver accepts the url.
72: * @param url the url to be tested
73: * @return true or false
74: */
75: public boolean acceptsURL(String url) throws SQLException {
76: return this.isServerUrl(url);
77: }
78:
79: }
|