org.apache.tomcat.jdbc.pool.interceptor.StatementCounterInterceptor Java Examples
The following examples show how to use
org.apache.tomcat.jdbc.pool.interceptor.StatementCounterInterceptor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestStatementCache.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testStatementClose1() throws Exception { init(); datasource.setJdbcInterceptors( TestStatementCacheInterceptor.class.getName() + "(prepared=true,callable=false,max=1);" + StatementCounterInterceptor.class.getName()); Connection con = datasource.getConnection(); StatementCounterInterceptor counter = findInterceptor(con, StatementCounterInterceptor.class); PreparedStatement ps1, ps2; ps1 = con.prepareStatement("select 1"); Assert.assertEquals(1, counter.getActiveCount()); ps1.close(); Assert.assertEquals("Statement goes into cache, not closed", 1, counter.getActiveCount()); ps1 = con.prepareStatement("select 1"); Assert.assertEquals("Reusing statement from cache", 1, counter.getActiveCount()); ps2 = con.prepareStatement("select 1"); Assert.assertEquals("Reusing statement from cache", 2, counter.getActiveCount()); ps2.close(); Assert.assertEquals("Statement goes into cache, not closed", 2, counter.getActiveCount()); ps1.close(); // Cache has "max=1". The following tests BZ 54732. Assert.assertEquals("Statement does not go into cache, closed", 1, counter.getActiveCount()); con.close(); Assert.assertEquals("Connection returned to the pool. Statement is in cache", 1, counter.getActiveCount()); datasource.close(); Assert.assertEquals("Pool cleared. All statements in cache are closed", 0, counter.getActiveCount()); }
Example #2
Source File: TestStatementCache.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testStatementClose2() throws Exception { init(); datasource.setJdbcInterceptors( TestStatementCacheInterceptor.class.getName() + "(prepared=false,callable=false,max=10);" + StatementCounterInterceptor.class.getName()); Connection con = datasource.getConnection(); StatementCounterInterceptor counter = findInterceptor(con, StatementCounterInterceptor.class); PreparedStatement ps1 = con.prepareStatement("select 1"); Assert.assertEquals(1, counter.getActiveCount()); ps1.close(); Assert.assertEquals("Statement is not pooled, closes immediately", 0, counter.getActiveCount()); }
Example #3
Source File: TestStatementCache.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Test public void testStatementClose1() throws Exception { init(); datasource.setJdbcInterceptors( TestStatementCacheInterceptor.class.getName() + "(prepared=true,callable=false,max=1);" + StatementCounterInterceptor.class.getName()); Connection con = datasource.getConnection(); StatementCounterInterceptor counter = findInterceptor(con, StatementCounterInterceptor.class); PreparedStatement ps1, ps2; ps1 = con.prepareStatement("select 1"); Assert.assertEquals(1, counter.getActiveCount()); ps1.close(); Assert.assertEquals("Statement goes into cache, not closed", 1, counter.getActiveCount()); ps1 = con.prepareStatement("select 1"); Assert.assertEquals("Reusing statement from cache", 1, counter.getActiveCount()); ps2 = con.prepareStatement("select 1"); Assert.assertEquals("Reusing statement from cache", 2, counter.getActiveCount()); ps2.close(); Assert.assertEquals("Statement goes into cache, not closed", 2, counter.getActiveCount()); ps1.close(); // Cache has "max=1". The following tests BZ 54732. Assert.assertEquals("Statement does not go into cache, closed", 1, counter.getActiveCount()); con.close(); Assert.assertEquals("Connection returned to the pool. Statement is in cache", 1, counter.getActiveCount()); datasource.close(); Assert.assertEquals("Pool cleared. All statements in cache are closed", 0, counter.getActiveCount()); }
Example #4
Source File: TestStatementCache.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Test public void testStatementClose2() throws Exception { init(); datasource.setJdbcInterceptors( TestStatementCacheInterceptor.class.getName() + "(prepared=false,callable=false,max=10);" + StatementCounterInterceptor.class.getName()); Connection con = datasource.getConnection(); StatementCounterInterceptor counter = findInterceptor(con, StatementCounterInterceptor.class); PreparedStatement ps1 = con.prepareStatement("select 1"); Assert.assertEquals(1, counter.getActiveCount()); ps1.close(); Assert.assertEquals("Statement is not pooled, closes immediately", 0, counter.getActiveCount()); }
Example #5
Source File: TestStatementCache.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Test public void testStatementClose1() throws Exception { init(); datasource.setJdbcInterceptors( TestStatementCacheInterceptor.class.getName() + "(prepared=true,callable=false,max=1);" + StatementCounterInterceptor.class.getName()); Connection con = datasource.getConnection(); StatementCounterInterceptor counter = findInterceptor(con, StatementCounterInterceptor.class); PreparedStatement ps1, ps2; ps1 = con.prepareStatement("select 1"); Assert.assertEquals(1, counter.getActiveCount()); ps1.close(); Assert.assertEquals("Statement goes into cache, not closed", 1, counter.getActiveCount()); ps1 = con.prepareStatement("select 1"); Assert.assertEquals("Reusing statement from cache", 1, counter.getActiveCount()); ps2 = con.prepareStatement("select 1"); Assert.assertEquals("Reusing statement from cache", 2, counter.getActiveCount()); ps2.close(); Assert.assertEquals("Statement goes into cache, not closed", 2, counter.getActiveCount()); ps1.close(); // Cache has "max=1". The following tests BZ 54732. Assert.assertEquals("Statement does not go into cache, closed", 1, counter.getActiveCount()); con.close(); Assert.assertEquals("Connection returned to the pool. Statement is in cache", 1, counter.getActiveCount()); datasource.close(); Assert.assertEquals("Pool cleared. All statements in cache are closed", 0, counter.getActiveCount()); }
Example #6
Source File: TestStatementCache.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Test public void testStatementClose2() throws Exception { init(); datasource.setJdbcInterceptors( TestStatementCacheInterceptor.class.getName() + "(prepared=false,callable=false,max=10);" + StatementCounterInterceptor.class.getName()); Connection con = datasource.getConnection(); StatementCounterInterceptor counter = findInterceptor(con, StatementCounterInterceptor.class); PreparedStatement ps1 = con.prepareStatement("select 1"); Assert.assertEquals(1, counter.getActiveCount()); ps1.close(); Assert.assertEquals("Statement is not pooled, closes immediately", 0, counter.getActiveCount()); }