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;
 import java.util.Map;
 
Created by The eXo Platform SAS.
Date: 2010

Author(s):
Alex Reshetnyak
Version:
$Id$
 
 public class JobRepositoryRestore extends Thread
 {
   
The apache logger.
 
    protected static Log log = ExoLogger.getLogger("exo.jcr.component.ext.JobRepositoryRestore");

   
REPOSITORY_RESTORE_STARTED. The state of start restore.
 
    public static final int REPOSITORY_RESTORE_STARTED = 1;

   
REPOSITORY_RESTORE_SUCCESSFUL. The state of restore successful.
 
    public static final int REPOSITORY_RESTORE_SUCCESSFUL = 2;

   
REPOSITORY_RESTORE_FAIL. The state of restore fail.
 
    public static final int REPOSITORY_RESTORE_FAIL = 3;

   
REPOSITORY_RESTORE_STARTED. The state of initialized restore.
 
    public static final int REPOSITORY_RESTORE_INITIALIZED = 4;

   
The state of restore.
 
    private int stateRestore;

   
The start time of restore.
 
    private Calendar startTime;

   
The end time of restore.
 
    private Calendar endTime;

   
The exception on restore.
   private Throwable restoreException = null;
removeJobOnceOver, in 'true' then restore job well remove after restore.
   private boolean removeJobOnceOver;
   public JobRepositoryRestore(RepositoryService repoServiceBackupManagerImpl backupManagerImpl,
      RepositoryEntry repositoryEntryMap<StringBackupChainLogworkspacesMapping,
      RepositoryBackupChainLog backupChainLogboolean removeJobOnceOver)
   {
      super("JobRepositoryRestore " + repositoryEntry.getName());
      this. = repoService;
      this. = backupManagerImpl;
      this. = repositoryEntry;
      this. = workspacesMapping;
      this. = backupChainLog;
      this. = removeJobOnceOver;
   }

   
Restore repository. Provide information about start and finish process.

Throws:
org.exoplatform.services.jcr.ext.backup.RepositoryRestoreExeption if exception occurred during restore
   final protected void restore() throws RepositoryRestoreExeption
   {
      try
      {
          = Calendar.getInstance();
         restoreRepository();
          = Calendar.getInstance();
      }
      catch (Throwable t)
      {
          = t;
         throw new RepositoryRestoreExeption(t.getMessage(), t);
      }
      finally
      {
         if ()
         {
            ..remove(this);
         }  
      }
   }

   
   {
      List<WorkspaceEntryoriginalWorkspaceEntrys = .getWorkspaceEntries();
      //Getting system workspace entry
      WorkspaceEntry systemWorkspaceEntry = null;
      for (WorkspaceEntry wsEntry : originalWorkspaceEntrys)
      {
         if (wsEntry.getName().equals(.getSystemWorkspaceName()))
         {
            systemWorkspaceEntry = wsEntry;
            break;
         }
      }
      WorkspaceInitializerEntry wieOriginal = systemWorkspaceEntry.getInitializer();
      //getting backup chail log to system workspace.
      BackupChainLog systemBackupChainLog = .get(systemWorkspaceEntry.getName());
      WorkspaceInitializerEntry wiEntry = getWorkspaceInitializerEntry(systemBackupChainLog);
      // set initializer
      systemWorkspaceEntry.setInitializer(wiEntry);
      ArrayList<WorkspaceEntrynewEntries = new ArrayList<WorkspaceEntry>();
      newEntries.add(systemWorkspaceEntry);
      .setWorkspaceEntries(newEntries);
      String currennWorkspaceName = .getSystemWorkspaceName();
      boolean restored = true;
      try
      {
         //set original initializer to created workspace.
         WorkspaceContainerFacade wcf = defRep.getWorkspaceContainer(systemWorkspaceEntry.getName());
         WorkspaceEntry createdWorkspaceEntry = (WorkspaceEntry)wcf.getComponent(WorkspaceEntry.class);
         createdWorkspaceEntry.setInitializer(wieOriginal);
         // save configuration to persistence (file or persister)
         .getConfig().retain();
         for (WorkspaceEntry wsEntry : originalWorkspaceEntrys)
         {
            if (!(wsEntry.getName().equals(.getSystemWorkspaceName())))
            {
               currennWorkspaceName = wsEntry.getName();
               .restore(.get(wsEntry.getName()), .getName(), wsEntry,
                  false);
            }
         }
      }
      catch (InvalidItemStateException e)
      {
         restored = false;
         .error(
            "Can not restore workspace \"" + currennWorkspaceName + " in repository \"" + .getName()
               + "\"."e);
         throw new RepositoryRestoreExeption("Can not restore workspace \"" + currennWorkspaceName
            + " in repository \"" + .getName() + "\"." + " There was database error."e);
      }
      catch (Throwable t)
      {
         restored = false;
         .error(
            "Can not restore workspace \"" + currennWorkspaceName + " in repository \"" + .getName()
               + "\"."t);
         throw new RepositoryRestoreExeption("Can not restore workspace \"" + currennWorkspaceName
            + " in repository \"" + .getName() + "\"."t);
      }
      finally
      {
         if (!restored)
         {
            try
            {
               removeRepository(.getName());
            }
            catch (Throwable thr)
            {
               .error("The partly restored repository \"" + .getName() + "\" can not be removed.",
                  thr);
            }
         }
      }
   }

   
Remove repository.

Parameters:
repositoryService RepositoryService, the repository service
repositoryName String, the repository name
Throws:
javax.jcr.RepositoryException will be generated the RepositoryException
org.exoplatform.services.jcr.config.RepositoryConfigurationException
   protected void removeRepository(RepositoryService repositoryServiceString repositoryName)
      throws RepositoryException,
   {
      ManageableRepository mr = null;
      try
      {
         mr = repositoryService.getRepository(repositoryName);
      }
      catch (RepositoryException e)
      {
         // The repository not exist.
      }
      if (mr != null)
      {
         closeAllSession(mr);
         repositoryService.removeRepository(repositoryName);
         repositoryService.getConfig().retain(); // save configuration to persistence (file or persister)
      }
   }
            throws BackupOperationExceptionClassNotFoundException
   {
      String fullBackupPath = systemBackupChainLog.getJobEntryInfos().get(0).getURL().getPath();
      String fullbackupType = null;
      try
      {
         if ((Class.forName(systemBackupChainLog.getFullBackupType()).equals(FullBackupJob.class)))
         {
            fullbackupType = systemBackupChainLog.getFullBackupType();
         }
         else if ((Class.forName(systemBackupChainLog.getFullBackupType())
                  .equals(org.exoplatform.services.jcr.ext.backup.impl.rdbms.FullBackupJob.class)))
         {
            fullbackupType = systemBackupChainLog.getFullBackupType();
         }
         else
         {
            throw new BackupOperationException("Class  \"" + systemBackupChainLog.getFullBackupType()
                     + "\" is not support as full backup.");
         }
      }
      catch (ClassNotFoundException e)
      {
         throw new BackupOperationException("Class \"" + systemBackupChainLog.getFullBackupType() + "\" is not found.",
                  e);
      }
      if ((Class.forName(fullbackupType).equals(FullBackupJob.class)))
      {
         // set the initializer BackupWorkspaceInitializer
         wiEntry.setType(BackupWorkspaceInitializer.class.getCanonicalName());
         List<SimpleParameterEntrywieParams = new ArrayList<SimpleParameterEntry>();
                  fullBackupPath).getParent())));
         wiEntry.setParameters(wieParams);
      }
      else if ((Class.forName(fullbackupType)
               .equals(org.exoplatform.services.jcr.ext.backup.impl.rdbms.FullBackupJob.class)))
      {
         // set the initializer RdbmsBackupWorkspaceInitializer
         wiEntry.setType(RdbmsBackupWorkspaceInitializer.class.getCanonicalName());
         List<SimpleParameterEntrywieParams = new ArrayList<SimpleParameterEntry>();
                  fullBackupPath).getParent())));
         wiEntry.setParameters(wieParams);
      }
      return wiEntry;
   }

   
