* @param properties PoolProperties - properties used to initialize the pool with
* @throws SQLException
*/
- protected void init (PoolProperties properties) throws SQLException {
+ protected void init(PoolProperties properties) throws SQLException {
poolProperties = properties;
//make space for 10 extra in case we flow over a bit
busy = new ArrayBlockingQueue<PooledConnection>(properties.getMaxActive(),false);
}
+ PoolProperties.InterceptorDefinition[] proxies = getPoolProperties().getJdbcInterceptorsAsArray();
+ for (int i=0; i<proxies.length; i++) {
+ try {
+ proxies[i].getInterceptorClass().newInstance().poolStarted(this);
+ }catch (Exception x) {
+ log.warn("Unable to inform interceptor of pool start.",x);
+ close(true);
+ throw new SQLException(x);
+ }
+ }
//initialize the pool with its initial set of members
PooledConnection[] initialPool = new PooledConnection[poolProperties.getInitialSize()];
try {
protected static Log log = LogFactory.getLog(DataSourceProxy.class);
protected volatile ConnectionPool pool = null;
+
public ConnectionPool getPool() {
return pool;
}
if (p!=null) p.close(all);
}
}catch (Exception x) {
- x.printStackTrace();
+ log.warn("Error duing connection pool closure.", x);
}
}
*/
public void poolClosed(ConnectionPool pool) {
}
+
+ /**
+ * This method is invoked by a connection pool when the pool is first started up, usually when the first connection is requested.
+ * Interceptor classes can override this method if they keep static
+ * variables or other tracking means around.
+ * <b>This method is only invoked on a single instance of the interceptor, and not on every instance created.</b>
+ * @param pool - the pool that is being closed.
+ */
+ public void poolStarted(ConnectionPool pool) {
+ }
+
}
public TestSlowQueryReport(String name) {
super(name);
}
-
public void testSlowSql() throws Exception {
int count = 3;
assertNull(SlowQueryReport.getPoolStats(pool.getName()));
}
+ public void testFailedSql() throws Exception {
+ int count = 3;
+ this.init();
+ this.datasource.setMaxActive(1);
+ this.datasource.setJdbcInterceptors(SlowQueryReport.class.getName());
+ Connection con = this.datasource.getConnection();
+ String slowSql = "select 1 from non_existent";
+ int exceptionCount = 0;
+ for (int i=0; i<count; i++) {
+ Statement st = con.createStatement();
+ try {
+ ResultSet rs = st.executeQuery(slowSql);
+ rs.close();
+ }catch (Exception x) {
+ exceptionCount++;
+ }
+ st.close();
+
+ }
+ Map<String,SlowQueryReport.QueryStats> map = SlowQueryReport.getPoolStats(datasource.getPool().getName());
+ assertNotNull(map);
+ assertEquals(1,map.size());
+ ConnectionPool pool = datasource.getPool();
+ String key = map.keySet().iterator().next();
+ SlowQueryReport.QueryStats stats = map.get(key);
+ System.out.println("Stats:"+stats);
+ con.close();
+ tearDown();
+ assertNull(SlowQueryReport.getPoolStats(pool.getName()));
+ }
+
+
}