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 di...@apache.org on 2001/10/29 23:11:25 UTC
cvs commit: jakarta-slide/src/stores/slidestore/oracle OracleContentStore.java
dirkv 01/10/29 14:11:25
Added: src/stores/slidestore/oracle OracleContentStore.java
Log:
Oracle compliant implementation of ContentStore usins oracle blob methods
(special thanks to Ting Ning for testing/debugging the standard implementation)
Revision Changes Path
1.1 jakarta-slide/src/stores/slidestore/oracle/OracleContentStore.java
Index: OracleContentStore.java
===================================================================
/*
* $Header: /home/cvs/jakarta-slide/src/stores/slidestore/oracle/OracleContentStore.java,v 1.1 2001/10/29 22:11:25 dirkv Exp $
* $Revision: 1.1 $
* $Date: 2001/10/29 22:11:25 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package slidestore.oracle;
import java.lang.reflect.Constructor;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.Vector;
import java.util.Date;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.File;
import java.sql.*;
import javax.transaction.xa.XAException;
import javax.transaction.xa.Xid;
import org.apache.slide.common.*;
import org.apache.slide.store.*;
import org.apache.slide.structure.*;
import org.apache.slide.security.*;
import org.apache.slide.content.*;
import org.apache.slide.util.logger.Logger;
import slidestore.reference.JDBCContentStore;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
/**
* Oracle compliant implementation of ContentStore.
*
* @author Dirk Verbeeck
* @version $Revision: 1.1 $
*/
public class OracleContentStore extends JDBCContentStore
implements ContentStore {
// --------------------------------------------------- ContentStore Methods
/**
* Store a revision.
*/
protected void storeContent(String revisionUri, String revisionNumber,
NodeRevisionDescriptor revisionDescriptor,
NodeRevisionContent revisionContent)
throws IOException, SQLException {
PreparedStatement insertStatement = connection.prepareStatement
("insert into revisioncontent (uri, xnumber, content) values(?,?, ?)");
insertStatement.setString(1, revisionUri);
insertStatement.setString(2, revisionNumber);
byte[] ba = " ".getBytes();
int len = ba.length;
ByteArrayInputStream bis = new ByteArrayInputStream(ba);
insertStatement.setBinaryStream(3, bis, len);
insertStatement.executeUpdate();
insertStatement.close();
bis.close();
InputStream is = revisionContent.streamContent();
if (null != is)
{
// Need to update the blob for Oracle to put the blob into databse
PreparedStatement selForUpdateStatement = connection.prepareStatement
("select content from revisioncontent where uri = ? and xnumber= ? for update");
selForUpdateStatement.setString(1, revisionUri);
selForUpdateStatement.setString(2, revisionNumber);
ResultSet rs = selForUpdateStatement.executeQuery();
int contentLength = -1;
OutputStream os = null;
if (rs.next())
{
// The following line should work but doesn't
// We are forced to use the oracle blob methods.
// This one doesn't work:
// OutputStream os = (rs.getBlob(1)).setBinaryStream(0);
// Working version:
// OutputStream os = ((oracle.sql.BLOB) rs.getBlob(1)).getBinaryOutputStream();
// Use reflection to remove compile time dependency on oracle driver
try {
Object blob = rs.getBlob(1);
Class[] paramsClasses = new Class[0];
Method getBinaryOutputStreamMethod = blob.getClass().getMethod
("getBinaryOutputStream", paramsClasses);
Object[] params = new Object[0];
os = (OutputStream) getBinaryOutputStreamMethod.invoke(blob, params);
}
catch (NoSuchMethodException ex) {
getLogger().log("Oracle driver error",LOG_CHANNEL,Logger.ERROR);
getLogger().log(ex.toString(),LOG_CHANNEL,Logger.ERROR);
}
catch (IllegalAccessException ex) {
getLogger().log("Oracle driver error",LOG_CHANNEL,Logger.ERROR);
getLogger().log(ex.toString(),LOG_CHANNEL,Logger.ERROR);
}
catch (InvocationTargetException ex) {
getLogger().log("Oracle driver error",LOG_CHANNEL,Logger.ERROR);
getLogger().log(ex.toString(),LOG_CHANNEL,Logger.ERROR);
}
}
if (os!=null) {
byte[] buf = new byte[BUFFER_SIZE];
int num = -1;
while ((num = is.read(buf)) > 0)
{
os.write(buf, 0, num);
contentLength = contentLength + num;
}
os.close();
}
rs.close();
selForUpdateStatement.close();
revisionDescriptor.setContentLength(contentLength);
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>