You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-user@jakarta.apache.org by Richard Emberson <re...@edgedynamics.com> on 2004/11/11 00:03:20 UTC

Re: SOLUTION - I also have trouble doing versionControl in Oracle...

This may not be the long term solution, but it works for both small
and large files.
My environment is: I am running Slide from a war file within an
ear file in JBoss.

The solution to oracle store problem was to modify the 
OracleRDBMSAdapter class file.

At the top of the file I added the following imports:


import java.io.*;
import org.apache.slide.common.Uri;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionContent;

I then copied the CommonRDBMSAdapter storeContent method to the
OracleRDBMSAdapter file and rewrote parts of it:

protected void storeContent(
     Connection connection, Uri uri,
     NodeRevisionDescriptor revisionDescriptor,
     NodeRevisionContent revisionContent) throws IOException, SQLException
{
     assureVersionInfo(connection, uri, revisionDescriptor);

     InputStream is = revisionContent.streamContent();
     if (is != null) {
         long blobLength = 0;
         File tempFile = null;

         if (bcompress) {
             getLogger().log("Compressing the data", LOG_CHANNEL,
Logger.DEBUG);
             StoreContentZip ziputil = new StoreContentZip();
             ziputil.Zip(is);
             is = ziputil.getInputStream();

             // fix RevisionDescriptor Content Length
             if (revisionDescriptor.getContentLength() == -1) {
 
revisionDescriptor.setContentLength(ziputil.getInitialContentLength());
             }

             blobLength = ziputil.getContentLength();
         } else {
             // fix RevisionDescriptor Content Length
             if (revisionDescriptor.getContentLength() == -1) {
                 try {
                     tempFile = File.createTempFile("content", null);
                     FileOutputStream fos = new FileOutputStream(tempFile);
                     try {
                         byte buffer[] = new byte[2048];
                         do {
                             int nChar = is.read(buffer);
                             if (nChar == -1) {
                                 break;
                             }
                             fos.write(buffer, 0, nChar);
                         } while (true);
                     } finally {
                         fos.close();
                     }
                     is.close();
                     is = new FileInputStream(tempFile);

                     revisionDescriptor.setContentLength(tempFile.length());

                 } catch (IOException ex) {
getLogger().log(ex.toString() + " during the calculation of the content
length.",
                         LOG_CHANNEL, Logger.ERROR);
                     throw ex;
                 }
             }

             blobLength = revisionDescriptor.getContentLength();
         }

         CallableStatement statement = null;
         try {
long versionID = getVersionID(connection, uri.toString(), 
revisionDescriptor);
/*
             statement = connection.prepareStatement(
                 "insert into VERSION_CONTENT (VERSION_ID, CONTENT) 
values (?,?)");
             statement.setLong(1, versionID);
             statement.setBinaryStream(2, is, (int) blobLength);
             statement.executeUpdate();
*/
             statement = connection.prepareCall(
                 "BEGIN "
                 + "insert into VERSION_CONTENT (VERSION_ID, CONTENT) "
                 + "values (?, empty_blob()) RETURN CONTENT into ?;"
                 + "END; "
                 );
             statement.setLong(1, versionID);
             statement.registerOutParameter(2, java.sql.Types.BLOB);

             statement.executeUpdate();

             // do these two lines using reflection
             // BLOB blob = (BLOB) statement.getBlob(2);
             // OutputStream os = blob.getBinaryOutputStream();

             Object bObj = statement.getBlob(2);
             Class bCls = bObj.getClass();
             OutputStream os = null;
             try {
                 java.lang.reflect.Method m =
                     bCls.getMethod("getBinaryOutputStream", new Class[] 
{});

                 os = (OutputStream)m.invoke(bObj, new Object[] {});
             } catch (Exception ex) {
                 ex.printStackTrace();
                 throw new IOException("Reflection error");
             }

             try {
                 byte buffer[] = new byte[2048];
                 do {
                     int nChar = is.read(buffer);
                     if (nChar == -1) {
                         break;
                     }
                     os.write(buffer, 0, nChar); 
                          } while (true);
             } finally {
                 os.flush();
                 os.close();
             }

             if (tempFile != null) {
                 is.close();
                 is = null;
                 tempFile.delete();
             }
         } finally {
             try {
                 close(statement);
             } finally {
                 if (is != null) {
                     // XXX some JDBC drivers seem to close the stream upon
                     // closing of
                     // the statement; if so this will raise an IOException
                     // silently ignore it...
                     try {
                         is.close();
                     } catch (IOException ioe) {
                         logger.log("Could not close stream", ioe,
LOG_CHANNEL, Logger.DEBUG);
                     }
                 }
             }
         }
     }
}


Two things to note:

First, I use a CallableStatement to return a Blob object.
Two, I use reflection to access the Blob's getBinaryOutputStream
method. The object that is returned from the line:

statement.getBlob(2);

Is actually an Oracle oracle.sql.BLOB object. Using reflection
allows all this to compile without needing any Oracle jars.
When you run it you've got to have Oracle jars or it will fail ...
of course you should not use the OracleRDBMSAdapter unless there
are Oracle jars around.

I would recommend bumping up the size of the copying arrays from
2048 to 4096 to speed things up a little.


RME
-- 
This email message is for the sole use of the intended recipient(s) and
may contain confidential information.  Any unauthorized review, use,
disclosure or distribution is prohibited.  If you are not the intended
recipient, please contact the sender by reply email and destroy all
copies of the original message.

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org


RE: "PUT" error when using jdbc/Oracle

Posted by Nick Longinow <ni...@vanhooseassociates.com>.
Karan

What is your stack trace ?

