[exo-jcr-commits] exo-jcr SVN: r3676 - jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Dec 17 05:46:18 EST 2010


Author: tolusha
Date: 2010-12-17 05:46:17 -0500 (Fri, 17 Dec 2010)
New Revision: 3676

Modified:
   jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java
   jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java
Log:
EXOJCR-1090: zip content

Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java	2010-12-17 10:45:11 UTC (rev 3675)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java	2010-12-17 10:46:17 UTC (rev 3676)
@@ -26,7 +26,6 @@
 import org.exoplatform.services.jcr.config.ValueStorageEntry;
 import org.exoplatform.services.jcr.config.WorkspaceEntry;
 import org.exoplatform.services.jcr.core.ManageableRepository;
-import org.exoplatform.services.jcr.dataflow.serialization.ObjectWriter;
 import org.exoplatform.services.jcr.ext.backup.BackupConfig;
 import org.exoplatform.services.jcr.ext.backup.BackupOperationException;
 import org.exoplatform.services.jcr.ext.backup.impl.AbstractFullBackupJob;
@@ -34,7 +33,7 @@
 import org.exoplatform.services.jcr.impl.Constants;
 import org.exoplatform.services.jcr.impl.core.lock.cacheable.AbstractCacheableLockManager;
 import org.exoplatform.services.jcr.impl.core.query.SystemSearchManager;
-import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectWriterImpl;
+import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectZipWriterImpl;
 import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
 import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
 import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
@@ -47,7 +46,6 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.net.URL;
 import java.security.PrivilegedExceptionAction;
 import java.sql.Connection;
@@ -58,6 +56,8 @@
 import java.sql.Types;
 import java.util.Calendar;
 import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
 
 import javax.naming.InitialContext;
 import javax.naming.NameNotFoundException;
@@ -73,48 +73,28 @@
    /**
     * Index directory in full backup storage.
     */
-  public static final String INDEX_DIR = "index";
+   public static final String INDEX_DIR = "index";
 
-  /**
-   * System index directory in full backup storage.
-   */
-  public static final String SYSTEM_INDEX_DIR = INDEX_DIR + "_" + SystemSearchManager.INDEX_DIR_SUFFIX;
+   /**
+    * System index directory in full backup storage.
+    */
+   public static final String SYSTEM_INDEX_DIR = INDEX_DIR + "_" + SystemSearchManager.INDEX_DIR_SUFFIX;
 
-  /**
-   * Value storage directory in full backup storage.
-   */
-  public static final String VALUE_STORAGE_DIR = "values";
+   /**
+    * Value storage directory in full backup storage.
+    */
+   public static final String VALUE_STORAGE_DIR = "values";
 
-  /**
-   * Suffix for content file.
-   */
-  public static final String CONTENT_FILE_SUFFIX = ".dump";
+   /**
+    * Suffix for content file.
+    */
+   public static final String CONTENT_FILE_SUFFIX = ".dump";
 
-  /**
-   * Suffix for content length file.
-   */
-  public static final String CONTENT_LEN_FILE_SUFFIX = ".len";
+   /**
+    * Suffix for content length file.
+    */
+   public static final String CONTENT_LEN_FILE_SUFFIX = ".len";
 
-  /**
-   * Content is absent.
-   */
-  public static final byte NULL_LEN = 0;
-
-  /**
-   * Content length value has byte type.
-   */
-  public static final byte BYTE_LEN = 1;
-
-  /**
-   * Content length value has integer type.
-   */
-  public static final byte INT_LEN = 2;
-
-  /**
-   * Content length value has long type.
-   */
-  public static final byte LONG_LEN = 3;
-
    /**
     * Logger.
     */
@@ -423,17 +403,19 @@
    {
       int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
 
-      ObjectWriter contentWriter = null;
-      ObjectWriter contentLenWriter = null;
+      ObjectZipWriterImpl contentWriter = null;
+      ObjectZipWriterImpl contentLenWriter = null;
       PreparedStatement stmt = null;
       ResultSet rs = null;
       try
       {
          File contentFile = new File(getStorageURL().getFile(), tableName + CONTENT_FILE_SUFFIX);
-         contentWriter = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(contentFile));
+         contentWriter = new ObjectZipWriterImpl(PrivilegedFileHelper.zipOutputStream(contentFile));
+         contentWriter.putNextEntry(new ZipEntry(tableName));
 
          File contentLenFile = new File(getStorageURL().getFile(), tableName + CONTENT_LEN_FILE_SUFFIX);
-         contentLenWriter = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(contentLenFile));
+         contentLenWriter = new ObjectZipWriterImpl(PrivilegedFileHelper.zipOutputStream(contentLenFile));
+         contentLenWriter.putNextEntry(new ZipEntry(tableName));
 
          stmt = jdbcConn.prepareStatement(script);
          rs = stmt.executeQuery();
