I'm just wondering why the method storeContent has been changed in the
OracleRDBMSAdapater. Following the oracle doc, It is mandatory to use the class
oracle.sql.BLOB for writing blobs. Is it no necessary for the new Oracle version ?
Why this method has been changed ?
If standard JDBC calls are made on Oracle for Blob management it is possible to have
some SqlException.
Here is a new version of the OracleRDBMSAdapater which support the oracle.sql.BLOB.
Furthermore, if the Oracle is running with Weblogic, another class have to be used
:-(. You can find here an adapater for Oracle running with weblogic.
Let me know if it is better to add them in Jira.
Christophe
Index: OracleRDBMSAdapter.java
===================================================================
RCS file:
/home/cvspublic/jakarta-slide/src/stores/org/apache/slide/store/impl/rdbms/OracleRDBMSAdapter.java,v
retrieving revision 1.10
diff -u -r1.10 OracleRDBMSAdapter.java
--- OracleRDBMSAdapter.java 20 Aug 2004 17:50:38 -0000 1.10
+++ OracleRDBMSAdapter.java 7 Sep 2004 20:57:37 -0000
@@ -111,6 +111,123 @@
}
}
+ 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) {
+ 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());
+ }
+ } 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;
+ }
+ }
+ }
+
+ PreparedStatement 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)
revisionDescriptor.getContentLength());
+ byte[] ba = " ".getBytes();
+ int len = ba.length;
+ ByteArrayInputStream bis = new ByteArrayInputStream(ba);
+ statement.setBinaryStream(2, bis, len);
+ statement.executeUpdate();
+ close(statement);
+
+ if (is != null)
+ {
+ PreparedStatement selForUpdateStatement =
connection.prepareStatement("select content from VERSION_CONTENT where VERSION_id = ?
for update");
+ selForUpdateStatement.setLong(1, versionID);
+ ResultSet rs = selForUpdateStatement.executeQuery();
+ OutputStream os = null;
+ if (rs.next())
+ {
+ os = ((oracle.sql.BLOB)
rs.getBlob(1)).getBinaryOutputStream();
+ }
+ if (os != null)
+ {
+ byte[] buf = new byte[2048];
+ int num = -1;
+ while((num=is.read(buf)) > 0)
+ {
+ os.write(buf, 0, num);
+ }
+ os.close();
+ }
+ rs.close();
+ selForUpdateStatement.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);
+ }
+ }
+ }
+ }
+ }
+ }
+
}
Index: WeblogicOracleRDBMSAdapter.java
===================================================================
RCS file: WeblogicOracleRDBMSAdapter.java
diff -N WeblogicOracleRDBMSAdapter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ WeblogicOracleRDBMSAdapter.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,233 @@
+/*
+ * $Header: Exp $
+ * $Revision: 1.10 $
+ * $Date: 2004/08/20 17:50:38 $
+ *
+ * ====================================================================
+ *
+ * Copyright 1999-2003 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.slide.store.impl.rdbms;
+
+import org.apache.slide.common.*;
+import org.apache.slide.content.*;
+import org.apache.slide.util.logger.Logger;
+
+import java.io.*;
+import java.sql.*;
+
+
+/**
+ * Adapter for Oracle 10 on Weblogic
+ *
+ * @version $Revision: 1.10 $
+ */
+public class WeblogicOracleRDBMSAdapter extends CommonRDBMSAdapter implements
SequenceAdapter {
+
+ protected static String normalizeSequenceName(String sequenceName) {
+ return sequenceName.replace('-', '_').toUpperCase() + "_SEQ";
+ }
+
+ // Constructor
+
+ public WeblogicOracleRDBMSAdapter(Service service, Logger logger) {
+ super(service, logger);
+ }
+
+
+ // Public Methods
+
+ public boolean isSequenceSupported(Connection conn) {
+ return true;
+ }
+
+ public boolean createSequence(Connection conn, String sequenceName) throws
ServiceAccessException {
+
+ String query = "CREATE SEQUENCE \"" + normalizeSequenceName(sequenceName) +
"\"";
+
+ PreparedStatement statement = null;
+
+ try {
+ statement = conn.prepareStatement(query);
+ statement.executeUpdate();
+ return true;
+ } catch (SQLException e) {
+ throw new ServiceAccessException(service, e);
+ } finally {
+ close(statement);
+ }
+
+ }
+
+ public long nextSequenceValue(Connection conn, String sequenceName) throws
ServiceAccessException {
+ String selectQuery = "SELECT \"" +
normalizeSequenceName(sequenceName)+"\".nextval FROM DUAL";
+
+ PreparedStatement selectStatement = null;
+ ResultSet res = null;
+
+ try {
+ selectStatement = conn.prepareStatement(selectQuery);
+ res = selectStatement.executeQuery();
+ if (!res.next()) {
+ throw new ServiceAccessException(service, "Could not increment
sequence " + sequenceName);
+ }
+ long value = res.getLong(1);
+ return value;
+ } catch (SQLException e) {
+ throw new ServiceAccessException(service, e);
+ } finally {
+ close(selectStatement, res);
+ }
+ }
+
+ public boolean sequenceExists(Connection conn, String sequenceName) throws
ServiceAccessException {
+
+ PreparedStatement selectStatement = null;
+ ResultSet res = null;
+
+ try {
+ selectStatement =
+ conn.prepareStatement("ALTER SEQUENCE \"" +
normalizeSequenceName(sequenceName) + "\" INCREMENT BY 1");
+ res = selectStatement.executeQuery();
+ return true;
+ } catch (SQLException e) {
+ return false;
+ } finally {
+ close(selectStatement, res);
+ }
+ }
+
+ 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) {
+ 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());
+ }
+ } 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;
+ }
+ }
+ }
+
+ PreparedStatement 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)
revisionDescriptor.getContentLength());
+ byte[] ba = " ".getBytes();
+ int len = ba.length;
+ ByteArrayInputStream bis = new ByteArrayInputStream(ba);
+ statement.setBinaryStream(2, bis, len);
+ statement.executeUpdate();
+ close(statement);
+
+ if (is != null)
+ {
+ PreparedStatement selForUpdateStatement =
connection.prepareStatement("select content from VERSION_CONTENT where VERSION_id = ?
for update");
+ selForUpdateStatement.setLong(1, versionID);
+ ResultSet rs = selForUpdateStatement.executeQuery();
+ OutputStream os = null;
+ if (rs.next())
+ {
+ os = ((weblogic.jdbc.vendor.oracle.OracleThinBlob)
rs.getBlob(1)).getBinaryOutputStream();
+ }
+ if (os != null)
+ {
+ byte[] buf = new byte[2048];
+ int num = -1;
+ while((num=is.read(buf)) > 0)
+ {
+ os.write(buf, 0, num);
+ }
+ os.close();
+ }
+ rs.close();
+ selForUpdateStatement.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);
+ }
+ }
+ }
+ }
+ }
+ }
+
+}
+
+
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]