@Override
protected void doRestore() throws Throwable
{
List<DataRestore> dataRestorers = new ArrayList<DataRestore>();
ManageableRepository repository = null;
try
{
repository = repositoryService.getRepository(repositoryEntry.getName());
}
catch (RepositoryConfigurationException e)
{
throw new RepositoryException(e);
}
List<Backupable> backupableComponents =
repository.getWorkspaceContainer(workspaceName).getComponentInstancesOfType(Backupable.class);
List<WorkspaceContainerFacade> workspacesWaits4Resume = new ArrayList<WorkspaceContainerFacade>();
Throwable throwable = null;
try
{
// set state SUSPENDED to other workspaces if singledb
if (workspaceEntry.getContainer().getParameterBoolean("multi-db") == false)
{
for (WorkspaceEntry we : repositoryEntry.getWorkspaceEntries())
{
if (!we.getName().equals(workspaceEntry.getName()))
{
WorkspaceContainerFacade wsContainer = repository.getWorkspaceContainer(we.getName());
wsContainer.setState(ManageableRepository.SUSPENDED);
workspacesWaits4Resume.add(wsContainer);
}
}
}
DataRestoreContext context = new DataRestoreContext(
new String[] {DataRestoreContext.STORAGE_DIR},
new Object[] {new File(restorePath)});
// restore all components
for (Backupable component : backupableComponents)
{
dataRestorers.add(component.getDataRestorer(context));
}
for (DataRestore restorer : dataRestorers)
{
restorer.clean();
}
for (DataRestore restorer : dataRestorers)
{
restorer.restore();
}
for (DataRestore restorer : dataRestorers)
{
restorer.commit();
}
}
catch (Throwable e)
{
throwable = e;
for (DataRestore restorer : dataRestorers)
{
try
{
restorer.rollback();
}
catch (BackupException e1)
{
LOG.error("Can't rollback restorer", e1);
}
}
throw e;
}
finally
{
for (DataRestore restorer : dataRestorers)
{
try
{
restorer.close();
}
catch (BackupException e)
{
LOG.error("Can't close restorer", e);
}
}
try
{
for (WorkspaceContainerFacade wsContainer : workspacesWaits4Resume)
{
wsContainer.setState(ManageableRepository.ONLINE);
}
}
catch (RepositoryException e)
{
if (throwable == null)
{
LOG.error("Con not set ONLYNE state for repository " + repository.getConfiguration().getName(), e);
}
else
{
throw new RepositoryException("Con not set ONLINE state for repository "
+ repository.getConfiguration().getName(), e);
}
}
}
}