@@ -475,7 +457,7 @@
                
                if (value == null)
                {
-                  contentLenWriter.writeByte(NULL_LEN);
+                  contentLenWriter.writeLong(-1);
                }
                else
                {
@@ -488,7 +470,7 @@
                      contentWriter.write(tmpBuff, 0, read);
                      len += read;
                   }
-                  writeCompressedContentLen(contentLenWriter, len);
+                  contentLenWriter.writeLong(len);
                }
             }
          }
@@ -497,11 +479,13 @@
       {
          if (contentWriter != null)
          {
+            contentWriter.closeEntry();
             contentWriter.close();
          }
 
          if (contentLenWriter != null)
          {
+            contentLenWriter.closeEntry();
             contentLenWriter.close();
          }
 
@@ -518,28 +502,6 @@
    }
 
    /**
-    * Write content length in output. 
-    */
-   private void writeCompressedContentLen(ObjectWriter out, long len) throws IOException
-   {
-      if (len < Byte.MAX_VALUE)
-      {
-         out.writeByte(BYTE_LEN);
-         out.writeByte((byte)len);
-      }
-      else if (len < Integer.MAX_VALUE)
-      {
-         out.writeByte(INT_LEN);
-         out.writeInt((int)len);
-      }
-      else
-      {
-         out.writeByte(LONG_LEN);
-         out.writeLong(len);
-      }
-   }
-
-   /**
     * {@inheritDoc}
     */
    public void stop()
@@ -575,12 +537,13 @@
       else
       {
          InputStream in = null;
-         OutputStream out = null;
+         ZipOutputStream out = null;
 
          try
          {
             in = PrivilegedFileHelper.fileInputStream(srcPath);
-            out = PrivilegedFileHelper.fileOutputStream(dstPath);
+            out = PrivilegedFileHelper.zipOutputStream(dstPath);
+            out.putNextEntry(new ZipEntry(srcPath.getName()));
 
             // Transfer bytes from in to out
             byte[] buf = new byte[2048];
@@ -601,6 +564,7 @@
 
             if (out != null)
             {
+               out.closeEntry();
                out.close();
             }
          }

Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java	2010-12-17 10:45:11 UTC (rev 3675)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java	2010-12-17 10:46:17 UTC (rev 3676)
@@ -38,7 +38,7 @@
 import org.exoplatform.services.jcr.impl.core.query.SystemSearchManager;
 import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
 import org.exoplatform.services.jcr.impl.dataflow.persistent.CacheableWorkspaceDataManager;
-import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectReaderImpl;
+import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectZipReaderImpl;
 import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
 import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
 import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
@@ -63,6 +63,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.zip.ZipInputStream;
 
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
@@ -468,12 +469,13 @@
       }
       else
       {
-         InputStream in = null;
+         ZipInputStream in = null;
          OutputStream out = null;
 
          try
          {
-            in = PrivilegedFileHelper.fileInputStream(srcPath);
+            in = PrivilegedFileHelper.zipInputStream(srcPath);
+            in.getNextEntry();
             out = PrivilegedFileHelper.fileOutputStream(dstPath);
 
             // Transfer bytes from in to out
@@ -509,8 +511,8 @@
    {
       String insertNodeQuery = null;
 
-      ObjectReader contentReader = null;
-      ObjectReader contentLenReader = null;
+      ObjectZipReaderImpl contentReader = null;
+      ObjectZipReaderImpl contentLenReader = null;
 
       PreparedStatement insertNode = null;
       ResultSet tableMetaData = null;
@@ -519,9 +521,12 @@
 
       try
       {
-         contentReader = new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(helper.contentFile));
-         contentLenReader = new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(helper.contentLenFile));
+         contentReader = new ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(helper.getContentFile()));
+         contentReader.getNextEntry();
 
+         contentLenReader = new ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(helper.getContentLenFile()));
+         contentLenReader.getNextEntry();
+
          // get information about backup table
          int sourceColumnCount = contentReader.readInt();
          
@@ -592,7 +597,7 @@
                {
                   try
                   {
-                     len = readCompressedContentLen(contentLenReader);
+                     len = contentLenReader.readLong();
                   }
                   catch (EOFException e)
                   {
@@ -611,7 +616,7 @@
 
                      throw new IOException("Content length file is empty but content still present", e);
                   }
-                  stream = spoolInputStream(contentReader, len);
+                  stream = len == -1 ? null : spoolInputStream(contentReader, len);
                }
 
                if (helper.getSkipColumnIndex() != null && helper.getSkipColumnIndex() == i)
