[jboss-cvs] jboss-portal/jems/src/main/org/jboss/portal/jems/hibernate ...

Julien Viet julien at jboss.com
Tue Aug 1 09:57:44 EDT 2006


  User: julien  
  Date: 06/08/01 09:57:44

  Modified:    jems/src/main/org/jboss/portal/jems/hibernate  
                        CacheableBlobUserType.java
  Added:       jems/src/main/org/jboss/portal/jems/hibernate  
                        ByteArrayBlob.java
  Log:
  - cms fixes
  - correct handling of -1 caching
  
  Revision  Changes    Path
  1.2       +27 -83    jboss-portal/jems/src/main/org/jboss/portal/jems/hibernate/CacheableBlobUserType.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheableBlobUserType.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-portal/jems/src/main/org/jboss/portal/jems/hibernate/CacheableBlobUserType.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- CacheableBlobUserType.java	31 Jul 2006 21:43:04 -0000	1.1
  +++ CacheableBlobUserType.java	1 Aug 2006 13:57:44 -0000	1.2
  @@ -23,7 +23,6 @@
   
   import org.hibernate.usertype.UserType;
   import org.hibernate.HibernateException;
  -import org.jboss.portal.common.util.Tools;
   
   import java.sql.ResultSet;
   import java.sql.SQLException;
  @@ -32,14 +31,11 @@
   import java.sql.Blob;
   import java.io.Serializable;
   import java.io.InputStream;
  -import java.io.OutputStream;
  -import java.io.ByteArrayInputStream;
   import java.io.IOException;
  -import java.io.ByteArrayOutputStream;
   
   /**
    * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class CacheableBlobUserType implements UserType
   {
  @@ -57,7 +53,7 @@
        return Blob.class;
      }
   
  -   public boolean equals(Object x, Object y)
  +   public boolean equals(Object x, Object y) throws HibernateException
      {
         if (x == y)
         {
  @@ -65,10 +61,17 @@
         }
         if (x != null && y != null)
         {
  -         ByteArrayBlob _x = (ByteArrayBlob)x;
  -         ByteArrayBlob _y = (ByteArrayBlob)y;
  +         try
  +         {
  +            ByteArrayBlob _x = ByteArrayBlob.get((Blob)x);
  +            ByteArrayBlob _y = ByteArrayBlob.get((Blob)y);
            return java.util.Arrays.equals(_x._bytes, _y._bytes);
         }
  +         catch (Exception e)
  +         {
  +            throw new HibernateException(e);
  +         }
  +      }
         return false;
      }
   
  @@ -122,101 +125,42 @@
         {
            return null;
         }
  -      return new ByteArrayBlob(((ByteArrayBlob)value));
  -   }
  -
  -   public boolean isMutable()
  +      try
      {
  -      return true;
  +         return ByteArrayBlob.create((Blob)value);
      }
  -
  -   public Serializable disassemble(Object value) throws HibernateException
  +      catch (Exception e)
      {
  -      return ((ByteArrayBlob)value)._bytes;
  +         throw new HibernateException(e);
      }
  -
  -   public Object assemble(Serializable cached, Object owner) throws HibernateException
  -   {
  -      return new ByteArrayBlob((byte[])cached);
      }
   
  -   public Object replace(Object original, Object target, Object owner) throws HibernateException
  -   {
  -      return original;
  -   }
  -
  -   public static final class ByteArrayBlob implements Blob
  -   {
  -
  -      /** . */
  -      private byte[] _bytes;
  -
  -      public ByteArrayBlob(InputStream in) throws IOException
  -      {
  -         ByteArrayOutputStream out = new ByteArrayOutputStream();
  -         Tools.copy(in, out);
  -         _bytes = out.toByteArray();
  -      }
  -
  -      public ByteArrayBlob(ByteArrayBlob that)
  -      {
  -         _bytes = that.getBytes(0, that._bytes.length);
  -      }
  -
  -      public ByteArrayBlob(byte[] _bytes)
  -      {
  -         this._bytes = _bytes;
  -      }
  -
  -      public ByteArrayBlob(Blob blob) throws SQLException
  -      {
  -         _bytes = blob.getBytes(1, (int) blob.length());
  -      }
  -
  -      public long length()
  +   public boolean isMutable()
         {
  -         return _bytes.length;
  +      return true;
         }
   
  -      public byte[] getBytes(long pos, int length)
  +   public Serializable disassemble(Object value) throws HibernateException
         {
  -         byte[] bytes = new byte[length];
  -         System.arraycopy(_bytes, (int)pos, bytes, 0, length);
  -         return bytes;
  -      }
  -
  -      public InputStream getBinaryStream()
  +      if (value == null)
         {
  -         return new ByteArrayInputStream(_bytes);
  +         return null;
         }
  -
  -      public int setBytes(long pos, byte[] bytes)
  -      {
  -         throw new UnsupportedOperationException();
  +      return ((ByteArrayBlob)value)._bytes;
         }
   
  -      public int setBytes(long pos, byte[] bytes, int offset, int len)
  +   public Object assemble(Serializable cached, Object owner) throws HibernateException
         {
  -         throw new UnsupportedOperationException();
  -      }
  -
  -      public OutputStream setBinaryStream(long pos)
  +      if (cached == null)
         {
  -         throw new UnsupportedOperationException();
  +         return null;
         }
  -      public long position(byte pattern[], long start)
  -      {
  -         throw new UnsupportedOperationException();
  +      return new ByteArrayBlob((byte[])cached);
         }
   
  -      public long position(Blob pattern, long start)
  +   public Object replace(Object original, Object target, Object owner) throws HibernateException
         {
  -         throw new UnsupportedOperationException();
  +      return original;
         }
   
  -      public void truncate(long len)
  -      {
  -         throw new UnsupportedOperationException();
  -      }
  -   }
   }
  
  
  
  1.1      date: 2006/08/01 13:57:44;  author: julien;  state: Exp;jboss-portal/jems/src/main/org/jboss/portal/jems/hibernate/ByteArrayBlob.java
  
  Index: ByteArrayBlob.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
  package org.jboss.portal.jems.hibernate;
  
  import org.jboss.portal.common.util.Tools;
  
  import java.sql.Blob;
  import java.sql.SQLException;
  import java.io.InputStream;
  import java.io.IOException;
  import java.io.ByteArrayOutputStream;
  import java.io.ByteArrayInputStream;
  import java.io.OutputStream;
  
  /**
   * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
   * @version $Revision: 1.1 $
   */
  public final class ByteArrayBlob implements Blob
  {
  
     /** . */
     byte[] _bytes;
  
     public ByteArrayBlob(InputStream in) throws IOException
     {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Tools.copy(in, out);
        _bytes = out.toByteArray();
     }
  
     public ByteArrayBlob(ByteArrayBlob that)
     {
        _bytes = that.getBytes(0, that._bytes.length);
     }
  
     public ByteArrayBlob(byte[] _bytes)
     {
        this._bytes = _bytes;
     }
  
     public ByteArrayBlob(Blob blob) throws SQLException
     {
        _bytes = blob.getBytes(1, (int)blob.length());
     }
  
     public long length()
     {
        return _bytes.length;
     }
  
     public byte[] getBytes(long pos, int length)
     {
        byte[] bytes = new byte[length];
        System.arraycopy(_bytes, (int)pos, bytes, 0, length);
        return bytes;
     }
  
     public InputStream getBinaryStream()
     {
        return new ByteArrayInputStream(_bytes);
     }
  
     public int setBytes(long pos, byte[] bytes)
     {
        throw new UnsupportedOperationException();
     }
  
     public int setBytes(long pos, byte[] bytes, int offset, int len)
     {
        throw new UnsupportedOperationException();
     }
  
     public OutputStream setBinaryStream(long pos)
     {
        throw new UnsupportedOperationException();
     }
  
     public long position(byte pattern[], long start)
     {
        throw new UnsupportedOperationException();
     }
  
     public long position(Blob pattern, long start)
     {
        throw new UnsupportedOperationException();
     }
  
     public void truncate(long len)
     {
        throw new UnsupportedOperationException();
     }
  
     public static ByteArrayBlob get(Blob blob) throws IOException, SQLException
     {
        if (blob instanceof ByteArrayBlob)
        {
           return (ByteArrayBlob)blob;
        }
        else
        {
           InputStream binaryStream = blob.getBinaryStream();
           return new ByteArrayBlob(binaryStream);
        }
     }
  
     public static ByteArrayBlob create(Blob blob) throws IOException, SQLException
     {
        if (blob instanceof ByteArrayBlob)
        {
           return new ByteArrayBlob((ByteArrayBlob)blob);
        }
        else
        {
           InputStream binaryStream = blob.getBinaryStream();
           return new ByteArrayBlob(binaryStream);
        }
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list