You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ma...@apache.org on 2003/07/29 18:54:15 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/broker/platforms Oracle9iLobHandler.java BlobWrapper.java ClobWrapper.java PlatformOracleImpl.java PlatformDefaultImpl.java PlatformOracle9iImpl.java Platform.java

mattbaird    2003/07/29 09:54:15

  Modified:    src/java/org/apache/ojb/broker/platforms
                        PlatformOracleImpl.java PlatformDefaultImpl.java
                        PlatformOracle9iImpl.java Platform.java
  Added:       src/java/org/apache/ojb/broker/platforms
                        Oracle9iLobHandler.java BlobWrapper.java
                        ClobWrapper.java
  Log:
  intermediate checkin for CLOB/BLOB support with Oracle drivers for objects bigger than 4K
  
  Revision  Changes    Path
  1.15      +2 -2      db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformOracleImpl.java
  
  Index: PlatformOracleImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformOracleImpl.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- PlatformOracleImpl.java	25 Jun 2003 21:50:30 -0000	1.14
  +++ PlatformOracleImpl.java	29 Jul 2003 16:54:12 -0000	1.15
  @@ -159,7 +159,7 @@
        *  Attempts to modify a private member in the Oracle thin driver's resultset
        *  to allow proper setting of large binary streams.
        */
  -    private void changePreparedStatementResultSetType(PreparedStatement ps)
  +    protected void changePreparedStatementResultSetType(PreparedStatement ps)
       {
           try
           {
  
  
  
  1.18      +7 -1      db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java
  
  Index: PlatformDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- PlatformDefaultImpl.java	16 Jul 2003 15:16:06 -0000	1.17
  +++ PlatformDefaultImpl.java	29 Jul 2003 16:54:12 -0000	1.18
  @@ -224,7 +224,7 @@
       {
           if (con == null)
           {
  -            log.error("Given connection was null, cannot prepare autoCommit state");
  +            log.error("Given m_connection was null, cannot prepare autoCommit state");
               return;
           }
           if (JdbcConnectionDescriptor.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE == jcd.getUseAutoCommit())
  @@ -331,4 +331,10 @@
           /*@todo implementation*/
           throw new UnsupportedOperationException("This feature is not supported by this implementation");
       }
  +
  +	public Object getClob(ResultSet rs, int jdbcType, String columnId) throws SQLException
  +	{
  +		java.sql.Clob aClob = rs.getClob(columnId);
  +		return (rs.wasNull() ? null : aClob.getSubString(1L, (int) aClob.length()));
  +	}
   }
  
  
  
  1.5       +142 -4    db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformOracle9iImpl.java
  
  Index: PlatformOracle9iImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformOracle9iImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PlatformOracle9iImpl.java	26 Jun 2003 19:07:50 -0000	1.4
  +++ PlatformOracle9iImpl.java	29 Jul 2003 16:54:12 -0000	1.5
  @@ -60,10 +60,11 @@
   
   import java.lang.reflect.InvocationTargetException;
   import java.lang.reflect.Method;
  -import java.sql.Connection;
  -import java.sql.PreparedStatement;
  -import java.sql.SQLException;
  -import java.sql.Statement;
  +import java.sql.*;
  +import java.io.ByteArrayInputStream;
  +import java.io.Reader;
  +import java.io.StringReader;
  +import java.io.InputStreamReader;
   
   /**
    *  This class is a concrete implementation of <code>Platform</code>. Provides
  @@ -99,11 +100,24 @@
   	private static Method SEND_BATCH = null;
   	private static Method SET_STATEMENT_CACHING_ENABLE = null;
   	private static Method SET_IMPLICIT_CACHING_ENABLED = null;
  +	private static Method SET_CLOB = null;
  +	private static Method SET_BLOB = null;
  +	private static boolean SET_CLOB_AND_LOB_SUPPORTED = false;
  +	private static Method GET_CLOB = null;
  +	private static boolean GET_CLOB_AND_LOB_SUPPORTED = false;
  +
   	private static boolean ROW_PREFETCH_SUPPORTED = true;
   	private static Method SET_ROW_PREFETCH = null;
   	private static final int STATEMENT_CACHE_SIZE = 100;
   	private static final int ROW_PREFETCH_SIZE = 100;
   
  +	// Session time zone has to be set while accessing Timestamp with
  +	// Time Zone and Timestamp with Local TimeZone datatypes.
  +	// OracleConnection has the APIs to set the session time zone.
  +	// Sets the session time zone to the time zone specified in the java
  +	// virtual machine.
  +	//((OracleConnection) m_connection).setSessionTimeZone(TimeZone.getDefault().getID());
  +
   
   	/**
   	 * enable oracle statement caching
  @@ -337,6 +351,130 @@
   		if (!SEND_BATCH_METHOD_EXISTS)
   		{
   			retval = super.executeBatch(stmt);
  +		}
  +		return retval;
  +	}
  +
  +	public void setObjectForStatement(PreparedStatement ps, int index, Object value, int sqlType) throws SQLException
  +	{
  +		if (SET_CLOB == null && SET_CLOB_AND_LOB_SUPPORTED)
  +		{
  +			try
  +			{
  +				SET_CLOB = ps.getClass().getMethod("setCLOB", new Class[]{Integer.TYPE, Class.forName("oracle.sql.CLOB")});
  +				SET_BLOB = ps.getClass().getMethod("setBLOB", new Class[]{Integer.TYPE, Class.forName("oracle.sql.BLOB")});
  +				SET_CLOB_AND_LOB_SUPPORTED = true;
  +			}
  +			catch (Throwable t)
  +			{
  +				SET_CLOB_AND_LOB_SUPPORTED = false;
  +			}
  +		}
  +		if (((sqlType == Types.VARBINARY) || (sqlType == Types.LONGVARBINARY)) && (value instanceof byte[]))
  +		{
  +			byte buf[] = (byte[]) value;
  +			ByteArrayInputStream inputStream = new ByteArrayInputStream(buf);
  +			super.changePreparedStatementResultSetType(ps);
  +			ps.setBinaryStream(index, inputStream, buf.length);
  +		}
  +		else if (value instanceof Double)
  +		{
  +			// workaround for the bug in Oracle thin driver
  +			ps.setDouble(index, ((Double) value).doubleValue());
  +		}
  +		else if (sqlType == Types.BIGINT && value instanceof Integer)
  +		{
  +			// workaround: Oracle thin driver problem when expecting long
  +			ps.setLong(index, ((Integer) value).intValue());
  +		}
  +		else if (sqlType == Types.INTEGER && value instanceof Long)
  +		{
  +			ps.setLong(index, ((Long) value).longValue());
  +		}
  +		else if (sqlType == Types.CLOB && value instanceof String)
  +		{
  +			if (SET_CLOB_AND_LOB_SUPPORTED)
  +			{
  +				try
  +				{
  +					SET_CLOB.invoke(ps, new Object[]{new Integer(index), Oracle9iLobHandler.createCLOBFromString(ps.getConnection(), (String) value)});
  +				}
  +				catch (IllegalAccessException e)
  +				{
  +					throw new SQLException(e.getMessage());
  +				}
  +				catch (IllegalArgumentException e)
  +				{
  +					throw new SQLException(e.getMessage());
  +				}
  +				catch (InvocationTargetException e)
  +				{
  +					throw new SQLException(e.getMessage());
  +				}
  +			}
  +		}
  +		else if (sqlType == Types.BLOB)
  +		{
  +			if (SET_CLOB_AND_LOB_SUPPORTED)
  +			{
  +				try
  +				{
  +					SET_BLOB.invoke(ps, new Object[]{new Integer(index)});
  +				}
  +				catch (IllegalAccessException e)
  +				{
  +					throw new SQLException(e.getMessage());
  +				}
  +				catch (IllegalArgumentException e)
  +				{
  +					throw new SQLException(e.getMessage());
  +				}
  +				catch (InvocationTargetException e)
  +				{
  +					throw new SQLException(e.getMessage());
  +				}
  +			}
  +		}
  +		else
  +		{
  +			super.setObjectForStatement(ps, index, value, sqlType);
  +		}
  +	}
  +
  +	public Object getClob(ResultSet rs, int jdbcType, String columnId) throws SQLException
  +	{
  +		String retval = "";
  +		if (GET_CLOB == null && GET_CLOB_AND_LOB_SUPPORTED)
  +		{
  +			try
  +			{
  +				GET_CLOB = rs.getClass().getMethod("getCLOB", new Class[]{String.class});
  +				GET_CLOB_AND_LOB_SUPPORTED = true;
  +			}
  +			catch (Throwable t)
  +			{
  +				GET_CLOB_AND_LOB_SUPPORTED = false;
  +			}
  +		}
  +		if (GET_CLOB_AND_LOB_SUPPORTED)
  +		{
  +			try
  +			{
  +				Object obj = GET_CLOB.invoke(rs, new Object[]{columnId});
  +				retval = Oracle9iLobHandler.convertCLOBtoString(rs.getStatement().getConnection(), obj);
  +			}
  +			catch (IllegalAccessException e)
  +			{
  +				throw new SQLException(e.getMessage());
  +			}
  +			catch (IllegalArgumentException e)
  +			{
  +				throw new SQLException(e.getMessage());
  +			}
  +			catch (InvocationTargetException e)
  +			{
  +				throw new SQLException(e.getMessage());
  +			}
   		}
   		return retval;
   	}
  
  
  
  1.17      +9 -4      db-ojb/src/java/org/apache/ojb/broker/platforms/Platform.java
  
  Index: Platform.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/Platform.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Platform.java	16 Jul 2003 15:16:07 -0000	1.16
  +++ Platform.java	29 Jul 2003 16:54:12 -0000	1.17
  @@ -75,7 +75,7 @@
   public interface Platform
   {
       /**
  -     * Called after a jdbc-connection statement was created.
  +     * Called after a jdbc-m_connection statement was created.
        */
       public void afterStatementCreate(Statement stmt) throws PlatformException;
   
  @@ -120,9 +120,9 @@
       public void initializeJdbcConnection(JdbcConnectionDescriptor jcd, Connection conn) throws PlatformException;
   
       /**
  -     * Used to do a temporary change of the connection autoCommit state.
  +     * Used to do a temporary change of the m_connection autoCommit state.
        * When using this method ensure to reset the original state before
  -     * connection was returned to pool or closed.
  +     * m_connection was returned to pool or closed.
        * Only when
        * {@link org.apache.ojb.broker.metadata.JdbcConnectionDescriptor#getUseAutoCommit()} was set to
        * {@link org.apache.ojb.broker.metadata.JdbcConnectionDescriptor#AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE}
  @@ -213,4 +213,9 @@
        * method should return the sql-query to obtain the last generated id.
        */
       public String getLastInsertIdentityQuery(String tableName);
  +
  +	/**
  +	 * Oracle has funky clobs.
  +	 */
  +	public Object getClob(ResultSet rs, int jdbcType, String columnId) throws SQLException;
   }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/platforms/Oracle9iLobHandler.java
  
  Index: Oracle9iLobHandler.java
  ===================================================================
  package org.apache.ojb.broker.platforms;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" 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",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * 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/>.
   */
  
  import java.io.*;
  import java.sql.Connection;
  
  /**
   * handles the Oracle LOB problems for 9i
   *
   * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
   */
  
  public class Oracle9iLobHandler
  {
  	Connection m_connection = null;
  	// Temporary LOBs
  	BlobWrapper m_tempBlob = null;
  
  	private static ClobWrapper createTempCLOB(Connection connection, ClobWrapper clob)
  	{
  		ClobWrapper tempClob = null;
  		if (clob != null)
  		{
  			try
  			{
  				// Create a temporary CLOB with duration session
  				tempClob = ClobWrapper.createTemporary(connection, true, ClobWrapper.DURATION_SESSION);
  
  				// Open the CLOB in readonly mode
  				clob.open(ClobWrapper.MODE_READONLY);
  
  				// Open the temporary CLOB in readwrite mode to enable writing
  				tempClob.open(ClobWrapper.MODE_READWRITE);
  
  				// No of bytes read each trip to database
  				int bytesread = 0;
  
  				// Get the input stream for reading from the CLOB
  				Reader clobReader = clob.getCharacterStream();
  
  				// Get the output stream for writing into the CLOB
  				Writer tempClobWriter = tempClob.getCharacterOutputStream();
  
  				// Create a buffer to read data
  				// getBufferSize() returns the optimal buffer size
  				char[] charbuffer = new char[clob.getBufferSize()];
  
  				// Read from the CLOB and write into the temporary CLOB
  				while ((bytesread = clobReader.read(charbuffer)) != -1)
  					tempClobWriter.write(charbuffer, 0, bytesread);
  
  				// Flush and close the streams
  				tempClobWriter.flush();
  				tempClobWriter.close();
  				clobReader.close();
  
  				// Close the CLOBs
  				clob.close();
  				tempClob.close();
  			}
  			catch (Exception ex)
  			{
  				// Since an error has been caught, free the temporary LOBs
  				freeTempLOB(tempClob, null);
  			}
  		}
  		return tempClob;
  	}
  
  	public static String convertCLOBtoString(Connection connection, Object nativeclob)
  	{
  		String retval = null;
  		ClobWrapper temp = new ClobWrapper();
  		temp.setClob(nativeclob);
  		/**
  		 * first, convert the clob to another clob. Thanks Oracle, you rule.
  		 */
  		ClobWrapper clob = createTempCLOB(connection, temp);
  
  		if (clob != null)
  		{
  			// Buffer to hold the CLOB data
  			StringBuffer clobdata = new StringBuffer();
  			// No of bytes read each trip to database
  			int bytesread = 0;
  			try
  			{
  				// Open the CLOB in readonly mode
  				clob.open(ClobWrapper.MODE_READONLY);
  				// Open the stream to read data
  				Reader clobReader = clob.getCharacterStream();
  				//  Buffer size is fixed using the getBufferSize() method which returns
  				//  the optimal buffer size to read data from the LOB
  				char[] charbuffer = new char[clob.getBufferSize()];
  				// Keep reading from the CLOB and append it to the stringbuffer till
  				// there is no more to read
  				while ((bytesread = clobReader.read(charbuffer)) != -1)
  				{
  					clobdata.append(charbuffer, 0, bytesread);
  				}
  				// Close the input stream
  				clobReader.close();
  				// Close the CLOB
  				clob.close();
  				retval = clobdata.toString();
  				clobdata = null;
  			}
  			catch (Exception ex)
  			{
  				// report
  			}
  		}
  		return retval;
  	}
  
  	public static Object createCLOBFromString(Connection conn, String clobData)
  	{
  		ClobWrapper clob = new ClobWrapper();
  		if (clobData != null)
  		{
  			try
  			{
  				clob = ClobWrapper.createTemporary(conn, true, ClobWrapper.DURATION_SESSION);
  
  				// Open the temporary CLOB in readwrite mode to enable writing
  				clob.open(ClobWrapper.MODE_READWRITE);
  
  				// Clear the previous contents of the CLOB
  				clob.trim(0);
  
  				// Get the output stream to write
  				Writer tempClobWriter = clob.getCharacterOutputStream();
  
  				// Write the data into the temporary CLOB
  				tempClobWriter.write(clobData);
  
  				// Flush and close the stream
  				tempClobWriter.flush();
  				tempClobWriter.close();
  
  				// Close the temporary CLOB
  				clob.close();
  			}
  			catch (Exception ex)
  			{
  				// Since an error has been caught, free the temporary LOBs
  				freeTempLOB(clob, null);
  			}
  		}
  		return clob.getClob();
  	}
  
  	/**
  	 *   Updates the content of the temporary BLOB with the new data in the file.
  	 **/
  	void createBLOBFromFile(File file)
  	{
  		if (file != null)
  		{
  			try
  			{
  				// If temporary BLOB has not yet been created, create new
  				if (m_tempBlob == null)
  				{
  					BlobWrapper temp = new BlobWrapper();
  					m_tempBlob = temp.createTemporary(m_connection, true,
  													  BlobWrapper.DURATION_SESSION);
  				}
  
  				// Open the temporary BLOB in readwrite mode to enable writing
  				m_tempBlob.open(BlobWrapper.MODE_READWRITE);
  
  				// Clear the contents of the temporary BLOB
  				m_tempBlob.trim(0);
  
  				// Get the input stream to read from the file
  				FileInputStream fileIStream = new FileInputStream(file);
  
  				// Get the output stream to write into the temporary BLOB
  				OutputStream tempBlobOStream = m_tempBlob.getBinaryOutputStream();
  
  				// Get the optimal buffer size to read bytes
  				byte[] buffer = new byte[m_tempBlob.getBufferSize()];
  
  				// No of bytes read in each trip to database
  				int bytesread = 0;
  
  				// Read from the file and write to the temporary BLOB
  				while ((bytesread = fileIStream.read(buffer)) != -1)
  					tempBlobOStream.write(buffer, 0, bytesread);
  
  				// Flush and close the streams
  				tempBlobOStream.flush();
  				fileIStream.close();
  				tempBlobOStream.close();
  
  				// Close the temporary BLOB
  				m_tempBlob.close();
  			}
  			catch (Exception ex)
  			{
  				// Since an error has been caught, free the temporary LOBs
  				freeTempLOB(null, m_tempBlob);
  			}
  		}
  	}
  
  	/**
  	 *   Frees the temporary LOBs when an exception is raised in the application
  	 *   or when the LOBs are no longer needed. If the LOBs are not freed , the
  	 *   space used by these LOBs are not reclaimed.
  	 **/
  	private static void freeTempLOB(ClobWrapper clob, BlobWrapper blob)
  	{
  		try
  		{
  			if (clob != null)
  			{
  				// If the CLOB is open, close it
  				if (clob.isOpen())
  				{
  					clob.close();
  				}
  
  				// Free the memory used by this CLOB
  				clob.freeTemporary();
  				clob = null;
  			}
  
  			if (blob != null)
  			{
  				// If the BLOB is open, close it
  				if (blob.isOpen())
  				{
  					blob.close();
  				}
  
  				// Free the memory used by this BLOB
  				blob.freeTemporary();
  				blob = null;
  			}
  		}
  		catch (Exception ex)
  		{
  		}
  	}
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/platforms/BlobWrapper.java
  
  Index: BlobWrapper.java
  ===================================================================
  package org.apache.ojb.broker.platforms;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" 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",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * 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/>.
   */
  
  import java.sql.Connection;
  import java.sql.SQLException;
  import java.io.InputStream;
  import java.io.OutputStream;
  
  /**
   * Created by IntelliJ IDEA.
   * User: matthew.baird
   * Date: Jun 26, 2003
   * Time: 3:58:47 PM
   * To change this template use Options | File Templates.
   */
  public class BlobWrapper
  {
  	public static final int MAX_CHUNK_SIZE = 32768;
  	public static final int DURATION_SESSION = 10;
  	public static final int DURATION_CALL = 12;
  	static final int OLD_WRONG_DURATION_SESSION = 1;
  	static final int OLD_WRONG_DURATION_CALL = 2;
  	public static final int MODE_READONLY = 0;
  	public static final int MODE_READWRITE = 1;
  
  	private Object m_blob;
  
  	public BlobWrapper createTemporary(Connection conn, boolean b, int i)
  	{
  		return new BlobWrapper();
  	}
  
  	public void open(int i) throws SQLException
  	{
  
  	}
  
  	public int getBufferSize() throws SQLException
  	{
  		return 1;
  	}
  
  	public void close() throws SQLException
  	{
  	}
  
  	public void trim(long l) throws SQLException
  	{
  
  	}
  
  	public void freeTemporary() throws SQLException
  	{
  
  	}
  
  	public InputStream getBinaryStream() throws SQLException
  	{
  		return null;
  	}
  
  	public OutputStream getBinaryOutputStream() throws SQLException
  	{
  		return null;
  	}
  
  	public boolean isOpen() throws SQLException
  	{
  		return true;
  	}
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/platforms/ClobWrapper.java
  
  Index: ClobWrapper.java
  ===================================================================
  package org.apache.ojb.broker.platforms;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" 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",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * 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/>.
   */
  
  import java.io.Reader;
  import java.io.Writer;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import java.sql.Connection;
  import java.sql.SQLException;
  
  /**
   * Wraps the Oracle CLOB type and makes it accessible via reflection without having to import the Oracle Classes.
   * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
   */
  
  public class ClobWrapper
  {
  	public static final int MAX_CHUNK_SIZE = 32768;
  	public static final int DURATION_SESSION = 10;
  	public static final int DURATION_CALL = 12;
  	static final int OLD_WRONG_DURATION_SESSION = 1;
  	static final int OLD_WRONG_DURATION_CALL = 2;
  	public static final int MODE_READONLY = 0;
  	public static final int MODE_READWRITE = 1;
  	private Object m_clob = null;
  
  	// methods
  	private static Method createTemporary = null;
  	private static Method open = null;
  	private static Method isOpen = null;
  	private static Method getCharacterStream = null;
  	private static Method getCharacterOutputStream = null;
  	private static Method getBufferSize = null;
  	private static Method close = null;
  	private static Method trim = null;
  	private static Method freeTemporary = null;
  
  	/**
  	 * initialize all the methods
  	 */
  	static
  	{
  		try
  		{
  			/**
  			 * try to find it
  			 */
  			Class clobClass = Class.forName("oracle.sql.CLOB");
  			createTemporary = clobClass.getDeclaredMethod("createTemporary", new Class[]{Connection.class, Boolean.TYPE, Integer.TYPE});
  			open = clobClass.getMethod("open", new Class[]{Integer.TYPE});
  			isOpen = clobClass.getMethod("isOpen", null);
  			getCharacterStream = clobClass.getMethod("getCharacterStream", null);
  			getCharacterOutputStream = clobClass.getMethod("getCharacterOutputStream", null);
  			getBufferSize = clobClass.getMethod("getBufferSize", null);
  			close = clobClass.getMethod("close", null);
  			trim = clobClass.getMethod("trim", new Class[]{Long.TYPE});
  			freeTemporary = clobClass.getMethod("freeTemporary", null);
  		}
  		catch (NoSuchMethodException e)
  		{
  			System.out.println(e.getMessage());
  		}
  		catch (SecurityException e)
  		{
  			System.out.println(e.getMessage());
  		}
  		catch (ClassNotFoundException e)
  		{
  			System.out.println(e.getMessage());
  		}
  	}
  
  	public Object getClob()
  	{
  		return m_clob;
  	}
  
  	public void setClob(Object clob)
  	{
  		m_clob = clob;
  	}
  
  	public static ClobWrapper createTemporary(Connection conn, boolean b, int i)
  	{
  		ClobWrapper retval = new ClobWrapper();
  		try
  		{
  			/**
  			 * passing null to the invoke means this is a static method.
  			 */
  			retval.m_clob = createTemporary.invoke(null, new Object[]{conn, new Boolean(b), new Integer(i)});
  		}
  		catch (IllegalAccessException e)
  		{
  			System.out.println(e.getMessage());
  		}
  		catch (IllegalArgumentException e)
  		{
  			System.out.println(e.getMessage());
  		}
  		catch (InvocationTargetException e)
  		{
  			System.out.println(e.getMessage());
  		}
  		return retval;
  	}
  
  	public void open(int i) throws SQLException
  	{
  		try
  		{
  			open.invoke(m_clob, new Object[]{new Integer(i)});
  		}
  		catch (Throwable e)
  		{
  			throw new SQLException(e.getMessage());
  		}
  	}
  
  	public boolean isOpen() throws SQLException
  	{
  		Boolean retval = null;
  		try
  		{
  			retval = (Boolean) isOpen.invoke(m_clob, null);
  		}
  		catch (Throwable e)
  		{
  			throw new SQLException(e.getMessage());
  		}
  		return retval.booleanValue();
  	}
  
  	public Reader getCharacterStream() throws SQLException
  	{
  		Reader retval = null;
  		try
  		{
  			retval = (Reader) getCharacterStream.invoke(m_clob, null);
  		}
  		catch (Throwable e)
  		{
  			throw new SQLException(e.getMessage());
  		}
  		return retval;
  	}
  
  	public Writer getCharacterOutputStream() throws SQLException
  	{
  		Writer retval = null;
  		try
  		{
  			retval = (Writer) getCharacterOutputStream.invoke(m_clob, null);
  		}
  		catch (Throwable e)
  		{
  			throw new SQLException(e.getMessage());
  		}
  		return retval;
  	}
  
  	public int getBufferSize() throws SQLException
  	{
  		Integer retval = null;
  		try
  		{
  			retval = (Integer) getBufferSize.invoke(m_clob, null);
  		}
  		catch (Throwable e)
  		{
  			throw new SQLException(e.getMessage());
  		}
  		return retval.intValue();
  	}
  
  	public void close() throws SQLException
  	{
  		try
  		{
  			close.invoke(m_clob, null);
  		}
  		catch (Throwable e)
  		{
  			throw new SQLException(e.getMessage());
  		}
  
  	}
  
  	public void trim(long l) throws SQLException
  	{
  		try
  		{
  			trim.invoke(m_clob, new Object[]{new Long(l)});
  		}
  		catch (Throwable e)
  		{
  			throw new SQLException(e.getMessage());
  		}
  
  	}
  
  	public void freeTemporary() throws SQLException
  	{
  		try
  		{
  			freeTemporary.invoke(m_clob, null);
  		}
  		catch (Throwable e)
  		{
  			throw new SQLException(e.getMessage());
  		}
  	}
  }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org