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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
