Public Member Functions | |
AbstractPoolConnectionManager (String backendUrl, String backendName, String login, String password, String driverPath, String driverClassName, int poolSize) | |
synchronized void | initializeConnections () throws SQLException |
synchronized void | initializeConnections (int initPoolSize) throws SQLException |
synchronized void | finalizeConnections () throws SQLException |
int | getCurrentNumberOfConnections () |
Protected Attributes | |
transient Stack | freeConnections |
transient Vector | activeConnections |
int | poolSize |
Definition at line 48 of file AbstractPoolConnectionManager.java.
|
Creates a new
Definition at line 88 of file AbstractPoolConnectionManager.java. References org.objectweb.cjdbc.common.log.Trace.debug(), and org.objectweb.cjdbc.common.log.Trace.isDebugEnabled(). 00091 { 00092 super(backendUrl, backendName, login, password, driverPath, driverClassName); 00093 00094 if (poolSize < 1) 00095 throw new IllegalArgumentException( 00096 "Illegal value for size of the pool connection manager: " + poolSize); 00097 00098 this.poolSize = poolSize; 00099 this.freeConnections = new Stack(); 00100 this.activeConnections = new Vector(poolSize); 00101 this.initialized = false; 00102 00103 if (logger.isDebugEnabled()) 00104 logger.debug(Translate.get("connection.backend.pool.created", 00105 new String[]{backendName, String.valueOf(poolSize)})); 00106 }
|
|
Implements org.objectweb.cjdbc.controller.connection.AbstractConnectionManager. Reimplemented in org.objectweb.cjdbc.controller.connection.VariablePoolConnectionManager. Definition at line 185 of file AbstractPoolConnectionManager.java. References org.objectweb.cjdbc.common.log.Trace.error(), and org.objectweb.cjdbc.common.log.Trace.info(). 00186 { 00187 if (!initialized) 00188 { 00189 String msg = Translate.get("connection.pool.not.initialized"); 00190 logger.error(msg); 00191 throw new SQLException(msg); 00192 } 00193 00194 Connection c; 00195 boolean error = false; 00196 00197 // Close free connections 00198 initialized = false; 00199 int freed = 0; 00200 while (!freeConnections.isEmpty()) 00201 { 00202 c = (Connection) freeConnections.pop(); 00203 try 00204 { 00205 c.close(); 00206 } 00207 catch (SQLException e) 00208 { 00209 error = true; 00210 } 00211 freed++; 00212 } 00213 if (logger.isInfoEnabled()) 00214 logger.info(Translate.get("connection.freed.connection", new String[]{ 00215 String.valueOf(freed), backendUrl})); 00216 00217 // Close active connections 00218 int size = activeConnections.size(); 00219 if (size > 0) 00220 { 00221 logger.warn(Translate.get("connection.connections.still.active", size)); 00222 for (int i = 0; i < size; i++) 00223 { 00224 c = (Connection) activeConnections.get(i); 00225 try 00226 { 00227 c.close(); 00228 } 00229 catch (SQLException e) 00230 { 00231 error = true; 00232 } 00233 } 00234 } 00235 00236 // Clear connections to ensure that the eventually not closed connections 00237 // will be closed when the objects will be garbage collected 00238 freeConnections.clear(); 00239 activeConnections.clear(); 00240 00241 if (error) 00242 { 00243 String msg = Translate.get("connection.free.connections.failed"); 00244 logger.error(msg); 00245 throw new SQLException(msg); 00246 } 00247 }
|
|
Implements org.objectweb.cjdbc.controller.connection.AbstractConnectionManager. Definition at line 252 of file AbstractPoolConnectionManager.java. 00253 {
00254 return poolSize;
00255 }
|
|
Initialize initPoolSize connections in the pool.
Definition at line 126 of file AbstractPoolConnectionManager.java. References org.objectweb.cjdbc.common.log.Trace.warn(). 00128 { 00129 if (initialized) 00130 throw new SQLException("Connection pool for backend '" + backendUrl 00131 + "' already initialized"); 00132 00133 if (initPoolSize > poolSize) 00134 { 00135 logger.warn(Translate.get("connection.max.poolsize.reached", 00136 new String[]{String.valueOf(initPoolSize), String.valueOf(poolSize), 00137 String.valueOf(poolSize)})); 00138 initPoolSize = poolSize; 00139 } 00140 00141 Connection c = null; 00142 00143 boolean connectionsAvailable = true; 00144 int i = 0; 00145 while ((i < initPoolSize) && connectionsAvailable) 00146 { 00147 c = getConnectionFromDriver(); 00148 00149 if (c == null) 00150 connectionsAvailable = false; 00151 00152 if (!connectionsAvailable) 00153 { 00154 if (i > 0) 00155 { 00156 logger.warn(Translate.get("connection.limit.poolsize", i)); 00157 } 00158 else 00159 { 00160 logger.warn(Translate.get("connection.initialize.pool.failed")); 00161 poolSize = 0; 00162 } 00163 } 00164 else 00165 { 00166 freeConnections.push(c); 00167 i++; 00168 } 00169 } 00170 00171 poolSize = i; 00172 initialized = true; 00173 00174 if (poolSize == 0) // Should never happen 00175 logger.error(Translate.get("connection.empty.pool")); 00176 if (logger.isDebugEnabled()) 00177 logger.debug(Translate.get("connection.pool.initialized", new String[]{ 00178 String.valueOf(initPoolSize), backendUrl})); 00179 00180 }
|
|
Implements org.objectweb.cjdbc.controller.connection.AbstractConnectionManager. Reimplemented in org.objectweb.cjdbc.controller.connection.VariablePoolConnectionManager. Definition at line 115 of file AbstractPoolConnectionManager.java. 00116 { 00117 initializeConnections(poolSize); 00118 }
|
|
Pool of currently used connections ( Definition at line 64 of file AbstractPoolConnectionManager.java. |
|
Stack of available connections (pool). Definition at line 58 of file AbstractPoolConnectionManager.java. |
|
Size of the connection pool with the real database. Definition at line 67 of file AbstractPoolConnectionManager.java. |