mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
支持HA
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@463 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -28,7 +28,7 @@ import com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl;
|
||||
|
||||
public class HAConnection extends WrapperAdapter implements Connection, ConnectionProxy {
|
||||
|
||||
private final HADataSource haDataSource;
|
||||
private final MultiDataSource haDataSource;
|
||||
|
||||
private Connection conn;
|
||||
|
||||
@@ -88,7 +88,7 @@ public class HAConnection extends WrapperAdapter implements Connection, Connecti
|
||||
connectedTime = new Date();
|
||||
}
|
||||
|
||||
public HADataSource getHaDataSource() {
|
||||
public MultiDataSource getHaDataSource() {
|
||||
return haDataSource;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@ public class HADataSource extends MultiDataSource implements DataSource {
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(HADataSource.class);
|
||||
|
||||
private final AtomicInteger connectionIdSeed = new AtomicInteger();
|
||||
private final AtomicInteger statementIdSeed = new AtomicInteger();
|
||||
private final AtomicInteger indexErrorCount = new AtomicInteger();
|
||||
|
||||
protected final List<DruidDataSource> notAvailableDatasources = new CopyOnWriteArrayList<DruidDataSource>();
|
||||
@@ -27,13 +25,7 @@ public class HADataSource extends MultiDataSource implements DataSource {
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
int requestNumber = connectionIdSeed.getAndIncrement();
|
||||
|
||||
return new HAConnection(this, requestNumber);
|
||||
}
|
||||
|
||||
public int createStatementId() {
|
||||
return statementIdSeed.getAndIncrement();
|
||||
return new HAConnection(this, createConnectionId());
|
||||
}
|
||||
|
||||
public Connection getConnectionInternal(int connectionId, String sql) throws SQLException {
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.alibaba.druid.pool.DataSourceAdapter;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
@@ -14,7 +15,18 @@ public abstract class MultiDataSource extends DataSourceAdapter {
|
||||
|
||||
protected ArrayList<DruidDataSource> dataSources;
|
||||
|
||||
private Properties properties = new Properties();
|
||||
private Properties properties = new Properties();
|
||||
|
||||
private final AtomicInteger connectionIdSeed = new AtomicInteger();
|
||||
private final AtomicInteger statementIdSeed = new AtomicInteger();
|
||||
|
||||
public int createConnectionId() {
|
||||
return connectionIdSeed.getAndIncrement();
|
||||
}
|
||||
|
||||
public int createStatementId() {
|
||||
return statementIdSeed.getAndIncrement();
|
||||
}
|
||||
|
||||
public MultiDataSource(){
|
||||
dataSources = new ArrayList<DruidDataSource>();
|
||||
@@ -35,4 +47,6 @@ public abstract class MultiDataSource extends DataSourceAdapter {
|
||||
|
||||
@Override
|
||||
public abstract Connection getConnection() throws SQLException;
|
||||
|
||||
public abstract Connection getConnectionInternal(int connectionId, String sql) throws SQLException;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user