Author: areshetnyak
Date: 2009-10-30 07:08:16 -0400 (Fri, 30 Oct 2009)
New Revision: 451
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/storage/jdbc/SQLExceptionHandler.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java
Log:
EXOJCR-218 : The exception JCRItemExistsException was added. This exception is throwing in
SQLExceptionHandler and catching in BackupWorkspaceinitializer, BackupManagerImpl.
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 2009-10-30
10:57:51 UTC (rev 450)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java 2009-10-30
11:08:16 UTC (rev 451)
@@ -37,6 +37,7 @@
import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
import
org.exoplatform.services.jcr.impl.dataflow.persistent.CacheableWorkspaceDataManager;
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.observation.ExtendedEvent;
@@ -67,19 +68,21 @@
*
* @version $Id: BackupWorkspaceInitializer.java 34801 2009-07-31 15:44:50Z dkatayev $
*/
-public class BackupWorkspaceInitializer extends SysViewWorkspaceInitializer
+public class BackupWorkspaceInitializer
+ extends SysViewWorkspaceInitializer
{
private final String restoreDir;
private FileCleaner fileCleaner;
public BackupWorkspaceInitializer(WorkspaceEntry config, RepositoryEntry repConfig,
- CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl
namespaceRegistry,
- LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager,
ValueFactoryImpl valueFactory,
- AccessManager accessManager) throws RepositoryConfigurationException,
PathNotFoundException, RepositoryException
+ CacheableWorkspaceDataManager dataManager, NamespaceRegistryImpl
namespaceRegistry,
+ LocationFactory locationFactory, NodeTypeManagerImpl nodeTypeManager,
ValueFactoryImpl valueFactory,
+ AccessManager accessManager) throws RepositoryConfigurationException,
PathNotFoundException,
+ RepositoryException
{
super(config, repConfig, dataManager, namespaceRegistry, locationFactory,
nodeTypeManager, valueFactory,
- accessManager);
+ accessManager);
this.fileCleaner = new FileCleaner();
@@ -98,7 +101,7 @@
if (isWorkspaceInitialized())
{
- return (NodeData)dataManager.getItemData(Constants.ROOT_UUID);
+ return (NodeData) dataManager.getItemData(Constants.ROOT_UUID);
}
try
@@ -116,10 +119,10 @@
// restore from incremental backup
incrementalRead();
- final NodeData root = (NodeData)dataManager.getItemData(Constants.ROOT_UUID);
+ final NodeData root = (NodeData) dataManager.getItemData(Constants.ROOT_UUID);
log.info("Workspace " + workspaceName + " restored from file
" + restorePath + " in "
- + (System.currentTimeMillis() - start) * 1d / 1000 + "sec");
+ + (System.currentTimeMillis() - start) * 1d / 1000 + "sec");
return root;
}
@@ -163,7 +166,7 @@
}
private void incrementalRestore(File incrementalBackupFile) throws
FileNotFoundException, IOException,
- ClassNotFoundException, RepositoryException
+ ClassNotFoundException, RepositoryException
{
ObjectInputStream ois = null;
try
@@ -200,14 +203,26 @@
catch (JCRInvalidItemStateException e)
{
TransactionChangesLog normalizeChangesLog =
- getNormalizedChangesLog(e.getIdentifier(), e.getState(), changesLog);
+ 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);
+ "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)
@@ -235,7 +250,7 @@
{
// Node... by ID and desc path
if (!item.getIdentifier().equals(collisionID)
- &&
!item.getQPath().isDescendantOf(citem.getData().getQPath()))
+ &&
!item.getQPath().isDescendantOf(citem.getData().getQPath()))
normalized.add(change);
}
else if (!item.getIdentifier().equals(collisionID))
@@ -273,7 +288,8 @@
return list;
}
- class BackupFilesFilter implements FileFilter
+ class BackupFilesFilter
+ implements FileFilter
{
public boolean accept(File pathname)
{
@@ -308,7 +324,7 @@
{
// read ChangesLog
- transactionChangesLog = (TransactionChangesLog)in.readObject();
+ transactionChangesLog = (TransactionChangesLog) in.readObject();
// read FixupStream count
int iFixupStream = in.readInt();
@@ -338,7 +354,7 @@
}
RestoreChangesLog restoreChangesLog =
- new RestoreChangesLog(transactionChangesLog, listFixupStreams, listFiles,
fileCleaner);
+ new RestoreChangesLog(transactionChangesLog, listFixupStreams,
listFiles, fileCleaner);
restoreChangesLog.restore();
@@ -347,7 +363,7 @@
}
else if (changesLogType ==
RestoreChangesLog.Type.ItemDataChangesLog_without_Streams)
{
- transactionChangesLog = (TransactionChangesLog)in.readObject();
+ transactionChangesLog = (TransactionChangesLog) in.readObject();
}
return transactionChangesLog;
@@ -372,8 +388,8 @@
}
else if (readBytes < bufferSize)
{
- ois.readFully(buf, 0, (int)readBytes);
- fos.write(buf, 0, (int)readBytes);
+ ois.readFully(buf, 0, (int) readBytes);
+ fos.write(buf, 0, (int) readBytes);
}
readBytes -= bufferSize;
}
@@ -402,7 +418,7 @@
private FileCleaner fileCleaner;
public RestoreChangesLog(TransactionChangesLog transactionChangesLog,
List<FixupStream> listFixupStreams,
- List<File> listFiles, FileCleaner fileCleaner)
+ List<File> listFiles, FileCleaner fileCleaner)
{
this.itemDataChangesLog = transactionChangesLog;
this.listFixupStream = listFixupStreams;
@@ -423,9 +439,9 @@
ItemState itemState =
listItemState.get(listFixupStream.get(i).getItemSateId());
ItemData itemData = itemState.getData();
- TransientPropertyData propertyData = (TransientPropertyData)itemData;
+ TransientPropertyData propertyData = (TransientPropertyData) itemData;
TransientValueData transientValueData =
-
(TransientValueData)(propertyData.getValues().get(listFixupStream.get(i).getValueDataId()));
+ (TransientValueData)
(propertyData.getValues().get(listFixupStream.get(i).getValueDataId()));
transientValueData.setStream(new FileInputStream(listFile.get(i)));
transientValueData.setFileCleaner(fileCleaner);
transientValueData.isByteArray();
@@ -436,7 +452,8 @@
}
}
- class FixupStream implements Externalizable
+ class FixupStream
+ implements Externalizable
{
int iItemStateId = -1;
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/SQLExceptionHandler.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/SQLExceptionHandler.java 2009-10-30
10:57:51 UTC (rev 450)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/SQLExceptionHandler.java 2009-10-30
11:08:16 UTC (rev 451)
@@ -23,6 +23,7 @@
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.QPathEntry;
import org.exoplatform.services.jcr.impl.storage.JCRInvalidItemStateException;
+import org.exoplatform.services.jcr.impl.storage.JCRItemExistsException;
import java.io.IOException;
import java.sql.SQLException;
@@ -175,7 +176,7 @@
{
// item already exists
message += "Item already exists in storage: " + itemInfo;
- ownException = new ItemExistsException(message, e);
+ ownException = new JCRItemExistsException(message, me.getIdentifier(),
ItemState.ADDED, e);
throw ownException;
}
@@ -183,7 +184,7 @@
if (me != null)
{
message += "Item already exists in storage: " + itemInfo;
- ownException = new ItemExistsException(message, e);
+ ownException = new JCRItemExistsException(message, me.getIdentifier(),
ItemState.ADDED, e);
throw ownException;
}
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2009-10-30
10:57:51 UTC (rev 450)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupManagerImpl.java 2009-10-30
11:08:16 UTC (rev 451)
@@ -49,6 +49,7 @@
import org.exoplatform.services.jcr.impl.core.SysViewWorkspaceInitializer;
import
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
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.observation.ExtendedEvent;
import org.exoplatform.services.jcr.util.IdGenerator;
@@ -88,7 +89,8 @@
* @version $Id: $
*/
-public class BackupManagerImpl implements BackupManager, Startable
+public class BackupManagerImpl
+ implements BackupManager, Startable
{
protected static Log log = ExoLogger.getLogger("ext.BackupManagerImpl");
@@ -144,7 +146,8 @@
private final AutoStopper stopper;
- class MessagesListener implements BackupJobListener
+ class MessagesListener
+ implements BackupJobListener
{
public void onError(BackupJob job, String message, Throwable error)
@@ -227,7 +230,8 @@
}
}
- class LogsFilter implements FileFilter
+ class LogsFilter
+ implements FileFilter
{
public boolean accept(File pathname)
@@ -236,7 +240,8 @@
}
}
- class TaskFilter implements FileFilter
+ class TaskFilter
+ implements FileFilter
{
public boolean accept(File pathname)
@@ -245,7 +250,8 @@
}
}
- class AutoStopper extends Thread
+ class AutoStopper
+ extends Thread
{
/**
@@ -398,8 +404,8 @@
*/
@Deprecated
public void restore(BackupChainLog log, String repositoryName, WorkspaceEntry
workspaceEntry)
- throws BackupOperationException, RepositoryException,
RepositoryConfigurationException,
- BackupConfigurationException
+ throws BackupOperationException, RepositoryException,
RepositoryConfigurationException,
+ BackupConfigurationException
{
List<JobEntryInfo> list = log.getJobEntryInfos();
@@ -457,8 +463,8 @@
}
protected void restoreOverInitializer(BackupChainLog log, String repositoryName,
WorkspaceEntry workspaceEntry)
- throws BackupOperationException, RepositoryException,
RepositoryConfigurationException,
- BackupConfigurationException
+ throws BackupOperationException, RepositoryException,
RepositoryConfigurationException,
+ BackupConfigurationException
{
List<JobEntryInfo> list = log.getJobEntryInfos();
@@ -516,7 +522,7 @@
}
private boolean workspaceAlreadyExist(String repository, String workspace) throws
RepositoryException,
- RepositoryConfigurationException
+ RepositoryConfigurationException
{
String[] ws = repoService.getRepository(repository).getWorkspaceNames();
@@ -530,7 +536,7 @@
* {@inheritDoc}
*/
public BackupChain startBackup(BackupConfig config) throws BackupOperationException,
BackupConfigurationException,
- RepositoryException, RepositoryConfigurationException
+ RepositoryException, RepositoryConfigurationException
{
return startBackup(config, null);
@@ -548,7 +554,7 @@
* @throws RepositoryConfigurationException
*/
BackupChain startBackup(BackupConfig config, BackupJobListener jobListener) throws
BackupOperationException,
- BackupConfigurationException, RepositoryException,
RepositoryConfigurationException
+ BackupConfigurationException, RepositoryException,
RepositoryConfigurationException
{
if (config.getIncrementalJobPeriod() < 0)
@@ -561,8 +567,8 @@
config.setIncrementalJobPeriod(defaultIncrementalJobPeriod);
BackupChain bchain =
- new BackupChainImpl(config, logsDirectory,
repoService.getRepository(config.getRepository()), fullBackupType,
- incrementalBackupType, IdGenerator.generate());
+ new BackupChainImpl(config, logsDirectory,
repoService.getRepository(config.getRepository()),
+ fullBackupType, incrementalBackupType, IdGenerator.generate());
bchain.addListener(messagesListener);
bchain.addListener(jobListener);
@@ -666,20 +672,20 @@
@Deprecated
private void fullRestore(String pathBackupFile, String repositoryName, String
workspaceName,
- WorkspaceEntry workspaceEntry) throws FileNotFoundException, IOException,
RepositoryException,
- RepositoryConfigurationException
+ WorkspaceEntry workspaceEntry) throws FileNotFoundException, IOException,
RepositoryException,
+ RepositoryConfigurationException
{
- RepositoryImpl defRep = (RepositoryImpl)repoService.getRepository(repositoryName);
+ RepositoryImpl defRep = (RepositoryImpl)
repoService.getRepository(repositoryName);
defRep.importWorkspace(workspaceEntry.getName(), new
FileInputStream(pathBackupFile));
}
private void fullRestoreOverInitializer(String pathBackupFile, String repositoryName,
WorkspaceEntry workspaceEntry)
- throws FileNotFoundException, IOException, RepositoryException,
RepositoryConfigurationException
+ throws FileNotFoundException, IOException, RepositoryException,
RepositoryConfigurationException
{
- RepositoryImpl defRep = (RepositoryImpl)repoService.getRepository(repositoryName);
+ RepositoryImpl defRep = (RepositoryImpl)
repoService.getRepository(repositoryName);
// set the initializer SysViewWorkspaceInitializer
WorkspaceInitializerEntry wiEntry = new WorkspaceInitializerEntry();
@@ -698,13 +704,13 @@
}
private void incrementalRestore(String pathBackupFile, String repositoryName, String
workspaceName)
- throws RepositoryException, RepositoryConfigurationException,
BackupOperationException, FileNotFoundException,
- IOException, ClassNotFoundException
+ throws RepositoryException, RepositoryConfigurationException,
BackupOperationException,
+ FileNotFoundException, IOException, ClassNotFoundException
{
- SessionImpl sesion =
(SessionImpl)repoService.getRepository(repositoryName).getSystemSession(workspaceName);
+ SessionImpl sesion = (SessionImpl)
repoService.getRepository(repositoryName).getSystemSession(workspaceName);
WorkspacePersistentDataManager dataManager =
-
(WorkspacePersistentDataManager)sesion.getContainer().getComponentInstanceOfType(
- WorkspacePersistentDataManager.class);
+ (WorkspacePersistentDataManager)
sesion.getContainer().getComponentInstanceOfType(
+ WorkspacePersistentDataManager.class);
ObjectInputStream ois = null;
File backupFile = null;
@@ -739,7 +745,7 @@
}
private void saveChangesLog(WorkspacePersistentDataManager dataManager,
TransactionChangesLog changesLog)
- throws RepositoryException, BackupOperationException
+ throws RepositoryException, BackupOperationException
{
try
{
@@ -748,14 +754,26 @@
catch (JCRInvalidItemStateException e)
{
TransactionChangesLog normalizeChangesLog =
- getNormalizedChangesLog(e.getIdentifier(), e.getState(), changesLog);
+ getNormalizedChangesLog(e.getIdentifier(), e.getState(), changesLog);
if (normalizeChangesLog != null)
saveChangesLog(dataManager, normalizeChangesLog);
else
throw new BackupOperationException(
- "Collisions found during save of restore changes log, but caused item
is not found by ID "
- + e.getIdentifier() + ". " + e, e);
+ "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(dataManager, 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)
@@ -783,7 +801,7 @@
{
// Node... by ID and desc path
if (!item.getIdentifier().equals(collisionID)
- &&
!item.getQPath().isDescendantOf(citem.getData().getQPath()))
+ &&
!item.getQPath().isDescendantOf(citem.getData().getQPath()))
normalized.add(change);
}
else if (!item.getIdentifier().equals(collisionID))
@@ -817,7 +835,7 @@
{
// read ChangesLog
- transactionChangesLog = (TransactionChangesLog)in.readObject();
+ transactionChangesLog = (TransactionChangesLog) in.readObject();
// read FixupStream count
int iFixupStream = in.readInt();
@@ -848,7 +866,7 @@
}
PendingChangesLog pendingChangesLog =
- new PendingChangesLog(transactionChangesLog, listFixupStreams, listFiles,
fileCleaner);
+ new PendingChangesLog(transactionChangesLog, listFixupStreams,
listFiles, fileCleaner);
pendingChangesLog.restore();
@@ -857,7 +875,7 @@
}
else if (changesLogType == PendingChangesLog.Type.CHANGESLOG_WITHOUT_STREAM)
{
- transactionChangesLog = (TransactionChangesLog)in.readObject();
+ transactionChangesLog = (TransactionChangesLog) in.readObject();
}
return transactionChangesLog;
@@ -882,8 +900,8 @@
}
else if (readBytes < bufferSize)
{
- ois.readFully(buf, 0, (int)readBytes);
- fos.write(buf, 0, (int)readBytes);
+ ois.readFully(buf, 0, (int) readBytes);
+ fos.write(buf, 0, (int) readBytes);
}
readBytes -= bufferSize;
}
@@ -905,7 +923,7 @@
* @throws RepositoryException
*/
private void writeParamsToRegistryService(SessionProvider sessionProvider) throws
IOException, SAXException,
- ParserConfigurationException, RepositoryException
+ ParserConfigurationException, RepositoryException
{
Document doc =
DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element root = doc.createElement(SERVICE_NAME);
@@ -931,7 +949,7 @@
* @throws PathNotFoundException
*/
private void readParamsFromRegistryService(SessionProvider sessionProvider) throws
PathNotFoundException,
- RepositoryException
+ RepositoryException
{
String entryPath = RegistryService.EXO_SERVICES + "/" + SERVICE_NAME +
"/" + BACKUP_PROPERTIES;
RegistryEntry registryEntry = registryService.getEntry(sessionProvider,
entryPath);
@@ -1043,7 +1061,7 @@
{
BackupChain chain = it.next();
if (repository.equals(chain.getBackupConfig().getRepository())
- && workspace.equals(chain.getBackupConfig().getWorkspace()))
+ && workspace.equals(chain.getBackupConfig().getWorkspace()))
return chain;
}
return null;
@@ -1146,13 +1164,13 @@
* {@inheritDoc}
*/
public void restore(BackupChainLog log, String repositoryName, WorkspaceEntry
workspaceEntry, boolean asynchronous)
- throws BackupOperationException, BackupConfigurationException,
RepositoryException,
- RepositoryConfigurationException
+ throws BackupOperationException, BackupConfigurationException,
RepositoryException,
+ RepositoryConfigurationException
{
if (asynchronous)
{
JobWorkspaceRestore jobRestore =
- new JobWorkspaceRestore(repoService, this, repositoryName, log,
workspaceEntry);
+ new JobWorkspaceRestore(repoService, this, repositoryName, log,
workspaceEntry);
restoreJobs.add(jobRestore);
jobRestore.start();
}