@@ -623,57 +628,58 @@
                   targetIndex--;
                   continue;
                }
-               else if (helper.getConvertColumnIndexes().contains(i))
-               {
-                  // convert column value
-                  ByteArrayInputStream ba = (ByteArrayInputStream)stream;
-                  byte[] readBuffer = new byte[ba.available()];
-                  ba.read(readBuffer);
 
-                  String currentValue = new String(readBuffer, Constants.DEFAULT_ENCODING);
-                  if (currentValue.equals(Constants.ROOT_PARENT_UUID))
+               // set 
+               if (stream != null)
+               {
+                  if (helper.getConvertColumnIndexes().contains(i))
                   {
-                     stream = new ByteArrayInputStream(Constants.ROOT_PARENT_UUID.getBytes());
-                  }
-                  else
-                  {
-                     if (helper.isMultiDb)
+                     // convert column value
+                     ByteArrayInputStream ba = (ByteArrayInputStream)stream;
+                     byte[] readBuffer = new byte[ba.available()];
+                     ba.read(readBuffer);
+
+                     String currentValue = new String(readBuffer, Constants.DEFAULT_ENCODING);
+                     if (currentValue.equals(Constants.ROOT_PARENT_UUID))
                      {
-                        if (!helper.isBackupMutliDb())
-                        {
-                           stream =
-                              new ByteArrayInputStream(new String(readBuffer, Constants.DEFAULT_ENCODING).substring(
-                                 helper.getBackupWorkspaceName().length()).getBytes());
-                        }
+                        stream = new ByteArrayInputStream(Constants.ROOT_PARENT_UUID.getBytes());
                      }
                      else
                      {
-                        if (helper.isBackupMutliDb())
+                        if (helper.isMultiDb)
                         {
-                           StringBuilder builder = new StringBuilder();
-                           builder.append(workspaceName);
-                           builder.append(currentValue);
-
-                           stream = new ByteArrayInputStream(builder.toString().getBytes());
+                           if (!helper.isBackupMutliDb())
+                           {
+                              stream =
+                                 new ByteArrayInputStream(new String(readBuffer, Constants.DEFAULT_ENCODING).substring(
+                                    helper.getBackupWorkspaceName().length()).getBytes());
+                           }
                         }
                         else
                         {
-                           StringBuilder builder = new StringBuilder();
-                           builder.append(workspaceName);
-                           builder.append(new String(readBuffer, Constants.DEFAULT_ENCODING).substring(helper
-                              .getBackupWorkspaceName().length()));
+                           if (helper.isBackupMutliDb())
+                           {
+                              StringBuilder builder = new StringBuilder();
+                              builder.append(workspaceName);
+                              builder.append(currentValue);
 
-                           stream = new ByteArrayInputStream(builder.toString().getBytes());
+                              stream = new ByteArrayInputStream(builder.toString().getBytes());
+                           }
+                           else
+                           {
+                              StringBuilder builder = new StringBuilder();
+                              builder.append(workspaceName);
+                              builder.append(new String(readBuffer, Constants.DEFAULT_ENCODING).substring(helper
+                                 .getBackupWorkspaceName().length()));
+
+                              stream = new ByteArrayInputStream(builder.toString().getBytes());
+                           }
                         }
                      }
+
+                     len = ((ByteArrayInputStream)stream).available();
                   }
 
-                  len = ((ByteArrayInputStream)stream).available();
-               }
-               
-               // set 
-               if (len != FullBackupJob.NULL_LEN)
-               {
                   if (columnType.get(i) == Types.INTEGER || columnType.get(i) == Types.BIGINT
                      || columnType.get(i) == Types.SMALLINT || columnType.get(i) == Types.TINYINT)
                   {
@@ -769,31 +775,6 @@
    }
 
    /**
-    * Write content length in output. 
-    */
-   private long readCompressedContentLen(ObjectReader in) throws IOException
-   {
-      byte lenType = in.readByte();
-
-      if (lenType == FullBackupJob.NULL_LEN)
-      {
-         return lenType;
-      }
-      else if (lenType == FullBackupJob.BYTE_LEN)
-      {
-         return in.readByte();
-      }
-      else if (lenType == FullBackupJob.INT_LEN)
-      {
-         return in.readInt();
-      }
-      else
-      {
-         throw new RuntimeException("Does not support to restore value more than 2G.");
-      }
-   }
-
-   /**
     * Spool input stream.
     */
    private InputStream spoolInputStream(ObjectReader in, long contentLen) throws IOException



More information about the exo-jcr-commits mailing list