KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > Driver


1 /* * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
2  * Initial Developer: H2 Group
3  */

4 package org.h2;
5
6 import java.sql.Connection JavaDoc;
7 import java.sql.DriverManager JavaDoc;
8 import java.sql.DriverPropertyInfo JavaDoc;
9 import java.sql.SQLException JavaDoc;
10 import java.util.Properties JavaDoc;
11
12 import org.h2.engine.Constants;
13 import org.h2.jdbc.JdbcConnection;
14 import org.h2.message.Message;
15 import org.h2.message.TraceSystem;
16
17 /**
18  * The database driver. An application should not use this class directly.
19  * The only thing the application needs to do is load the driver. This can be done
20  * using Class.forName:
21  * <pre>
22  * Class.forName("org.h2.Driver");
23  * </pre>
24  */

25 public class Driver implements java.sql.Driver JavaDoc {
26
27     // TODO server: maybe start/stop a server using DriverManager.getConnection ?
28
private static Driver instance = new Driver();
29
30     static {
31         try {
32             DriverManager.registerDriver(instance);
33         } catch (SQLException JavaDoc e) {
34             TraceSystem.traceThrowable(e);
35         }
36     }
37
38     /**
39      * This method should not be called by an application.
40      *
41      * @return the new connection
42      */

43     public Connection JavaDoc connect(String JavaDoc url, Properties JavaDoc info) throws SQLException JavaDoc {
44         try {
45             if (info == null) {
46                 info = new Properties JavaDoc();
47             }
48             if (!acceptsURL(url)) {
49                 return null;
50             }
51             synchronized (this) {
52                 return new JdbcConnection(url, info);
53             }
54         } catch (Throwable JavaDoc e) {
55             throw Message.convert(e);
56         }
57     }
58
59     /**
60      * This method should not be called by an application.
61      *
62      * @return if the driver understands the URL
63      */

64     public boolean acceptsURL(String JavaDoc url) {
65         return url != null && url.startsWith(Constants.START_URL);
66     }
67
68     /**
69      * This method should not be called by an application.
70      *
71      * @return the major version number
72      */

73     public int getMajorVersion() {
74         return Constants.VERSION_MAJOR;
75     }
76
77     /**
78      * This method should not be called by an application.
79      *
80      * @return the minor version number
81      */

82     public int getMinorVersion() {
83         return Constants.VERSION_MINOR;
84     }
85
86     /**
87      * This method should not be called by an application.
88      *
89      * @return a zero length array
90      */

91     public DriverPropertyInfo JavaDoc[] getPropertyInfo(String JavaDoc url, Properties JavaDoc info) {
92         return new DriverPropertyInfo JavaDoc[0];
93     }
94
95     /**
96      * This method should not be called by an application.
97      *
98      * @return true
99      */

100     public boolean jdbcCompliant() {
101         return true;
102     }
103     
104     /**
105      * INTERNAL
106      */

107     public static void load() {
108     }
109
110 }
111
Popular Tags