Re: Datasources in Shark

David Simón <[email protected]> Tue, 20 Sep 2005 12:00:48 +0200
Newsgroups gmane.comp.java.enhydra.shark
Message-ID <[email protected]>
Hello,

The insertBlob method is executed and it is working. We only faced a
problem since we are using db pool connection and in this case it fails
if the jar from Oracle is both in the WEB-INF/lib directory and in the
specific Application Server directory. The solution is to NOT have the
jar in the WEB-INF/lib directory, only in the App Server directory,
otherwise the code fails (some kind of code execution confussion I
guess).

Regarding the code, the only difference to your code is that we have
changed this line:

blobOut = ((OracleThinBlob)blob).getBinaryOutputStream(); 

into this one:

blobOut =((BLOB)blob).getBinaryOutputStream();           

BTW, our Oracle version is 9.2.0.

Kind regards.

David.

We have tested

> Hello David,
> 
> We tried using oracle.sql.BLOB also and it works fine for reading data. As I can remember there was some incompatibility at writing data (sorry, I cannot give more details as it was long ago). And as we were forced to use weblogic.jdbc.vendor.oracle.OracleThinBlob for writing (there is no matter which object you will use for reading - dependancy is already introduced) we preferred the weblogic.jdbc.vendor.oracle.OracleThinBlob for reading too.
> 
> It is possible that we missed something, so please test and publish your code. Please note that using version 1.1-2 optimizations, you might never write a BLOB (you can choose "non-standard" mode for writing Shark data to the database, which avoids using of BLOBS when possible), so double-check that your tests pass the insertBlob() method.
> 
> Best Regards,
> Monique
> 
> David Simón wrote:
> > Hello,
> > 
> > First of all, I would like to say that finally we have migrated to Shark 
> > 1.1-2 last week. Now we are testing it and although we have had some 
> > problems it seems is working better, at least we can use db pools from 
> > our Application Server :-)
> > 
> > One of the problems was the one of the message below, but thanks to 
> > Monique code it was solved (thank you). However we have made a little 
> > change, we use oracle.sql.BLOB instead of 
> > weblogic.jdbc.vendor.oracle.OracleThinBlob and it works fine too. We 
> > think this may be interesting for you because it is not Application 
> > Server dependant.
> > 
> > Another problem is that the method getAssignment of the ExecutionManager 
> > is throwing a "Null pointer exception" instead of returnin a null when 
> > the user has not assigned the activity we are asking for. The process  
> > id, the activity id and the resource passed to the method are correct 
> > and it works if the user is assigned to the activity, but according to 
> > the documentation if the user is not assigned it should return a null. 
> > Does anyone know why is this happening?
> > 
> > Thank you. We will keep on testing.
> > 
> > Best regards.
> > 
> > David
> > 
> >> 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 <http://forum.java.sun.com/thread.jspa?threadID=492989&messageID=2319777>
> >> >
> >> >
> >> > regards
> >>
> >>
> >> plain text document adjunto (OracleDriverDependencies.java)
> >>
> >> 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() );
> >>   }
> >> }
> >> plain text document adjunto (message-footer.txt)
> >>
> >> --
> >> You receive this message as a subscriber of the [email protected] <mailto:[email protected]> mailing list.
> >> To unsubscribe: mailto:[email protected] <mailto:[email protected]>
> >> For general help: mailto:[email protected] <mailto:[email protected]>?subject=help
> >> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
> 
> 
> plain text document adjunto (message-footer.txt)
> 
> --
> 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
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