クラス org.objectweb.cjdbc.controller.connection.DriverManager

すべてのメンバ一覧

説明

This class defines a DriverManager. In contrast to java.sql.DriverManager this class allows to use Drivers with the same name but with different versions, if no drivername is used it is a wrapper around java.sql.DriverManager.

作者:
Emmanuel Cecchet
バージョン:
1.0

DriverManager.java52 行で定義されています。

Static Public メソッド

Connection getConnection (String url, String user, String password, String driverPathName, String driverClassName) throws SQLException
void loadDriverClass (String driverClassName) throws ClassNotFoundException
File convertToAbsolutePath (String pathName) throws IOException

スタティック変数

Trace logger

Static Private メソッド

File getDriversDir () throws IOException
Connection getConnectionForDriver (String url, String user, String password, Driver driver) throws SQLException
Driver loadDriver (File path, String driverClassName) throws ClassNotFoundException, InstantiationException, IllegalAccessException

Static Private 変数

Set defaultDrivers = new HashSet()
Map namedDrivers = new HashMap()


メソッド

File org.objectweb.cjdbc.controller.connection.DriverManager.convertToAbsolutePath String  pathName  )  throws IOException [static]
 

convert a path into an absolute path if the path is already an absolute path, it is just returned otherwise a relative path is considered to be relative to the drivers directory

引数:
pathName the relativ or absolute path
戻り値:
the converted path
例外:
IOException if the converted path does not exist
DriverManager.java208 行で定義されています。

参照先 org.objectweb.cjdbc.controller.connection.DriverManager.getDriversDir(), と org.objectweb.cjdbc.controller.connection.DriverManager.logger.

参照元 org.objectweb.cjdbc.controller.connection.DriverManager.getConnection().

00209 { 00210 File dir = null; 00211 00212 if (pathName != null) 00213 { 00214 File path = new File(pathName); 00215 if (path.canRead()) 00216 return path; 00217 else 00218 throw new IOException("Invalid path name " + pathName); 00219 } 00220 else 00221 { 00222 dir = getDriversDir(); 00223 } 00224 00225 if (!dir.canRead()) 00226 { 00227 String msg = Translate.get("controller.driver.dir.not.found"); 00228 logger.error(msg); 00229 throw new IOException(msg); 00230 } 00231 00232 return dir; 00233 }

Connection org.objectweb.cjdbc.controller.connection.DriverManager.getConnection String  url,
String  user,
String  password,
String  driverPathName,
String  driverClassName
throws SQLException [static]
 

Attempts to establish a connection to the given database URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.

引数:
url a database url of the form jdbc:subprotocol:subname
user the database user on whose behalf the connection is being made
password the user's password
driverPathName the path where the driver classes are located, null if default directory
driverClassName the class name of the driver
戻り値:
a connection to the URL
例外:
SQLException if a database access error occurs
DriverManager.java85 行で定義されています。

参照先 org.objectweb.cjdbc.controller.connection.DriverManager.convertToAbsolutePath(), org.objectweb.cjdbc.controller.connection.DriverManager.getConnectionForDriver(), org.objectweb.cjdbc.controller.connection.DriverManager.getDriversDir(), org.objectweb.cjdbc.controller.connection.DriverManager.loadDriver(), org.objectweb.cjdbc.controller.connection.DriverManager.loadDriverClass(), org.objectweb.cjdbc.controller.connection.DriverManager.logger, と org.objectweb.cjdbc.controller.connection.DriverManager.namedDrivers.

