[teiid-commits] teiid SVN: r2793 - in branches/7.1.x/client/src: main/java/org/teiid/netty/handler/codec/serialization and 2 other directories.
teiid-commits at lists.jboss.org
teiid-commits at lists.jboss.org
Thu Dec 23 12:46:42 EST 2010
Author: rareddy
Date: 2010-12-23 12:46:42 -0500 (Thu, 23 Dec 2010)
New Revision: 2793
Modified:
branches/7.1.x/client/src/main/java/org/teiid/jdbc/PreparedStatementImpl.java
branches/7.1.x/client/src/main/java/org/teiid/netty/handler/codec/serialization/CompactObjectOutputStream.java
branches/7.1.x/client/src/test/java/org/teiid/jdbc/TestPreparedStatement.java
branches/7.1.x/client/src/test/java/org/teiid/netty/handler/codec/serialization/TestObjectDecoderInputStream.java
Log:
TEIID-1407: Fixing the NotSeializable exception in the case of inserting lobs
Modified: branches/7.1.x/client/src/main/java/org/teiid/jdbc/PreparedStatementImpl.java
===================================================================
--- branches/7.1.x/client/src/main/java/org/teiid/jdbc/PreparedStatementImpl.java 2010-12-23 01:51:14 UTC (rev 2792)
+++ branches/7.1.x/client/src/main/java/org/teiid/jdbc/PreparedStatementImpl.java 2010-12-23 17:46:42 UTC (rev 2793)
@@ -300,6 +300,10 @@
* @throws SQLException if parameter type/datatype do not match
*/
public void setBlob (int parameterIndex, Blob x) throws SQLException {
+ if (x == null) {
+ this.setObject(parameterIndex, null);
+ return;
+ }
setObject(parameterIndex, x);
}
@@ -345,6 +349,10 @@
* @throws SQLException if parameter type/datatype do not match.
*/
public void setClob (int parameterIndex, Clob x) throws SQLException {
+ if (x == null) {
+ this.setObject(parameterIndex, null);
+ return;
+ }
setObject(parameterIndex, x);
}
@@ -697,6 +705,10 @@
public void setBlob(int parameterIndex, final InputStream inputStream)
throws SQLException {
+ if (inputStream == null) {
+ this.setObject(parameterIndex, null);
+ return;
+ }
this.setObject(parameterIndex, new BlobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
@@ -720,6 +732,10 @@
}
public void setClob(int parameterIndex, final Reader reader) throws SQLException {
+ if (reader == null) {
+ this.setObject(parameterIndex, null);
+ return;
+ }
this.setObject(parameterIndex, new ClobImpl(new InputStreamFactory() {
@Override
Modified: branches/7.1.x/client/src/main/java/org/teiid/netty/handler/codec/serialization/CompactObjectOutputStream.java
===================================================================
--- branches/7.1.x/client/src/main/java/org/teiid/netty/handler/codec/serialization/CompactObjectOutputStream.java 2010-12-23 01:51:14 UTC (rev 2792)
+++ branches/7.1.x/client/src/main/java/org/teiid/netty/handler/codec/serialization/CompactObjectOutputStream.java 2010-12-23 17:46:42 UTC (rev 2793)
@@ -65,6 +65,7 @@
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.TeiidException;
import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.types.BaseLob;
import org.teiid.core.types.BlobImpl;
import org.teiid.core.types.BlobType;
import org.teiid.core.types.ClobImpl;
@@ -182,40 +183,63 @@
@Override
protected Object replaceObject(Object obj) throws IOException {
- if (obj instanceof Serializable) {
+ if (obj instanceof BaseLob) {
+ try {
+ if (obj instanceof SQLXMLImpl) {
+ streams.add(((SQLXMLImpl)obj).getBinaryStream());
+ StreamFactoryReference sfr = new SQLXMLImpl();
+ references.add(sfr);
+ return sfr;
+ } else if (obj instanceof ClobImpl) {
+ streams.add(new ReaderInputStream(((ClobImpl)obj).getCharacterStream(), Charset.forName(Streamable.ENCODING)));
+ StreamFactoryReference sfr = new ClobImpl();
+ references.add(sfr);
+ return sfr;
+ } else if (obj instanceof BlobImpl) {
+ streams.add(((Blob)obj).getBinaryStream());
+ StreamFactoryReference sfr = new BlobImpl();
+ references.add(sfr);
+ return sfr;
+ }
+ } catch (SQLException e) {
+ throw new IOException(e);
+ }
+ }
+ else if (obj instanceof Serializable) {
return obj;
}
- try {
- if (obj instanceof Reader) {
- streams.add(new ReaderInputStream((Reader)obj, Charset.forName(Streamable.ENCODING)));
- StreamFactoryReference sfr = new SerializableReader();
- references.add(sfr);
- return sfr;
- } else if (obj instanceof InputStream) {
- streams.add((InputStream)obj);
- StreamFactoryReference sfr = new SerializableInputStream();
- references.add(sfr);
- return sfr;
- } else if (obj instanceof SQLXML) {
- streams.add(((SQLXML)obj).getBinaryStream());
- StreamFactoryReference sfr = new SQLXMLImpl();
- references.add(sfr);
- return sfr;
- } else if (obj instanceof Clob) {
- //TODO: see if this is a ClobImpl and grab the underlying stream
- streams.add(new ReaderInputStream(((Clob)obj).getCharacterStream(), Charset.forName(Streamable.ENCODING)));
- StreamFactoryReference sfr = new ClobImpl();
- references.add(sfr);
- return sfr;
- } else if (obj instanceof Blob) {
- streams.add(((Blob)obj).getBinaryStream());
- StreamFactoryReference sfr = new BlobImpl();
- references.add(sfr);
- return sfr;
- }
- } catch (SQLException e) {
- throw new IOException(e);
- }
+ else {
+ try {
+ if (obj instanceof Reader) {
+ streams.add(new ReaderInputStream((Reader)obj, Charset.forName(Streamable.ENCODING)));
+ StreamFactoryReference sfr = new SerializableReader();
+ references.add(sfr);
+ return sfr;
+ } else if (obj instanceof InputStream) {
+ streams.add((InputStream)obj);
+ StreamFactoryReference sfr = new SerializableInputStream();
+ references.add(sfr);
+ return sfr;
+ } else if (obj instanceof SQLXML) {
+ streams.add(((SQLXML)obj).getBinaryStream());
+ StreamFactoryReference sfr = new SQLXMLImpl();
+ references.add(sfr);
+ return sfr;
+ } else if (obj instanceof Clob) {
+ streams.add(new ReaderInputStream(((Clob)obj).getCharacterStream(), Charset.forName(Streamable.ENCODING)));
+ StreamFactoryReference sfr = new ClobImpl();
+ references.add(sfr);
+ return sfr;
+ } else if (obj instanceof Blob) {
+ streams.add(((Blob)obj).getBinaryStream());
+ StreamFactoryReference sfr = new BlobImpl();
+ references.add(sfr);
+ return sfr;
+ }
+ } catch (SQLException e) {
+ throw new IOException(e);
+ }
+ }
return super.replaceObject(obj);
}
Modified: branches/7.1.x/client/src/test/java/org/teiid/jdbc/TestPreparedStatement.java
===================================================================
--- branches/7.1.x/client/src/test/java/org/teiid/jdbc/TestPreparedStatement.java 2010-12-23 01:51:14 UTC (rev 2792)
+++ branches/7.1.x/client/src/test/java/org/teiid/jdbc/TestPreparedStatement.java 2010-12-23 17:46:42 UTC (rev 2793)
@@ -24,6 +24,7 @@
import static org.junit.Assert.*;
+import java.sql.Blob;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
@@ -210,6 +211,11 @@
assertEquals("MMPreparedStatement.ParameterValuesList does not match", expectedParameterValues, statement.getParameterValuesList()); //$NON-NLS-1$
}
+ @Test public void testSetBlob() throws Exception {
+ PreparedStatementImpl stmt = getMMPreparedStatement("delete from table where col=?"); //$NON-NLS-1$
+ stmt.setBlob(1, (Blob)null);
+ }
+
/**
* Test the <code>addBatch()</code> method of <code>MMPreparedStatement</code>
* using a batch with an empty parameter value list. The test will verify
Modified: branches/7.1.x/client/src/test/java/org/teiid/netty/handler/codec/serialization/TestObjectDecoderInputStream.java
===================================================================
--- branches/7.1.x/client/src/test/java/org/teiid/netty/handler/codec/serialization/TestObjectDecoderInputStream.java 2010-12-23 01:51:14 UTC (rev 2792)
+++ branches/7.1.x/client/src/test/java/org/teiid/netty/handler/codec/serialization/TestObjectDecoderInputStream.java 2010-12-23 17:46:42 UTC (rev 2793)
@@ -28,11 +28,17 @@
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.StringReader;
import java.net.SocketTimeoutException;
+import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
+import org.teiid.core.types.ClobImpl;
+import org.teiid.core.types.InputStreamFactory;
+import org.teiid.core.types.Streamable;
+import org.teiid.core.util.ReaderInputStream;
import static org.junit.Assert.*;
@@ -76,4 +82,23 @@
assertEquals(testValue, ObjectDecoderInputStream.getIntFromBytes(baos.toByteArray()));
}
+
+ @Test public void testReplaceObject() throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectEncoderOutputStream out = new ObjectEncoderOutputStream(new DataOutputStream(baos), 512);
+
+ ClobImpl clob = new ClobImpl(new InputStreamFactory() {
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return new ReaderInputStream(new StringReader("Clob contents"), Charset.forName(Streamable.ENCODING)); //$NON-NLS-1$
+ }
+
+ }, -1);
+
+ out.writeObject(clob);
+
+ ObjectDecoderInputStream in = new ObjectDecoderInputStream(new DataInputStream(new ByteArrayInputStream(baos.toByteArray())), Thread.currentThread().getContextClassLoader(), 1024);
+ Object result = in.readObject();
+ assertTrue(result instanceof ClobImpl);
+ }
}
More information about the teiid-commits
mailing list