Re: Patch to Village (Oracle Clobs)
Daniel Rall <[email protected]> 30 Jun 2003 17:09:22 -0700
| Newsgroups | gmane.comp.db.village.devel |
|---|---|
| Message-ID | <[email protected]> |
FYI, John McNally committed some related code: From: [email protected] Subject: cvs commit: village/com/workingdogs/village Value.java To: [email protected] Cc: Date: Wed, 25 Jun 2003 08:28:06 -0700 (PDT) jmcnally 03/06/25 08:28:06 Modified: com/workingdogs/village Value.java Log: Patch to Value.java handling of Blobs. Submitted by Jetspeed developers. Revision Changes Path 1.19 +12 -3 village/com/workingdogs/village/Value.java Index: Value.java =================================================================== RCS file: /home/cvs/village/com/workingdogs/village/Value.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- Value.java 30 Jul 2002 23:20:51 -0000 1.18 +++ Value.java 25 Jun 2003 15:28:05 -0000 1.19 @@ -54,6 +54,7 @@ package com.workingdogs.village; import java.math.BigDecimal; +import java.sql.Blob; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -67,7 +68,7 @@ cross between a row and column and contains the information held there. @author Jon S. Stevens <A HREF="mailto:[email protected]">[email protected]</A> -@version $Revision: 1.18 $ +@version $Revision: 1.19 $ */ public class Value { @@ -149,10 +150,14 @@ case Types.LONGVARBINARY: case Types.VARBINARY: case Types.BINARY: - case Types.BLOB: valueObject = rs.getBytes (columnNumber); break; + case Types.BLOB: + Blob blob = rs.getBlob(columnNumber); + valueObject = blob.getBytes(1, (int) blob.length()); + break; + case Types.LONGVARCHAR: case Types.CHAR: case Types.VARCHAR: @@ -264,7 +269,11 @@ case Types.VARBINARY: case Types.BINARY: case Types.BLOB: - stmt.setBytes (stmtNumber, this.asBytes()); + // The following form is reported to work and be necessary for + // Oracle when the blob exceeds 4k. + byte[] value = this.asBytes(); + stmt.setBinaryStream(stmtNumber, + new java.io.ByteArrayInputStream(value), value.length); break; case Types.LONGVARCHAR: Scott Miller <[email protected]> writes: > Hi, > > I have been trying to use Torque as a database abstraction layer for an Oracle > database containing CLOBs. However, Village does not properly retrieve or set > CLOB values with Oracle. This is because Village uses the ResultSet.getString > method to read the CLOB value from the database and the > PreparedStatement.setString method to set the CLOB value. This approach will > work for many JDBC drivers because they support the handling of CLOBs as > Strings. However, the Oracle JDBC driver does not support this conversition. > I have modified Value.java to properly handle Oracle clobs. This file is > attached to this email. I am not sure of the proper avenue to submit a patch > for Village, so I am hoping that someone can advise me on the best course of > action. The rest of this email is devoted to a brief explanation of the code > change. > > Because Oracle's JDBC driver does not support the CLOB to String conversion, > you need to actually use the java.sql.Clob interface, which is implemented by > oracle.sql.CLOB. You can refer to the Clob object by the java.sql.Clob > interface during data retrieval, because there is no need to instantiate an > instance of the Class. The constructor of the Value class was modified to > handle retrieval by simply adding a Types.CLOB case to the switch statement. > > Unfortunately, you need to create an instance of the clob object when you want > to set the CLOB data, so you must refer to the oracle.sql.CLOB class. > However, in order to not rely on the Oracle JDBC driver at compile time, I > have writted the code to use reflection to create an instance of > oracle.sql.CLOB and set the value. This code is located in the > setPreparedStatementValue method of the Value class. > > Any advice on how to submit this update would be appreciated. > > Thanks, > > Scott > > > > > _______________________________________________ > Village-dev mailing list > [email protected] > http://share.whichever.com/mailman/listinfo/village-dev -- Daniel Rall