mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
ha
This commit is contained in:
@@ -1,19 +1,23 @@
|
||||
package com.alibaba.druid.pool.ha;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
|
||||
public class DataSourceHolder {
|
||||
public class DataSourceHolder implements Closeable {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
private boolean enable;
|
||||
private final DruidDataSource dataSource;
|
||||
private boolean enable = true;
|
||||
private final AtomicLong connectCount = new AtomicLong();
|
||||
private final AtomicLong connectErrorCount = new AtomicLong();
|
||||
|
||||
public DataSourceHolder(DruidDataSource dataSource){
|
||||
if (dataSource == null) {
|
||||
throw new IllegalArgumentException("dataSource is null");
|
||||
}
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@@ -33,10 +37,6 @@ public class DataSourceHolder {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
public void setDataSource(DruidDataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
public long getConnectCount() {
|
||||
return connectCount.get();
|
||||
}
|
||||
@@ -46,10 +46,6 @@ public class DataSourceHolder {
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
if (dataSource == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return dataSource.getUrl();
|
||||
}
|
||||
|
||||
@@ -65,4 +61,9 @@ public class DataSourceHolder {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
dataSource.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user