1 21 22 package org.apache.derby.jdbc; 23 24 import java.sql.DriverManager ; 25 import java.sql.Driver ; 26 import java.sql.Connection ; 27 import java.sql.DriverPropertyInfo ; 28 import java.sql.SQLException ; 29 30 import java.io.PrintStream ; 31 import java.util.Properties ; 32 33 import org.apache.derby.iapi.reference.MessageId; 34 import org.apache.derby.iapi.reference.Attribute; 35 import org.apache.derby.iapi.services.i18n.MessageService; 36 import org.apache.derby.iapi.jdbc.JDBCBoot; 37 38 39 55 public class AutoloadedDriver implements Driver 56 { 57 private static boolean _engineForcedDown = false; 59 60 private static Driver _driverModule; 65 66 static 67 { 68 try { 69 DriverManager.registerDriver( new AutoloadedDriver() ); 70 } 71 catch (SQLException se) 72 { 73 String message = MessageService.getTextMessage 74 (MessageId.JDBC_DRIVER_REGISTER_ERROR, se.getMessage() ); 75 76 throw new IllegalStateException ( message ); 77 } 78 } 79 80 83 88 public boolean acceptsURL(String url) throws SQLException { 89 90 return ( isBooted() && InternalDriver.embeddedDriverAcceptsURL(url) ); 96 } 97 98 99 104 public Connection connect(String url, Properties info) 105 throws SQLException 106 { 107 if (!InternalDriver.embeddedDriverAcceptsURL(url)) { return null; } 116 117 return getDriverModule().connect(url, info); 118 } 119 120 125 public DriverPropertyInfo [] getPropertyInfo(String url, Properties info) 126 throws SQLException 127 { 128 return getDriverModule().getPropertyInfo(url, info); 129 } 130 131 135 public int getMajorVersion() { 136 try { 137 return (getDriverModule().getMajorVersion()); 138 } 139 catch (SQLException se) { 140 return 0; 141 } 142 } 143 147 public int getMinorVersion() { 148 try { 149 return (getDriverModule().getMinorVersion()); 150 } 151 catch (SQLException se) { 152 return 0; 153 } 154 } 155 156 160 public boolean jdbcCompliant() { 161 try { 162 return (getDriverModule().jdbcCompliant()); 163 } 164 catch (SQLException se) { 165 return false; 166 } 167 } 168 169 175 179 public static Driver getDriverModule() throws SQLException { 180 181 if ( _engineForcedDown ) 182 { 183 throw new SQLException 185 (MessageService.getTextMessage(MessageId.CORE_JDBC_DRIVER_UNREGISTERED)); 186 } 187 188 if ( !isBooted() ) { EmbeddedDriver.boot(); } 189 190 return _driverModule; 191 } 192 193 196 protected static void registerDriverModule( Driver driver ) 197 { 198 _driverModule = driver; 199 _engineForcedDown = false; 200 } 201 202 206 protected static void unregisterDriverModule() 207 { 208 _driverModule = null; 209 _engineForcedDown = true; 210 } 211 212 213 216 private static boolean isBooted() 217 { 218 return ( _driverModule != null ); 219 } 220 221 } 222 223 | Popular Tags |