mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -290,8 +290,12 @@ public interface Filter extends Wrapper {
|
||||
|
||||
Object resultSet_getObject(FilterChain chain, ResultSetProxy resultSet, int columnIndex) throws SQLException;
|
||||
|
||||
<T> T resultSet_getObject(FilterChain chain, ResultSetProxy resultSet, int columnIndex, Class<T> type) throws SQLException;
|
||||
|
||||
Object resultSet_getObject(FilterChain chain, ResultSetProxy resultSet, String columnLabel) throws SQLException;
|
||||
|
||||
<T> T resultSet_getObject(FilterChain chain, ResultSetProxy resultSet, String columnLabel, Class<T> type) throws SQLException;
|
||||
|
||||
int resultSet_findColumn(FilterChain chain, ResultSetProxy resultSet, String columnLabel) throws SQLException;
|
||||
|
||||
java.io.Reader resultSet_getCharacterStream(FilterChain chain, ResultSetProxy resultSet, int columnIndex)
|
||||
|
||||
@@ -1698,6 +1698,11 @@ public abstract class FilterAdapter extends NotificationBroadcasterSupport imple
|
||||
return chain.resultSet_getObject(result, columnIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex, Class<T> type) throws SQLException {
|
||||
return chain.resultSet_getObject(result, columnIndex, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex,
|
||||
java.util.Map<String, Class<?>> map) throws SQLException {
|
||||
@@ -1709,6 +1714,11 @@ public abstract class FilterAdapter extends NotificationBroadcasterSupport imple
|
||||
return chain.resultSet_getObject(result, columnLabel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel, Class<T> type) throws SQLException {
|
||||
return chain.resultSet_getObject(result, columnLabel, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel,
|
||||
java.util.Map<String, Class<?>> map) throws SQLException {
|
||||
|
||||
@@ -266,8 +266,12 @@ public interface FilterChain {
|
||||
|
||||
Object resultSet_getObject(ResultSetProxy resultSet, int columnIndex) throws SQLException;
|
||||
|
||||
<T> T resultSet_getObject(ResultSetProxy resultSet, int columnIndex, Class<T> type) throws SQLException;
|
||||
|
||||
Object resultSet_getObject(ResultSetProxy resultSet, String columnLabel) throws SQLException;
|
||||
|
||||
<T> T resultSet_getObject(ResultSetProxy resultSet, String columnLabel, Class<T> type) throws SQLException;
|
||||
|
||||
int resultSet_findColumn(ResultSetProxy resultSet, String columnLabel) throws SQLException;
|
||||
|
||||
java.io.Reader resultSet_getCharacterStream(ResultSetProxy resultSet, int columnIndex) throws SQLException;
|
||||
|
||||
@@ -1368,6 +1368,32 @@ public class FilterChainImpl implements FilterChain {
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T resultSet_getObject(ResultSetProxy rs, int columnIndex, Class<T> type) throws SQLException {
|
||||
if (this.pos < filterSize) {
|
||||
return nextFilter()
|
||||
.resultSet_getObject(this, rs, columnIndex, type);
|
||||
}
|
||||
|
||||
Object obj = rs.getResultSetRaw().getObject(columnIndex, type);
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
StatementProxy statement = rs.getStatementProxy();
|
||||
return (T) new ResultSetProxyImpl(statement
|
||||
, (ResultSet) obj
|
||||
, dataSource.createResultSetId()
|
||||
, statement.getLastExecuteSql()
|
||||
);
|
||||
}
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
return (T) wrap(
|
||||
rs.getStatementProxy(), (Clob) obj);
|
||||
}
|
||||
|
||||
return (T) obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resultSet_getObject(ResultSetProxy rs, String columnLabel) throws SQLException {
|
||||
if (this.pos < filterSize) {
|
||||
@@ -1394,6 +1420,32 @@ public class FilterChainImpl implements FilterChain {
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T resultSet_getObject(ResultSetProxy rs, String columnLabel, Class<T> type) throws SQLException {
|
||||
if (this.pos < filterSize) {
|
||||
return nextFilter()
|
||||
.resultSet_getObject(this, rs, columnLabel, type);
|
||||
}
|
||||
|
||||
T obj = rs.getResultSetRaw()
|
||||
.getObject(columnLabel, type);
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
StatementProxy stmt = rs.getStatementProxy();
|
||||
return (T) new ResultSetProxyImpl(stmt
|
||||
, (ResultSet) obj
|
||||
, dataSource.createResultSetId()
|
||||
, stmt.getLastExecuteSql()
|
||||
);
|
||||
}
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
return (T) wrap(rs.getStatementProxy(), (Clob) obj);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int resultSet_findColumn(ResultSetProxy rs, String columnLabel) throws SQLException {
|
||||
if (this.pos < filterSize) {
|
||||
|
||||
@@ -85,14 +85,8 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
Object value = null;
|
||||
switch (columnType) {
|
||||
case Types.CHAR:
|
||||
value = super.resultSet_getString(chain, result, columnIndex);
|
||||
break;
|
||||
case Types.CLOB:
|
||||
value = super.resultSet_getString(chain, result, columnIndex);
|
||||
break;
|
||||
case Types.LONGVARCHAR:
|
||||
value = super.resultSet_getString(chain, result, columnIndex);
|
||||
break;
|
||||
case Types.VARCHAR:
|
||||
value = super.resultSet_getString(chain, result, columnIndex);
|
||||
break;
|
||||
@@ -103,6 +97,27 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
return decodeObject(result.getStatementProxy().getConnectionProxy(), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex, Class<T> type) throws SQLException {
|
||||
ResultSet rawResultSet = result.getResultSetRaw();
|
||||
ResultSetMetaData metadata = rawResultSet.getMetaData();
|
||||
int columnType = metadata.getColumnType(columnIndex);
|
||||
|
||||
Object value = null;
|
||||
switch (columnType) {
|
||||
case Types.CHAR:
|
||||
case Types.CLOB:
|
||||
case Types.LONGVARCHAR:
|
||||
case Types.VARCHAR:
|
||||
value = super.resultSet_getString(chain, result, columnIndex);
|
||||
break;
|
||||
default:
|
||||
value = super.resultSet_getObject(chain, result, columnIndex, type);
|
||||
}
|
||||
|
||||
return (T) decodeObject(result.getStatementProxy().getConnectionProxy(), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex,
|
||||
java.util.Map<String, Class<?>> map) throws SQLException {
|
||||
@@ -113,14 +128,8 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
Object value = null;
|
||||
switch (columnType) {
|
||||
case Types.CHAR:
|
||||
value = super.resultSet_getString(chain, result, columnIndex);
|
||||
break;
|
||||
case Types.CLOB:
|
||||
value = super.resultSet_getString(chain, result, columnIndex);
|
||||
break;
|
||||
case Types.LONGVARCHAR:
|
||||
value = super.resultSet_getString(chain, result, columnIndex);
|
||||
break;
|
||||
case Types.VARCHAR:
|
||||
value = super.resultSet_getString(chain, result, columnIndex);
|
||||
break;
|
||||
@@ -141,14 +150,8 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
Object value = null;
|
||||
switch (columnType) {
|
||||
case Types.CHAR:
|
||||
value = super.resultSet_getString(chain, result, columnLabel);
|
||||
break;
|
||||
case Types.CLOB:
|
||||
value = super.resultSet_getString(chain, result, columnLabel);
|
||||
break;
|
||||
case Types.LONGVARCHAR:
|
||||
value = super.resultSet_getString(chain, result, columnLabel);
|
||||
break;
|
||||
case Types.VARCHAR:
|
||||
value = super.resultSet_getString(chain, result, columnLabel);
|
||||
break;
|
||||
@@ -158,6 +161,27 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
return decodeObject(result.getStatementProxy().getConnectionProxy(), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel, Class<T> type) throws SQLException {
|
||||
ResultSet rawResultSet = result.getResultSetRaw();
|
||||
ResultSetMetaData metadata = rawResultSet.getMetaData();
|
||||
int columnIndex = rawResultSet.findColumn(columnLabel);
|
||||
int columnType = metadata.getColumnType(columnIndex);
|
||||
|
||||
Object value = null;
|
||||
switch (columnType) {
|
||||
case Types.CHAR:
|
||||
case Types.CLOB:
|
||||
case Types.LONGVARCHAR:
|
||||
case Types.VARCHAR:
|
||||
value = super.resultSet_getString(chain, result, columnLabel);
|
||||
break;
|
||||
default:
|
||||
value = super.resultSet_getObject(chain, result, columnLabel, type);
|
||||
}
|
||||
return (T) decodeObject(result.getStatementProxy().getConnectionProxy(), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel,
|
||||
java.util.Map<String, Class<?>> map) throws SQLException {
|
||||
|
||||
@@ -795,6 +795,21 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex, Class<T> type) throws SQLException {
|
||||
T obj = chain.resultSet_getObject(result, columnIndex, type);
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
clobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (ClobProxy) obj);
|
||||
} else if (obj instanceof Blob) {
|
||||
blobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (Blob) obj);
|
||||
} else if (obj instanceof String) {
|
||||
result.addReadStringLength(((String) obj).length());
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex,
|
||||
java.util.Map<String, Class<?>> map) throws SQLException {
|
||||
@@ -826,6 +841,21 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel, Class<T> type) throws SQLException {
|
||||
T obj = chain.resultSet_getObject(result, columnLabel, type);
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
clobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (ClobProxy) obj);
|
||||
} else if (obj instanceof Blob) {
|
||||
blobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (Blob) obj);
|
||||
} else if (obj instanceof String) {
|
||||
result.addReadStringLength(((String) obj).length());
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel,
|
||||
java.util.Map<String, Class<?>> map) throws SQLException {
|
||||
|
||||
@@ -42,7 +42,6 @@ import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
|
||||
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
@@ -176,6 +175,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|
||||
private static List<Filter> autoFilters = null;
|
||||
private boolean loadSpifilterSkip = false;
|
||||
private volatile DataSourceDisableException disableException = null;
|
||||
|
||||
protected static final AtomicLongFieldUpdater<DruidDataSource> recycleErrorCountUpdater
|
||||
= AtomicLongFieldUpdater.newUpdater(DruidDataSource.class, "recycleErrorCount");
|
||||
@@ -1507,6 +1507,11 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|
||||
if (!enable) {
|
||||
connectErrorCountUpdater.incrementAndGet(this);
|
||||
|
||||
if (disableException != null) {
|
||||
throw disableException;
|
||||
}
|
||||
|
||||
throw new DataSourceDisableException();
|
||||
}
|
||||
|
||||
@@ -2002,6 +2007,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
this.closed = true;
|
||||
this.closeTimeMillis = System.currentTimeMillis();
|
||||
|
||||
disableException = new DataSourceDisableException();
|
||||
|
||||
for (Filter filter : filters) {
|
||||
filter.destroy();
|
||||
}
|
||||
@@ -2092,6 +2099,10 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|
||||
if (!enable) {
|
||||
connectErrorCountUpdater.incrementAndGet(this);
|
||||
if (disableException != null) {
|
||||
throw disableException;
|
||||
}
|
||||
|
||||
throw new DataSourceDisableException();
|
||||
}
|
||||
}
|
||||
@@ -2139,6 +2150,11 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|
||||
if (!enable) {
|
||||
connectErrorCountUpdater.incrementAndGet(this);
|
||||
|
||||
if (disableException != null) {
|
||||
throw disableException;
|
||||
}
|
||||
|
||||
throw new DataSourceDisableException();
|
||||
}
|
||||
} catch (InterruptedException ie) {
|
||||
@@ -2428,18 +2444,14 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
|
||||
private int errorCount = 0;
|
||||
private boolean initTask = false;
|
||||
private long taskId;
|
||||
private final long taskId;
|
||||
|
||||
public CreateConnectionTask() {
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
taskId = createTaskIdSeedUpdater.getAndIncrement(DruidDataSource.this);
|
||||
}
|
||||
|
||||
public CreateConnectionTask(boolean initTask) {
|
||||
init();
|
||||
taskId = createTaskIdSeedUpdater.getAndIncrement(DruidDataSource.this);
|
||||
this.initTask = initTask;
|
||||
}
|
||||
|
||||
@@ -2527,7 +2539,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
return;
|
||||
}
|
||||
|
||||
this.init();
|
||||
createSchedulerFuture = createScheduler.schedule(this, timeBetweenConnectErrorMillis, TimeUnit.MILLISECONDS);
|
||||
return;
|
||||
}
|
||||
@@ -2568,7 +2579,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
return;
|
||||
}
|
||||
|
||||
this.init();
|
||||
createSchedulerFuture = createScheduler.schedule(this, timeBetweenConnectErrorMillis, TimeUnit.MILLISECONDS);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1764,10 +1764,10 @@ public final class DruidPooledResultSet extends PoolableWrapper implements Resul
|
||||
}
|
||||
|
||||
public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
return rs.getObject(columnIndex, type);
|
||||
}
|
||||
|
||||
public <T> T getObject(String columnLabel, Class<T> type) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
return rs.getObject(columnLabel, type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1549,7 +1549,10 @@ public class ResultSetProxyImpl extends WrapperProxyImpl implements ResultSetPro
|
||||
}
|
||||
|
||||
public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
FilterChainImpl chain = createChain();
|
||||
Object value = chain.resultSet_getObject(this, columnIndex, type);
|
||||
recycleFilterChain(chain);
|
||||
return (T) value;
|
||||
}
|
||||
|
||||
public <T> T getObject(String columnLabel, Class<T> type) throws SQLException {
|
||||
|
||||
@@ -991,6 +991,11 @@ public class WallFilter extends FilterAdapter implements WallFilterMBean {
|
||||
return chain.resultSet_getObject(resultSet, resultSet.getPhysicalColumn(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T resultSet_getObject(FilterChain chain, ResultSetProxy resultSet, int columnIndex, Class<T> type) throws SQLException {
|
||||
return chain.resultSet_getObject(resultSet, resultSet.getPhysicalColumn(columnIndex), type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resultSet_getObject(FilterChain chain, ResultSetProxy resultSet, int columnIndex,
|
||||
java.util.Map<String, Class<?>> map) throws SQLException {
|
||||
|
||||
Reference in New Issue
Block a user