support JDBC 4.1

This commit is contained in:
高铁
2019-07-14 13:21:15 +08:00
parent 6368449a1d
commit 39ac64c32e
8 changed files with 151 additions and 19 deletions
@@ -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 {
@@ -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 {