Re: Datasources in Shark
Monique Maker <[email protected]>
| Newsgroups | gmane.comp.java.enhydra.shark |
|---|---|
| Message-ID | <[email protected]> |
Hello Vladimir,
We investigate the problem and our solution was to change
com.lutris.appserver.server.sql.oracle.OracleDriverDependencies.java
from dods-6.5-1. As it might help someone else, here is our code (I am
not sure the list accepts attachments, but just in case I will attach
the file too):
-----------------------------------------------------------------------
package com.lutris.appserver.server.sql.oracle;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Blob;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.enhydra.dods.DriverDependencies;
import weblogic.jdbc.vendor.oracle.OracleThinBlob;
import com.lutris.appserver.server.sql.DBConnection;
import com.lutris.dods.builder.generator.query.RDBColumn;
/**
* This implementation refects the specifics of Oracle DB connections
* handled in BEA WebLogic 8.1 SP2.
*/
public class OracleDriverDependencies implements DriverDependencies {
private static final int BUFFER_LENGTH = 2048;
public boolean isBlobAccessSpecial() {
return true;
}
public void insertBlob(DBConnection conn, byte[] cont, RDBColumn
primary, RDBColumn column, String handle) throws SQLException {
PreparedStatement update;
String sqlStatement;
ResultSet rs;
Blob blob;
OutputStream blobOut;
InputStream dataIn;
byte[] buffer = new byte[ BUFFER_LENGTH ];
int length;
if ( cont != null ) {
sqlStatement = "select " + column.getColumnName() + " from " +
column.getTableName()
+ " where " + primary.getColumnName() + " = ? "
+ " FOR UPDATE";
update = conn.getConnection().prepareStatement( sqlStatement );
try {
update.setString( 1, handle );
rs = update.executeQuery();
try {
rs.next();
blob = rs.getBlob( 1 );
// blob.setBytes( 1, cont ); // really sorry, this feature is not
supported
dataIn = new ByteArrayInputStream( cont );
try {
blobOut =
((OracleThinBlob)blob).getBinaryOutputStream();
try {
while ( ( length = dataIn.read( buffer, 0, buffer.length )
) != -1 ) {
blobOut.write(buffer, 0, length);
}
} finally {
blobOut.close();
}
} finally {
dataIn.close();
}
} catch (IOException ex) { // the blob was not written properly
throw new SQLException( "BLOB writing failed for statement: "
+ sqlStatement );
} finally {
rs.close();
}
} finally {
update.close();
}
}
}
public byte[] readBlob(ResultSet rs, String colName) throws SQLException {
// BLOB blob = ((OracleResultSet)rs).getBLOB(colName);
Blob blob = rs.getBlob( colName ); // VK, 2005-07-12: Use the
standard java.sql.ResultSet
if ( null == blob )
return null;
return blob.getBytes( 1L, (int) blob.length() );
}
}
-----------------------------------------------------------------------
Note that you will need the weblojc.jar in your classpath when building
the DODS as we use the WebLogic specific class OracleThinBlob. We do
not know if these changes are needed for BEA WebLogic 9.x.
Note that Shark rebuild is not required for this change to take effect.
The only thing you need to do is to copy
<dods-6.5-1_project_dir>\output\lib\dbvendors\oracle.jar
to an appropriate place (we copy it directly in our project directory,
as we are using Shark as library).
Best Regards,
Monique
Vladimir Puskas wrote:
> Hello Monique
>
> you wrote:
>
>> Oops!
>> Sorry, it was our fault: Somehow the dods-runtime.jar file from
>> version 1.0.1 fall among the files from 1.1-2. When we removed it
>> everything went well with the "standard" Oracle connection.
>> Unfortunately we are still not able to make Shark to use datasuorce.
>> Run fails with the following error:
>>
>> SharkEngineManager -> Shark engine is being initialized ...
>> ...
>> 2005-07-12 08:57:52,601: SharkUtilities -> synchronizing XPDL cache
>> version:1118762756000
>> 2005-07-12 08:57:52,804: Problem while initializing caches !!!
>> java.lang.ClassCastException
>> at
>> com.lutris.appserver.server.sql.oracle.OracleDriverDependencies.readBlob(OracleDriverDependencies.java:69)
>>
>> at
>> org.enhydra.shark.repositorypersistence.data.XPDLDataDO.initFromResultSet(XPDLDataDO.java:3297)
>>
>> Has anyone met similar problem?
>
>
> To be honest we haven't tried this combination (oracle-data source).
>
> Because Oracle has peculiar way of reading and storing BLOBs
> OracleDriverDependences was introduced - in line 69 it directly casts
> java.sql.ResultSet into oracle.jdbc.OracleResultSet to perform BLOB
> extraction... It's now obvious ResultSet coming form data-source doesn't
> fit this. With Enhydra/Tomcat it is
> org.apache.tomcat.dbcp.dbcp.DelegatingResultSet and AFAICS you're
> using WebLogic...
>
> Thread on [1] might be helpful, but I doubt we can provide general
> enough solution, due to proposed casting to Commons DBPC classes.
>
> [1]
> http://forum.java.sun.com/thread.jspa?threadID=492989&messageID=2319777
>
>
> regards
OracleDriverDependencies.java
(text/plain, 2.8 KB)
package com.lutris.appserver.server.sql.oracle;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Blob;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.enhydra.dods.DriverDependencies;
import weblogic.jdbc.vendor.oracle.OracleThinBlob;
import com.lutris.appserver.server.sql.DBConnection;
import com.lutris.dods.builder.generator.query.RDBColumn;
/**
* This implementation refects the specifics of Oracle DB connections
* handled in BEA WebLogic 8.1 SP2. Updated by i:FAO
*/
public class OracleDriverDependencies implements DriverDependencies {
private static final int BUFFER_LENGTH = 2048;
public boolean isBlobAccessSpecial() {
return true;
}
public void insertBlob(DBConnection conn, byte[] cont, RDBColumn primary, RDBColumn column, String handle) throws SQLException {
PreparedStatement update;
String sqlStatement;
ResultSet rs;
Blob blob;
OutputStream blobOut;
InputStream dataIn;
byte[] buffer = new byte[ BUFFER_LENGTH ];
int length;
if ( cont != null ) {
sqlStatement = "select " + column.getColumnName() + " from " + column.getTableName()
+ " where " + primary.getColumnName() + " = ? "
+ " FOR UPDATE";
update = conn.getConnection().prepareStatement( sqlStatement );
try {
update.setString( 1, handle );
rs = update.executeQuery();
try {
rs.next();
blob = rs.getBlob( 1 );
// blob.setBytes( 1, cont ); // really sorry, this feature is not supported
dataIn = new ByteArrayInputStream( cont );
try {
blobOut = ((OracleThinBlob)blob).getBinaryOutputStream();
try {
while ( ( length = dataIn.read( buffer, 0, buffer.length ) ) != -1 ) {
blobOut.write(buffer, 0, length);
}
} finally {
blobOut.close();
}
} finally {
dataIn.close();
}
} catch (IOException ex) { // the blob was not written properly
throw new SQLException( "BLOB writing failed for statement: "+sqlStatement );
} finally {
rs.close();
}
} finally {
update.close();
}
}
}
public byte[] readBlob(ResultSet rs, String colName) throws SQLException {
// BLOB blob = ((OracleResultSet)rs).getBLOB(colName);
Blob blob = rs.getBlob( colName ); // VK, 2005-07-12: Use the standard java.sql.ResultSet
if ( null == blob )
return null;
return blob.getBytes( 1L, (int) blob.length() );
}
}
message-footer.txt
(text/plain, 271 B)
-- You receive this message as a subscriber of the [email protected] mailing list. To unsubscribe: mailto:[email protected] For general help: mailto:[email protected]?subject=help ObjectWeb mailing lists service home page: http://www.objectweb.org/wws