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

Julien Viet julien at jboss.com
Mon Jul 31 17:43:03 EDT 2006


  User: julien  
  Date: 06/07/31 17:43:03

  Modified:    cms/src/main/org/jboss/portal/cms/hibernate 
                        HibernateStore.java
  Log:
  - add CacheableBlobUserType
  - make the jackrabbit PM use CacheableUserType to avoid 10000 request per page view to the DB
  
  Revision  Changes    Path
  1.25      +30 -29    jboss-portal/cms/src/main/org/jboss/portal/cms/hibernate/HibernateStore.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: HibernateStore.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-portal/cms/src/main/org/jboss/portal/cms/hibernate/HibernateStore.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -b -r1.24 -r1.25
  --- HibernateStore.java	17 Jul 2006 13:11:25 -0000	1.24
  +++ HibernateStore.java	31 Jul 2006 21:43:03 -0000	1.25
  @@ -41,13 +41,13 @@
   import org.apache.jackrabbit.core.fs.RandomAccessOutputStream;
   import org.apache.jackrabbit.util.TransientFileFactory;
   import org.apache.log4j.Logger;
  -import org.hibernate.Hibernate;
   import org.hibernate.Query;
   import org.hibernate.Session;
   import org.hibernate.SessionFactory;
   import org.hibernate.Transaction;
   import org.jboss.portal.cms.util.HibernateUtil;
   import org.jboss.portal.common.util.Tools;
  +import org.jboss.portal.jems.hibernate.CacheableBlobUserType;
   
   /**
    * This is a FileSystem store using Hibernate, built on the DBFilesystem class packaged with Apache Jackrabbit
  @@ -969,7 +969,7 @@
                                 throw new Exception("No such Entry " + name);
                              }
   
  -                           versionEntry.setData(Hibernate.createBlob(in));
  +                           versionEntry.setData(createBlob(in));
                              versionEntry.setLastmod(System.currentTimeMillis());
                              versionEntry.setLength(length);
   
  @@ -986,7 +986,7 @@
                                 throw new Exception("No such Entry " + name);
                              }
   
  -                           cmsEntry.setData(Hibernate.createBlob(in));
  +                           cmsEntry.setData(createBlob(in));
                              cmsEntry.setLastmod(System.currentTimeMillis());
                              cmsEntry.setLength(length);
   
  @@ -1003,7 +1003,7 @@
                                 throw new Exception("No such Entry " + name);
                              }
   
  -                           repoEntry.setData(Hibernate.createBlob(in));
  +                           repoEntry.setData(createBlob(in));
                              repoEntry.setLastmod(System.currentTimeMillis());
                              repoEntry.setLength(length);
   
  @@ -1034,17 +1034,17 @@
                           in = new FileInputStream(f);
                           if(schemaObjectPrefix.equals(HibernateStoreConstants.versionClassName))
                           {
  -                           VersionEntry versionEntry = new VersionEntry(parentDir, name, Hibernate.createBlob(in), System.currentTimeMillis(), length);
  +                           VersionEntry versionEntry = new VersionEntry(parentDir, name, createBlob(in), System.currentTimeMillis(), length);
                              session.save(versionEntry);
                           }
                           else if(schemaObjectPrefix.equals(HibernateStoreConstants.cmsClassName))
                           {
  -                           CMSEntry cmsEntry = new CMSEntry(parentDir, name, Hibernate.createBlob(in), System.currentTimeMillis(), length);
  +                           CMSEntry cmsEntry = new CMSEntry(parentDir, name, createBlob(in), System.currentTimeMillis(), length);
                              session.save(cmsEntry);
                           }
                           else if(schemaObjectPrefix.equals(HibernateStoreConstants.repositoryClassName))
                           {
  -                           RepositoryEntry repoEntry = new RepositoryEntry(parentDir, name, Hibernate.createBlob(in), System.currentTimeMillis(), length);
  +                           RepositoryEntry repoEntry = new RepositoryEntry(parentDir, name, createBlob(in), System.currentTimeMillis(), length);
                              session.save(repoEntry);
                           }
                           session.flush();
  @@ -1069,10 +1069,7 @@
                  }
                  finally
                  {
  -                  if(in != null)
  -                  {
  -                     in.close();
  -                  }
  +                  Tools.safeClose(in);
                     // temp file can now safely be removed
                     f.delete();
                     f = null;
  @@ -1088,6 +1085,13 @@
         }
      }
   
  +   private Blob createBlob(InputStream in)
  +      throws IOException
  +   {
  +      // return Hibernate.createBlob(in);
  +      return new CacheableBlobUserType.ByteArrayBlob(in);
  +   }
  +
      /**
       *
       */
  @@ -1137,7 +1141,7 @@
               }
               finally
               {
  -               out.close();
  +               Tools.safeClose(out);
   //               in.close();
               }
            }
  @@ -1174,7 +1178,7 @@
                                 throw new Exception("No such Entry " + name);
                              }
   
  -                           versionEntry.setData(Hibernate.createBlob(in));
  +                           versionEntry.setData(createBlob(in));
                              versionEntry.setLastmod(System.currentTimeMillis());
                              versionEntry.setLength(length);
   
  @@ -1191,7 +1195,7 @@
                                 throw new Exception("No such Entry " + name);
                              }
   
  -                           cmsEntry.setData(Hibernate.createBlob(in));
  +                           cmsEntry.setData(createBlob(in));
                              cmsEntry.setLastmod(System.currentTimeMillis());
                              cmsEntry.setLength(length);
   
  @@ -1208,7 +1212,7 @@
                                 throw new Exception("No such Entry " + name);
                              }
   
  -                           repoEntry.setData(Hibernate.createBlob(in));
  +                           repoEntry.setData(createBlob(in));
                              repoEntry.setLastmod(System.currentTimeMillis());
                              repoEntry.setLength(length);
   
  @@ -1239,17 +1243,17 @@
                           in = new FileInputStream(f);
                           if(schemaObjectPrefix.equals(HibernateStoreConstants.versionClassName))
                           {
  -                           VersionEntry versionEntry = new VersionEntry(parentDir, name, Hibernate.createBlob(in), System.currentTimeMillis(), length);
  +                           VersionEntry versionEntry = new VersionEntry(parentDir, name, createBlob(in), System.currentTimeMillis(), length);
                              session.save(versionEntry);
                           }
                           else if(schemaObjectPrefix.equals(HibernateStoreConstants.cmsClassName))
                           {
  -                           CMSEntry cmsEntry = new CMSEntry(parentDir, name, Hibernate.createBlob(in), System.currentTimeMillis(), length);
  +                           CMSEntry cmsEntry = new CMSEntry(parentDir, name, createBlob(in), System.currentTimeMillis(), length);
                              session.save(cmsEntry);
                           }
                           else if(schemaObjectPrefix.equals(HibernateStoreConstants.repositoryClassName))
                           {
  -                           RepositoryEntry repoEntry = new RepositoryEntry(parentDir, name, Hibernate.createBlob(in), System.currentTimeMillis(), length);
  +                           RepositoryEntry repoEntry = new RepositoryEntry(parentDir, name, createBlob(in), System.currentTimeMillis(), length);
                              session.save(repoEntry);
                           }
                           session.flush();
  @@ -1274,10 +1278,7 @@
                  }
                  finally
                  {
  -                  if(in != null)
  -                  {
  -                     in.close();
  -                  }
  +                  Tools.safeClose(in);
                     // temp file can now safely be removed
                     f.delete();
                     f = null;
  
  
  



More information about the jboss-cvs-commits mailing list