Close all open session in repository

   {
      for (String wsName : mr.getWorkspaceNames())
      {
         if (!mr.canRemoveWorkspace(wsName))
         {
            WorkspaceContainerFacade wc = mr.getWorkspaceContainer(wsName);
            SessionRegistry sessionRegistry = (SessionRegistry)wc.getComponent(SessionRegistry.class);
            sessionRegistry.closeSessions(wsName);
         }
      }
   }

   
   public void run()
   {
      try
      {
         restore();
      }
      catch (Throwable t)
      {
         .error("The restore was fail"t);
      }
   }

   
getRestoreException.

Returns:
Throwable return the exception of repository restore.
   {
      return ;
   }

   
getStateRestore.

Returns:
int return state of restore.
   public int getStateRestore()
   {
      return ;
   }

   
getBeginTime.

Returns:
Calendar return the start time of restore
   public Calendar getStartTime()
   {
      return ;
   }

   
getEndTime.

Returns:
Calendar return the end time of restore
   public Calendar getEndTime()
   {
      return ;
   }

   
getRepositoryName.

Returns:
String the name of destination repository
   public String getRepositoryName()
   {
      return .getName();
   }

   
GetRepositoryBackupChainLog.

Returns:
repositoryBackupChainLog
   {
      return ;
   }

   
getRepositoryEntry.

Returns:
repositoryBackupChainLog
   {
      return ;
   }
New to GrepCode? Check out our FAQ X