src/org/objectweb/cjdbc/controller/connection/AbstractConnectionManager.java

説明を見る。
00001 00025 package org.objectweb.cjdbc.controller.connection; 00026 00027 import java.io.Serializable; 00028 import java.sql.Connection; 00029 import java.sql.SQLException; 00030 import java.util.Hashtable; 00031 00032 import org.objectweb.cjdbc.common.exceptions.UnreachableBackendException; 00033 import org.objectweb.cjdbc.common.i18n.Translate; 00034 import org.objectweb.cjdbc.common.log.Trace; 00035 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags; 00036 import org.objectweb.cjdbc.common.xml.XmlComponent; 00037 00047 public abstract class AbstractConnectionManager 00048 implements 00049 Serializable, 00050 XmlComponent, 00051 Cloneable 00052 { 00053 /* 00054 * How the code is organized ? 1. Member variables 2. Connection handling 3. 00055 * Getter/Setter (possibly in alphabetical order) 00056 */ 00057 00059 static Trace logger = Trace 00060 .getLogger("org.objectweb.cjdbc.controller.connection"); 00061 00063 protected String backendUrl; 00064 00068 protected String backendName; 00069 00071 protected String rLogin; 00072 00074 protected String rPassword; 00075 00077 protected String driverClassName; 00078 00082 protected String driverPath; 00083 00085 protected boolean initialized; 00086 00088 private transient Hashtable connectionForTransaction; 00089 00091 private String vLogin; 00092 00093 /* 00094 * Constructor(s) 00095 */ 00096 00112 public AbstractConnectionManager(String backendUrl, String backendName, 00113 String rLogin, String rPassword, String driverPath, String driverClassName) 00114 { 00115 if (backendUrl == null) 00116 throw new IllegalArgumentException( 00117 "Illegal null database backend URL in AbstractConnectionManager constructor"); 00118 00119 if (backendName == null) 00120 throw new IllegalArgumentException( 00121 "Illegal null database backend name in AbstractConnectionManager constructor"); 00122 00123 if (rLogin == null) 00124 throw new IllegalArgumentException( 00125 "Illegal null database backend login in AbstractConnectionManager constructor"); 00126 00127 if (rPassword == null) 00128 throw new IllegalArgumentException( 00129 "Illegal null database backend password in AbstractConnectionManager constructor"); 00130 00131 if (driverPath != null) 00132 { 00133 if (driverClassName == null) 00134 { 00135 throw new IllegalArgumentException( 00136 "Illegal null database backend driverClassName in AbstractConnectionManager constructor"); 00137 } 00138 } 00139 this.backendUrl = backendUrl; 00140 this.backendName = backendName; 00141 this.rLogin = rLogin; 00142 this.rPassword = rPassword; 00143 this.driverPath = driverPath; 00144 this.driverClassName = driverClassName; 00145 connectionForTransaction = new Hashtable(); 00146 00147 } 00148 00158 public AbstractConnectionManager copy(String url, String name) 00159 throws Exception 00160 { 00161 AbstractConnectionManager connectionManager = (AbstractConnectionManager) this 00162 .clone(); 00163 connectionManager.backendName = name; 00164 connectionManager.backendUrl = url; 00165 return connectionManager; 00166 } 00167 00168 /* 00169 * Connection handling 00170 */ 00171 00178 public abstract void initializeConnections() throws SQLException; 00179 00185 public abstract void finalizeConnections() throws SQLException; 00186 00193 public Connection getConnectionFromDriver() 00194 00195 { 00196 try 00197 { 00198 return DriverManager.getConnection(backendUrl, rLogin, rPassword, 00199 driverPath, driverClassName); 00200 } 00201 catch (SQLException ignore) 00202 { 00203 if (logger.isDebugEnabled()) 00204 { 00205 logger.debug("failed to get connection for driver ", ignore); 00206 } 00207 return null; 00208 } 00209 } 00210 00218 public abstract Connection getConnection() throws UnreachableBackendException; 00219 00231 public Connection getConnection(long transactionId) 00232 throws UnreachableBackendException 00233 { 00234 Connection c = getConnection(); 00235 if (c != null) 00236 connectionForTransaction.put(new Long(transactionId), c); 00237 return c; 00238 } 00239 00249 public Connection retrieveConnection(long transactionId) 00250 { 00251 Long id = new Long(transactionId); 00252 return (Connection) connectionForTransaction.get(id); 00253 } 00254 00260 public abstract void releaseConnection(Connection connection); 00261 00269 public void releaseConnection(long transactionId) 00270 { 00271 Connection c = (Connection) connectionForTransaction.remove(new Long( 00272 transactionId)); 00273 00274 if (c == null) 00275 logger.error(Translate.get("connection.transaction.unknown", 00276 transactionId)); 00277 else 00278 releaseConnection(c); 00279 } 00280 00286 public abstract void deleteConnection(Connection connection); 00287 00295 public void deleteConnection(long transactionId) 00296 { 00297 Connection c = (Connection) connectionForTransaction.remove(new Long( 00298 transactionId)); 00299 00300 if (c == null) 00301 logger.error(Translate.get("connection.transaction.unknown", 00302 transactionId)); 00303 else 00304 deleteConnection(c); 00305 } 00306 00312 public boolean isInitialized() 00313 { 00314 return initialized; 00315 } 00316 00317 /* 00318 * Getter/setter methods 00319 */ 00320 00326 public String getLogin() 00327 { 00328 return rLogin; 00329 } 00330 00336 public void setLogin(String rLogin) 00337 { 00338 this.rLogin = rLogin; 00339 } 00340 00346 public String getPassword() 00347 { 00348 return rPassword; 00349 } 00350 00356 public void setPassword(String rPassword) 00357 { 00358 this.rPassword = rPassword; 00359 } 00360 00361 /* 00362 * Debug/monitoring information 00363 */ 00364 00370 public abstract String getXmlImpl(); 00371 00375 public String getXml() 00376 { 00377 StringBuffer info = new StringBuffer(); 00378 info.append("<" + DatabasesXmlTags.ELT_ConnectionManager + " " 00379 + DatabasesXmlTags.ATT_vLogin + "=\"" + vLogin + "\" " + "" 00380 + DatabasesXmlTags.ATT_rLogin + "=\"" + rLogin + "\" " + "" 00381 + DatabasesXmlTags.ATT_rPassword + "=\"" + rPassword + "\" " + ">"); 00382 info.append(this.getXmlImpl()); 00383 info.append("</" + DatabasesXmlTags.ELT_ConnectionManager + ">"); 00384 return info.toString(); 00385 } 00386 00393 protected void finalize() throws Throwable 00394 { 00395 if (isInitialized()) 00396 finalizeConnections(); 00397 super.finalize(); 00398 } 00399 00403 public String getVLogin() 00404 { 00405 return vLogin; 00406 } 00407 00411 public void setVLogin(String login) 00412 { 00413 vLogin = login; 00414 } 00415 00421 public abstract int getCurrentNumberOfConnections(); 00422 00428 public String getDriverClassName() 00429 { 00430 return driverClassName; 00431 } 00432 00438 public void setDriverClassName(String driverClassName) 00439 { 00440 this.driverClassName = driverClassName; 00441 } 00442 00448 public String getDriverPath() 00449 { 00450 return driverPath; 00451 } 00452 00458 public void setDriverPath(String driverPath) 00459 { 00460 this.driverPath = driverPath; 00461 } 00462 00463 protected abstract Object clone() throws CloneNotSupportedException; 00464 }

CJDBCversion1.0.4に対してTue Oct 12 15:16:00 2004に生成されました。 doxygen 1.3.8