本文整理汇总了Java中org.apache.tomcat.jdbc.pool.PooledConnection类的典型用法代码示例。如果您正苦于以下问题:Java PooledConnection类的具体用法?Java PooledConnection怎么用?Java PooledConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PooledConnection类属于org.apache.tomcat.jdbc.pool包,在下文中一共展示了PooledConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: disconnected
import org.apache.tomcat.jdbc.pool.PooledConnection; //导入依赖的package包/类
@Override
public void disconnected(ConnectionPool parent, PooledConnection con, boolean finalizing) {
@SuppressWarnings("unchecked")
ConcurrentHashMap<CacheKey,CachedStatement> statements =
(ConcurrentHashMap<CacheKey,CachedStatement>)con.getAttributes().get(STATEMENT_CACHE_ATTR);
if (statements!=null) {
for (Map.Entry<CacheKey, CachedStatement> p : statements.entrySet()) {
closeStatement(p.getValue());
}
statements.clear();
}
super.disconnected(parent, con, finalizing);
}
示例2: resetTimer
import org.apache.tomcat.jdbc.pool.PooledConnection; //导入依赖的package包/类
public boolean resetTimer() {
boolean result = false;
JdbcInterceptor interceptor = this.getNext();
while (interceptor!=null && result==false) {
if (interceptor instanceof ProxyConnection) {
PooledConnection con = ((ProxyConnection)interceptor).getConnection();
if (con!=null) {
con.setTimestamp(System.currentTimeMillis());
result = true;
} else {
break;
}
}
interceptor = interceptor.getNext();
}
return result;
}
示例3: testSuspect
import org.apache.tomcat.jdbc.pool.PooledConnection; //导入依赖的package包/类
@Test
public void testSuspect() throws Exception {
this.datasource.setMaxActive(100);
this.datasource.setMaxIdle(100);
this.datasource.setInitialSize(0);
this.datasource.getPoolProperties().setAbandonWhenPercentageFull(0);
this.datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(100);
this.datasource.getPoolProperties().setRemoveAbandoned(true);
this.datasource.getPoolProperties().setRemoveAbandonedTimeout(100);
this.datasource.getPoolProperties().setSuspectTimeout(1);
this.datasource.getPoolProperties().setLogAbandoned(true);
Connection con = datasource.getConnection();
Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive());
Thread.sleep(3000);
PooledConnection pcon = con.unwrap(PooledConnection.class);
Assert.assertTrue("Connection should be marked suspect",pcon.isSuspect());
con.close();
}
示例4: testCleanupCloseConnectionNegative
import org.apache.tomcat.jdbc.pool.PooledConnection; //导入依赖的package包/类
@Test
public void testCleanupCloseConnectionNegative() {
try {
TestConnectionAction test = new TestConnectionAction();
DalConnection connHolder = getDalConnection();
test.connHolder = connHolder;
test.statement = test.connHolder.getConn().createStatement();
test.rs = test.statement.executeQuery("select * from " + SqlServerTestInitializer.TABLE_NAME);
test.rs.next();
PooledConnection c = (PooledConnection)connHolder.getConn().unwrap(PooledConnection.class);
connHolder.error(new NullPointerException("0800"));
test.cleanup();
assertTrue(!c.isDiscarded());
assertTrue(!c.isReleased());
assertNotNull(test);
assertTrue(test.conn == null);
assertTrue(test.statement == null);
assertTrue(test.rs == null);
assertTrue(test.connHolder == null);
} catch (Exception ex) {
ex.printStackTrace();
fail("There should be no exception here");
}
}
示例5: reset
import org.apache.tomcat.jdbc.pool.PooledConnection; //导入依赖的package包/类
@Override
public void reset(ConnectionPool parent, PooledConnection con)
{
trackedConnPool = parent;
trackedPooledCon = con;
if (parent != null && con != null)
{
ConnPair cp = new ConnPair();
cp.conn = con;
cp.thread = Thread.currentThread();
Set<ConnPair> pairs = conns.get(parent);
if (pairs != null)
{
conns.get(parent).add(cp);
}
}
}
示例6: testSuspect
import org.apache.tomcat.jdbc.pool.PooledConnection; //导入依赖的package包/类
public void testSuspect() throws Exception {
this.init();
this.datasource.setMaxActive(100);
this.datasource.setMaxIdle(100);
this.datasource.setInitialSize(0);
this.datasource.getPoolProperties().setAbandonWhenPercentageFull(0);
this.datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(100);
this.datasource.getPoolProperties().setRemoveAbandoned(true);
this.datasource.getPoolProperties().setRemoveAbandonedTimeout(100);
this.datasource.getPoolProperties().setSuspectTimeout(1);
this.datasource.getPoolProperties().setLogAbandoned(true);
Connection con = datasource.getConnection();
assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive());
Thread.sleep(3000);
PooledConnection pcon = con.unwrap(PooledConnection.class);
assertTrue("Connection should be marked suspect",pcon.isSuspect());
con.close();
}
示例7: create
import org.apache.tomcat.jdbc.pool.PooledConnection; //导入依赖的package包/类
@Override
protected PooledConnection create(final boolean incrementCounter) {
final PooledConnection con = super.create(incrementCounter);
if (getPoolProperties().getDataSource() == null) { // using driver
// init driver with TCCL
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null) {
cl = TomEEConnectionPool.class.getClassLoader();
}
try {
Reflections.set(con, "driver", Class.forName(getPoolProperties().getDriverClassName(), true, cl).newInstance());
} catch (final ClassNotFoundException cnfe) {
try { // custom resource classloader
Reflections.set(con, "driver", Class.forName(getPoolProperties().getDriverClassName(), true, creationLoader).newInstance());
} catch (final Exception e) {
// will fail later, no worry
}
} catch (final Exception cn) {
// will fail later, no worry
}
}
return con;
}
示例8: reset
import org.apache.tomcat.jdbc.pool.PooledConnection; //导入依赖的package包/类
@Override
public void reset(ConnectionPool parent, PooledConnection con) {
super.reset(parent, con);
if (parent!=null) {
poolName = parent.getName();
pool = parent;
registerJmx();
}
}
示例9: reset
import org.apache.tomcat.jdbc.pool.PooledConnection; //导入依赖的package包/类
@Override
public void reset(ConnectionPool parent, PooledConnection con) {
super.reset(parent, con);
if (parent==null) {
cacheSize = null;
this.pcon = null;
} else {
cacheSize = cacheSizeMap.get(parent);
this.pcon = con;
if (!pcon.getAttributes().containsKey(STATEMENT_CACHE_ATTR)) {
ConcurrentHashMap<CacheKey,CachedStatement> cache = new ConcurrentHashMap<CacheKey, CachedStatement>();
pcon.getAttributes().put(STATEMENT_CACHE_ATTR,cache);
}
}
}
示例10: reset
import org.apache.tomcat.jdbc.pool.PooledConnection; //导入依赖的package包/类
@Override
public void reset(ConnectionPool parent, PooledConnection con) {
super.reset(parent, con);
if (parent!=null)
queries = SlowQueryReport.perPoolStats.get(parent.getName());
else
queries = null;
}
示例11: disconnected
import org.apache.tomcat.jdbc.pool.PooledConnection; //导入依赖的package包/类
@Override
public void disconnected(ConnectionPool parent, PooledConnection con, boolean finalizing) {
//we are resetting, reset our defaults
autoCommit = null;
transactionIsolation = null;
readOnly = null;
catalog = null;
super.disconnected(parent, con, finalizing);
}
示例12: create
import org.apache.tomcat.jdbc.pool.PooledConnection; //导入依赖的package包/类
/**
* Creates a mocked SQL connection, that looks like a tomcat-jdbc pooled connection.
* @param username the username to use
* @param password the password to use
* @return the connection
* @throws SQLException
*/
public static Connection create(String username, String password) throws SQLException {
PoolProperties poolProps = new PoolProperties();
poolProps.setUsername(username);
poolProps.setPassword(password);
poolProps.setDataSource(new MockDataSource());
ConnectionPool pool = new ConnectionPool(poolProps);
PooledConnection pooledConnection = new PooledConnection(poolProps, pool);
pooledConnection.connect();
ProxyConnection proxyConnection = new ProxyConnection(null, pooledConnection, true) {};
DisposableConnectionFacade invocationHandler = new DisposableConnectionFacade(proxyConnection) {};
Connection connection = (Connection) Proxy.newProxyInstance(DisposableConnectionFacade.class.getClassLoader(), new Class[] {Connection.class}, invocationHandler);
return connection;
}
示例13: reset
import org.apache.tomcat.jdbc.pool.PooledConnection; //导入依赖的package包/类
@Override
public void reset(ConnectionPool parent, PooledConnection con) {
// TODO Auto-generated method stub
super.reset(parent, con);
if (parent!=null) {
poolName = parent.getName();
pool = parent;
registerJmx();
}
}
示例14: reset
import org.apache.tomcat.jdbc.pool.PooledConnection; //导入依赖的package包/类
@Override
public void reset(ConnectionPool parent, PooledConnection con) {
super.reset(parent, con);
if (parent==null) {
cacheSize = null;
this.pcon = null;
} else {
cacheSize = cacheSizeMap.get(parent);
this.pcon = con;
if (!pcon.getAttributes().containsKey(STATEMENT_CACHE_ATTR)) {
ConcurrentHashMap<String,CachedStatement> cache = new ConcurrentHashMap<String, CachedStatement>();
pcon.getAttributes().put(STATEMENT_CACHE_ATTR,cache);
}
}
}
示例15: disconnected
import org.apache.tomcat.jdbc.pool.PooledConnection; //导入依赖的package包/类
@Override
public void disconnected(ConnectionPool parent, PooledConnection con, boolean finalizing) {
@SuppressWarnings("unchecked")
ConcurrentHashMap<String,CachedStatement> statements =
(ConcurrentHashMap<String,CachedStatement>)con.getAttributes().get(STATEMENT_CACHE_ATTR);
if (statements!=null) {
for (Map.Entry<String, CachedStatement> p : statements.entrySet()) {
closeStatement(p.getValue());
}
statements.clear();
}
super.disconnected(parent, con, finalizing);
}