mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
尝试一个新的DruidDataSource
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@260 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -30,7 +30,7 @@ import javax.sql.StatementEventListener;
|
||||
*/
|
||||
public final class ConnectionHolder {
|
||||
|
||||
private final DruidDataSource dataSource;
|
||||
private final DruidAbstractDataSource dataSource;
|
||||
private final Connection conn;
|
||||
private final List<ConnectionEventListener> connectionEventListeners = new CopyOnWriteArrayList<ConnectionEventListener>();
|
||||
private final List<StatementEventListener> statementEventListeners = new CopyOnWriteArrayList<StatementEventListener>();
|
||||
@@ -85,7 +85,7 @@ public final class ConnectionHolder {
|
||||
return statementPool;
|
||||
}
|
||||
|
||||
public DruidDataSource getDataSource() {
|
||||
public DruidAbstractDataSource getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import javax.security.auth.callback.NameCallback;
|
||||
import javax.security.auth.callback.PasswordCallback;
|
||||
@@ -726,6 +727,36 @@ public abstract class DruidAbstractDataSource implements DataSource, DataSourceP
|
||||
return createTimespan / (1000 * 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Driver getRawDriver() {
|
||||
return driver;
|
||||
}
|
||||
|
||||
private final AtomicLong connectionIdSeed = new AtomicLong(10000);
|
||||
private final AtomicLong statementIdSeed = new AtomicLong(20000);
|
||||
private final AtomicLong resultSetIdSeed = new AtomicLong(50000);
|
||||
|
||||
public long createConnectionId() {
|
||||
return connectionIdSeed.incrementAndGet();
|
||||
}
|
||||
|
||||
public long createStatementId() {
|
||||
return statementIdSeed.getAndIncrement();
|
||||
}
|
||||
|
||||
public long createResultSetId() {
|
||||
return resultSetIdSeed.getAndIncrement();
|
||||
}
|
||||
|
||||
|
||||
void initStatement(Statement stmt) throws SQLException {
|
||||
if (queryTimeout > 0) {
|
||||
stmt.setQueryTimeout(queryTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void recycle(PoolableConnection pooledConnection) throws SQLException;
|
||||
|
||||
abstract void incrementCreateCount();
|
||||
|
||||
public static class DruidPoolConnectionFactory implements ConnectionFactory {
|
||||
|
||||
@@ -18,14 +18,12 @@ package com.alibaba.druid.pool;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Driver;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@@ -615,16 +613,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Driver getRawDriver() {
|
||||
return driver;
|
||||
}
|
||||
|
||||
void initStatement(Statement stmt) throws SQLException {
|
||||
if (queryTimeout > 0) {
|
||||
stmt.setQueryTimeout(queryTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
/** Instance key */
|
||||
protected String instanceKey = null;
|
||||
@@ -687,19 +675,5 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
return names;
|
||||
}
|
||||
|
||||
private final AtomicLong connectionIdSeed = new AtomicLong(10000);
|
||||
private final AtomicLong statementIdSeed = new AtomicLong(20000);
|
||||
private final AtomicLong resultSetIdSeed = new AtomicLong(50000);
|
||||
|
||||
public long createConnectionId() {
|
||||
return connectionIdSeed.incrementAndGet();
|
||||
}
|
||||
|
||||
public long createStatementId() {
|
||||
return statementIdSeed.getAndIncrement();
|
||||
}
|
||||
|
||||
public long createResultSetId() {
|
||||
return resultSetIdSeed.getAndIncrement();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.alibaba.druid.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class DruidDataSource2 extends DruidAbstractDataSource {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection(String username, String password) throws SQLException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
void incrementCreateCount() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void recycle(PoolableConnection pooledConnection) throws SQLException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user