00088 { 00089 Driver driver = null; 00090 boolean isDefaultPath = false; 00091 00092 if (driverPathName == null) 00093 { 00094 // no path specified 00095 // have we already loaded this driver 00096 driver = (Driver) namedDrivers.get(driverClassName); 00097 if (driver == null) 00098 { 00099 // the driver has not yet been loaded 00100 // first we try to load class from classpath 00101 try 00102 { 00103 if (driverClassName != null) 00104 { 00105 loadDriverClass(driverClassName); 00106 } 00107 return java.sql.DriverManager.getConnection(url, user, password); 00108 } 00109 catch (ClassNotFoundException e) 00110 { 00111 if (driverClassName == null) 00112 { 00113 throw new SQLException( 00114 "could not load driver as no class name is specified "); 00115 } 00116 try 00117 { 00118 driverPathName = getDriversDir().getAbsolutePath(); 00119 isDefaultPath = true; 00120 } 00121 catch (IOException ioExc) 00122 { 00123 throw new SQLException("could not find default drivers directory"); 00124 } 00125 } 00126 } 00127 } 00128 00129 if (driver == null) 00130 { 00131 // have we already loaded this named driver ? 00132 driver = (Driver) namedDrivers.get(driverPathName); 00133 } 00134 00135 if (driver == null) 00136 { 00137 // no driver with this name has been loaded so far 00138 try 00139 { 00140 File path = convertToAbsolutePath(driverPathName); 00141 // we load the driver now 00142 if (logger.isDebugEnabled()) 00143 { 00144 logger.debug("loading driver with name " + driverPathName 00145 + " for class " + driverClassName); 00146 } 00147 driver = loadDriver(path, driverClassName); 00148 } 00149 catch (Exception e) 00150 { 00151 if (logger.isDebugEnabled()) 00152 { 00153 logger.debug("could not load driver for class " + driverClassName, e); 00154 } 00155 throw new SQLException("could not load driver for class name " 00156 + driverClassName + " and driverPath " + driverPathName); 00157 } 00158 00159 // driver has been loaded successfully, we cache it for 00160 // further use 00161 if (isDefaultPath) 00162 {// we cache it with the class name 00163 namedDrivers.put(driverClassName, driver); 00164 } 00165 else 00166 { 00167 // we cache it with the pathName 00168 namedDrivers.put(driverPathName, driver); 00169 } 00170 } 00171 00172 return getConnectionForDriver(url, user, password, driver); 00173 }

Connection org.objectweb.cjdbc.controller.connection.DriverManager.getConnectionForDriver String  url,
String  user,
String  password,
Driver  driver
throws SQLException [static, private]
 

DriverManager.java250 行で定義されています。

参照元 org.objectweb.cjdbc.controller.connection.DriverManager.getConnection().

00252 { 00253 java.util.Properties info = new java.util.Properties(); 00254 if (user != null) 00255 { 00256 info.put("user", user); 00257 } 00258 if (password != null) 00259 { 00260 info.put("password", password); 00261 } 00262 00263 return driver.connect(url, info); 00264 }

File org.objectweb.cjdbc.controller.connection.DriverManager.getDriversDir  )  throws IOException [static, private]
 

DriverManager.java235 行で定義されています。

参照先 org.objectweb.cjdbc.controller.connection.DriverManager.logger.

参照元 org.objectweb.cjdbc.controller.connection.DriverManager.convertToAbsolutePath(), と org.objectweb.cjdbc.controller.connection.DriverManager.getConnection().

00236 { 00237 URL url = Controller.class 00238 .getResource(ControllerConstants.C_JDBC_DRIVER_JAR_FILE); 00239 File driversDir = new File(url.getFile()).getParentFile(); 00240 00241 if (!driversDir.exists()) 00242 { 00243 String msg = Translate.get("controller.driver.dir.not.found"); 00244 logger.error(msg); 00245 throw new IOException(msg); 00246 } 00247 return driversDir; 00248 }

Driver org.objectweb.cjdbc.controller.connection.DriverManager.loadDriver File  path,
String  driverClassName
throws ClassNotFoundException, InstantiationException, IllegalAccessException [static, private]
 

DriverManager.java266 行で定義されています。

参照先 org.objectweb.cjdbc.controller.connection.DriverManager.logger.

参照元 org.objectweb.cjdbc.controller.connection.DriverManager.getConnection().

00269 { 00270 ClassLoader loader = new DriverClassLoader(null, path); 00271 00272 // load java.sql.DriverManager with the new classloader 00273 // Driver instances register with the DriverManager and we want the new 00274 // Driver to register with its own DriverManager 00275 // Otherwise the new Driver would register with the default DriverManager 00276 // and possibly overwrite an other driver with the same name 00277 Class.forName(java.sql.DriverManager.class.getName(), true, loader); 00278 00279 // load class 00280 Class driverClass = Class.forName(driverClassName, true, loader); 00281 00282 if (logger.isDebugEnabled()) 00283 logger.debug(Translate.get("backend.driver.loaded", driverClassName)); 00284 00285 // get an instance of the class and return it 00286 return (Driver) driverClass.newInstance(); 00287 00288 }

void org.objectweb.cjdbc.controller.connection.DriverManager.loadDriverClass String  driverClassName  )  throws ClassNotFoundException [static]
 

Load the driver class

引数:
driverClassName the class name of the driver
例外:
ClassNotFoundException if the class could not be found
DriverManager.java181 行で定義されています。

参照先 org.objectweb.cjdbc.controller.connection.DriverManager.defaultDrivers, と org.objectweb.cjdbc.controller.connection.DriverManager.logger.

参照元 org.objectweb.cjdbc.controller.connection.DriverManager.getConnection().

00183 { 00184 if (!defaultDrivers.contains(driverClassName)) 00185 { 00186 if (logger.isDebugEnabled()) 00187 { 00188 logger.debug("we are using default classloader and driverClassName =" 00189 + driverClassName); 00190 } 00191 Class.forName(driverClassName); 00192 if (logger.isDebugEnabled()) 00193 logger.debug(Translate.get("backend.driver.loaded", driverClassName)); 00194 // the driver was successfully loaded 00195 defaultDrivers.add(driverClassName); 00196 } 00197 }


変数

Set org.objectweb.cjdbc.controller.connection.DriverManager.defaultDrivers = new HashSet() [static, private]
 

Driver class names read from default drivers, without driverPath DriverManager.java62 行で定義されています。

参照元 org.objectweb.cjdbc.controller.connection.DriverManager.loadDriverClass().

Trace org.objectweb.cjdbc.controller.connection.DriverManager.logger [static, package]
 

初期値:

Trace .getLogger("org.objectweb.cjdbc.controller.connection.DriverManager")
Logger instance. DriverManager.java56 行で定義されています。

参照元 org.objectweb.cjdbc.controller.connection.DriverManager.convertToAbsolutePath(), org.objectweb.cjdbc.controller.connection.DriverManager.getConnection(), org.objectweb.cjdbc.controller.connection.DriverManager.getDriversDir(), org.objectweb.cjdbc.controller.connection.DriverManager.loadDriver(), と org.objectweb.cjdbc.controller.connection.DriverManager.loadDriverClass().

Map org.objectweb.cjdbc.controller.connection.DriverManager.namedDrivers = new HashMap() [static, private]
 

We keep a reference to already loaded named drivers. Each named driver has been loaded with a separate classloader. DriverManager.java68 行で定義されています。

参照元 org.objectweb.cjdbc.controller.connection.DriverManager.getConnection().


このクラスの説明は次のファイルから生成されました:
CJDBCversion1.0.4に対してTue Oct 12 15:16:39 2004に生成されました。 doxygen 1.3.8