Nick

-----Original Message-----
From: Karan Tyagi [mailto:karan.tyagi@towersperrin.com] 
Sent: Thursday, November 11, 2004 11:26 AM
To: Slide Users Mailing List
Subject: "PUT" error when using jdbc/Oracle

Hi All,

I am getting an Internal Server Error (500) , when I am trying to use the 
"PUT" command from the command line to upload a file.

Setup:

Slide 2.1 b2
WebLogic server 8.1
Oracle  9.2.0.4.0

Also,  auto-version-control is set to false.

Would appreciate any help on this.

Regards,
- Karan




NOTICE:  This communication may contain confidential, proprietary or 
legally privileged information. It is intended only for the person(s) to 
whom it is addressed.  If you are not an intended recipient, you may not 
use, read, retransmit, disseminate or take any action in reliance upon it. 
Please notify the sender that you have received it in error and 
immediately delete the entire communication, including any attachments. 
Towers Perrin does not encrypt and cannot ensure the confidentiality or 
integrity of external e-mail communications and, therefore, cannot be 
responsible for any unauthorized access, disclosure, use or tampering that 
may occur during transmission.  This communication is not intended to 
create or modify any obligation, contract or warranty of Towers Perrin, 
unless the firm clearly expresses such an intent.


---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org


"PUT" error when using jdbc/Oracle

Posted by Karan Tyagi <ka...@towersperrin.com>.
Hi All,

I am getting an Internal Server Error (500) , when I am trying to use the 
"PUT" command from the command line to upload a file.

Setup:

Slide 2.1 b2
WebLogic server 8.1
Oracle  9.2.0.4.0

Also,  auto-version-control is set to false.

Would appreciate any help on this.

Regards,
- Karan




NOTICE:  This communication may contain confidential, proprietary or 
legally privileged information. It is intended only for the person(s) to 
whom it is addressed.  If you are not an intended recipient, you may not 
use, read, retransmit, disseminate or take any action in reliance upon it. 
Please notify the sender that you have received it in error and 
immediately delete the entire communication, including any attachments. 
Towers Perrin does not encrypt and cannot ensure the confidentiality or 
integrity of external e-mail communications and, therefore, cannot be 
responsible for any unauthorized access, disclosure, use or tampering that 
may occur during transmission.  This communication is not intended to 
create or modify any obligation, contract or warranty of Towers Perrin, 
unless the firm clearly expresses such an intent.

Re: SOLUTION - I also have trouble doing versionControl in Oracle...

Posted by Richard Emberson <re...@edgedynamics.com>.
Just a small performance modification:

Since the type of the object returned by the statement

statement.getBlob(2);

is "oracle.sql.BLOB", one could have an instance variable

protected java.lang.reflect.Method blobGetOutStreamMethod;

and in OracleRDBMSAdapter's constructor

// only need to lookup the method once
Class bCls = Class.forName("oracle.sql.BLOB");
blobGetOutStreamMethod =
      bCls.getMethod("getBinaryOutputStream", new Class[] {});

Then in the storeContent method one would have:

...
Object bObj = statement.getBlob(2);
OutputStream os = null;
try {
   os = (OutputStream)m.invoke(bObj, new Object[] {});
} catch (Exception ex) {
....

which eliminates the getClass and method lookup calls.

Also, just to make sure resources get freed up:

change
         if (tempFile != null) {
             is.close();
             is = null;
             tempFile.delete();
         }
     } finally {

to
     } finally {
         if (tempFile != null) {
             try {
                 is.close();
             } catch (Exception ex) {
                 // ignore
             }
             is = null;
             if (! tempFile.delete()) {
               logger.log("Could not delete file \""
                 + tempFile.getAbsolutePath()
                 + "\"");
             }
         }




Richard



Davide Savazzi wrote:
> On Thursday 11 November 2004 00:03, Richard Emberson wrote:
> 
>>This may not be the long term solution, but it works for both small
>>and large files.
>>My environment is: I am running Slide from a war file within an
>>ear file in JBoss.
> 
> 
> Thanks for the patch! Tomorrow I'll test it in my environment and then commit 
> it :)
> 


-- 
This email message is for the sole use of the intended recipient(s) and
may contain confidential information.  Any unauthorized review, use,
disclosure or distribution is prohibited.  If you are not the intended
recipient, please contact the sender by reply email and destroy all
copies of the original message.

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org


RE: SOLUTION - I also have trouble doing versionControl in Oracle...

Posted by Nick Longinow <ni...@vanhooseassociates.com>.
Thanks Richard and Davide.

-----Original Message-----
From: Davide Savazzi [mailto:davide.savazzi@corefandango.net] 
Sent: Wednesday, November 10, 2004 7:00 PM
To: Slide Users Mailing List
Subject: Re: SOLUTION - I also have trouble doing versionControl in
Oracle...

On Thursday 11 November 2004 00:03, Richard Emberson wrote:
> This may not be the long term solution, but it works for both small
> and large files.
> My environment is: I am running Slide from a war file within an
> ear file in JBoss.

Thanks for the patch! Tomorrow I'll test it in my environment and then
commit 
it :)

-- 
Davide Savazzi

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org


Re: SOLUTION - I also have trouble doing versionControl in Oracle...

Posted by Davide Savazzi <da...@corefandango.net>.
On Thursday 11 November 2004 00:03, Richard Emberson wrote:
> This may not be the long term solution, but it works for both small
> and large files.
> My environment is: I am running Slide from a war file within an
> ear file in JBoss.

Thanks for the patch! Tomorrow I'll test it in my environment and then commit 
it :)

-- 
Davide Savazzi

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org