Код:
compile:
[javac] Compiling 1839 source files to C:\*****\build\classes
[javac] C:\*****\java\*****\commons\dbcp\BasicDataSource.java:45: warning: [unchecked] unchecked call to GenericObjectPool(PoolableObjectFactory<T>) as a member of the raw type GenericObjectPool
[javac] GenericObjectPool connectionPool = new GenericObjectPool(null);
[javac] ^
[javac] where T is a type-variable:
[javac] T extends Object declared in class GenericObjectPool
BasicDataSource.java
Код:
public class BasicDataSource implements DataSource
{
private final PoolingDataSource _source;
private final ObjectPool<?> _connectionPool;
public BasicDataSource(String driver, String connectURI, String uname, String passwd, int maxActive, int maxIdle, int idleTimeOut, int idleTestPeriod, boolean poolPreparedStatements)
{
GenericObjectPool connectionPool = new GenericObjectPool(null);
connectionPool.setMaxActive(maxActive);
connectionPool.setMaxIdle(maxIdle);
connectionPool.setMinIdle(1);
connectionPool.setMaxWait(-1L);
connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
connectionPool.setTestOnBorrow(false);
connectionPool.setTestWhileIdle(true);
connectionPool.setTimeBetweenEvictionRunsMillis(idleTestPeriod * 1000L);
connectionPool.setNumTestsPerEvictionRun(maxActive);
connectionPool.setMinEvictableIdleTimeMillis(idleTimeOut * 1000L);
GenericKeyedObjectPoolFactory<?, ?> statementPoolFactory = null;
if(poolPreparedStatements)
statementPoolFactory = new GenericKeyedObjectPoolFactory<Object, Object>(null, -1, GenericObjectPool.WHEN_EXHAUSTED_FAIL, 0L, 1, GenericKeyedObjectPool.DEFAULT_MAX_TOTAL);
Properties connectionProperties = new Properties();
connectionProperties.put("user", uname);
connectionProperties.put("password", passwd);
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, connectionProperties);
@SuppressWarnings("unused")
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, statementPoolFactory, "SELECT 1", false, true);
PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
_connectionPool = connectionPool;
_source = dataSource;
}
public Connection getConnection(Connection con) throws SQLException
{
return con == null || con.isClosed() ? con = _source.getConnection() : con;
}
public int getBusyConnectionCount() throws SQLException
{
return _connectionPool.getNumActive();
}
public int getIdleConnectionCount() throws SQLException
{
return _connectionPool.getNumIdle();
}
public void shutdown() throws Exception
{
_connectionPool.close();
}
@Override
public PrintWriter getLogWriter() throws SQLException
{
return _source.getLogWriter();
}
@Override
public void setLogWriter(PrintWriter out) throws SQLException
{
_source.setLogWriter(out);
}
@Override
public void setLoginTimeout(int seconds) throws SQLException
{
throw new UnsupportedOperationException();
}
public Logger getParentLogger() throws SQLFeatureNotSupportedException
{
return Logger.getLogger(BasicDataSource.class.getName());
}
@Override
public int getLoginTimeout() throws SQLException
{
throw new UnsupportedOperationException();
}
@Override
public <T> T unwrap(Class<T> iface) throws SQLException
{
throw new UnsupportedOperationException();
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException
{
return false;
}
@Override
public Connection getConnection() throws SQLException
{
return _source.getConnection();
}
@Override
public Connection getConnection(String username, String password) throws SQLException
{
throw new UnsupportedOperationException();
}
}