From 978519c05408dc2ead6053280985faf673885228 Mon Sep 17 00:00:00 2001 From: wenshao Date: Fri, 13 May 2011 14:42:52 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Clob=E5=92=8CNClob=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.alibabatech.com/svn/druid/trunk@60 b9813039-fb51-4c41-a8b9-e21c2acb5095 --- .../alibaba/druid/filter/FilterChainImpl.java | 68 +++++++++++++++---- .../druid/proxy/jdbc/ClobProxyImpl.java | 6 +- .../alibaba/druid/proxy/jdbc/NClobProxy.java | 7 ++ .../druid/proxy/jdbc/NClobProxyImpl.java | 25 +++++++ 4 files changed, 89 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/alibaba/druid/proxy/jdbc/NClobProxy.java create mode 100644 src/main/java/com/alibaba/druid/proxy/jdbc/NClobProxyImpl.java diff --git a/src/main/java/com/alibaba/druid/filter/FilterChainImpl.java b/src/main/java/com/alibaba/druid/filter/FilterChainImpl.java index 493ce8365a..440233ce66 100644 --- a/src/main/java/com/alibaba/druid/filter/FilterChainImpl.java +++ b/src/main/java/com/alibaba/druid/filter/FilterChainImpl.java @@ -52,6 +52,8 @@ import com.alibaba.druid.proxy.jdbc.ClobProxyImpl; import com.alibaba.druid.proxy.jdbc.ConnectionProxy; import com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl; import com.alibaba.druid.proxy.jdbc.DataSourceProxy; +import com.alibaba.druid.proxy.jdbc.NClobProxy; +import com.alibaba.druid.proxy.jdbc.NClobProxyImpl; import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy; import com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl; import com.alibaba.druid.proxy.jdbc.ResultSetProxy; @@ -171,11 +173,11 @@ public class FilterChainImpl implements FilterChain { } Clob clob = connection.getConnectionRaw().createClob(); - + if (clob == null) { return null; } - + return wrap(connection, clob); } @@ -185,7 +187,13 @@ public class FilterChainImpl implements FilterChain { return nextFilter().connection_createNClob(this, connection); } - return connection.getConnectionRaw().createNClob(); + NClob nclob = connection.getConnectionRaw().createNClob(); + + if (nclob == null) { + return null; + } + + return wrap(connection, nclob); } @Override @@ -1623,7 +1631,7 @@ public class FilterChainImpl implements FilterChain { } Clob clob = resultSet.getResultSetRaw().getClob(columnIndex); - + if (clob == null) { return null; } @@ -1674,11 +1682,11 @@ public class FilterChainImpl implements FilterChain { } Clob clob = resultSet.getResultSetRaw().getClob(columnLabel); - + if (clob == null) { return null; } - + return wrap(resultSet.getStatementProxy().getConnectionProxy(), clob); } @@ -1923,7 +1931,14 @@ public class FilterChainImpl implements FilterChain { if (this.pos < filterSize) { return nextFilter().resultSet_getNClob(this, resultSet, columnIndex); } - return resultSet.getResultSetRaw().getNClob(columnIndex); + + NClob nclob = resultSet.getResultSetRaw().getNClob(columnIndex); + + if (nclob == null) { + return null; + } + + return wrap(resultSet.getStatementProxy().getConnectionProxy(), nclob); } @Override @@ -1931,7 +1946,14 @@ public class FilterChainImpl implements FilterChain { if (this.pos < filterSize) { return nextFilter().resultSet_getNClob(this, resultSet, columnLabel); } - return resultSet.getResultSetRaw().getNClob(columnLabel); + + NClob nclob = resultSet.getResultSetRaw().getNClob(columnLabel); + + if (nclob == null) { + return null; + } + + return wrap(resultSet.getStatementProxy().getConnectionProxy(), nclob); } @Override @@ -1939,6 +1961,7 @@ public class FilterChainImpl implements FilterChain { if (this.pos < filterSize) { return nextFilter().resultSet_getSQLXML(this, resultSet, columnIndex); } + return resultSet.getResultSetRaw().getSQLXML(columnIndex); } @@ -3352,11 +3375,11 @@ public class FilterChainImpl implements FilterChain { } Clob clob = statement.getRawCallableStatement().getClob(parameterIndex); - + if (clob == null) { return null; } - + return wrap(statement.getConnectionProxy(), clob); } @@ -3846,11 +3869,11 @@ public class FilterChainImpl implements FilterChain { } Clob clob = statement.getRawCallableStatement().getClob(parameterName); - + if (clob == null) { return null; } - + return wrap(statement.getConnectionProxy(), clob); } @@ -3989,7 +4012,14 @@ public class FilterChainImpl implements FilterChain { if (this.pos < filterSize) { return nextFilter().callableStatement_getNClob(this, statement, parameterIndex); } - return statement.getRawCallableStatement().getNClob(parameterIndex); + + NClob nclob = statement.getRawCallableStatement().getNClob(parameterIndex); + + if (nclob == null) { + return null; + } + + return wrap(statement.getConnectionProxy(), nclob); } @Override @@ -3997,7 +4027,14 @@ public class FilterChainImpl implements FilterChain { if (this.pos < filterSize) { return nextFilter().callableStatement_getNClob(this, statement, parameterName); } - return statement.getRawCallableStatement().getNClob(parameterName); + + NClob nclob = statement.getRawCallableStatement().getNClob(parameterName); + + if (nclob == null) { + return null; + } + + return wrap(statement.getConnectionProxy(), nclob); } @Override @@ -4335,7 +4372,10 @@ public class FilterChainImpl implements FilterChain { public ClobProxy wrap(ConnectionProxy connection, Clob clob) { return new ClobProxyImpl(dataSource, connection, clob); + } + public NClobProxy wrap(ConnectionProxy connection, NClob clob) { + return new NClobProxyImpl(dataSource, connection, clob); } private final AtomicLong connectionIdSeed = new AtomicLong(10000); diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/ClobProxyImpl.java b/src/main/java/com/alibaba/druid/proxy/jdbc/ClobProxyImpl.java index 6a73f0e105..ffb8c207e3 100644 --- a/src/main/java/com/alibaba/druid/proxy/jdbc/ClobProxyImpl.java +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/ClobProxyImpl.java @@ -30,10 +30,10 @@ import com.alibaba.druid.filter.FilterChainImpl; */ public class ClobProxyImpl implements ClobProxy { - private final Clob clob; - private final ConnectionProxy connection; + protected final Clob clob; + protected final ConnectionProxy connection; - private final DataSourceProxy dataSource; + protected final DataSourceProxy dataSource; public ClobProxyImpl(DataSourceProxy dataSource, ConnectionProxy connection, Clob clob){ this.dataSource = dataSource; diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/NClobProxy.java b/src/main/java/com/alibaba/druid/proxy/jdbc/NClobProxy.java new file mode 100644 index 0000000000..f10c977947 --- /dev/null +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/NClobProxy.java @@ -0,0 +1,7 @@ +package com.alibaba.druid.proxy.jdbc; + +import java.sql.NClob; + +public interface NClobProxy extends ClobProxy, NClob { + NClob getRawNClob(); +} diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/NClobProxyImpl.java b/src/main/java/com/alibaba/druid/proxy/jdbc/NClobProxyImpl.java new file mode 100644 index 0000000000..b6c8d98d59 --- /dev/null +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/NClobProxyImpl.java @@ -0,0 +1,25 @@ +package com.alibaba.druid.proxy.jdbc; + +import java.sql.NClob; + +import com.alibaba.druid.filter.FilterChain; +import com.alibaba.druid.filter.FilterChainImpl; + +public class NClobProxyImpl extends ClobProxyImpl implements NClobProxy { + + private final NClob nclob; + + public NClobProxyImpl(DataSourceProxy dataSource, ConnectionProxy connection, NClob clob){ + super(dataSource, connection, clob); + this.nclob = clob; + } + + public FilterChain createChain() { + return new FilterChainImpl(dataSource); + } + + @Override + public NClob getRawNClob() { + return nclob; + } +}