[exo-jcr-commits] exo-jcr SVN: r4325 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl: backup/rdbms and 6 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Apr 28 08:11:16 EDT 2011


Author: tolusha
Date: 2011-04-28 08:11:15 -0400 (Thu, 28 Apr 2011)
New Revision: 4325

Added:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/ComplexDataRestore.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DataRestore.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DummyDataRestore.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/JCRRestore.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestore.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DirectoryRestore.java
Removed:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/ComplexDataRestor.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DataRestor.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DummyDataRestor.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/JCRRestor.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestor.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DirectoryRestor.java
Modified:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/Backupable.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/JdbcBackupable.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cacheable/AbstractCacheableLockManager.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/ISPNCacheWorkspaceStorageCache.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
Log:
EXOJCR-1324: Misspelling in some class names

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/Backupable.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/Backupable.java	2011-04-28 11:48:05 UTC (rev 4324)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/Backupable.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -52,6 +52,6 @@
     * @throws RestoreException
     *          if any exception occurred
     */
-   DataRestor getDataRestorer(File storageDir) throws BackupException;
+   DataRestore getDataRestorer(File storageDir) throws BackupException;
 
 }

Deleted: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/ComplexDataRestor.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/ComplexDataRestor.java	2011-04-28 11:48:05 UTC (rev 4324)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/ComplexDataRestor.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -1,109 +0,0 @@
-/*
- * Copyright (C) 2003-2010 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see<http://www.gnu.org/licenses/>.
- */
-package org.exoplatform.services.jcr.impl.backup;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * Date: 21 01 2011
- * 
- * @author <a href="mailto:anatoliy.bazko at exoplatform.com.ua">Anatoliy Bazko</a>
- * @version $Id: ComplexDataRestor.java 34360 2010-11-11 11:11:11Z tolusha $
- */
-public class ComplexDataRestor implements DataRestor
-{
-
-   /**
-    * List of restorers.
-    */
-   private List<DataRestor> restorers = new ArrayList<DataRestor>();
-
-   /**
-    * Constructor ComplexDataRestor.
-    * 
-    * @param restorers
-    */
-   public ComplexDataRestor(List<DataRestor> restorers)
-   {
-      this.restorers.addAll(restorers);
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void clean() throws BackupException
-   {
-      for (DataRestor restorer : restorers)
-      {
-         restorer.clean();
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void restore() throws BackupException
-   {
-      for (DataRestor restorer : restorers)
-      {
-         restorer.restore();
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void commit() throws BackupException
-   {
-      for (DataRestor restorer : restorers)
-      {
-         restorer.commit();
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void rollback() throws BackupException
-   {
-      for (DataRestor restorer : restorers)
-      {
-         restorer.rollback();
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void close() throws BackupException
-   {
-      try
-      {
-         for (DataRestor restorer : restorers)
-         {
-            restorer.close();
-         }
-      }
-      finally
-      {
-         restorers.clear();
-      }
-   }
-}

Copied: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/ComplexDataRestore.java (from rev 4323, jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/ComplexDataRestor.java)
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/ComplexDataRestore.java	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/ComplexDataRestore.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.backup;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * Date: 21 01 2011
+ * 
+ * @author <a href="mailto:anatoliy.bazko at exoplatform.com.ua">Anatoliy Bazko</a>
+ * @version $Id: ComplexDataRestore.java 34360 2010-11-11 11:11:11Z tolusha $
+ */
+public class ComplexDataRestore implements DataRestore
+{
+
+   /**
+    * List of restorers.
+    */
+   private List<DataRestore> restorers = new ArrayList<DataRestore>();
+
+   /**
+    * Constructor ComplexDataRestor.
+    * 
+    * @param restorers
+    */
+   public ComplexDataRestore(List<DataRestore> restorers)
+   {
+      this.restorers.addAll(restorers);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void clean() throws BackupException
+   {
+      for (DataRestore restorer : restorers)
+      {
+         restorer.clean();
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void restore() throws BackupException
+   {
+      for (DataRestore restorer : restorers)
+      {
+         restorer.restore();
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void commit() throws BackupException
+   {
+      for (DataRestore restorer : restorers)
+      {
+         restorer.commit();
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void rollback() throws BackupException
+   {
+      for (DataRestore restorer : restorers)
+      {
+         restorer.rollback();
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void close() throws BackupException
+   {
+      try
+      {
+         for (DataRestore restorer : restorers)
+         {
+            restorer.close();
+         }
+      }
+      finally
+      {
+         restorers.clear();
+      }
+   }
+}

Deleted: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DataRestor.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DataRestor.java	2011-04-28 11:48:05 UTC (rev 4324)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DataRestor.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2003-2010 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see<http://www.gnu.org/licenses/>.
- */
-package org.exoplatform.services.jcr.impl.backup;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * Date: 22 01 2011
- * 
- * @author <a href="mailto:anatoliy.bazko at exoplatform.com.ua">Anatoliy Bazko</a>
- * @version $Id: DataRestor.java.java 34360 2010-11-11 11:11:11Z tolusha $
- */
-public interface DataRestor
-{
-
-   /**
-    * Clean old data from the storage. 
-    * 
-    * @throws RestoreException
-    *          if any exception is occurred
-    */
-   void clean() throws BackupException;
-
-   /**
-    * Restore new data into storage.
-    * 
-    * @throws RestoreException
-    *          if any exception is occurred
-    */
-   void restore() throws BackupException;
-
-   /**
-    * Commit changes. 
-    * 
-    * @throws RestoreException
-    *          if any exception is occurred
-    */
-   void commit() throws BackupException;
-
-   /**
-    * Rollback changes. 
-    * 
-    * @throws RestoreException
-    *          if any exception is occurred
-    */
-   void rollback() throws BackupException;
-
-   /**
-    * Close DataRestor. 
-    * 
-    * @throws RestoreException
-    *          if any exception is occurred
-    */
-   void close() throws BackupException;
-}

Copied: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DataRestore.java (from rev 4323, jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DataRestor.java)
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DataRestore.java	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DataRestore.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.backup;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * Date: 22 01 2011
+ * 
+ * @author <a href="mailto:anatoliy.bazko at exoplatform.com.ua">Anatoliy Bazko</a>
+ * @version $Id: DataRestore.java.java 34360 2010-11-11 11:11:11Z tolusha $
+ */
+public interface DataRestore
+{
+
+   /**
+    * Clean old data from the storage. 
+    * 
+    * @throws RestoreException
+    *          if any exception is occurred
+    */
+   void clean() throws BackupException;
+
+   /**
+    * Restore new data into storage.
+    * 
+    * @throws RestoreException
+    *          if any exception is occurred
+    */
+   void restore() throws BackupException;
+
+   /**
+    * Commit changes. 
+    * 
+    * @throws RestoreException
+    *          if any exception is occurred
+    */
+   void commit() throws BackupException;
+
+   /**
+    * Rollback changes. 
+    * 
+    * @throws RestoreException
+    *          if any exception is occurred
+    */
+   void rollback() throws BackupException;
+
+   /**
+    * Close DataRestor. 
+    * 
+    * @throws RestoreException
+    *          if any exception is occurred
+    */
+   void close() throws BackupException;
+}

Deleted: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DummyDataRestor.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DummyDataRestor.java	2011-04-28 11:48:05 UTC (rev 4324)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DummyDataRestor.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2003-2010 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see<http://www.gnu.org/licenses/>.
- */
-package org.exoplatform.services.jcr.impl.backup;
-
-/***
- * Created by The eXo Platform SAS.
- *
- * Date: 21 01 2011
- * 
- * @author <a href="mailto:anatoliy.bazko at exoplatform.com.ua">Anatoliy Bazko</a>
- * @version $Id: DummyDataRestor.java 34360 2010-11-11 11:11:11Z tolusha $
- */
-public class DummyDataRestor implements DataRestor
-{
-   /**
-    * {@inheritDoc}
-    */
-   public void restore() throws BackupException
-   {
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void clean() throws BackupException
-   {
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void commit() throws BackupException
-   {
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void rollback() throws BackupException
-   {
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void close() throws BackupException
-   {
-   }
-}

Copied: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DummyDataRestore.java (from rev 4323, jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DummyDataRestor.java)
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DummyDataRestore.java	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/DummyDataRestore.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.backup;
+
+/***
+ * Created by The eXo Platform SAS.
+ *
+ * Date: 21 01 2011
+ * 
+ * @author <a href="mailto:anatoliy.bazko at exoplatform.com.ua">Anatoliy Bazko</a>
+ * @version $Id: DummyDataRestore.java 34360 2010-11-11 11:11:11Z tolusha $
+ */
+public class DummyDataRestore implements DataRestore
+{
+   /**
+    * {@inheritDoc}
+    */
+   public void restore() throws BackupException
+   {
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void clean() throws BackupException
+   {
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void commit() throws BackupException
+   {
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void rollback() throws BackupException
+   {
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void close() throws BackupException
+   {
+   }
+}

Deleted: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/JCRRestor.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/JCRRestor.java	2011-04-28 11:48:05 UTC (rev 4324)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/JCRRestor.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -1,448 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * 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.exoplatform.services.jcr.impl.backup;
-
-import org.exoplatform.commons.utils.PrivilegedFileHelper;
-import org.exoplatform.commons.utils.PrivilegedSystemHelper;
-import org.exoplatform.services.jcr.dataflow.ChangesLogIterator;
-import org.exoplatform.services.jcr.dataflow.DataManager;
-import org.exoplatform.services.jcr.dataflow.ItemState;
-import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
-import org.exoplatform.services.jcr.dataflow.PlainChangesLogImpl;
-import org.exoplatform.services.jcr.dataflow.TransactionChangesLog;
-import org.exoplatform.services.jcr.dataflow.persistent.PersistedPropertyData;
-import org.exoplatform.services.jcr.datamodel.ItemData;
-import org.exoplatform.services.jcr.datamodel.ValueData;
-import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.StreamPersistedValueData;
-import org.exoplatform.services.jcr.impl.storage.JCRInvalidItemStateException;
-import org.exoplatform.services.jcr.impl.storage.JCRItemExistsException;
-import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
-import org.exoplatform.services.jcr.impl.util.io.SpoolFile;
-import org.exoplatform.services.jcr.observation.ExtendedEvent;
-
-import java.io.EOFException;
-import java.io.Externalizable;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutput;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.jcr.RepositoryException;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * Date: 24 01 2011
- * 
- * Class contains commons method for JCR restore operation.
- * - get path to full backup<br>
- * - get list of incremental backup files<br>
- * - perform incremental restore function<br>
- * 
- * @author <a href="mailto:anatoliy.bazko at exoplatform.com.ua">Anatoliy Bazko</a>
- * @version $Id: JCRRestorerHelper.java 34360 2010-11-11 11:11:11Z tolusha $
- */
-public class JCRRestor
-{
-
-   private final DataManager dataManager;
-
-   private final FileCleaner fileCleaner;
-
-   private final File tempDir = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
-
-   public JCRRestor(DataManager dataManager, FileCleaner fileCleaner)
-   {
-      this.dataManager = dataManager;
-      this.fileCleaner = fileCleaner;
-   }
-
-   /**
-    * Returns file with full backup. In case of RDBMS backup 
-    * it may be a directory. 
-    *  
-    * @param restoreDir
-    * @return
-    */
-   public static File getFullBackupFile(File restoreDir)
-   {
-      Pattern p = Pattern.compile(".+\\.0");
-
-      for (File f : PrivilegedFileHelper.listFiles(restoreDir, new FileFilter()
-      {
-         public boolean accept(File pathname)
-         {
-            Pattern p = Pattern.compile(".+\\.[0-9]+");
-            Matcher m = p.matcher(pathname.getName());
-            return m.matches();
-         }
-      }))
-      {
-         Matcher m = p.matcher(f.getName());
-         if (m.matches())
-         {
-            return f;
-         }
-      }
-
-      return null;
-   }
-
-   /**
-    * Get list of incremental backup files.
-    *  
-    * @param restoreDir
-    * @return list of files
-    */
-   public static List<File> getIncrementalFiles(File restoreDir)
-   {
-      ArrayList<File> list = new ArrayList<File>();
-
-      Pattern fullBackupPattern = Pattern.compile(".+\\.0");
-
-      for (File f : PrivilegedFileHelper.listFiles(restoreDir, new FileFilter()
-      {
-         public boolean accept(File pathname)
-         {
-            Pattern p = Pattern.compile(".+\\.[0-9]+");
-            Matcher m = p.matcher(pathname.getName());
-            return m.matches();
-         }
-      }))
-      {
-         if (fullBackupPattern.matcher(f.getName()).matches() == false)
-         {
-            list.add(f);
-         }
-      }
-
-      return list;
-   }
-
-   /**
-    * Perform incremental restore operation.
-    * 
-    * @param incrementalBackupFile
-    *          incremental backup file
-    * @throws FileNotFoundException
-    * @throws IOException
-    * @throws ClassNotFoundException
-    * @throws RepositoryException
-    */
-   public void incrementalRestore(File incrementalBackupFile) throws FileNotFoundException, IOException,
-      ClassNotFoundException, RepositoryException
-   {
-      ObjectInputStream ois = null;
-      try
-      {
-         ois = new ObjectInputStream(PrivilegedFileHelper.fileInputStream(incrementalBackupFile));
-
-         while (true)
-         {
-            TransactionChangesLog changesLog = readExternal(ois);
-            changesLog.setSystemId(Constants.JCR_CORE_RESTORE_WORKSPACE_INITIALIZER_SYSTEM_ID); // mark changes
-
-            ChangesLogIterator cli = changesLog.getLogIterator();
-            while (cli.hasNextLog())
-            {
-               if (cli.nextLog().getEventType() == ExtendedEvent.LOCK)
-                  cli.removeLog();
-            }
-
-            saveChangesLog(changesLog);
-         }
-      }
-      catch (EOFException ioe)
-      {
-         // ok - reading all data from backup file;
-      }
-   }
-
-   private void saveChangesLog(TransactionChangesLog changesLog) throws RepositoryException
-   {
-      try
-      {
-         dataManager.save(changesLog);
-      }
-      catch (JCRInvalidItemStateException e)
-      {
-         TransactionChangesLog normalizeChangesLog =
-            getNormalizedChangesLog(e.getIdentifier(), e.getState(), changesLog);
-         if (normalizeChangesLog != null)
-            saveChangesLog(normalizeChangesLog);
-         else
-            throw new RepositoryException(
-               "Collisions found during save of restore changes log, but caused item is not found by ID "
-                  + e.getIdentifier() + ". " + e, e);
-      }
-      catch (JCRItemExistsException e)
-      {
-         TransactionChangesLog normalizeChangesLog =
-            getNormalizedChangesLog(e.getIdentifier(), e.getState(), changesLog);
-         if (normalizeChangesLog != null)
-            saveChangesLog(normalizeChangesLog);
-         else
-            throw new RepositoryException(
-               "Collisions found during save of restore changes log, but caused item is not found by ID "
-                  + e.getIdentifier() + ". " + e, e);
-      }
-   }
-
-   private TransactionChangesLog getNormalizedChangesLog(String collisionID, int state, TransactionChangesLog changesLog)
-   {
-      ItemState citem = changesLog.getItemState(collisionID);
-
-      if (citem != null)
-      {
-
-         TransactionChangesLog result = new TransactionChangesLog();
-         result.setSystemId(changesLog.getSystemId());
-
-         ChangesLogIterator cli = changesLog.getLogIterator();
-         while (cli.hasNextLog())
-         {
-            ArrayList<ItemState> normalized = new ArrayList<ItemState>();
-            PlainChangesLog next = cli.nextLog();
-            for (ItemState change : next.getAllStates())
-            {
-               if (state == change.getState())
-               {
-                  ItemData item = change.getData();
-                  // targeted state
-                  if (citem.isNode())
-                  {
-                     // Node... by ID and desc path
-                     if (!item.getIdentifier().equals(collisionID)
-                        && !item.getQPath().isDescendantOf(citem.getData().getQPath()))
-                        normalized.add(change);
-                  }
-                  else if (!item.getIdentifier().equals(collisionID))
-                  {
-                     // Property... by ID
-                     normalized.add(change);
-                  }
-               }
-               else
-                  // another state
-                  normalized.add(change);
-            }
-
-            PlainChangesLog plog = new PlainChangesLogImpl(normalized, next.getSessionId(), next.getEventType());
-            result.addLog(plog);
-         }
-
-         return result;
-      }
-
-      return null;
-   }
-
-   private TransactionChangesLog readExternal(ObjectInputStream in) throws IOException, ClassNotFoundException
-   {
-      int changesLogType = in.readInt();
-
-      TransactionChangesLog transactionChangesLog = null;
-
-      if (changesLogType == RestoreChangesLog.Type.ItemDataChangesLog_with_Streams)
-      {
-
-         // read ChangesLog
-         transactionChangesLog = (TransactionChangesLog)in.readObject();
-
-         // read FixupStream count
-         int iFixupStream = in.readInt();
-
-         ArrayList<FixupStream> listFixupStreams = new ArrayList<FixupStream>();
-
-         for (int i = 0; i < iFixupStream; i++)
-         {
-            FixupStream fs = new FixupStream();
-            fs.readExternal(in);
-            listFixupStreams.add(fs);
-         }
-
-         // read stream data
-         int iStreamCount = in.readInt();
-         ArrayList<SpoolFile> listFiles = new ArrayList<SpoolFile>();
-
-         for (int i = 0; i < iStreamCount; i++)
-         {
-
-            // read file size
-            long fileSize = in.readLong();
-
-            // read content file
-            listFiles.add(getAsFile(in, fileSize));
-         }
-
-         RestoreChangesLog restoreChangesLog =
-            new RestoreChangesLog(transactionChangesLog, listFixupStreams, listFiles, fileCleaner);
-
-         restoreChangesLog.restore();
-
-      }
-      else if (changesLogType == RestoreChangesLog.Type.ItemDataChangesLog_without_Streams)
-      {
-         transactionChangesLog = (TransactionChangesLog)in.readObject();
-      }
-
-      return transactionChangesLog;
-   }
-
-   private SpoolFile getAsFile(ObjectInputStream ois, long fileSize) throws IOException
-   {
-      int bufferSize = 1024 * 8;
-      byte[] buf = new byte[bufferSize];
-
-      SpoolFile tempFile = SpoolFile.createTempFile("vdincb" + System.currentTimeMillis(), ".stmp", tempDir);
-      FileOutputStream fos = PrivilegedFileHelper.fileOutputStream(tempFile);
-      long readBytes = fileSize;
-
-      while (readBytes > 0)
-      {
-         // long longTemp = readByte - bufferSize;
-         if (readBytes >= bufferSize)
-         {
-            ois.readFully(buf);
-            fos.write(buf);
-         }
-         else if (readBytes < bufferSize)
-         {
-            ois.readFully(buf, 0, (int)readBytes);
-            fos.write(buf, 0, (int)readBytes);
-         }
-         readBytes -= bufferSize;
-      }
-
-      fos.flush();
-      fos.close();
-
-      return tempFile;
-   }
-
-   class RestoreChangesLog
-   {
-      public class Type
-      {
-         public static final int ItemDataChangesLog_without_Streams = 1;
-
-         public static final int ItemDataChangesLog_with_Streams = 2;
-      }
-
-      private TransactionChangesLog itemDataChangesLog;
-
-      private List<FixupStream> listFixupStream;
-
-      private List<SpoolFile> listFile;
-
-      private FileCleaner fileCleaner;
-
-      public RestoreChangesLog(TransactionChangesLog transactionChangesLog, List<FixupStream> listFixupStreams,
-         List<SpoolFile> listFiles, FileCleaner fileCleaner)
-      {
-         this.itemDataChangesLog = transactionChangesLog;
-         this.listFixupStream = listFixupStreams;
-         this.listFile = listFiles;
-         this.fileCleaner = fileCleaner;
-      }
-
-      public TransactionChangesLog getItemDataChangesLog()
-      {
-         return itemDataChangesLog;
-      }
-
-      public void restore() throws IOException
-      {
-         List<ItemState> listItemState = itemDataChangesLog.getAllStates();
-         for (int i = 0; i < this.listFixupStream.size(); i++)
-         {
-            ItemState itemState = listItemState.get(listFixupStream.get(i).getItemSateId());
-            ItemData itemData = itemState.getData();
-
-            PersistedPropertyData propertyData = (PersistedPropertyData)itemData;
-            ValueData vd = (propertyData.getValues().get(listFixupStream.get(i).getValueDataId()));
-
-            // re-init the value
-            propertyData.getValues().set(listFixupStream.get(i).getValueDataId(),
-               new StreamPersistedValueData(vd.getOrderNumber(), listFile.get(i)));
-         }
-
-         for (int i = 0; i < listFile.size(); i++)
-            fileCleaner.addFile(listFile.get(i));
-      }
-   }
-
-   class FixupStream implements Externalizable
-   {
-      int iItemStateId = -1;
-
-      int iValueDataId = -1;
-
-      public FixupStream()
-      {
-      }
-
-      public FixupStream(int itemState_, int valueData_)
-      {
-         iItemStateId = itemState_;
-         iValueDataId = valueData_;
-      }
-
-      public int getItemSateId()
-      {
-         return iItemStateId;
-      }
-
-      public int getValueDataId()
-      {
-         return iValueDataId;
-      }
-
-      public boolean compare(FixupStream fs)
-      {
-         boolean b = true;
-         if (fs.getItemSateId() != this.getItemSateId())
-            b = false;
-         if (fs.getValueDataId() != this.getValueDataId())
-            b = false;
-         return b;
-      }
-
-      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
-      {
-         iItemStateId = in.readInt();
-         iValueDataId = in.readInt();
-      }
-
-      public void writeExternal(ObjectOutput out) throws IOException
-      {
-         out.writeInt(iItemStateId);
-         out.writeInt(iValueDataId);
-      }
-   }
-}

Copied: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/JCRRestore.java (from rev 4323, jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/JCRRestor.java)
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/JCRRestore.java	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/JCRRestore.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -0,0 +1,448 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * 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.exoplatform.services.jcr.impl.backup;
+
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
+import org.exoplatform.commons.utils.PrivilegedSystemHelper;
+import org.exoplatform.services.jcr.dataflow.ChangesLogIterator;
+import org.exoplatform.services.jcr.dataflow.DataManager;
+import org.exoplatform.services.jcr.dataflow.ItemState;
+import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
+import org.exoplatform.services.jcr.dataflow.PlainChangesLogImpl;
+import org.exoplatform.services.jcr.dataflow.TransactionChangesLog;
+import org.exoplatform.services.jcr.dataflow.persistent.PersistedPropertyData;
+import org.exoplatform.services.jcr.datamodel.ItemData;
+import org.exoplatform.services.jcr.datamodel.ValueData;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.StreamPersistedValueData;
+import org.exoplatform.services.jcr.impl.storage.JCRInvalidItemStateException;
+import org.exoplatform.services.jcr.impl.storage.JCRItemExistsException;
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.io.SpoolFile;
+import org.exoplatform.services.jcr.observation.ExtendedEvent;
+
+import java.io.EOFException;
+import java.io.Externalizable;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * Date: 24 01 2011
+ * 
+ * Class contains commons method for JCR restore operation.
+ * - get path to full backup<br>
+ * - get list of incremental backup files<br>
+ * - perform incremental restore function<br>
+ * 
+ * @author <a href="mailto:anatoliy.bazko at exoplatform.com.ua">Anatoliy Bazko</a>
+ * @version $Id: JCRRestore.java 34360 2010-11-11 11:11:11Z tolusha $
+ */
+public class JCRRestore
+{
+
+   private final DataManager dataManager;
+
+   private final FileCleaner fileCleaner;
+
+   private final File tempDir = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
+
+   public JCRRestore(DataManager dataManager, FileCleaner fileCleaner)
+   {
+      this.dataManager = dataManager;
+      this.fileCleaner = fileCleaner;
+   }
+
+   /**
+    * Returns file with full backup. In case of RDBMS backup 
+    * it may be a directory. 
+    *  
+    * @param restoreDir
+    * @return
+    */
+   public static File getFullBackupFile(File restoreDir)
+   {
+      Pattern p = Pattern.compile(".+\\.0");
+
+      for (File f : PrivilegedFileHelper.listFiles(restoreDir, new FileFilter()
+      {
+         public boolean accept(File pathname)
+         {
+            Pattern p = Pattern.compile(".+\\.[0-9]+");
+            Matcher m = p.matcher(pathname.getName());
+            return m.matches();
+         }
+      }))
+      {
+         Matcher m = p.matcher(f.getName());
+         if (m.matches())
+         {
+            return f;
+         }
+      }
+
+      return null;
+   }
+
+   /**
+    * Get list of incremental backup files.
+    *  
+    * @param restoreDir
+    * @return list of files
+    */
+   public static List<File> getIncrementalFiles(File restoreDir)
+   {
+      ArrayList<File> list = new ArrayList<File>();
+
+      Pattern fullBackupPattern = Pattern.compile(".+\\.0");
+
+      for (File f : PrivilegedFileHelper.listFiles(restoreDir, new FileFilter()
+      {
+         public boolean accept(File pathname)
+         {
+            Pattern p = Pattern.compile(".+\\.[0-9]+");
+            Matcher m = p.matcher(pathname.getName());
+            return m.matches();
+         }
+      }))
+      {
+         if (fullBackupPattern.matcher(f.getName()).matches() == false)
+         {
+            list.add(f);
+         }
+      }
+
+      return list;
+   }
+
+   /**
+    * Perform incremental restore operation.
+    * 
+    * @param incrementalBackupFile
+    *          incremental backup file
+    * @throws FileNotFoundException
+    * @throws IOException
+    * @throws ClassNotFoundException
+    * @throws RepositoryException
+    */
+   public void incrementalRestore(File incrementalBackupFile) throws FileNotFoundException, IOException,
+      ClassNotFoundException, RepositoryException
+   {
+      ObjectInputStream ois = null;
+      try
+      {
+         ois = new ObjectInputStream(PrivilegedFileHelper.fileInputStream(incrementalBackupFile));
+
+         while (true)
+         {
+            TransactionChangesLog changesLog = readExternal(ois);
+            changesLog.setSystemId(Constants.JCR_CORE_RESTORE_WORKSPACE_INITIALIZER_SYSTEM_ID); // mark changes
+
+            ChangesLogIterator cli = changesLog.getLogIterator();
+            while (cli.hasNextLog())
+            {
+               if (cli.nextLog().getEventType() == ExtendedEvent.LOCK)
+                  cli.removeLog();
+            }
+
+            saveChangesLog(changesLog);
+         }
+      }
+      catch (EOFException ioe)
+      {
+         // ok - reading all data from backup file;
+      }
+   }
+
+   private void saveChangesLog(TransactionChangesLog changesLog) throws RepositoryException
+   {
+      try
+      {
+         dataManager.save(changesLog);
+      }
+      catch (JCRInvalidItemStateException e)
+      {
+         TransactionChangesLog normalizeChangesLog =
+            getNormalizedChangesLog(e.getIdentifier(), e.getState(), changesLog);
+         if (normalizeChangesLog != null)
+            saveChangesLog(normalizeChangesLog);
+         else
+            throw new RepositoryException(
+               "Collisions found during save of restore changes log, but caused item is not found by ID "
+                  + e.getIdentifier() + ". " + e, e);
+      }
+      catch (JCRItemExistsException e)
+      {
+         TransactionChangesLog normalizeChangesLog =
+            getNormalizedChangesLog(e.getIdentifier(), e.getState(), changesLog);
+         if (normalizeChangesLog != null)
+            saveChangesLog(normalizeChangesLog);
+         else
+            throw new RepositoryException(
+               "Collisions found during save of restore changes log, but caused item is not found by ID "
+                  + e.getIdentifier() + ". " + e, e);
+      }
+   }
+
+   private TransactionChangesLog getNormalizedChangesLog(String collisionID, int state, TransactionChangesLog changesLog)
+   {
+      ItemState citem = changesLog.getItemState(collisionID);
+
+      if (citem != null)
+      {
+
+         TransactionChangesLog result = new TransactionChangesLog();
+         result.setSystemId(changesLog.getSystemId());
+
+         ChangesLogIterator cli = changesLog.getLogIterator();
+         while (cli.hasNextLog())
+         {
+            ArrayList<ItemState> normalized = new ArrayList<ItemState>();
+            PlainChangesLog next = cli.nextLog();
+            for (ItemState change : next.getAllStates())
+            {
+               if (state == change.getState())
+               {
+                  ItemData item = change.getData();
+                  // targeted state
+                  if (citem.isNode())
+                  {
+                     // Node... by ID and desc path
+                     if (!item.getIdentifier().equals(collisionID)
+                        && !item.getQPath().isDescendantOf(citem.getData().getQPath()))
+                        normalized.add(change);
+                  }
+                  else if (!item.getIdentifier().equals(collisionID))
+                  {
+                     // Property... by ID
+                     normalized.add(change);
+                  }
+               }
+               else
+                  // another state
+                  normalized.add(change);
+            }
+
+            PlainChangesLog plog = new PlainChangesLogImpl(normalized, next.getSessionId(), next.getEventType());
+            result.addLog(plog);
+         }
+
+         return result;
+      }
+
+      return null;
+   }
+
+   private TransactionChangesLog readExternal(ObjectInputStream in) throws IOException, ClassNotFoundException
+   {
+      int changesLogType = in.readInt();
+
+      TransactionChangesLog transactionChangesLog = null;
+
+      if (changesLogType == RestoreChangesLog.Type.ItemDataChangesLog_with_Streams)
+      {
+
+         // read ChangesLog
+         transactionChangesLog = (TransactionChangesLog)in.readObject();
+
+         // read FixupStream count
+         int iFixupStream = in.readInt();
+
+         ArrayList<FixupStream> listFixupStreams = new ArrayList<FixupStream>();
+
+         for (int i = 0; i < iFixupStream; i++)
+         {
+            FixupStream fs = new FixupStream();
+            fs.readExternal(in);
+            listFixupStreams.add(fs);
+         }
+
+         // read stream data
+         int iStreamCount = in.readInt();
+         ArrayList<SpoolFile> listFiles = new ArrayList<SpoolFile>();
+
+         for (int i = 0; i < iStreamCount; i++)
+         {
+
+            // read file size
+            long fileSize = in.readLong();
+
+            // read content file
+            listFiles.add(getAsFile(in, fileSize));
+         }
+
+         RestoreChangesLog restoreChangesLog =
+            new RestoreChangesLog(transactionChangesLog, listFixupStreams, listFiles, fileCleaner);
+
+         restoreChangesLog.restore();
+
+      }
+      else if (changesLogType == RestoreChangesLog.Type.ItemDataChangesLog_without_Streams)
+      {
+         transactionChangesLog = (TransactionChangesLog)in.readObject();
+      }
+
+      return transactionChangesLog;
+   }
+
+   private SpoolFile getAsFile(ObjectInputStream ois, long fileSize) throws IOException
+   {
+      int bufferSize = 1024 * 8;
+      byte[] buf = new byte[bufferSize];
+
+      SpoolFile tempFile = SpoolFile.createTempFile("vdincb" + System.currentTimeMillis(), ".stmp", tempDir);
+      FileOutputStream fos = PrivilegedFileHelper.fileOutputStream(tempFile);
+      long readBytes = fileSize;
+
+      while (readBytes > 0)
+      {
+         // long longTemp = readByte - bufferSize;
+         if (readBytes >= bufferSize)
+         {
+            ois.readFully(buf);
+            fos.write(buf);
+         }
+         else if (readBytes < bufferSize)
+         {
+            ois.readFully(buf, 0, (int)readBytes);
+            fos.write(buf, 0, (int)readBytes);
+         }
+         readBytes -= bufferSize;
+      }
+
+      fos.flush();
+      fos.close();
+
+      return tempFile;
+   }
+
+   class RestoreChangesLog
+   {
+      public class Type
+      {
+         public static final int ItemDataChangesLog_without_Streams = 1;
+
+         public static final int ItemDataChangesLog_with_Streams = 2;
+      }
+
+      private TransactionChangesLog itemDataChangesLog;
+
+      private List<FixupStream> listFixupStream;
+
+      private List<SpoolFile> listFile;
+
+      private FileCleaner fileCleaner;
+
+      public RestoreChangesLog(TransactionChangesLog transactionChangesLog, List<FixupStream> listFixupStreams,
+         List<SpoolFile> listFiles, FileCleaner fileCleaner)
+      {
+         this.itemDataChangesLog = transactionChangesLog;
+         this.listFixupStream = listFixupStreams;
+         this.listFile = listFiles;
+         this.fileCleaner = fileCleaner;
+      }
+
+      public TransactionChangesLog getItemDataChangesLog()
+      {
+         return itemDataChangesLog;
+      }
+
+      public void restore() throws IOException
+      {
+         List<ItemState> listItemState = itemDataChangesLog.getAllStates();
+         for (int i = 0; i < this.listFixupStream.size(); i++)
+         {
+            ItemState itemState = listItemState.get(listFixupStream.get(i).getItemSateId());
+            ItemData itemData = itemState.getData();
+
+            PersistedPropertyData propertyData = (PersistedPropertyData)itemData;
+            ValueData vd = (propertyData.getValues().get(listFixupStream.get(i).getValueDataId()));
+
+            // re-init the value
+            propertyData.getValues().set(listFixupStream.get(i).getValueDataId(),
+               new StreamPersistedValueData(vd.getOrderNumber(), listFile.get(i)));
+         }
+
+         for (int i = 0; i < listFile.size(); i++)
+            fileCleaner.addFile(listFile.get(i));
+      }
+   }
+
+   class FixupStream implements Externalizable
+   {
+      int iItemStateId = -1;
+
+      int iValueDataId = -1;
+
+      public FixupStream()
+      {
+      }
+
+      public FixupStream(int itemState_, int valueData_)
+      {
+         iItemStateId = itemState_;
+         iValueDataId = valueData_;
+      }
+
+      public int getItemSateId()
+      {
+         return iItemStateId;
+      }
+
+      public int getValueDataId()
+      {
+         return iValueDataId;
+      }
+
+      public boolean compare(FixupStream fs)
+      {
+         boolean b = true;
+         if (fs.getItemSateId() != this.getItemSateId())
+            b = false;
+         if (fs.getValueDataId() != this.getValueDataId())
+            b = false;
+         return b;
+      }
+
+      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+      {
+         iItemStateId = in.readInt();
+         iValueDataId = in.readInt();
+      }
+
+      public void writeExternal(ObjectOutput out) throws IOException
+      {
+         out.writeInt(iItemStateId);
+         out.writeInt(iValueDataId);
+      }
+   }
+}

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/JdbcBackupable.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/JdbcBackupable.java	2011-04-28 11:48:05 UTC (rev 4324)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/JdbcBackupable.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -38,6 +38,6 @@
     * @throws RestoreException
     *          if any exception occurred
     */
-   DataRestor getDataRestorer(File storageDir, Connection jdbcConn) throws BackupException;
+   DataRestore getDataRestorer(File storageDir, Connection jdbcConn) throws BackupException;
 
 }

Deleted: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestor.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestor.java	2011-04-28 11:48:05 UTC (rev 4324)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestor.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -1,657 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * 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.exoplatform.services.jcr.impl.backup.rdbms;
-
-import org.exoplatform.commons.utils.PrivilegedFileHelper;
-import org.exoplatform.commons.utils.PrivilegedSystemHelper;
-import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
-import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
-import org.exoplatform.services.jcr.dataflow.serialization.ObjectReader;
-import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.backup.BackupException;
-import org.exoplatform.services.jcr.impl.backup.DataRestor;
-import org.exoplatform.services.jcr.impl.clean.rdbms.DBClean;
-import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanService;
-import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectZipReaderImpl;
-import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
-import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
-import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
-import java.io.ByteArrayInputStream;
-import java.io.EOFException;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Types;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import javax.naming.NamingException;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * Date: 22 01 2011
- * 
- * @author <a href="mailto:anatoliy.bazko at exoplatform.com.ua">Anatoliy Bazko</a>
- * @version $Id: DBRestor.java 34360 2010-11-11 11:11:11Z tolusha $
- */
-public class DBRestor implements DataRestor
-{
-   /**
-    * The maximum possible batch size.
-    */
-   private final int MAXIMUM_BATCH_SIZE = 1000;
-
-   /**
-    * List of temporary files.
-    */
-   private final List<File> spoolFileList = new ArrayList<File>();
-
-   /**
-    *  The file cleaner.
-    */
-   private final FileCleaner fileCleaner;
-
-   /**
-    * Temporary directory.
-    */
-   private final File tempDir = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
-
-   /**
-    * Maximum buffer size.
-    */
-   private final int maxBufferSize;
-
-   /**
-    * Logger.
-    */
-   protected static final Log LOG = ExoLogger.getLogger("exo.jcr.component.core.DBRestor");
-
-   /**
-    * Connection to database.
-    */
-   private final Connection jdbcConn;
-
-   /**
-    * Directory with tables dump.
-    */
-   private final File storageDir;
-
-   /**
-    * Restore table rules.
-    */
-   private final Map<String, RestoreTableRule> tables;
-
-   /**
-    * Database cleaner.
-    */
-   private final DBClean dbClean;
-
-   /**
-    * Constructor DBRestor.
-    * 
-    * @throws NamingException 
-    * @throws SQLException 
-    * @throws RepositoryConfigurationException 
-    */
-   public DBRestor(File storageDir, Connection jdbcConn, Map<String, RestoreTableRule> tables,
-      WorkspaceEntry wsConfig, FileCleaner fileCleaner) throws NamingException, SQLException,
-      RepositoryConfigurationException
-   {
-      this.jdbcConn = jdbcConn;
-      this.fileCleaner = fileCleaner;
-      this.maxBufferSize =
-         wsConfig.getContainer().getParameterInteger(JDBCWorkspaceDataContainer.MAXBUFFERSIZE_PROP,
-            JDBCWorkspaceDataContainer.DEF_MAXBUFFERSIZE);
-
-      this.storageDir = storageDir;
-      this.tables = tables;
-      this.dbClean = DBCleanService.getDBCleaner(this.jdbcConn, wsConfig);
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void clean() throws BackupException
-   {
-      try
-      {
-         dbClean.clean();
-      }
-      catch (SQLException e)
-      {
-         throw new BackupException(e);
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void restore() throws BackupException
-   {
-      Statement st = null;
-
-      try
-      {
-         int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
-
-         for (Entry<String, RestoreTableRule> entry : tables.entrySet())
-         {
-            String tableName = entry.getKey();
-            RestoreTableRule restoreRule = entry.getValue();
-
-            String constraint = null;
-            if (tableName.equals("JCR_SITEM") || tableName.equals("JCR_MITEM"))
-            {
-               if (dialect != DBBackup.DB_DIALECT_SYBASE)
-               {
-                  // resolve constraint name depends on database
-                  String constraintName;
-                  if (dialect == DBBackup.DB_DIALECT_DB2 || dialect == DBBackup.DB_DIALECT_DB2V8)
-                  {
-                     constraintName = "JCR_FK_" + (restoreRule.getDstMultiDb() ? "M" : "S") + "ITEM_PAREN";
-                  }
-                  else
-                  {
-                     constraintName = "JCR_FK_" + (restoreRule.getDstMultiDb() ? "M" : "S") + "ITEM_PARENT";
-                  }
-                  constraint =
-                     "CONSTRAINT " + constraintName + " FOREIGN KEY(PARENT_ID) REFERENCES " + tableName + "(ID)";
-
-                  // drop constraint
-                  st = jdbcConn.createStatement();
-
-                  if (dialect == DBBackup.DB_DIALECT_MYSQL || dialect == DBBackup.DB_DIALECT_MYSQL_UTF8)
-                  {
-                     st.execute("ALTER TABLE " + tableName + " DROP FOREIGN KEY " + constraintName);
-                  }
-                  else
-                  {
-                     st.execute("ALTER TABLE " + tableName + " DROP CONSTRAINT " + constraintName);
-                  }
-               }
-            }
-
-            restoreTable(storageDir, jdbcConn, tableName, restoreRule);
-
-            if (constraint != null)
-            {
-               // add constraint
-               st.execute("ALTER TABLE " + tableName + " ADD " + constraint);
-            }
-         }
-      }
-      catch (IOException e)
-      {
-         throw new BackupException(e);
-      }
-      catch (SQLException e)
-      {
-         SQLException next = e.getNextException();
-         String errorTrace = "";
-         while (next != null)
-         {
-            errorTrace += next.getMessage() + "; ";
-            next = next.getNextException();
-         }
-
-         Throwable cause = e.getCause();
-         String msg = "SQL Exception: " + errorTrace + (cause != null ? " (Cause: " + cause.getMessage() + ")" : "");
-
-         throw new BackupException(msg, e);
-      }
-      finally
-      {
-         if (st != null)
-         {
-            try
-            {
-               st.close();
-            }
-            catch (SQLException e)
-            {
-               LOG.warn("Can't close statemnt", e);
-            }
-         }
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void commit() throws BackupException
-   {
-      try
-      {
-         jdbcConn.commit();
-      }
-      catch (SQLException e)
-      {
-         throw new BackupException(e);
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void rollback() throws BackupException
-   {
-      try
-      {
-         jdbcConn.rollback();
-      }
-      catch (SQLException e)
-      {
-         throw new BackupException(e);
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void close() throws BackupException
-   {
-      try
-      {
-         // in case for shared connection
-         if (!jdbcConn.isClosed())
-         {
-            jdbcConn.close();
-         }
-      }
-      catch (SQLException e)
-      {
-         throw new BackupException(e);
-      }
-   }
-
-   /**
-    * Restore table.
-    */
-   private void restoreTable(File storageDir, Connection jdbcConn, String tableName, RestoreTableRule restoreRule)
-      throws IOException, SQLException
-   {
-      // Need privileges
-      SecurityManager security = System.getSecurityManager();
-      if (security != null)
-      {
-         security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
-      }
-
-      ObjectZipReaderImpl contentReader = null;
-      ObjectZipReaderImpl contentLenReader = null;
-
-      PreparedStatement insertNode = null;
-      ResultSet tableMetaData = null;
-
-      int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
-
-      // switch table name to lower case
-      if (dialect == DBBackup.DB_DIALECT_PGSQL)
-      {
-         tableName = tableName.toLowerCase();
-      }
-
-      try
-      {
-         contentReader = new ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(restoreRule.getContentFile()));
-         contentReader.getNextEntry();
-
-         contentLenReader =
-            new ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(restoreRule.getContentLenFile()));
-         contentLenReader.getNextEntry();
-
-         // get information about source table
-         int sourceColumnCount = contentReader.readInt();
-
-         List<Integer> columnType = new ArrayList<Integer>();
-         List<String> columnName = new ArrayList<String>();
-
-         for (int i = 0; i < sourceColumnCount; i++)
-         {
-            columnType.add(contentReader.readInt());
-            columnName.add(contentReader.readString());
-         }
-
-         int targetColumnCount = sourceColumnCount;
-         if (restoreRule.getDeleteColumnIndex() != null)
-         {
-            targetColumnCount--;
-         }
-         else if (restoreRule.getNewColumnIndex() != null)
-         {
-            targetColumnCount++;
-
-            columnType.add(restoreRule.getNewColumnIndex(), restoreRule.getNewColumnType());
-
-            String newColumnName =
-               dialect == DBBackup.DB_DIALECT_PGSQL ? restoreRule.getNewColumnName().toLowerCase() : restoreRule
-                  .getNewColumnName();
-            columnName.add(restoreRule.getNewColumnIndex(), newColumnName);
-         }
-
-         // construct statement
-         String names = "";
-         String parameters = "";
-         for (int i = 0; i < targetColumnCount; i++)
-         {
-            if (restoreRule.getSkipColumnIndex() != null && restoreRule.getSkipColumnIndex() == i)
-            {
-               continue;
-            }
-            names += columnName.get(i) + (i == targetColumnCount - 1 ? "" : ",");
-            parameters += "?" + (i == targetColumnCount - 1 ? "" : ",");
-         }
-
-         int batchSize = 0;
-         insertNode =
-            jdbcConn.prepareStatement("INSERT INTO " + tableName + " (" + names + ") VALUES(" + parameters + ")");
-
-         // set data
-         outer : while (true)
-         {
-            for (int i = 0, targetIndex = 0; i < columnType.size(); i++, targetIndex++)
-            {
-               InputStream stream;
-               long len;
-
-               if (restoreRule.getNewColumnIndex() != null && restoreRule.getNewColumnIndex() == i)
-               {
-                  stream =
-                     new ByteArrayInputStream(restoreRule.getDstContainerName().getBytes(Constants.DEFAULT_ENCODING));
-                  len = ((ByteArrayInputStream)stream).available();
-               }
-               else
-               {
-                  try
-                  {
-                     len = contentLenReader.readLong();
-                  }
-                  catch (EOFException e)
-                  {
-                     if (i == 0)
-                     {
-                        // content length file is empty check content file
-                        try
-                        {
-                           contentReader.readByte();
-                        }
-                        catch (EOFException e1)
-                        {
-                           break outer;
-                        }
-                     }
-
-                     throw new IOException("Content length file is empty but content still present", e);
-                  }
-                  stream = len == -1 ? null : spoolInputStream(contentReader, len);
-               }
-
-               if (restoreRule.getSkipColumnIndex() != null && restoreRule.getSkipColumnIndex() == i)
-               {
-                  targetIndex--;
-                  continue;
-               }
-               else if (restoreRule.getDeleteColumnIndex() != null && restoreRule.getDeleteColumnIndex() == i)
-               {
-                  targetIndex--;
-                  continue;
-               }
-
-               // set 
-               if (stream != null)
-               {
-                  if (restoreRule.getConvertColumnIndex() != null && restoreRule.getConvertColumnIndex().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))
-                     {
-                        stream = new ByteArrayInputStream(Constants.ROOT_PARENT_UUID.getBytes());
-                     }
-                     else
-                     {
-                        if (restoreRule.getDstMultiDb())
-                        {
-                           if (!restoreRule.getSrcMultiDb())
-                           {
-                              stream =
-                                 new ByteArrayInputStream(new String(readBuffer, Constants.DEFAULT_ENCODING).substring(
-                                    restoreRule.getSrcContainerName().length()).getBytes());
-                           }
-                        }
-                        else
-                        {
-                           if (restoreRule.getSrcMultiDb())
-                           {
-                              StringBuilder builder = new StringBuilder();
-                              builder.append(restoreRule.getDstContainerName());
-                              builder.append(currentValue);
-
-                              stream = new ByteArrayInputStream(builder.toString().getBytes());
-                           }
-                           else
-                           {
-                              StringBuilder builder = new StringBuilder();
-                              builder.append(restoreRule.getDstContainerName());
-                              builder.append(new String(readBuffer, Constants.DEFAULT_ENCODING).substring(restoreRule
-                                 .getSrcContainerName().length()));
-
-                              stream = new ByteArrayInputStream(builder.toString().getBytes());
-                           }
-                        }
-                     }
-
-                     len = ((ByteArrayInputStream)stream).available();
-                  }
-
-                  if (columnType.get(i) == Types.INTEGER || columnType.get(i) == Types.BIGINT
-                     || columnType.get(i) == Types.SMALLINT || columnType.get(i) == Types.TINYINT)
-                  {
-                     ByteArrayInputStream ba = (ByteArrayInputStream)stream;
-                     byte[] readBuffer = new byte[ba.available()];
-                     ba.read(readBuffer);
-
-                     String value = new String(readBuffer, Constants.DEFAULT_ENCODING);
-                     insertNode.setLong(targetIndex + 1, Integer.parseInt(value));
-                  }
-                  else if (columnType.get(i) == Types.BIT)
-                  {
-                     ByteArrayInputStream ba = (ByteArrayInputStream)stream;
-                     byte[] readBuffer = new byte[ba.available()];
-                     ba.read(readBuffer);
-
-                     String value = new String(readBuffer);
-                     if (dialect == DBBackup.DB_DIALECT_PGSQL)
-                     {
-                        insertNode.setBoolean(targetIndex + 1, value.equals("t"));
-                     }
-                     else
-                     {
-                        insertNode.setBoolean(targetIndex + 1, value.equals("1"));
-                     }
-                  }
-                  else if (columnType.get(i) == Types.BOOLEAN)
-                  {
-                     ByteArrayInputStream ba = (ByteArrayInputStream)stream;
-                     byte[] readBuffer = new byte[ba.available()];
-                     ba.read(readBuffer);
-
-                     String value = new String(readBuffer);
-                     insertNode.setBoolean(targetIndex + 1, value.equals("true"));
-                  }
-                  else if (columnType.get(i) == Types.VARBINARY || columnType.get(i) == Types.LONGVARBINARY
-                     || columnType.get(i) == Types.BLOB || columnType.get(i) == Types.BINARY
-                     || columnType.get(i) == Types.OTHER)
-                  {
-                     insertNode.setBinaryStream(targetIndex + 1, stream, (int)len);
-                  }
-                  else
-                  {
-                     byte[] readBuffer = new byte[(int)len];
-                     stream.read(readBuffer);
-
-                     insertNode.setString(targetIndex + 1, new String(readBuffer, Constants.DEFAULT_ENCODING));
-                  }
-               }
-               else
-               {
-                  insertNode.setNull(targetIndex + 1, columnType.get(i));
-               }
-            }
-
-            // add statement to batch
-            insertNode.addBatch();
-
-            if (++batchSize == MAXIMUM_BATCH_SIZE)
-            {
-               insertNode.executeBatch();
-               batchSize = 0;
-            }
-         }
-
-         if (batchSize != 0)
-         {
-            insertNode.executeBatch();
-         }
-      }
-      finally
-      {
-         if (contentReader != null)
-         {
-            contentReader.close();
-         }
-
-         if (contentLenReader != null)
-         {
-            contentLenReader.close();
-         }
-
-         if (insertNode != null)
-         {
-            insertNode.close();
-         }
-
-         // delete all temporary files
-         for (File file : spoolFileList)
-         {
-            if (!PrivilegedFileHelper.delete(file))
-            {
-               fileCleaner.addFile(file);
-            }
-         }
-
-         if (tableMetaData != null)
-         {
-            tableMetaData.close();
-         }
-      }
-   }
-
-   /**
-    * Spool input stream.
-    */
-   private InputStream spoolInputStream(ObjectReader in, long contentLen) throws IOException
-   {
-      byte[] buffer = new byte[0];
-      byte[] tmpBuff;
-      long readLen = 0;
-      File sf = null;
-      OutputStream sfout = null;
-
-      try
-      {
-         while (true)
-         {
-            int needToRead = contentLen - readLen > 2048 ? 2048 : (int)(contentLen - readLen);
-            tmpBuff = new byte[needToRead];
-
-            if (needToRead == 0)
-            {
-               break;
-            }
-
-            in.readFully(tmpBuff);
-
-            if (sfout != null)
-            {
-               sfout.write(tmpBuff);
-            }
-            else if (readLen + needToRead > maxBufferSize && fileCleaner != null)
-            {
-               sf = PrivilegedFileHelper.createTempFile("jcrvd", null, tempDir);
-               sfout = PrivilegedFileHelper.fileOutputStream(sf);
-
-               sfout.write(buffer);
-               sfout.write(tmpBuff);
-               buffer = null;
-            }
-            else
-            {
-               // reallocate new buffer and spool old buffer contents
-               byte[] newBuffer = new byte[(int)(readLen + needToRead)];
-               System.arraycopy(buffer, 0, newBuffer, 0, (int)readLen);
-               System.arraycopy(tmpBuff, 0, newBuffer, (int)readLen, needToRead);
-               buffer = newBuffer;
-            }
-
-            readLen += needToRead;
-         }
-
-         if (buffer != null)
-         {
-            return new ByteArrayInputStream(buffer);
-         }
-         else
-         {
-            return PrivilegedFileHelper.fileInputStream(sf);
-         }
-      }
-      finally
-      {
-         if (sfout != null)
-         {
-            sfout.close();
-         }
-
-         if (sf != null)
-         {
-            spoolFileList.add(sf);
-         }
-      }
-   }
-}
-
-

Copied: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestore.java (from rev 4323, jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestor.java)
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestore.java	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestore.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -0,0 +1,657 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * 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.exoplatform.services.jcr.impl.backup.rdbms;
+
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
+import org.exoplatform.commons.utils.PrivilegedSystemHelper;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
+import org.exoplatform.services.jcr.dataflow.serialization.ObjectReader;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.backup.BackupException;
+import org.exoplatform.services.jcr.impl.backup.DataRestore;
+import org.exoplatform.services.jcr.impl.clean.rdbms.DBClean;
+import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanService;
+import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectZipReaderImpl;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.io.ByteArrayInputStream;
+import java.io.EOFException;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.naming.NamingException;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * Date: 22 01 2011
+ * 
+ * @author <a href="mailto:anatoliy.bazko at exoplatform.com.ua">Anatoliy Bazko</a>
+ * @version $Id: DBRestor.java 34360 2010-11-11 11:11:11Z tolusha $
+ */
+public class DBRestore implements DataRestore
+{
+   /**
+    * The maximum possible batch size.
+    */
+   private final int MAXIMUM_BATCH_SIZE = 1000;
+
+   /**
+    * List of temporary files.
+    */
+   private final List<File> spoolFileList = new ArrayList<File>();
+
+   /**
+    *  The file cleaner.
+    */
+   private final FileCleaner fileCleaner;
+
+   /**
+    * Temporary directory.
+    */
+   private final File tempDir = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
+
+   /**
+    * Maximum buffer size.
+    */
+   private final int maxBufferSize;
+
+   /**
+    * Logger.
+    */
+   protected static final Log LOG = ExoLogger.getLogger("exo.jcr.component.core.DBRestor");
+
+   /**
+    * Connection to database.
+    */
+   private final Connection jdbcConn;
+
+   /**
+    * Directory with tables dump.
+    */
+   private final File storageDir;
+
+   /**
+    * Restore table rules.
+    */
+   private final Map<String, RestoreTableRule> tables;
+
+   /**
+    * Database cleaner.
+    */
+   private final DBClean dbClean;
+
+   /**
+    * Constructor DBRestor.
+    * 
+    * @throws NamingException 
+    * @throws SQLException 
+    * @throws RepositoryConfigurationException 
+    */
+   public DBRestore(File storageDir, Connection jdbcConn, Map<String, RestoreTableRule> tables,
+      WorkspaceEntry wsConfig, FileCleaner fileCleaner) throws NamingException, SQLException,
+      RepositoryConfigurationException
+   {
+      this.jdbcConn = jdbcConn;
+      this.fileCleaner = fileCleaner;
+      this.maxBufferSize =
+         wsConfig.getContainer().getParameterInteger(JDBCWorkspaceDataContainer.MAXBUFFERSIZE_PROP,
+            JDBCWorkspaceDataContainer.DEF_MAXBUFFERSIZE);
+
+      this.storageDir = storageDir;
+      this.tables = tables;
+      this.dbClean = DBCleanService.getDBCleaner(this.jdbcConn, wsConfig);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void clean() throws BackupException
+   {
+      try
+      {
+         dbClean.clean();
+      }
+      catch (SQLException e)
+      {
+         throw new BackupException(e);
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void restore() throws BackupException
+   {
+      Statement st = null;
+
+      try
+      {
+         int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
+
+         for (Entry<String, RestoreTableRule> entry : tables.entrySet())
+         {
+            String tableName = entry.getKey();
+            RestoreTableRule restoreRule = entry.getValue();
+
+            String constraint = null;
+            if (tableName.equals("JCR_SITEM") || tableName.equals("JCR_MITEM"))
+            {
+               if (dialect != DBBackup.DB_DIALECT_SYBASE)
+               {
+                  // resolve constraint name depends on database
+                  String constraintName;
+                  if (dialect == DBBackup.DB_DIALECT_DB2 || dialect == DBBackup.DB_DIALECT_DB2V8)
+                  {
+                     constraintName = "JCR_FK_" + (restoreRule.getDstMultiDb() ? "M" : "S") + "ITEM_PAREN";
+                  }
+                  else
+                  {
+                     constraintName = "JCR_FK_" + (restoreRule.getDstMultiDb() ? "M" : "S") + "ITEM_PARENT";
+                  }
+                  constraint =
+                     "CONSTRAINT " + constraintName + " FOREIGN KEY(PARENT_ID) REFERENCES " + tableName + "(ID)";
+
+                  // drop constraint
+                  st = jdbcConn.createStatement();
+
+                  if (dialect == DBBackup.DB_DIALECT_MYSQL || dialect == DBBackup.DB_DIALECT_MYSQL_UTF8)
+                  {
+                     st.execute("ALTER TABLE " + tableName + " DROP FOREIGN KEY " + constraintName);
+                  }
+                  else
+                  {
+                     st.execute("ALTER TABLE " + tableName + " DROP CONSTRAINT " + constraintName);
+                  }
+               }
+            }
+
+            restoreTable(storageDir, jdbcConn, tableName, restoreRule);
+
+            if (constraint != null)
+            {
+               // add constraint
+               st.execute("ALTER TABLE " + tableName + " ADD " + constraint);
+            }
+         }
+      }
+      catch (IOException e)
+      {
+         throw new BackupException(e);
+      }
+      catch (SQLException e)
+      {
+         SQLException next = e.getNextException();
+         String errorTrace = "";
+         while (next != null)
+         {
+            errorTrace += next.getMessage() + "; ";
+            next = next.getNextException();
+         }
+
+         Throwable cause = e.getCause();
+         String msg = "SQL Exception: " + errorTrace + (cause != null ? " (Cause: " + cause.getMessage() + ")" : "");
+
+         throw new BackupException(msg, e);
+      }
+      finally
+      {
+         if (st != null)
+         {
+            try
+            {
+               st.close();
+            }
+            catch (SQLException e)
+            {
+               LOG.warn("Can't close statemnt", e);
+            }
+         }
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void commit() throws BackupException
+   {
+      try
+      {
+         jdbcConn.commit();
+      }
+      catch (SQLException e)
+      {
+         throw new BackupException(e);
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void rollback() throws BackupException
+   {
+      try
+      {
+         jdbcConn.rollback();
+      }
+      catch (SQLException e)
+      {
+         throw new BackupException(e);
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void close() throws BackupException
+   {
+      try
+      {
+         // in case for shared connection
+         if (!jdbcConn.isClosed())
+         {
+            jdbcConn.close();
+         }
+      }
+      catch (SQLException e)
+      {
+         throw new BackupException(e);
+      }
+   }
+
+   /**
+    * Restore table.
+    */
+   private void restoreTable(File storageDir, Connection jdbcConn, String tableName, RestoreTableRule restoreRule)
+      throws IOException, SQLException
+   {
+      // Need privileges
+      SecurityManager security = System.getSecurityManager();
+      if (security != null)
+      {
+         security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
+      }
+
+      ObjectZipReaderImpl contentReader = null;
+      ObjectZipReaderImpl contentLenReader = null;
+
+      PreparedStatement insertNode = null;
+      ResultSet tableMetaData = null;
+
+      int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
+
+      // switch table name to lower case
+      if (dialect == DBBackup.DB_DIALECT_PGSQL)
+      {
+         tableName = tableName.toLowerCase();
+      }
+
+      try
+      {
+         contentReader = new ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(restoreRule.getContentFile()));
+         contentReader.getNextEntry();
+
+         contentLenReader =
+            new ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(restoreRule.getContentLenFile()));
+         contentLenReader.getNextEntry();
+
+         // get information about source table
+         int sourceColumnCount = contentReader.readInt();
+
+         List<Integer> columnType = new ArrayList<Integer>();
+         List<String> columnName = new ArrayList<String>();
+
+         for (int i = 0; i < sourceColumnCount; i++)
+         {
+            columnType.add(contentReader.readInt());
+            columnName.add(contentReader.readString());
+         }
+
+         int targetColumnCount = sourceColumnCount;
+         if (restoreRule.getDeleteColumnIndex() != null)
+         {
+            targetColumnCount--;
+         }
+         else if (restoreRule.getNewColumnIndex() != null)
+         {
+            targetColumnCount++;
+
+            columnType.add(restoreRule.getNewColumnIndex(), restoreRule.getNewColumnType());
+
+            String newColumnName =
+               dialect == DBBackup.DB_DIALECT_PGSQL ? restoreRule.getNewColumnName().toLowerCase() : restoreRule
+                  .getNewColumnName();
+            columnName.add(restoreRule.getNewColumnIndex(), newColumnName);
+         }
+
+         // construct statement
+         String names = "";
+         String parameters = "";
+         for (int i = 0; i < targetColumnCount; i++)
+         {
+            if (restoreRule.getSkipColumnIndex() != null && restoreRule.getSkipColumnIndex() == i)
+            {
+               continue;
+            }
+            names += columnName.get(i) + (i == targetColumnCount - 1 ? "" : ",");
+            parameters += "?" + (i == targetColumnCount - 1 ? "" : ",");
+         }
+
+         int batchSize = 0;
+         insertNode =
+            jdbcConn.prepareStatement("INSERT INTO " + tableName + " (" + names + ") VALUES(" + parameters + ")");
+
+         // set data
+         outer : while (true)
+         {
+            for (int i = 0, targetIndex = 0; i < columnType.size(); i++, targetIndex++)
+            {
+               InputStream stream;
+               long len;
+
+               if (restoreRule.getNewColumnIndex() != null && restoreRule.getNewColumnIndex() == i)
+               {
+                  stream =
+                     new ByteArrayInputStream(restoreRule.getDstContainerName().getBytes(Constants.DEFAULT_ENCODING));
+                  len = ((ByteArrayInputStream)stream).available();
+               }
+               else
+               {
+                  try
+                  {
+                     len = contentLenReader.readLong();
+                  }
+                  catch (EOFException e)
+                  {
+                     if (i == 0)
+                     {
+                        // content length file is empty check content file
+                        try
+                        {
+                           contentReader.readByte();
+                        }
+                        catch (EOFException e1)
+                        {
+                           break outer;
+                        }
+                     }
+
+                     throw new IOException("Content length file is empty but content still present", e);
+                  }
+                  stream = len == -1 ? null : spoolInputStream(contentReader, len);
+               }
+
+               if (restoreRule.getSkipColumnIndex() != null && restoreRule.getSkipColumnIndex() == i)
+               {
+                  targetIndex--;
+                  continue;
+               }
+               else if (restoreRule.getDeleteColumnIndex() != null && restoreRule.getDeleteColumnIndex() == i)
+               {
+                  targetIndex--;
+                  continue;
+               }
+
+               // set 
+               if (stream != null)
+               {
+                  if (restoreRule.getConvertColumnIndex() != null && restoreRule.getConvertColumnIndex().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))
+                     {
+                        stream = new ByteArrayInputStream(Constants.ROOT_PARENT_UUID.getBytes());
+                     }
+                     else
+                     {
+                        if (restoreRule.getDstMultiDb())
+                        {
+                           if (!restoreRule.getSrcMultiDb())
+                           {
+                              stream =
+                                 new ByteArrayInputStream(new String(readBuffer, Constants.DEFAULT_ENCODING).substring(
+                                    restoreRule.getSrcContainerName().length()).getBytes());
+                           }
+                        }
+                        else
+                        {
+                           if (restoreRule.getSrcMultiDb())
+                           {
+                              StringBuilder builder = new StringBuilder();
+                              builder.append(restoreRule.getDstContainerName());
+                              builder.append(currentValue);
+
+                              stream = new ByteArrayInputStream(builder.toString().getBytes());
+                           }
+                           else
+                           {
+                              StringBuilder builder = new StringBuilder();
+                              builder.append(restoreRule.getDstContainerName());
+                              builder.append(new String(readBuffer, Constants.DEFAULT_ENCODING).substring(restoreRule
+                                 .getSrcContainerName().length()));
+
+                              stream = new ByteArrayInputStream(builder.toString().getBytes());
+                           }
+                        }
+                     }
+
+                     len = ((ByteArrayInputStream)stream).available();
+                  }
+
+                  if (columnType.get(i) == Types.INTEGER || columnType.get(i) == Types.BIGINT
+                     || columnType.get(i) == Types.SMALLINT || columnType.get(i) == Types.TINYINT)
+                  {
+                     ByteArrayInputStream ba = (ByteArrayInputStream)stream;
+                     byte[] readBuffer = new byte[ba.available()];
+                     ba.read(readBuffer);
+
+                     String value = new String(readBuffer, Constants.DEFAULT_ENCODING);
+                     insertNode.setLong(targetIndex + 1, Integer.parseInt(value));
+                  }
+                  else if (columnType.get(i) == Types.BIT)
+                  {
+                     ByteArrayInputStream ba = (ByteArrayInputStream)stream;
+                     byte[] readBuffer = new byte[ba.available()];
+                     ba.read(readBuffer);
+
+                     String value = new String(readBuffer);
+                     if (dialect == DBBackup.DB_DIALECT_PGSQL)
+                     {
+                        insertNode.setBoolean(targetIndex + 1, value.equals("t"));
+                     }
+                     else
+                     {
+                        insertNode.setBoolean(targetIndex + 1, value.equals("1"));
+                     }
+                  }
+                  else if (columnType.get(i) == Types.BOOLEAN)
+                  {
+                     ByteArrayInputStream ba = (ByteArrayInputStream)stream;
+                     byte[] readBuffer = new byte[ba.available()];
+                     ba.read(readBuffer);
+
+                     String value = new String(readBuffer);
+                     insertNode.setBoolean(targetIndex + 1, value.equals("true"));
+                  }
+                  else if (columnType.get(i) == Types.VARBINARY || columnType.get(i) == Types.LONGVARBINARY
+                     || columnType.get(i) == Types.BLOB || columnType.get(i) == Types.BINARY
+                     || columnType.get(i) == Types.OTHER)
+                  {
+                     insertNode.setBinaryStream(targetIndex + 1, stream, (int)len);
+                  }
+                  else
+                  {
+                     byte[] readBuffer = new byte[(int)len];
+                     stream.read(readBuffer);
+
+                     insertNode.setString(targetIndex + 1, new String(readBuffer, Constants.DEFAULT_ENCODING));
+                  }
+               }
+               else
+               {
+                  insertNode.setNull(targetIndex + 1, columnType.get(i));
+               }
+            }
+
+            // add statement to batch
+            insertNode.addBatch();
+
+            if (++batchSize == MAXIMUM_BATCH_SIZE)
+            {
+               insertNode.executeBatch();
+               batchSize = 0;
+            }
+         }
+
+         if (batchSize != 0)
+         {
+            insertNode.executeBatch();
+         }
+      }
+      finally
+      {
+         if (contentReader != null)
+         {
+            contentReader.close();
+         }
+
+         if (contentLenReader != null)
+         {
+            contentLenReader.close();
+         }
+
+         if (insertNode != null)
+         {
+            insertNode.close();
+         }
+
+         // delete all temporary files
+         for (File file : spoolFileList)
+         {
+            if (!PrivilegedFileHelper.delete(file))
+            {
+               fileCleaner.addFile(file);
+            }
+         }
+
+         if (tableMetaData != null)
+         {
+            tableMetaData.close();
+         }
+      }
+   }
+
+   /**
+    * Spool input stream.
+    */
+   private InputStream spoolInputStream(ObjectReader in, long contentLen) throws IOException
+   {
+      byte[] buffer = new byte[0];
+      byte[] tmpBuff;
+      long readLen = 0;
+      File sf = null;
+      OutputStream sfout = null;
+
+      try
+      {
+         while (true)
+         {
+            int needToRead = contentLen - readLen > 2048 ? 2048 : (int)(contentLen - readLen);
+            tmpBuff = new byte[needToRead];
+
+            if (needToRead == 0)
+            {
+               break;
+            }
+
+            in.readFully(tmpBuff);
+
+            if (sfout != null)
+            {
+               sfout.write(tmpBuff);
+            }
+            else if (readLen + needToRead > maxBufferSize && fileCleaner != null)
+            {
+               sf = PrivilegedFileHelper.createTempFile("jcrvd", null, tempDir);
+               sfout = PrivilegedFileHelper.fileOutputStream(sf);
+
+               sfout.write(buffer);
+               sfout.write(tmpBuff);
+               buffer = null;
+            }
+            else
+            {
+               // reallocate new buffer and spool old buffer contents
+               byte[] newBuffer = new byte[(int)(readLen + needToRead)];
+               System.arraycopy(buffer, 0, newBuffer, 0, (int)readLen);
+               System.arraycopy(tmpBuff, 0, newBuffer, (int)readLen, needToRead);
+               buffer = newBuffer;
+            }
+
+            readLen += needToRead;
+         }
+
+         if (buffer != null)
+         {
+            return new ByteArrayInputStream(buffer);
+         }
+         else
+         {
+            return PrivilegedFileHelper.fileInputStream(sf);
+         }
+      }
+      finally
+      {
+         if (sfout != null)
+         {
+            sfout.close();
+         }
+
+         if (sf != null)
+         {
+            spoolFileList.add(sf);
+         }
+      }
+   }
+}
+
+

Deleted: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DirectoryRestor.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DirectoryRestor.java	2011-04-28 11:48:05 UTC (rev 4324)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DirectoryRestor.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -1,195 +0,0 @@
-/*
- * Copyright (C) 2003-2010 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see<http://www.gnu.org/licenses/>.
- */
-package org.exoplatform.services.jcr.impl.backup.rdbms;
-
-import org.exoplatform.commons.utils.PrivilegedFileHelper;
-import org.exoplatform.commons.utils.PrivilegedSystemHelper;
-import org.exoplatform.services.jcr.impl.backup.BackupException;
-import org.exoplatform.services.jcr.impl.backup.DataRestor;
-import org.exoplatform.services.jcr.impl.util.io.DirectoryHelper;
-import org.exoplatform.services.jcr.util.IdGenerator;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author <a href="mailto:anatoliy.bazko at gmail.com">Anatoliy Bazko</a>
- * @version $Id: DirectoryRestorer.java 34360 2009-07-22 23:58:59Z tolusha $
- */
-public class DirectoryRestor implements DataRestor
-{
-
-   /**
-    * Logger.
-    */
-   protected final static Log LOG = ExoLogger.getLogger("exo.jcr.component.core.DirectoryRestorer");
-
-   /**
-    * The list of directories with actual data.
-    */
-   protected final List<File> dataDirs = new ArrayList<File>();
-
-   /**
-    * The list of directories with backuped data.
-    */
-   protected final List<File> backupDirs = new ArrayList<File>();
-
-   /**
-    * The list of temporary directories.
-    */
-   private final List<File> tmpDirs = new ArrayList<File>();
-
-   /**
-    * Java temporary directory.
-    */
-   protected final File tempDir = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
-
-   /**
-    * The prefix for temporary directories.
-    */
-   private static final String PREFIX = "dr";
-
-   /**
-    * Constructor DirectoryRestorer.
-    * 
-    * @param dataDirs
-    * @param backupDirs
-    */
-   public DirectoryRestor(List<File> dataDirs, List<File> backupDirs)
-   {
-      this.dataDirs.addAll(dataDirs);
-      this.backupDirs.addAll(backupDirs);
-   }
-
-   /**
-    * Constructor DirectoryRestorer.
-    * 
-    * @param dataDir
-    * @param backupDir
-    */
-   public DirectoryRestor(File dataDir, File backupDir)
-   {
-      this.dataDirs.add(dataDir);
-      this.backupDirs.add(backupDir);
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void clean() throws BackupException
-   {
-      for (File dataDir : dataDirs)
-      {
-         try
-         {
-            File tmpDir = new File(tempDir, PREFIX + IdGenerator.generate());
-            PrivilegedFileHelper.mkdirs(tmpDir);
-            tmpDirs.add(tmpDir);
-
-            if (PrivilegedFileHelper.exists(dataDir))
-            {
-               DirectoryHelper.copyDirectory(dataDir, tmpDir);
-               DirectoryHelper.removeDirectory(dataDir);
-            }
-         }
-         catch (IOException e)
-         {
-            throw new BackupException(e);
-         }
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void restore() throws BackupException
-   {
-      for (int i = 0; i < backupDirs.size(); i++)
-      {
-         File backupDir = backupDirs.get(i);
-         File dataDir = dataDirs.get(i);
-
-         try
-         {
-            DirectoryHelper.uncompressDirectory(backupDir, dataDir);
-         }
-         catch (IOException e)
-         {
-            throw new BackupException(e);
-         }
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void commit() throws BackupException
-   {
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void rollback() throws BackupException
-   {
-      for (int i = 0; i < tmpDirs.size(); i++)
-      {
-         try
-         {
-            File tmpDir = tmpDirs.get(i);
-            File dataDir = dataDirs.get(i);
-
-            if (PrivilegedFileHelper.exists(dataDir))
-            {
-               DirectoryHelper.removeDirectory(dataDir);
-            }
-
-            DirectoryHelper.copyDirectory(tmpDir, dataDir);
-         }
-         catch (IOException e)
-         {
-            throw new BackupException(e);
-         }
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void close() throws BackupException
-   {
-      for (File tmpDir : tmpDirs)
-      {
-         try
-         {
-            DirectoryHelper.removeDirectory(tmpDir);
-         }
-         catch (IOException e)
-         {
-            throw new BackupException(e);
-         }
-      }
-
-      dataDirs.clear();
-      backupDirs.clear();
-      tmpDirs.clear();
-   }
-}

Copied: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DirectoryRestore.java (from rev 4323, jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DirectoryRestor.java)
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DirectoryRestore.java	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DirectoryRestore.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -0,0 +1,195 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.backup.rdbms;
+
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
+import org.exoplatform.commons.utils.PrivilegedSystemHelper;
+import org.exoplatform.services.jcr.impl.backup.BackupException;
+import org.exoplatform.services.jcr.impl.backup.DataRestore;
+import org.exoplatform.services.jcr.impl.util.io.DirectoryHelper;
+import org.exoplatform.services.jcr.util.IdGenerator;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko at gmail.com">Anatoliy Bazko</a>
+ * @version $Id: DirectoryRestorere.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class DirectoryRestore implements DataRestore
+{
+
+   /**
+    * Logger.
+    */
+   protected final static Log LOG = ExoLogger.getLogger("exo.jcr.component.core.DirectoryRestorer");
+
+   /**
+    * The list of directories with actual data.
+    */
+   protected final List<File> dataDirs = new ArrayList<File>();
+
+   /**
+    * The list of directories with backuped data.
+    */
+   protected final List<File> backupDirs = new ArrayList<File>();
+
+   /**
+    * The list of temporary directories.
+    */
+   private final List<File> tmpDirs = new ArrayList<File>();
+
+   /**
+    * Java temporary directory.
+    */
+   protected final File tempDir = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
+
+   /**
+    * The prefix for temporary directories.
+    */
+   private static final String PREFIX = "dr";
+
+   /**
+    * Constructor DirectoryRestorer.
+    * 
+    * @param dataDirs
+    * @param backupDirs
+    */
+   public DirectoryRestore(List<File> dataDirs, List<File> backupDirs)
+   {
+      this.dataDirs.addAll(dataDirs);
+      this.backupDirs.addAll(backupDirs);
+   }
+
+   /**
+    * Constructor DirectoryRestorer.
+    * 
+    * @param dataDir
+    * @param backupDir
+    */
+   public DirectoryRestore(File dataDir, File backupDir)
+   {
+      this.dataDirs.add(dataDir);
+      this.backupDirs.add(backupDir);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void clean() throws BackupException
+   {
+      for (File dataDir : dataDirs)
+      {
+         try
+         {
+            File tmpDir = new File(tempDir, PREFIX + IdGenerator.generate());
+            PrivilegedFileHelper.mkdirs(tmpDir);
+            tmpDirs.add(tmpDir);
+
+            if (PrivilegedFileHelper.exists(dataDir))
+            {
+               DirectoryHelper.copyDirectory(dataDir, tmpDir);
+               DirectoryHelper.removeDirectory(dataDir);
+            }
+         }
+         catch (IOException e)
+         {
+            throw new BackupException(e);
+         }
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void restore() throws BackupException
+   {
+      for (int i = 0; i < backupDirs.size(); i++)
+      {
+         File backupDir = backupDirs.get(i);
+         File dataDir = dataDirs.get(i);
+
+         try
+         {
+            DirectoryHelper.uncompressDirectory(backupDir, dataDir);
+         }
+         catch (IOException e)
+         {
+            throw new BackupException(e);
+         }
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void commit() throws BackupException
+   {
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void rollback() throws BackupException
+   {
+      for (int i = 0; i < tmpDirs.size(); i++)
+      {
+         try
+         {
+            File tmpDir = tmpDirs.get(i);
+            File dataDir = dataDirs.get(i);
+
+            if (PrivilegedFileHelper.exists(dataDir))
+            {
+               DirectoryHelper.removeDirectory(dataDir);
+            }
+
+            DirectoryHelper.copyDirectory(tmpDir, dataDir);
+         }
+         catch (IOException e)
+         {
+            throw new BackupException(e);
+         }
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   public void close() throws BackupException
+   {
+      for (File tmpDir : tmpDirs)
+      {
+         try
+         {
+            DirectoryHelper.removeDirectory(tmpDir);
+         }
+         catch (IOException e)
+         {
+            throw new BackupException(e);
+         }
+      }
+
+      dataDirs.clear();
+      backupDirs.clear();
+      tmpDirs.clear();
+   }
+}

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java	2011-04-28 11:48:05 UTC (rev 4324)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -28,7 +28,7 @@
 import org.exoplatform.services.jcr.datamodel.IllegalNameException;
 import org.exoplatform.services.jcr.datamodel.NodeData;
 import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.backup.JCRRestor;
+import org.exoplatform.services.jcr.impl.backup.JCRRestore;
 import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeManagerImpl;
 import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
 import org.exoplatform.services.jcr.impl.dataflow.persistent.CacheableWorkspaceDataManager;
@@ -63,7 +63,7 @@
 
       restoreDir = restorePath;
 
-      String fullBackupPath = PrivilegedFileHelper.getAbsolutePath(JCRRestor.getFullBackupFile(new File(restoreDir)));
+      String fullBackupPath = PrivilegedFileHelper.getAbsolutePath(JCRRestore.getFullBackupFile(new File(restoreDir)));
 
       if (fullBackupPath == null)
       {
@@ -97,8 +97,8 @@
          dataManager.save(tLog);
 
          // restore from incremental backup
-         JCRRestor restorer = new JCRRestor(dataManager, fileCleaner);
-         for (File incrBackupFile : JCRRestor.getIncrementalFiles(new File(restoreDir)))
+         JCRRestore restorer = new JCRRestore(dataManager, fileCleaner);
+         for (File incrBackupFile : JCRRestore.getIncrementalFiles(new File(restoreDir)))
          {
             restorer.incrementalRestore(incrBackupFile);
          }

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cacheable/AbstractCacheableLockManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cacheable/AbstractCacheableLockManager.java	2011-04-28 11:48:05 UTC (rev 4324)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cacheable/AbstractCacheableLockManager.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -38,8 +38,8 @@
 import org.exoplatform.services.jcr.impl.Constants;
 import org.exoplatform.services.jcr.impl.backup.BackupException;
 import org.exoplatform.services.jcr.impl.backup.Backupable;
-import org.exoplatform.services.jcr.impl.backup.DataRestor;
-import org.exoplatform.services.jcr.impl.backup.DummyDataRestor;
+import org.exoplatform.services.jcr.impl.backup.DataRestore;
+import org.exoplatform.services.jcr.impl.backup.DummyDataRestore;
 import org.exoplatform.services.jcr.impl.backup.rdbms.DBBackup;
 import org.exoplatform.services.jcr.impl.core.SessionDataManager;
 import org.exoplatform.services.jcr.impl.core.lock.LockRemover;
@@ -864,7 +864,7 @@
    /**
     * {@inheritDoc}
     */
-   public DataRestor getDataRestorer(File storageDir) throws BackupException
+   public DataRestore getDataRestorer(File storageDir) throws BackupException
    {
       List<LockData> locks = new ArrayList<LockData>();
 
@@ -876,7 +876,7 @@
          // it is possible that backup was created on configuration without Backupable WorkspaceLockManager class
          if (!PrivilegedFileHelper.exists(contentFile))
          {
-            return new DummyDataRestor();
+            return new DummyDataRestore();
          }
 
          in = new ObjectInputStream(PrivilegedFileHelper.fileInputStream(contentFile));
@@ -917,20 +917,20 @@
          }
       }
 
-      return new CacheLocksRestor(locks);
+      return new CacheLocksRestore(locks);
    }
 
    /**
     * Cache restorer.
     */
-   protected class CacheLocksRestor implements DataRestor
+   protected class CacheLocksRestore implements DataRestore
    {
 
       final private List<LockData> backupLocks = new ArrayList<LockData>();
 
       private List<LockData> actualLocks = new ArrayList<LockData>();
 
-      CacheLocksRestor(final List<LockData> backupLocks)
+      CacheLocksRestore(final List<LockData> backupLocks)
       {
          this.backupLocks.addAll(backupLocks);
       }

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java	2011-04-28 11:48:05 UTC (rev 4324)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -50,11 +50,11 @@
 import org.exoplatform.services.jcr.impl.Constants;
 import org.exoplatform.services.jcr.impl.backup.BackupException;
 import org.exoplatform.services.jcr.impl.backup.Backupable;
-import org.exoplatform.services.jcr.impl.backup.DataRestor;
+import org.exoplatform.services.jcr.impl.backup.DataRestore;
 import org.exoplatform.services.jcr.impl.backup.ResumeException;
 import org.exoplatform.services.jcr.impl.backup.SuspendException;
 import org.exoplatform.services.jcr.impl.backup.Suspendable;
-import org.exoplatform.services.jcr.impl.backup.rdbms.DirectoryRestor;
+import org.exoplatform.services.jcr.impl.backup.rdbms.DirectoryRestore;
 import org.exoplatform.services.jcr.impl.core.LocationFactory;
 import org.exoplatform.services.jcr.impl.core.NamespaceRegistryImpl;
 import org.exoplatform.services.jcr.impl.core.SessionDataManager;
@@ -1548,7 +1548,7 @@
    /**
     * {@inheritDoc}}
     */
-   public DataRestor getDataRestorer(File storageDir) throws BackupException
+   public DataRestore getDataRestorer(File storageDir) throws BackupException
    {
       try
       {
@@ -1561,7 +1561,7 @@
          }
          else
          {
-            return new DirectoryRestor(getIndexDirectory(), backupDir);
+            return new DirectoryRestore(getIndexDirectory(), backupDir);
          }
       }
       catch (RepositoryConfigurationException e)

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/ISPNCacheWorkspaceStorageCache.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/ISPNCacheWorkspaceStorageCache.java	2011-04-28 11:48:05 UTC (rev 4324)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/ISPNCacheWorkspaceStorageCache.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -42,7 +42,7 @@
 import org.exoplatform.services.jcr.impl.Constants;
 import org.exoplatform.services.jcr.impl.backup.BackupException;
 import org.exoplatform.services.jcr.impl.backup.Backupable;
-import org.exoplatform.services.jcr.impl.backup.DataRestor;
+import org.exoplatform.services.jcr.impl.backup.DataRestore;
 import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
 import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
 import org.exoplatform.services.jcr.infinispan.ISPNCacheFactory;
@@ -535,7 +535,6 @@
 
          // order children by orderNumber, as HashSet returns children in other order
          Collections.sort(childs, new NodesOrderComparator<NodeData>());
-
          return childs;
       }
       else
@@ -898,7 +897,7 @@
 
       while (keys.hasNext())
       {
-         CacheKey key = (CacheKey)keys.next();
+         CacheKey key = keys.next();
          if (key instanceof CacheId)
          {
             ItemData data = (ItemData)cache.get(key);
@@ -1188,9 +1187,9 @@
    /**
     * {@inheritDoc}
     */
-   public DataRestor getDataRestorer(File storageDir) throws BackupException
+   public DataRestore getDataRestorer(File storageDir) throws BackupException
    {
-      return new DataRestor()
+      return new DataRestore()
       {
          /**
           * {@inheritDoc}

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java	2011-04-28 11:48:05 UTC (rev 4324)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -40,7 +40,7 @@
 import org.exoplatform.services.jcr.impl.Constants;
 import org.exoplatform.services.jcr.impl.backup.BackupException;
 import org.exoplatform.services.jcr.impl.backup.Backupable;
-import org.exoplatform.services.jcr.impl.backup.DataRestor;
+import org.exoplatform.services.jcr.impl.backup.DataRestore;
 import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
 import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
 import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory;
@@ -1583,9 +1583,9 @@
    /**
     * {@inheritDoc}
     */
-   public DataRestor getDataRestorer(File storageDir) throws BackupException
+   public DataRestore getDataRestorer(File storageDir) throws BackupException
    {
-      return new DataRestor()
+      return new DataRestore()
       {
          /**
           * {@inheritDoc}

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java	2011-04-28 11:48:05 UTC (rev 4324)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java	2011-04-28 12:11:15 UTC (rev 4325)
@@ -29,12 +29,12 @@
 import org.exoplatform.services.jcr.dataflow.serialization.ObjectWriter;
 import org.exoplatform.services.jcr.impl.Constants;
 import org.exoplatform.services.jcr.impl.backup.BackupException;
-import org.exoplatform.services.jcr.impl.backup.ComplexDataRestor;
-import org.exoplatform.services.jcr.impl.backup.DataRestor;
+import org.exoplatform.services.jcr.impl.backup.ComplexDataRestore;
+import org.exoplatform.services.jcr.impl.backup.DataRestore;
 import org.exoplatform.services.jcr.impl.backup.JdbcBackupable;
 import org.exoplatform.services.jcr.impl.backup.rdbms.DBBackup;
-import org.exoplatform.services.jcr.impl.backup.rdbms.DBRestor;
-import org.exoplatform.services.jcr.impl.backup.rdbms.DirectoryRestor;
+import org.exoplatform.services.jcr.impl.backup.rdbms.DBRestore;
+import org.exoplatform.services.jcr.impl.backup.rdbms.DirectoryRestore;
 import org.exoplatform.services.jcr.impl.backup.rdbms.RestoreTableRule;
 import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanService;
 import org.exoplatform.services.jcr.impl.core.query.NodeDataIndexingIterator;
@@ -1164,10 +1164,10 @@
    /**
     * {@inheritDoc}
     */
-   public DataRestor getDataRestorer(File storageDir, Connection jdbcConn) throws BackupException
+   public DataRestore getDataRestorer(File storageDir, Connection jdbcConn) throws BackupException
    {
 
-      List<DataRestor> restorers = new ArrayList<DataRestor>();
+      List<DataRestore> restorers = new ArrayList<DataRestore>();
 
       ObjectReader backupInfo = null;
       try
@@ -1280,7 +1280,7 @@
          }
          tables.put(dstTableName, restoreTableRule);
          
-         restorers.add(new DBRestor(storageDir, jdbcConn, tables, wsConfig, swapCleaner));
+         restorers.add(new DBRestore(storageDir, jdbcConn, tables, wsConfig, swapCleaner));
 
          // prepare value storage restorer
          File backupValueStorageDir = new File(storageDir, "values");
@@ -1316,7 +1316,7 @@
                }
             }
 
-            restorers.add(new DirectoryRestor(dataDirs, backupDirs));
+            restorers.add(new DirectoryRestore(dataDirs, backupDirs));
          }
          else
          {
@@ -1327,7 +1327,7 @@
             }
          }
 
-         return new ComplexDataRestor(restorers);
+         return new ComplexDataRestore(restorers);
       }
       catch (FileNotFoundException e)
       {
@@ -1368,7 +1368,7 @@
    /**
     * {@inheritDoc}
     */
-   public DataRestor getDataRestorer(File storageDir) throws BackupException
+   public DataRestore getDataRestorer(File storageDir) throws BackupException
    {
       try
       {



More information about the exo-jcr-commits mailing list