Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.ext.backup.impl;
 
 
 import java.io.File;
 import java.util.List;
 
Created by The eXo Platform SAS. Date: 24 01 2011

Author(s):
Anatoliy Bazko
Version:
$Id: JobExistingWorkspaceSameConfigRestore.java 34360 2010-11-11 11:11:11Z tolusha $
 
 {
   
The logger.
 
    private static final Log LOG = ExoLogger.getLogger("exo.jcr.component.ext.JobExistingWorkspaceSameConfigRestore");

   
JobExistingWorkspaceSameConfigRestore constructor.
 
    public JobExistingWorkspaceSameConfigRestore(RepositoryService repositoryServiceBackupManager backupManager,
       String repositoryNameBackupChainLog logWorkspaceEntry wEntry)
    {
       super(repositoryServicebackupManagerrepositoryNamelogwEntry);
    }

   
 
    @Override
    protected void restoreWorkspace() throws WorkspaceRestoreException
    {
       // list of data restorers
       List<DataRestoredataRestorer = new ArrayList<DataRestore>();
 
       List<WorkspaceContainerFacadeworkspacesWaits4Resume = new ArrayList<WorkspaceContainerFacade>();
       try
       {
 
          if (.getContainer().getParameterBoolean("multi-db") == false)
          {
             for (String wsName : repository.getWorkspaceNames())
             {
                WorkspaceContainerFacade wsContainer = repository.getWorkspaceContainer(wsName);
                wsContainer.setState(.);
 
                workspacesWaits4Resume.add(wsContainer);
             }
          }
          else
          {
             WorkspaceContainerFacade wsContainer = repository.getWorkspaceContainer(.getName());
 
             wsContainer.setState(.);
             workspacesWaits4Resume.add(wsContainer);
          }
 
          // get all restorers
         List<Backupablebackupable =
                  repository.getWorkspaceContainer(.getName())
               .getComponentInstancesOfType(Backupable.class);
         File storageDir = .getBackupConfig().getBackupDir();
         File fullBackupDir = JCRRestore.getFullBackupFile(storageDir);
         DataRestoreContext context = new DataRestoreContext(
                  new String[] {.}, 
                  new Object[] {fullBackupDir});
         for (Backupable component : backupable)
         {
            dataRestorer.add(component.getDataRestorer(context));
         }
         for (DataRestore restorer : dataRestorer)
         {
            restorer.clean();
         }
         for (DataRestore restorer : dataRestorer)
         {
            restorer.restore();
         }
         
         for (DataRestore restorer : dataRestorer)
         {
            restorer.commit();
         }
         for (WorkspaceContainerFacade wsContainer : workspacesWaits4Resume)
         {
            wsContainer.setState(.);
         }
         // incremental restore
         DataManager dataManager =
                  (WorkspacePersistentDataManagerrepository.getWorkspaceContainer(.getName()).getComponent(
                           WorkspacePersistentDataManager.class);
         FileCleanerHolder fileCleanHolder =
                  (FileCleanerHolderrepository.getWorkspaceContainer(.getName())
               .getComponent(FileCleanerHolder.class);
         JCRRestore restorer = new JCRRestore(dataManagerfileCleanHolder.getFileCleaner());
         for (File incrBackupFile : JCRRestore.getIncrementalFiles(storageDir))
         {
            restorer.incrementalRestore(incrBackupFile);
         }
      }
      catch (Throwable t)
      {
         // rollback
         for (DataRestore restorer : dataRestorer)
         {
            try
            {
               restorer.rollback();
            }
            catch (BackupException e)
            {
               .error("Can't rollback changes"e);
            }
         }
         throw new WorkspaceRestoreException("Workspace " + .getName() + " was not restored"t);
      }
      finally
      {
         // close
         for (DataRestore restorer : dataRestorer)
         {
            try
            {
               restorer.close();
            }
            catch (BackupException e)
            {
               .error("Can't close restorer"e);
            }
         }
         try
         {
            for (WorkspaceContainerFacade wsContainer : workspacesWaits4Resume)
            {
               wsContainer.setState(.);
            }
         }
         catch (RepositoryException e)
         {
            .error("Can't resume component"e);
         }
      }
   }
New to GrepCode? Check out our FAQ X