You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by bu...@apache.org on 2004/08/03 12:41:19 UTC
DO NOT REPLY [Bug 30445] New: -
RDBMS adapter for Weblogic/Oracle
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=30445>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=30445
RDBMS adapter for Weblogic/Oracle
Summary: RDBMS adapter for Weblogic/Oracle
Product: Slide
Version: Nightly
Platform: Other
OS/Version: All
Status: NEW
Severity: Normal
Priority: Other
Component: Stores
AssignedTo: slide-dev@jakarta.apache.org
ReportedBy: christophe.lombart@sword-technologies.com
The following RDBMS adapter is required for running Slide on Weblogic & Oracle
because Weblogic has to use the class
"weblogic.jdbc.vendor.oracle.OracleThinBlob" in order to save blob into an
Oracle DB.
---------------------------------------------------------------------------------
package org.apache.slide.store.impl.rdbms;
import org.apache.slide.common.*;
import org.apache.slide.content.*;
import org.apache.slide.store.impl.rdbms.CommonRDBMSAdapter;
import org.apache.slide.store.impl.rdbms.SequenceAdapter;
import org.apache.slide.util.logger.Logger;
import java.io.*;
import java.sql.*;
/**
*
* Slide Adapter for Weblogic/oracle.
*
*/
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);
}
}
// Private Methods
protected void storeContent(
Connection connection,
Uri uri,
NodeRevisionDescriptor revisionDescriptor,
NodeRevisionContent revisionContent)
throws IOException, SQLException
{
getLogger().log("storeContent: " + uri, Logger.DEBUG);
assureVersionInfo(connection, uri, revisionDescriptor);
long versionContentId = getVersionContentId(connection, uri,
revisionDescriptor);
insertEmptyContent(connection, versionContentId);
PreparedStatement statement = connection.prepareStatement(
"SELECT vc.CONTENT FROM VERSION_CONTENT vc WHERE vc.VERSION_ID = ?
FOR UPDATE");
try {
statement.setLong(1, versionContentId);
ResultSet res = statement.executeQuery();
try {
res.next();
Blob blob = res.getBlob(1);
InputStream in = revisionContent.streamContent();
OutputStream out = ((weblogic.jdbc.vendor.oracle.OracleThinBlob)
blob).getBinaryOutputStream();
if (bcompress) {
getLogger().log("Compressing the data", LOG_CHANNEL, 6);
StoreContentZip ziputil = new StoreContentZip();
ziputil.Zip(in);
in = ziputil.getInputStream();
}
try {
copy(in, out, ((weblogic.jdbc.vendor.oracle.OracleThinBlob)
blob).getBufferSize());
} finally {
close(out);
}
} finally {
close(res);
}
} finally {
close(statement);
}
}
private long getVersionContentId(Connection connection, Uri uri,
NodeRevisionDescriptor revisionDescriptor)
throws SQLException
{
PreparedStatement statement = connection.prepareStatement(
"select vh.VERSION_ID from VERSION_HISTORY vh, URI u " +
"where vh.URI_ID = u.URI_ID and u.URI_STRING = ? and vh.REVISION_NO"
+
getRevisionNumberAsWhereQueryFragement(revisionDescriptor.getRevisionNumber()));
try {
statement.setString(1, uri.toString());
ResultSet res = statement.executeQuery();
try {
res.next();
return res.getLong(1);
} finally {
close(res);
}
} finally {
close(statement);
}
}
private void insertEmptyContent(Connection connection, long versionContentId)
throws SQLException
{
PreparedStatement statement = connection.prepareStatement(
"insert into VERSION_CONTENT (VERSION_ID, CONTENT) values (?, EMPTY_BLOB())");
try {
statement.setLong(1, versionContentId);
statement.executeUpdate();
} finally {
close(statement);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org