Author: tolusha
Date: 2011-01-11 07:13:15 -0500 (Tue, 11 Jan 2011)
New Revision: 3789
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/BackupException.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/Backupable.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/DumpTable.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/RestoreException.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/RestoreTable.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/ResumeException.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/SuspendException.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/Suspendable.java
Removed:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoReader.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoWriter.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/WorkspaceContainerFacade.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/security/JCRRuntimePermissions.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/lock/infinispan/ISPNCacheableLockManagerImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.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/core/query/lucene/MultiIndex.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/WorkspacePersistentDataManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRDBMSBackupManager.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsFullBackupJob.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/TesterRdbmsWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.ext/src/test/resources/test.policy
Log:
EXOJCR-1130: Implement approach using the marker Backupable
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/WorkspaceContainerFacade.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/WorkspaceContainerFacade.java 2011-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/WorkspaceContainerFacade.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -20,6 +20,8 @@
import org.exoplatform.services.jcr.impl.WorkspaceContainer;
+import java.util.List;
+
/**
* Created by The eXo Platform SAS .<br/> An entry point to the implementation,
used for extending
* functionality
@@ -54,6 +56,18 @@
}
/**
+ * Returns list of components of specific type.
+ *
+ * @param componentType
+ * component type
+ * @return List<Object>
+ */
+ public List getComponentInstancesOfType(Class componentType)
+ {
+ return container.getComponentInstancesOfType(componentType);
+ }
+
+ /**
* @param key
* - an internal key of internal component
* @return the component
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/security/JCRRuntimePermissions.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/security/JCRRuntimePermissions.java 2011-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/security/JCRRuntimePermissions.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -31,4 +31,5 @@
public static final RuntimePermission MANAGE_REPOSITORY_PERMISSION = new
RuntimePermission("manageRepository");
+
}
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-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cacheable/AbstractCacheableLockManager.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -104,6 +104,11 @@
protected LockRemover lockRemover;
/**
+ * Workspace configuration;
+ */
+ protected final WorkspaceEntry config;
+
+ /**
* SessionLockManagers that uses this LockManager.
*/
protected Map<String, CacheableSessionLockManager> sessionLockManagers;
@@ -164,6 +169,7 @@
lockTimeOut = DEFAULT_LOCK_TIMEOUT;
}
+ this.config = config;
this.dataManager = dataManager;
this.sessionLockManagers = new ConcurrentHashMap<String,
CacheableSessionLockManager>();
this.tm = transactionManager;
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNCacheableLockManagerImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNCacheableLockManagerImpl.java 2011-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNCacheableLockManagerImpl.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -17,12 +17,16 @@
*/
package org.exoplatform.services.jcr.impl.core.lock.infinispan;
+import org.exoplatform.commons.utils.PrivilegedSystemHelper;
+import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.jmx.annotations.NameTemplate;
import org.exoplatform.management.jmx.annotations.Property;
+import org.exoplatform.services.jcr.config.LockManagerEntry;
import org.exoplatform.services.jcr.config.MappedParametrizedObjectEntry;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.SimpleParameterEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.impl.core.lock.LockRemoverHolder;
import
org.exoplatform.services.jcr.impl.core.lock.cacheable.AbstractCacheableLockManager;
@@ -31,6 +35,12 @@
import
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.BackupException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Backupable;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.DumpTable;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.RestoreException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.RestoreTable;
import org.exoplatform.services.jcr.infinispan.ISPNCacheFactory;
import org.exoplatform.services.jcr.infinispan.PrivilegedISPNCacheHelper;
import org.exoplatform.services.log.ExoLogger;
@@ -39,6 +49,8 @@
import org.exoplatform.services.transaction.TransactionService;
import org.infinispan.Cache;
+import java.io.File;
+import java.io.IOException;
import java.io.Serializable;
import java.security.AccessController;
import java.security.PrivilegedActionException;
@@ -52,6 +64,8 @@
import javax.jcr.RepositoryException;
import javax.jcr.lock.LockException;
import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
import javax.sql.DataSource;
import javax.transaction.TransactionManager;
@@ -61,7 +75,7 @@
*/
@Managed
@NameTemplate(@Property(key = "service", value = "lockmanager"))
-public class ISPNCacheableLockManagerImpl extends AbstractCacheableLockManager
+public class ISPNCacheableLockManagerImpl extends AbstractCacheableLockManager implements
Backupable
{
/**
@@ -394,4 +408,198 @@
}
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void backup(File storageDir) throws BackupException
+ {
+ Connection jdbcConn = null;
+
+ try
+ {
+ List<String> tableNames = new ArrayList<String>();
+ String dsName = null;
+
+ LockManagerEntry lockManagerEntry = config.getLockManager();
+ if (lockManagerEntry != null)
+ {
+ for (SimpleParameterEntry entry : lockManagerEntry.getParameters())
+ {
+ if (entry.getName().equals(INFINISPAN_JDBC_TABLE_NAME))
+ {
+ tableNames.add(entry.getValue());
+ }
+ else if (entry.getName().equals(INFINISPAN_JDBC_CL_DATASOURCE))
+ {
+ dsName = entry.getValue();
+ }
+ }
+ }
+
+ final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
+ if (ds == null)
+ {
+ throw new NameNotFoundException("Data source " + dsName + "
not found");
+ }
+
+ jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new
PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return ds.getConnection();
+
+ }
+ });
+
+ for (String table : tableNames)
+ {
+ DumpTable.dump(jdbcConn, table, "SELECT * FROM " + table,
storageDir);
+ }
+ }
+ 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);
+ }
+ catch (NamingException e)
+ {
+ throw new BackupException(e);
+ }
+ finally
+ {
+ if (jdbcConn != null)
+ {
+ try
+ {
+ jdbcConn.close();
+ }
+ catch (SQLException e)
+ {
+ throw new BackupException(e);
+ }
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void restore(File storageDir) throws RestoreException
+ {
+ Connection jdbcConn = null;
+
+ try
+ {
+ List<String> tableNames = new ArrayList<String>();
+ String dsName = null;
+
+ LockManagerEntry lockManagerEntry = config.getLockManager();
+ if (lockManagerEntry != null)
+ {
+ for (SimpleParameterEntry entry : lockManagerEntry.getParameters())
+ {
+ if (entry.getName().equals(INFINISPAN_JDBC_TABLE_NAME))
+ {
+ tableNames.add(entry.getValue());
+ }
+ else if (entry.getName().equals(INFINISPAN_JDBC_CL_DATASOURCE))
+ {
+ dsName = entry.getValue();
+ }
+ }
+ }
+
+ final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
+ if (ds == null)
+ {
+ throw new NameNotFoundException("Data source " + dsName + "
not found");
+ }
+
+ jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new
PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return ds.getConnection();
+
+ }
+ });
+ jdbcConn.setAutoCommit(false);
+
+ int maxBufferSize =
+
config.getContainer().getParameterInteger(JDBCWorkspaceDataContainer.MAXBUFFERSIZE_PROP,
+ JDBCWorkspaceDataContainer.DEF_MAXBUFFERSIZE);
+ File tempDir = new
File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
+
+ RestoreTable restoreTable = new RestoreTable(null, tempDir, maxBufferSize);
+ restoreTable.setSrcContainerName(null);
+ restoreTable.setSrcMultiDb(null);
+ restoreTable.setDstContainerName(null);
+ restoreTable.setDstMultiDb(null);
+ restoreTable.setSkipColumnIndex(null);
+ restoreTable.setDeleteColumnIndex(null);
+ restoreTable.setNewColumnIndex(null);
+ restoreTable.setConvertColumnIndex(null);
+
+ for (String table : tableNames)
+ {
+ restoreTable.setContentFile(new File(storageDir, table +
DumpTable.CONTENT_FILE_SUFFIX));
+ restoreTable.setContentLenFile(new File(storageDir, table +
DumpTable.CONTENT_LEN_FILE_SUFFIX));
+
+ restoreTable.restore(jdbcConn, table, storageDir);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RestoreException(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 RestoreException(msg, e);
+ }
+ catch (NamingException e)
+ {
+ throw new RestoreException(e);
+ }
+ finally
+ {
+ if (jdbcConn != null)
+ {
+ try
+ {
+ jdbcConn.close();
+ }
+ catch (SQLException e)
+ {
+ throw new RestoreException(e);
+ }
+ }
+ }
+ }
+
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2011-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -16,12 +16,16 @@
*/
package org.exoplatform.services.jcr.impl.core.lock.jbosscache;
+import org.exoplatform.commons.utils.PrivilegedSystemHelper;
+import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.jmx.annotations.NameTemplate;
import org.exoplatform.management.jmx.annotations.Property;
+import org.exoplatform.services.jcr.config.LockManagerEntry;
import org.exoplatform.services.jcr.config.MappedParametrizedObjectEntry;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.SimpleParameterEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.impl.core.lock.LockRemoverHolder;
import
org.exoplatform.services.jcr.impl.core.lock.cacheable.AbstractCacheableLockManager;
@@ -30,9 +34,15 @@
import
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.BackupException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Backupable;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.DumpTable;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.RestoreException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.RestoreTable;
import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory;
+import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory.CacheType;
import org.exoplatform.services.jcr.jbosscache.PrivilegedJBossCacheHelper;
-import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory.CacheType;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.naming.InitialContextInitializer;
@@ -47,6 +57,8 @@
import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.lock.TimeoutException;
+import java.io.File;
+import java.io.IOException;
import java.io.Serializable;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -61,6 +73,8 @@
import javax.jcr.RepositoryException;
import javax.jcr.lock.LockException;
import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
import javax.sql.DataSource;
import javax.transaction.TransactionManager;
@@ -74,7 +88,7 @@
*/
@Managed
@NameTemplate(@Property(key = "service", value = "lockmanager"))
-public class CacheableLockManagerImpl extends AbstractCacheableLockManager
+public class CacheableLockManagerImpl extends AbstractCacheableLockManager implements
Backupable
{
public static final String JBOSSCACHE_JDBC_CL_DATASOURCE =
"jbosscache-cl-cache.jdbc.datasource";
@@ -570,4 +584,199 @@
node.setResident(true);
}
+ /**
+ * {@inheritDoc}
+ */
+ public void backup(File storageDir) throws BackupException
+ {
+ Connection jdbcConn = null;
+
+ try
+ {
+ List<String> tableNames = new ArrayList<String>();
+ String dsName = null;
+
+ LockManagerEntry lockManagerEntry = config.getLockManager();
+ if (lockManagerEntry != null)
+ {
+ for (SimpleParameterEntry entry : lockManagerEntry.getParameters())
+ {
+ if (entry.getName().equals(JBOSSCACHE_JDBC_TABLE_NAME))
+ {
+ tableNames.add(entry.getValue());
+ tableNames.add(entry.getValue() + "_D");
+ }
+ else if (entry.getName().equals(JBOSSCACHE_JDBC_CL_DATASOURCE))
+ {
+ dsName = entry.getValue();
+ }
+ }
+ }
+
+ final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
+ if (ds == null)
+ {
+ throw new NameNotFoundException("Data source " + dsName + "
not found");
+ }
+
+ jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new
PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return ds.getConnection();
+
+ }
+ });
+
+ for (String table : tableNames)
+ {
+ DumpTable.dump(jdbcConn, table, "SELECT * FROM " + table,
storageDir);
+ }
+ }
+ 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);
+ }
+ catch (NamingException e)
+ {
+ throw new BackupException(e);
+ }
+ finally
+ {
+ if (jdbcConn != null)
+ {
+ try
+ {
+ jdbcConn.close();
+ }
+ catch (SQLException e)
+ {
+ throw new BackupException(e);
+ }
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void restore(File storageDir) throws RestoreException
+ {
+ Connection jdbcConn = null;
+
+ try
+ {
+ List<String> tableNames = new ArrayList<String>();
+ String dsName = null;
+
+ LockManagerEntry lockManagerEntry = config.getLockManager();
+ if (lockManagerEntry != null)
+ {
+ for (SimpleParameterEntry entry : lockManagerEntry.getParameters())
+ {
+ if (entry.getName().equals(JBOSSCACHE_JDBC_TABLE_NAME))
+ {
+ tableNames.add(entry.getValue());
+ tableNames.add(entry.getValue() + "_D");
+ }
+ else if (entry.getName().equals(JBOSSCACHE_JDBC_CL_DATASOURCE))
+ {
+ dsName = entry.getValue();
+ }
+ }
+ }
+
+ final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
+ if (ds == null)
+ {
+ throw new NameNotFoundException("Data source " + dsName + "
not found");
+ }
+
+ jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new
PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return ds.getConnection();
+
+ }
+ });
+ jdbcConn.setAutoCommit(false);
+
+ int maxBufferSize =
+
config.getContainer().getParameterInteger(JDBCWorkspaceDataContainer.MAXBUFFERSIZE_PROP,
+ JDBCWorkspaceDataContainer.DEF_MAXBUFFERSIZE);
+ File tempDir = new
File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
+
+ RestoreTable restoreTable = new RestoreTable(null, tempDir, maxBufferSize);
+ restoreTable.setSrcContainerName(null);
+ restoreTable.setSrcMultiDb(null);
+ restoreTable.setDstContainerName(null);
+ restoreTable.setDstMultiDb(null);
+ restoreTable.setSkipColumnIndex(null);
+ restoreTable.setDeleteColumnIndex(null);
+ restoreTable.setNewColumnIndex(null);
+ restoreTable.setConvertColumnIndex(null);
+
+ for (String table : tableNames)
+ {
+ restoreTable.setContentFile(new File(storageDir, table +
DumpTable.CONTENT_FILE_SUFFIX));
+ restoreTable.setContentLenFile(new File(storageDir, table +
DumpTable.CONTENT_LEN_FILE_SUFFIX));
+
+ restoreTable.restore(jdbcConn, table, storageDir);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RestoreException(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 RestoreException(msg, e);
+ }
+ catch (NamingException e)
+ {
+ throw new RestoreException(e);
+ }
+ finally
+ {
+ if (jdbcConn != null)
+ {
+ try
+ {
+ jdbcConn.close();
+ }
+ catch (SQLException e)
+ {
+ throw new RestoreException(e);
+ }
+ }
+ }
+ }
+
}
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-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -18,9 +18,9 @@
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.WildcardQuery;
-import org.apache.lucene.search.BooleanClause.Occur;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.services.document.DocumentReaderService;
import org.exoplatform.services.jcr.config.QueryHandlerEntry;
@@ -52,6 +52,9 @@
import org.exoplatform.services.jcr.impl.core.value.PathValue;
import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
import
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.ResumeException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.SuspendException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Suspendable;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.factories.annotations.NonVolatile;
@@ -86,7 +89,7 @@
* @version $Id: SearchManager.java 1008 2009-12-11 15:14:51Z nzamosenchuk $
*/
@NonVolatile
-public class SearchManager implements Startable, MandatoryItemsPersistenceListener
+public class SearchManager implements Startable, MandatoryItemsPersistenceListener,
Suspendable
{
/**
@@ -140,7 +143,7 @@
* The unique name of the related workspace
*/
protected final String wsId;
-
+
/**
* Creates a new <code>SearchManager</code>.
*
@@ -854,4 +857,26 @@
return wsId;
}
+ /**
+ * {@inheritDoc}
+ */
+ public void suspend() throws SuspendException
+ {
+ if (handler instanceof Suspendable)
+ {
+ ((Suspendable)handler).suspend();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void resume() throws ResumeException
+ {
+ if (handler instanceof Suspendable)
+ {
+ ((Suspendable)handler).resume();
+ }
+ }
+
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -2576,6 +2576,28 @@
}
/**
+ * Suspends multi index: flush volatile index and stop merger.
+ *
+ * @throws IOException
+ */
+ protected void suspend() throws IOException
+ {
+ flush();
+ merger.dispose();
+ }
+
+ /**
+ * Resume mulit index by starting merger.
+ *
+ * @throws IOException
+ */
+ protected void resume() throws IOException
+ {
+ merger = doInitIndexMerger();
+ merger.start();
+ }
+
+ /**
* Refresh list of indexes. Used to be called asynchronously when list changes. New,
actual list is read from
* IndexInfos.
* @throws IOException
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2011-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -62,6 +62,9 @@
import org.exoplatform.services.jcr.impl.core.query.SearchIndexConfigurationHelper;
import org.exoplatform.services.jcr.impl.core.query.lucene.directory.DirectoryManager;
import org.exoplatform.services.jcr.impl.core.query.lucene.directory.FSDirectoryManager;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.ResumeException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.SuspendException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Suspendable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
@@ -95,7 +98,7 @@
* Implements a {@link org.apache.jackrabbit.core.query.QueryHandler} using
* Lucene.
*/
-public class SearchIndex extends AbstractQueryHandler implements IndexerIoModeListener
+public class SearchIndex extends AbstractQueryHandler implements IndexerIoModeListener,
Suspendable
{
private static final DefaultQueryNodeFactory DEFAULT_QUERY_NODE_FACTORY = new
DefaultQueryNodeFactory();
@@ -2806,4 +2809,40 @@
log.error("Can not recover error log.", e);
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void suspend() throws SuspendException
+ {
+ if (modeHandler.getMode() == IndexerIoMode.READ_WRITE)
+ {
+ try
+ {
+ index.suspend();
+ }
+ catch (IOException e)
+ {
+ throw new SuspendException(e);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void resume() throws ResumeException
+ {
+ if (modeHandler.getMode() == IndexerIoMode.READ_WRITE)
+ {
+ try
+ {
+ index.resume();
+ }
+ catch (IOException e)
+ {
+ throw new ResumeException(e);
+ }
+ }
+ }
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/WorkspacePersistentDataManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/WorkspacePersistentDataManager.java 2011-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/WorkspacePersistentDataManager.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -42,6 +42,9 @@
import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
import org.exoplatform.services.jcr.impl.storage.SystemDataContainerHolder;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.ResumeException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.SuspendException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Suspendable;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
import org.exoplatform.services.log.ExoLogger;
@@ -55,6 +58,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.jcr.InvalidItemStateException;
import javax.jcr.RepositoryException;
@@ -67,7 +71,7 @@
* @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady
Azarenkov</a>
* @version $Id$
*/
-public abstract class WorkspacePersistentDataManager implements PersistentDataManager
+public abstract class WorkspacePersistentDataManager implements PersistentDataManager,
Suspendable
{
/**
@@ -86,10 +90,6 @@
protected final WorkspaceDataContainer systemDataContainer;
/**
- * Value sorages provider (for dest file suggestion on save).
- */
- // TODO protected final ValueStoragePluginProvider valueStorageProvider;
- /**
* Persistent level listeners. This listeners can be filtered by filters from
* <code>liestenerFilters</code> list.
*/
@@ -110,6 +110,8 @@
*/
protected boolean readOnly = false;
+ protected ReentrantReadWriteLock rwl = new ReentrantReadWriteLock(true);
+
/**
* WorkspacePersistentDataManager constructor.
*
@@ -119,12 +121,10 @@
* holder of system workspace data container
*/
public WorkspacePersistentDataManager(WorkspaceDataContainer dataContainer,
- //ValueStoragePluginProvider valueStorageProvider,
SystemDataContainerHolder systemDataContainerHolder)
{
this.dataContainer = dataContainer;
this.systemDataContainer = systemDataContainerHolder.getContainer();
- // this.valueStorageProvider = valueStorageProvider;
this.listeners = new ArrayList<ItemsPersistenceListener>();
this.mandatoryListeners = new
ArrayList<MandatoryItemsPersistenceListener>();
@@ -136,6 +136,8 @@
*/
public void save(final ItemStateChangesLog changesLog) throws RepositoryException
{
+ rwl.readLock().lock();
+
// check if this workspace container is not read-only
if (readOnly && !(changesLog instanceof ReadOnlyThroughChanges))
{
@@ -184,6 +186,8 @@
}
notifySaveItems(persistedLog, true);
+
+ rwl.readLock().unlock();
}
class ChangesLogPersister
@@ -838,4 +842,20 @@
this.readOnly = status;
}
+ /**
+ * {@inheritDoc}
+ */
+ public void suspend() throws SuspendException
+ {
+ rwl.writeLock().lock();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void resume() throws ResumeException
+ {
+ rwl.writeLock().unlock();
+ }
+
}
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-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -24,7 +24,17 @@
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.RepositoryEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.dataflow.serialization.ObjectReader;
+import org.exoplatform.services.jcr.dataflow.serialization.ObjectWriter;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectReaderImpl;
+import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectWriterImpl;
import org.exoplatform.services.jcr.impl.storage.WorkspaceDataContainerBase;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.BackupException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Backupable;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.DumpTable;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.RestoreException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.RestoreTable;
import org.exoplatform.services.jcr.impl.storage.jdbc.db.GenericConnectionFactory;
import org.exoplatform.services.jcr.impl.storage.jdbc.db.HSQLDBConnectionFactory;
import org.exoplatform.services.jcr.impl.storage.jdbc.db.MySQLConnectionFactory;
@@ -48,14 +58,19 @@
import org.picocontainer.Startable;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashSet;
+import java.util.Set;
import javax.jcr.RepositoryException;
import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import javax.sql.DataSource;
@@ -65,7 +80,7 @@
* @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter
Nedonosko</a>
* @version $Id:GenericWorkspaceDataContainer.java 13433 2007-03-15 16:07:23Z peterit $
*/
-public class JDBCWorkspaceDataContainer extends WorkspaceDataContainerBase implements
Startable
+public class JDBCWorkspaceDataContainer extends WorkspaceDataContainerBase implements
Startable, Backupable
{
protected static final Log LOG =
ExoLogger.getLogger("exo.jcr.component.core.JDBCWorkspaceDataContainer");
@@ -983,4 +998,365 @@
return checkSNSNewConnection;
}
+ /**
+ * {@inheritDoc}
+ */
+ public void backup(File storageDir) throws BackupException
+ {
+ ObjectWriter backupInfo = null;
+ Connection jdbcConn = null;
+
+ try
+ {
+ backupInfo =
+ new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(new
File(storageDir,
+ "JDBCWorkspaceDataContainer.info")));
+
+ backupInfo.writeString(containerName);
+ backupInfo.writeBoolean(multiDb);
+
+ final DataSource ds = (DataSource)new InitialContext().lookup(dbSourceName);
+ if (ds == null)
+ {
+ throw new NameNotFoundException("Data source " + dbSourceName +
" not found");
+ }
+
+ jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new
PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return ds.getConnection();
+
+ }
+ });
+
+ String[][] scripts;
+ if (multiDb)
+ {
+ scripts =
+ new String[][]{
+ {"JCR_MITEM", "select * from JCR_MITEM where
JCR_MITEM.name <> '" + Constants.ROOT_PARENT_NAME + "'"},
+ {"JCR_MVALUE", "select * from JCR_MVALUE"},
{"JCR_MREF", "select * from JCR_MREF"}};
+ }
+ else
+ {
+ scripts =
+ new String[][]{
+ {"JCR_SITEM", "select * from JCR_SITEM where
CONTAINER_NAME='" + containerName + "'"},
+ {
+ "JCR_SVALUE",
+ "select * from JCR_SVALUE where exists(select * from JCR_SITEM
where JCR_SITEM.ID=JCR_SVALUE.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME='"
+ + containerName + "')"},
+ {
+ "JCR_SREF",
+ "select * from JCR_SREF where exists(select * from JCR_SITEM
where JCR_SITEM.ID=JCR_SREF.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME='"
+ + containerName + "')"}};
+ }
+
+ for (String script[] : scripts)
+ {
+ DumpTable.dump(jdbcConn, script[0], script[1], storageDir);
+ }
+ }
+ 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);
+ }
+ catch (NamingException e)
+ {
+ throw new BackupException(e);
+ }
+ finally
+ {
+ if (backupInfo != null)
+ {
+ try
+ {
+ backupInfo.close();
+ }
+ catch (IOException e)
+ {
+ throw new BackupException(e);
+ }
+ }
+
+ if (jdbcConn != null)
+ {
+ try
+ {
+ jdbcConn.close();
+ }
+ catch (SQLException e)
+ {
+ throw new BackupException(e);
+ }
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void restore(File storageDir) throws RestoreException
+ {
+ ObjectReader backupInfo = null;
+ Statement st = null;
+ Connection jdbcConn = null;
+
+ try
+ {
+ final DataSource ds = (DataSource)new InitialContext().lookup(dbSourceName);
+ if (ds == null)
+ {
+ throw new NameNotFoundException("Data source " + dbSourceName +
" not found");
+ }
+
+ jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new
PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return ds.getConnection();
+
+ }
+ });
+ jdbcConn.setAutoCommit(false);
+
+ int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
+
+ backupInfo =
+ new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(new
File(storageDir,
+ "JDBCWorkspaceDataContainer.info")));
+
+ String srcContainerName = backupInfo.readString();
+ boolean srcMultiDb = backupInfo.readBoolean();
+
+ String[] tablesSuffix = new String[]{"ITEM", "VALUE",
"REF"};
+
+ File tempDir = new
File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
+ RestoreTable restoreTable = new RestoreTable(swapCleaner, tempDir,
maxBufferSize);
+
+ restoreTable.setSrcContainerName(srcContainerName);
+ restoreTable.setSrcMultiDb(srcMultiDb);
+ restoreTable.setDstContainerName(containerName);
+ restoreTable.setDstMultiDb(multiDb);
+
+ for (String tableSuffix : tablesSuffix)
+ {
+ String dstTableName = "JCR_" + (multiDb ? "M" :
"S") + tableSuffix;
+ String srcTableName = "JCR_" + (srcMultiDb ? "M" :
"S") + tableSuffix;
+
+ restoreTable.setContentFile(new File(storageDir, srcTableName +
DumpTable.CONTENT_FILE_SUFFIX));
+ restoreTable.setContentLenFile(new File(storageDir, srcTableName +
DumpTable.CONTENT_LEN_FILE_SUFFIX));
+
+ String constraint = null;
+ if (tableSuffix.equals("ITEM"))
+ {
+ if (dialect != DumpTable.DB_DIALECT_MYSQL && dialect !=
DumpTable.DB_DIALECT_MYSQL_UTF8)
+ {
+ // resolve constraint name depends on database
+ String constraintName;
+ if (dialect == DumpTable.DB_DIALECT_DB2 || dialect ==
DumpTable.DB_DIALECT_DB2V8)
+ {
+ constraintName = "JCR_FK_" + (multiDb ? "M" :
"S") + "ITEM_PAREN";
+ }
+ else
+ {
+ constraintName = "JCR_FK_" + (multiDb ? "M" :
"S") + "ITEM_PARENT";
+ }
+ constraint =
+ "CONSTRAINT " + constraintName + " FOREIGN
KEY(PARENT_ID) REFERENCES " + dstTableName + "(ID)";
+
+ // drop constraint
+ st = jdbcConn.createStatement();
+ st.execute("ALTER TABLE " + dstTableName + " DROP
CONSTRAINT " + constraintName);
+ jdbcConn.commit();
+ }
+
+ if (multiDb)
+ {
+ restoreTable.setSkipColumnIndex(null);
+ restoreTable.setNewColumnIndex(null);
+
+ if (!srcMultiDb)
+ {
+ // CONTAINER_NAME column index
+ restoreTable.setDeleteColumnIndex(4);
+
+ // ID and PARENT_ID column indexes
+ Set<Integer> convertColumnIndex = new
HashSet<Integer>();
+ convertColumnIndex.add(0);
+ convertColumnIndex.add(1);
+ restoreTable.setConvertColumnIndex(convertColumnIndex);
+ }
+ else
+ {
+ restoreTable.setDeleteColumnIndex(null);
+ restoreTable.setConvertColumnIndex(null);
+ }
+ }
+ else
+ {
+ if (srcMultiDb)
+ {
+ // CONTAINER_NAME column index
+ restoreTable.setNewColumnIndex(4);
+ restoreTable.setSkipColumnIndex(null);
+ restoreTable.setDeleteColumnIndex(null);
+
+ // ID and PARENT_ID column indexes
+ Set<Integer> convertColumnIndex = new
HashSet<Integer>();
+ convertColumnIndex.add(0);
+ convertColumnIndex.add(1);
+ restoreTable.setConvertColumnIndex(convertColumnIndex);
+ }
+ else
+ {
+ restoreTable.setNewColumnIndex(null);
+ restoreTable.setSkipColumnIndex(null);
+ restoreTable.setDeleteColumnIndex(null);
+
+ // ID and PARENT_ID and CONTAINER_NAME column indexes
+ Set<Integer> convertColumnIndex = new
HashSet<Integer>();
+ convertColumnIndex.add(0);
+ convertColumnIndex.add(1);
+ convertColumnIndex.add(4);
+ restoreTable.setConvertColumnIndex(convertColumnIndex);
+ }
+ }
+ }
+ else if (tableSuffix.equals("VALUE"))
+ {
+ // auto increment ID column
+ restoreTable.setSkipColumnIndex(0);
+ restoreTable.setDeleteColumnIndex(null);
+ restoreTable.setNewColumnIndex(null);
+
+ if (!multiDb || !srcMultiDb)
+ {
+ // PROPERTY_ID column index
+ Set<Integer> convertColumnIndex = new HashSet<Integer>();
+ convertColumnIndex.add(3);
+ restoreTable.setConvertColumnIndex(convertColumnIndex);
+ }
+ else
+ {
+ restoreTable.setConvertColumnIndex(null);
+ }
+ }
+ else
+ {
+ restoreTable.setSkipColumnIndex(null);
+ restoreTable.setDeleteColumnIndex(null);
+ restoreTable.setNewColumnIndex(null);
+
+ if (!multiDb || !srcMultiDb)
+ {
+ // NODE_ID and PROPERTY_ID column indexes
+ Set<Integer> convertColumnIndex = new HashSet<Integer>();
+ convertColumnIndex.add(0);
+ convertColumnIndex.add(1);
+ restoreTable.setConvertColumnIndex(convertColumnIndex);
+ }
+ else
+ {
+ restoreTable.setConvertColumnIndex(null);
+ }
+ }
+
+ restoreTable.restore(jdbcConn, dstTableName, storageDir);
+
+ if (tableSuffix.equals("ITEM"))
+ {
+ if (constraint != null)
+ {
+ // add constraint
+ st = jdbcConn.createStatement();
+ st.execute("ALTER TABLE " + dstTableName + " ADD "
+ constraint);
+ jdbcConn.commit();
+ }
+ }
+ }
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new RestoreException(e);
+ }
+ catch (IOException e)
+ {
+ throw new RestoreException(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 RestoreException(msg, e);
+ }
+ catch (NamingException e)
+ {
+ throw new RestoreException(e);
+ }
+ finally
+ {
+ if (backupInfo != null)
+ {
+ try
+ {
+ backupInfo.close();
+ }
+ catch (IOException e)
+ {
+ throw new RestoreException(e);
+ }
+ }
+
+ if (st != null)
+ {
+ try
+ {
+ st.close();
+ }
+ catch (SQLException e)
+ {
+ throw new RestoreException(e);
+ }
+ }
+
+ if (jdbcConn != null)
+ {
+ try
+ {
+ jdbcConn.close();
+ }
+ catch (SQLException e)
+ {
+ throw new RestoreException(e);
+ }
+ }
+ }
+ }
+
}
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/BackupException.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/BackupException.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/BackupException.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -0,0 +1,61 @@
+/*
+ * 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.storage.jdbc.backup;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy
Bazko</a>
+ * @version $Id: BackupException 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class BackupException extends Exception
+{
+ /**
+ * Constructor BackupException.
+ *
+ * @param message
+ * the message
+ */
+ public BackupException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Constructor BackupException.
+ *
+ * @param cause
+ * the cause
+ */
+ public BackupException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * Constructor BackupException.
+ *
+ * @param message
+ * the message
+ * @param cause
+ * the cause
+ */
+ public BackupException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/Backupable.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/Backupable.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/Backupable.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -0,0 +1,54 @@
+/*
+ * 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.storage.jdbc.backup;
+
+import java.io.File;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy
Bazko</a>
+ * @version $Id: Backupable.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public interface Backupable
+{
+ /**
+ * Runtime permission for backup and restore operations.
+ */
+ public static final RuntimePermission BACKUP_RESTORE_PERMISSION = new
RuntimePermission("backupRestoreOperations");
+
+ /**
+ * Backup data.
+ *
+ * @param storageDir
+ * the directory to store backup
+ * @throws BackupException
+ * if any exception occurred
+ */
+ void backup(File storageDir) throws BackupException;
+
+ /**
+ * Restore data.
+ *
+ * @param storageDir
+ * the directory where backup is stored
+ * @throws RestoreException
+ * if any exception occurred
+ */
+ void restore(File storageDir) throws RestoreException;
+
+}
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/DumpTable.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/DumpTable.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/DumpTable.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -0,0 +1,206 @@
+/*
+ * 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.storage.jdbc.backup;
+
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectZipWriterImpl;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.zip.ZipEntry;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy
Bazko</a>
+ * @version $Id: DumpTable.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class DumpTable
+{
+ /**
+ * Suffix for content file.
+ */
+ public static final String CONTENT_FILE_SUFFIX = ".dump";
+
+ /**
+ * Suffix for content length file.
+ */
+ public static final String CONTENT_LEN_FILE_SUFFIX = ".len";
+
+ /**
+ * Generic dialect.
+ */
+ public static final int DB_DIALECT_GENERIC =
DBConstants.DB_DIALECT_GENERIC.hashCode();
+
+ /**
+ * HSQLDB dialect.
+ */
+ public static final int DB_DIALECT_HSQLDB = DBConstants.DB_DIALECT_HSQLDB.hashCode();
+
+ /**
+ * MySQL dialect.
+ */
+ public static final int DB_DIALECT_MYSQL = DBConstants.DB_DIALECT_MYSQL.hashCode();
+
+ /**
+ * MySQL-UTF8 dialect.
+ */
+ public static final int DB_DIALECT_MYSQL_UTF8 =
DBConstants.DB_DIALECT_MYSQL_UTF8.hashCode();
+
+ /**
+ * DB2 dialect.
+ */
+ public static final int DB_DIALECT_DB2 = DBConstants.DB_DIALECT_DB2.hashCode();
+
+ /**
+ * DB2V8 dialect.
+ */
+ public static final int DB_DIALECT_DB2V8 = DBConstants.DB_DIALECT_DB2V8.hashCode();
+
+ /**
+ * PGSQL dialect.
+ */
+ public static final int DB_DIALECT_PGSQL = DBConstants.DB_DIALECT_PGSQL.hashCode();
+
+ /**
+ * Dump table.
+ *
+ * @throws IOException
+ * @throws SQLException
+ */
+ public static void dump(Connection jdbcConn, String tableName, String script, File
storageDir)
+ throws IOException, SQLException
+ {
+ // Need privileges
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ {
+ security.checkPermission(Backupable.BACKUP_RESTORE_PERMISSION);
+ }
+
+ int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
+
+ ObjectZipWriterImpl contentWriter = null;
+ ObjectZipWriterImpl contentLenWriter = null;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try
+ {
+ File contentFile = new File(storageDir, tableName + CONTENT_FILE_SUFFIX);
+ contentWriter = new
ObjectZipWriterImpl(PrivilegedFileHelper.zipOutputStream(contentFile));
+ contentWriter.putNextEntry(new ZipEntry(tableName));
+
+ File contentLenFile = new File(storageDir, tableName +
CONTENT_LEN_FILE_SUFFIX);
+ contentLenWriter = new
ObjectZipWriterImpl(PrivilegedFileHelper.zipOutputStream(contentLenFile));
+ contentLenWriter.putNextEntry(new ZipEntry(tableName));
+
+ stmt = jdbcConn.prepareStatement(script);
+ rs = stmt.executeQuery();
+ ResultSetMetaData metaData = rs.getMetaData();
+
+ int columnCount = metaData.getColumnCount();
+ int[] columnType = new int[columnCount];
+
+ contentWriter.writeInt(columnCount);
+ for (int i = 0; i < columnCount; i++)
+ {
+ columnType[i] = metaData.getColumnType(i + 1);
+ contentWriter.writeInt(columnType[i]);
+ contentWriter.writeString(metaData.getColumnName(i + 1));
+ }
+
+ // Now we can output the actual data
+ while (rs.next())
+ {
+ for (int i = 0; i < columnCount; i++)
+ {
+ InputStream value;
+ if (dialect == DB_DIALECT_HSQLDB)
+ {
+ if (columnType[i] == Types.VARBINARY)
+ {
+ value = rs.getBinaryStream(i + 1);
+ }
+ else
+ {
+ String str = rs.getString(i + 1);
+ value = str == null ? null : new
ByteArrayInputStream(str.getBytes(Constants.DEFAULT_ENCODING));
+ }
+ }
+ else
+ {
+ value = rs.getBinaryStream(i + 1);
+ }
+
+ if (value == null)
+ {
+ contentLenWriter.writeLong(-1);
+ }
+ else
+ {
+ long len = 0;
+ int read = 0;
+ byte[] tmpBuff = new byte[2048];
+
+ while ((read = value.read(tmpBuff)) >= 0)
+ {
+ contentWriter.write(tmpBuff, 0, read);
+ len += read;
+ }
+ contentLenWriter.writeLong(len);
+ }
+ }
+ }
+ }
+ finally
+ {
+ if (contentWriter != null)
+ {
+ contentWriter.closeEntry();
+ contentWriter.close();
+ }
+
+ if (contentLenWriter != null)
+ {
+ contentLenWriter.closeEntry();
+ contentLenWriter.close();
+ }
+
+ if (rs != null)
+ {
+ rs.close();
+ }
+
+ if (stmt != null)
+ {
+ stmt.close();
+ }
+ }
+ }
+
+}
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/RestoreException.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/RestoreException.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/RestoreException.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -0,0 +1,61 @@
+/*
+ * 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.storage.jdbc.backup;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy
Bazko</a>
+ * @version $Id: RestoreException.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class RestoreException extends Exception
+{
+ /**
+ * Constructor RestoreException.
+ *
+ * @param message
+ * the message
+ */
+ public RestoreException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Constructor RestoreException.
+ *
+ * @param cause
+ * the cause
+ */
+ public RestoreException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * Constructor RestoreException.
+ *
+ * @param message
+ * the message
+ * @param cause
+ * the cause
+ */
+ public RestoreException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/RestoreTable.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/RestoreTable.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/RestoreTable.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -0,0 +1,501 @@
+/*
+ * 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.storage.jdbc.backup;
+
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
+import org.exoplatform.services.jcr.dataflow.serialization.ObjectReader;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectZipReaderImpl;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+
+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.Types;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy
Bazko</a>
+ * @version $Id: DumpTable.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class RestoreTable
+{
+ /**
+ * 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;
+
+ /**
+ * Maximum buffer size.
+ */
+ private final int maxBufferSize;
+
+ private File contentFile;
+
+ private File contentLenFile;
+
+ private Integer deleteColumnIndex = null;
+
+ private Integer skipColumnIndex = null;
+
+ private Integer newColumnIndex = null;
+
+ private Set<Integer> convertColumnIndex = new HashSet<Integer>();
+
+ private String srcContainerName;
+
+ private String dstContainerName;
+
+ private Boolean srcMultiDb;
+
+ private Boolean dstMultiDb;
+
+ /**
+ * Constructor RestoreTable.
+ */
+ public RestoreTable(FileCleaner fileCleaner, File tempDir, int maxBufferSize)
+ {
+ this.fileCleaner = fileCleaner;
+ this.tempDir = tempDir;
+ this.maxBufferSize = maxBufferSize;
+ }
+
+ /**
+ * Restore table.
+ */
+ public void restore(Connection jdbcConn, String tableName, File storageDir) throws
IOException, SQLException
+ {
+ // Need privileges
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ {
+ security.checkPermission(Backupable.BACKUP_RESTORE_PERMISSION);
+ }
+
+ ObjectZipReaderImpl contentReader = null;
+ ObjectZipReaderImpl contentLenReader = null;
+
+ PreparedStatement insertNode = null;
+ ResultSet tableMetaData = null;
+
+ int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
+
+ try
+ {
+ contentReader = new
ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(contentFile));
+ contentReader.getNextEntry();
+
+ contentLenReader = new
ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(contentLenFile));
+ 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());
+ }
+
+ // collect information about target table
+ List<Integer> newColumnType = new ArrayList<Integer>();
+ List<String> newColumnName = new ArrayList<String>();
+
+ tableMetaData = jdbcConn.getMetaData().getColumns(null, null, tableName,
"%");
+ while (tableMetaData.next())
+ {
+ newColumnName.add(tableMetaData.getString("COLUMN_NAME"));
+ newColumnType.add(tableMetaData.getInt("DATA_TYPE"));
+ }
+
+ int targetColumnCount = sourceColumnCount;
+ if (deleteColumnIndex != null)
+ {
+ targetColumnCount--;
+ }
+ else if (newColumnIndex != null)
+ {
+ targetColumnCount++;
+ columnType.add(newColumnIndex, newColumnType.get(newColumnIndex));
+ }
+
+ // construct statement
+ String names = "";
+ String parameters = "";
+ for (int i = 0; i < targetColumnCount; i++)
+ {
+ if (skipColumnIndex != null && skipColumnIndex == i)
+ {
+ continue;
+ }
+ names += newColumnName.get(i) + (i == targetColumnCount - 1 ? "" :
",");
+ parameters += "?" + (i == targetColumnCount - 1 ? "" :
",");
+ }
+ 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 (newColumnIndex != null && newColumnIndex == i)
+ {
+ stream = new
ByteArrayInputStream(dstContainerName.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 (skipColumnIndex != null && skipColumnIndex == i)
+ {
+ targetIndex--;
+ continue;
+ }
+ else if (deleteColumnIndex != null && deleteColumnIndex == i)
+ {
+ targetIndex--;
+ continue;
+ }
+
+ // set
+ if (stream != null)
+ {
+ if (convertColumnIndex != null &&
convertColumnIndex.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 (dstMultiDb)
+ {
+ if (!srcMultiDb)
+ {
+ stream =
+ new ByteArrayInputStream(new String(readBuffer,
Constants.DEFAULT_ENCODING).substring(
+ srcContainerName.length()).getBytes());
+ }
+ }
+ else
+ {
+ if (srcMultiDb)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(dstContainerName);
+ builder.append(currentValue);
+
+ stream = new
ByteArrayInputStream(builder.toString().getBytes());
+ }
+ else
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(dstContainerName);
+ builder.append(new String(readBuffer,
Constants.DEFAULT_ENCODING)
+ .substring(srcContainerName.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 == DumpTable.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 (dialect == DumpTable.DB_DIALECT_HSQLDB)
+ {
+ if (columnType.get(i) == Types.VARBINARY)
+ {
+ 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.setBinaryStream(targetIndex + 1, stream, (int)len);
+ }
+ }
+ }
+ else
+ {
+ insertNode.setNull(targetIndex + 1, columnType.get(i));
+ }
+ }
+ insertNode.addBatch();
+ }
+
+ insertNode.executeBatch();
+ jdbcConn.commit();
+ }
+ 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);
+ }
+ }
+ }
+
+ public void setContentFile(File contentFile)
+ {
+ this.contentFile = contentFile;
+ }
+
+ public void setContentLenFile(File contentLenFile)
+ {
+ this.contentLenFile = contentLenFile;
+ }
+
+ public void setDeleteColumnIndex(Integer deleteColumnIndex)
+ {
+ this.deleteColumnIndex = deleteColumnIndex;
+ }
+
+ public void setSkipColumnIndex(Integer skipColumnIndex)
+ {
+ this.skipColumnIndex = skipColumnIndex;
+ }
+
+ public void setNewColumnIndex(Integer newColumnIndex)
+ {
+ this.newColumnIndex = newColumnIndex;
+ }
+
+ public void setConvertColumnIndex(Set<Integer> convertColumnIndex)
+ {
+ this.convertColumnIndex = convertColumnIndex;
+ }
+
+ public void setSrcContainerName(String srcContainerName)
+ {
+ this.srcContainerName = srcContainerName;
+ }
+
+ public void setDstContainerName(String dstContainerName)
+ {
+ this.dstContainerName = dstContainerName;
+ }
+
+ public void setSrcMultiDb(Boolean srcMultiDb)
+ {
+ this.srcMultiDb = srcMultiDb;
+ }
+
+ public void setDstMultiDb(Boolean dstMultiDb)
+ {
+ this.dstMultiDb = dstMultiDb;
+ }
+}
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/ResumeException.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/ResumeException.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/ResumeException.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -0,0 +1,50 @@
+/*
+ * 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.storage.jdbc.backup;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy
Bazko</a>
+ * @version $Id: ResumeException 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class ResumeException extends Exception
+{
+ /**
+ * Constructor ResumeException.
+ *
+ * @param cause
+ * the cause
+ */
+ public ResumeException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * Constructor ResumeException.
+ *
+ * @param message
+ * the message
+ * @param cause
+ * the cause
+ */
+ public ResumeException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/SuspendException.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/SuspendException.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/SuspendException.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -0,0 +1,50 @@
+/*
+ * 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.storage.jdbc.backup;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy
Bazko</a>
+ * @version $Id: SuspendException.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class SuspendException extends Exception
+{
+ /**
+ * Constructor SuspendException.
+ *
+ * @param cause
+ * the cause
+ */
+ public SuspendException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * Constructor SuspendException.
+ *
+ * @param message
+ * the message
+ * @param cause
+ * the cause
+ */
+ public SuspendException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/Suspendable.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/Suspendable.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/Suspendable.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -0,0 +1,42 @@
+/*
+ * 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.storage.jdbc.backup;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy
Bazko</a>
+ * @version $Id: Suspendable.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public interface Suspendable
+{
+
+ /**
+ * Suspend current operations.
+ *
+ * @throws SuspendException of error occurred
+ */
+ void suspend() throws SuspendException;
+
+ /**
+ * Resume operations.
+ *
+ * @throws ResumeException of error occurred
+ */
+ void resume() throws ResumeException;
+
+}
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java 2011-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -19,8 +19,6 @@
package org.exoplatform.services.jcr.ext.backup.impl.rdbms;
import org.exoplatform.commons.utils.PrivilegedFileHelper;
-import org.exoplatform.commons.utils.SecurityHelper;
-import org.exoplatform.services.jcr.config.LockManagerEntry;
import org.exoplatform.services.jcr.config.QueryHandlerParams;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.ValueStorageEntry;
@@ -30,41 +28,26 @@
import org.exoplatform.services.jcr.ext.backup.BackupOperationException;
import org.exoplatform.services.jcr.ext.backup.impl.AbstractFullBackupJob;
import org.exoplatform.services.jcr.ext.backup.impl.FileNameProducer;
-import org.exoplatform.services.jcr.impl.Constants;
-import
org.exoplatform.services.jcr.impl.core.lock.cacheable.AbstractCacheableLockManager;
import org.exoplatform.services.jcr.impl.core.query.SystemSearchManager;
-import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectZipWriterImpl;
-import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
-import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
-import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.BackupException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Backupable;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.ResumeException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.SuspendException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Suspendable;
import org.exoplatform.services.jcr.impl.storage.value.fs.FileValueStorage;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import java.security.PrivilegedExceptionAction;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Types;
import java.util.Calendar;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
-import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-import javax.sql.DataSource;
-
/**
* Created by The eXo Platform SARL Author : Alex Reshetnyak
alex.reshetnyak(a)exoplatform.com.ua Nov
* 21, 2007
@@ -87,57 +70,11 @@
public static final String VALUE_STORAGE_DIR = "values";
/**
- * Suffix for content file.
- */
- public static final String CONTENT_FILE_SUFFIX = ".dump";
-
- /**
- * Suffix for content length file.
- */
- public static final String CONTENT_LEN_FILE_SUFFIX = ".len";
-
- /**
* Logger.
*/
protected static Log log =
ExoLogger.getLogger("exo.jcr.component.ext.FullBackupJob");
/**
- * Generic dialect.
- */
- public static final int DB_DIALECT_GENERIC =
DBConstants.DB_DIALECT_GENERIC.hashCode();
-
- /**
- * HSQLDB dialect.
- */
- public static final int DB_DIALECT_HSQLDB = DBConstants.DB_DIALECT_HSQLDB.hashCode();
-
- /**
- * MySQL dialect.
- */
- public static final int DB_DIALECT_MYSQL = DBConstants.DB_DIALECT_MYSQL.hashCode();
-
- /**
- * MySQL-UTF8 dialect.
- */
- public static final int DB_DIALECT_MYSQL_UTF8 =
DBConstants.DB_DIALECT_MYSQL_UTF8.hashCode();
-
- /**
- * DB2 dialect.
- */
- public static final int DB_DIALECT_DB2 = DBConstants.DB_DIALECT_DB2.hashCode();
-
- /**
- * DB2V8 dialect.
- */
- public static final int DB_DIALECT_DB2V8 = DBConstants.DB_DIALECT_DB2V8.hashCode();
-
- /**
- * PGSQL dialect.
- */
- public static final int DB_DIALECT_PGSQL = DBConstants.DB_DIALECT_PGSQL.hashCode();
-
-
- /**
* {@inheritDoc}
*/
@Override
@@ -183,8 +120,12 @@
{
notifyListeners();
- Connection jdbcConn = null;
- Statement lockStatemnt = null;
+ List<Backupable> backupableComponents =
+
repository.getWorkspaceContainer(workspaceName).getComponentInstancesOfType(Backupable.class);
+
+ List<Suspendable> suspendableComponents =
+
repository.getWorkspaceContainer(workspaceName).getComponentInstancesOfType(Suspendable.class);
+
try
{
WorkspaceEntry workspaceEntry = null;
@@ -196,158 +137,44 @@
break;
}
}
+
if (workspaceEntry == null)
{
throw new RepositoryConfigurationException("Workpace name " +
workspaceName
+ " not found in repository configuration");
}
- String dsName =
workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
- if (dsName == null)
+ // suspend all components
+ for (Suspendable component : suspendableComponents)
{
- throw new RepositoryConfigurationException("Data source name not found
in workspace configuration "
- + workspaceName);
+ component.suspend();
}
- String multiDb =
workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB);
- if (multiDb == null)
+ // backup all components
+ for (Backupable component : backupableComponents)
{
- throw new
RepositoryConfigurationException(JDBCWorkspaceDataContainer.MULTIDB
- + " parameter not found in workspace " + workspaceName + "
configuration");
+ component.backup(new File(getStorageURL().getFile()));
}
- boolean isMultiDb = Boolean.parseBoolean(multiDb);
- final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
- if (ds == null)
- {
- throw new NameNotFoundException("Data source " + dsName + "
not found");
- }
-
- jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new
PrivilegedExceptionAction<Connection>()
- {
- public Connection run() throws Exception
- {
- return ds.getConnection();
-
- }
- });
-
- RDBMSBackupInfoWriter backupInfoWriter = new
RDBMSBackupInfoWriter(getStorageURL().getFile());
-
- backupInfoWriter.setRepositoryName(repository.getConfiguration().getName());
- backupInfoWriter.setWorkspaceName(workspaceName);
- backupInfoWriter.setMultiDb(isMultiDb);
-
- // dump JCR data
- String[][] scripts;
- if (isMultiDb)
- {
- scripts =
- new String[][]{
- {"JCR_MITEM", "select * from JCR_MITEM where
JCR_MITEM.name <> '" + Constants.ROOT_PARENT_NAME + "'"},
- {"JCR_MVALUE", "select * from JCR_MVALUE"},
{"JCR_MREF", "select * from JCR_MREF"}};
- }
- else
- {
- scripts =
- new String[][]{
- {"JCR_SITEM", "select * from JCR_SITEM where
CONTAINER_NAME='" + workspaceName + "'"},
- {
- "JCR_SVALUE",
- "select * from JCR_SVALUE where exists(select * from JCR_SITEM
where JCR_SITEM.ID=JCR_SVALUE.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME='"
- + workspaceName + "')"},
- {
- "JCR_SREF",
- "select * from JCR_SREF where exists(select * from JCR_SITEM
where JCR_SITEM.ID=JCR_SREF.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME='"
- + workspaceName + "')"}};
- }
-
- backupInfoWriter.setItemTableName(scripts[0][0]);
- backupInfoWriter.setValueTableName(scripts[1][0]);
- backupInfoWriter.setRefTableName(scripts[2][0]);
-
-
- // TODO set workspace waiting
-
- // Lock tables
- // ResultSet rs = null;
- // try
- // {
- // DatabaseMetaData metaData = jdbcConn.getMetaData();
- //
- // rs = metaData.getTables(null, null, "%", new
String[]{"TABLE"});
- // lockStatemnt = jdbcConn.createStatement();
- // int dialect = DialectDetecter.detect(metaData).hashCode();
- //
- // if (dialect == DB_DIALECT_HSQLDB)
- // {
- // while (rs.next())
- // {
- // lockStatemnt.execute("SET TABLE " +
rs.getString("TABLE_NAME") + " READONLY TRUE");
- // }
- // }
- // else if (dialect == DB_DIALECT_MYSQL || dialect ==
DB_DIALECT_MYSQL_UTF8)
- // {
- // String lock = "";
- // while (rs.next())
- // {
- // lock += rs.getString("TABLE_NAME") + "
READ,";
- // }
- // lockStatemnt.execute("LOCK TABLES " +
lock.substring(0, lock.length() - 1));
- // }
- // }
- // finally
- // {
- // if (rs != null)
- // {
- // rs.close();
- // }
- // }
-
- // dump JCR data
- for (String script[] : scripts)
- {
- dumpTable(jdbcConn, script[0], script[1]);
- }
-
- // dump JCR LOCK data
- LockManagerEntry lockEntry = workspaceEntry.getLockManager();
- if (lockEntry != null)
- {
- List<String> lockTableNames =
AbstractCacheableLockManager.getLockTableNames(lockEntry);
- backupInfoWriter.setLockTableNames(lockTableNames);
-
- for (String tableName : lockTableNames)
- {
- dumpTable(jdbcConn, tableName,
AbstractCacheableLockManager.getSelectScript(tableName));
- }
- }
-
backupValueStorage(workspaceEntry);
backupIndex(workspaceEntry);
-
- // write backup information
- backupInfoWriter.write();
-
- // TODO set workspace waiting
-
}
catch (RepositoryConfigurationException e)
{
log.error("Full backup failed " + getStorageURL().getPath(), e);
notifyError("Full backup failed", e);
}
- catch (NameNotFoundException e)
+ catch (SuspendException e)
{
log.error("Full backup failed " + getStorageURL().getPath(), e);
notifyError("Full backup failed", e);
}
- catch (NamingException e)
+ catch (BackupException e)
{
log.error("Full backup failed " + getStorageURL().getPath(), e);
notifyError("Full backup failed", e);
}
- catch (SQLException e)
+ catch (BackupOperationException e)
{
log.error("Full backup failed " + getStorageURL().getPath(), e);
notifyError("Full backup failed", e);
@@ -357,57 +184,15 @@
log.error("Full backup failed " + getStorageURL().getPath(), e);
notifyError("Full backup failed", e);
}
- catch (BackupOperationException e)
- {
- log.error("Full backup failed " + getStorageURL().getPath(), e);
- notifyError("Full backup failed", e);
- }
finally
{
- if (jdbcConn != null)
+ for (Suspendable component : suspendableComponents)
{
try
{
- // unlock tables
- // if (lockStatemnt != null)
- // {
- // ResultSet rs = null;
- // try
- // {
- // DatabaseMetaData metaData =
jdbcConn.getMetaData();
- // int dialect =
DialectDetecter.detect(metaData).hashCode();
- //
- // if (dialect == DB_DIALECT_HSQLDB)
- // {
- // rs = metaData.getTables(null, null,
"%", new String[]{"TABLE"});
- // while (rs.next())
- // {
- // String tableName =
rs.getString("TABLE_NAME");
- // lockStatemnt.execute("SET TABLE " +
tableName + " READONLY FALSE");
- // }
- // }
- // else
- // {
- // lockStatemnt.execute("UNLOCK
TABLES");
- // }
- // }
- // finally
- // {
- // if (rs != null)
- // {
- // rs.close();
- // }
- //
- // if (lockStatemnt != null)
- // {
- // lockStatemnt.close();
- // }
- // }
- // }
-
- jdbcConn.close();
+ component.resume();
}
- catch (SQLException e)
+ catch (ResumeException e)
{
log.error("Full backup failed " + getStorageURL().getPath(),
e);
notifyError("Full backup failed", e);
@@ -494,112 +279,6 @@
}
/**
- * Dump table.
- */
- protected void dumpTable(Connection jdbcConn, String tableName, String script) throws
SQLException, IOException,
- BackupOperationException
- {
- int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
-
- ObjectZipWriterImpl contentWriter = null;
- ObjectZipWriterImpl contentLenWriter = null;
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try
- {
- File contentFile = new File(getStorageURL().getFile(), tableName +
CONTENT_FILE_SUFFIX);
- contentWriter = new
ObjectZipWriterImpl(PrivilegedFileHelper.zipOutputStream(contentFile));
- contentWriter.putNextEntry(new ZipEntry(tableName));
-
- File contentLenFile = new File(getStorageURL().getFile(), tableName +
CONTENT_LEN_FILE_SUFFIX);
- contentLenWriter = new
ObjectZipWriterImpl(PrivilegedFileHelper.zipOutputStream(contentLenFile));
- contentLenWriter.putNextEntry(new ZipEntry(tableName));
-
- stmt = jdbcConn.prepareStatement(script);
- rs = stmt.executeQuery();
- ResultSetMetaData metaData = rs.getMetaData();
-
- int columnCount = metaData.getColumnCount();
- int[] columnType = new int[columnCount];
-
- contentWriter.writeInt(columnCount);
- for (int i = 0; i < columnCount; i++)
- {
- columnType[i] = metaData.getColumnType(i + 1);
- contentWriter.writeInt(columnType[i]);
- contentWriter.writeString(metaData.getColumnName(i + 1));
- }
-
- // Now we can output the actual data
- while (rs.next())
- {
- for (int i = 0; i < columnCount; i++)
- {
- InputStream value;
- if (dialect == DB_DIALECT_HSQLDB)
- {
- if (columnType[i] == Types.VARBINARY)
- {
- value = rs.getBinaryStream(i+1);
- }
- else
- {
- String str = rs.getString(i+1);
- value = str == null ? null : new
ByteArrayInputStream(str.getBytes(Constants.DEFAULT_ENCODING));
- }
- }
- else
- {
- value = rs.getBinaryStream(i+1);
- }
-
- if (value == null)
- {
- contentLenWriter.writeLong(-1);
- }
- else
- {
- long len = 0;
- int read = 0;
- byte[] tmpBuff = new byte[2048];
-
- while ((read = value.read(tmpBuff)) >= 0)
- {
- contentWriter.write(tmpBuff, 0, read);
- len += read;
- }
- contentLenWriter.writeLong(len);
- }
- }
- }
- }
- finally
- {
- if (contentWriter != null)
- {
- contentWriter.closeEntry();
- contentWriter.close();
- }
-
- if (contentLenWriter != null)
- {
- contentLenWriter.closeEntry();
- contentLenWriter.close();
- }
-
- if (rs != null)
- {
- rs.close();
- }
-
- if (stmt != null)
- {
- stmt.close();
- }
- }
- }
-
- /**
* {@inheritDoc}
*/
public void stop()
Deleted:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoReader.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoReader.java 2011-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoReader.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -1,180 +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.ext.backup.impl.rdbms;
-
-import org.exoplatform.commons.utils.PrivilegedFileHelper;
-import org.exoplatform.services.jcr.dataflow.serialization.ObjectReader;
-import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectReaderImpl;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Contains information about performed backup.
- *
- * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy
Bazko</a>
- * @version $Id: RDBMSBackupInfoReader.java 34360 2009-07-22 23:58:59Z tolusha $
- */
-public class RDBMSBackupInfoReader
-{
-
- /**
- * File which contains necessary information about backup.
- */
- public static final String BACKUP_INFO = "backup.info";
-
- /**
- * Workspace name.
- */
- private final String workspaceName;
-
- /**
- * Repository name.
- */
- private final String repositoryName;
-
- /**
- * Is multi-db.
- */
- private final boolean isMultiDb;
-
- /**
- * Table name for items.
- */
- private final String itemTableName;
-
- /**
- * Table name for values.
- */
- private final String valueTableName;
-
- /**
- * Table name for referenceable data.
- */
- private final String refTableName;
-
- /**
- * Lock table names.
- */
- private final List<String> lockTableNames = new ArrayList<String>();
-
- /**
- * Constructor RDBMSBackupInfoReader.java.
- *
- * @param dir
- * The directory where file with backup information was stored.
- */
- public RDBMSBackupInfoReader(String dir) throws IOException
- {
- ObjectReader backupInfoReader =
- new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(new File(dir,
BACKUP_INFO)));
-
- try
- {
- this.repositoryName = backupInfoReader.readString();
- this.workspaceName = backupInfoReader.readString();
- this.isMultiDb = backupInfoReader.readBoolean();
- this.itemTableName = backupInfoReader.readString();
- this.valueTableName = backupInfoReader.readString();
- this.refTableName = backupInfoReader.readString();
-
- int lockTablesCount = backupInfoReader.readInt();
- for (int i = 0; i < lockTablesCount; i++)
- {
- lockTableNames.add(backupInfoReader.readString());
- }
- }
- finally
- {
- backupInfoReader.close();
- }
- }
-
- /**
- * Returns the original repository name where backup was performed.
- *
- * @return repository name
- */
- public String getRepositoryName()
- {
- return repositoryName;
- }
-
- /**
- * Returns the original workspace name where backup was performed.
- *
- * @return workspace name
- */
- public String getWorkspaceName()
- {
- return workspaceName;
- }
-
- /**
- * Returns the original value of multi-db parameter of workspace from which backup was
performed.
- *
- * @return multi-db parameter
- */
- public boolean isMultiDb()
- {
- return isMultiDb;
- }
-
- /**
- * Returns the original table name of items from which backup was performed.
- *
- * @return table name
- */
- public String getItemTableName()
- {
- return itemTableName;
- }
-
- /**
- * Returns the original table name of values from which backup was performed.
- *
- * @return table name
- */
- public String getValueTableName()
- {
- return valueTableName;
- }
-
- /**
- * Returns the original table name of referenceable data from which backup was
performed.
- *
- * @return table name
- */
- public String getRefTableName()
- {
- return refTableName;
- }
-
- /**
- * Returns the original table names of lock data from which backup was performed.
- *
- * @return list of table names
- */
- public List<String> getLockTableNames()
- {
- return lockTableNames;
- }
-}
Deleted:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoWriter.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoWriter.java 2011-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoWriter.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -1,192 +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.ext.backup.impl.rdbms;
-
-import org.exoplatform.commons.utils.PrivilegedFileHelper;
-import org.exoplatform.services.jcr.dataflow.serialization.ObjectWriter;
-import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectWriterImpl;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Contains information about performed backup.
- *
- * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy
Bazko</a>
- * @version $Id: RDBMSBackupInfo.java 34360 2009-07-22 23:58:59Z tolusha $
- */
-public class RDBMSBackupInfoWriter
-{
-
- /**
- * Workspace name.
- */
- private String workspaceName;
-
- /**
- * Repository name.
- */
- private String repositoryName;
-
- /**
- * Is multi-db.
- */
- private boolean isMultiDb;
-
- /**
- * Table name for items.
- */
- private String itemTableName;
-
- /**
- * Table name for values.
- */
- private String valueTableName;
-
- /**
- * Table name for referenceable data.
- */
- private String refTableName;
-
- /**
- * Lock table names.
- */
- private List<String> lockTableNames = new ArrayList<String>();
-
- /**
- * The directory where file with backup information will be stored.
- */
- private final String dir;
-
- /**
- * Constructor RDBMSBackupInfoWriter.
- *
- * @param dir
- * The directory where file with backup information was stored.
- */
- public RDBMSBackupInfoWriter(String dir)
- {
- this.dir = dir;
- }
-
- /**
- * Returns the original repository name where backup was performed.
- *
- * @return repository name
- */
- public void setRepositoryName(String repositoryName)
- {
- this.repositoryName = repositoryName;
- }
-
- /**
- * Returns the original workspace name where backup was performed.
- *
- * @return workspace name
- */
- public void setWorkspaceName(String workspaceName)
- {
- this.workspaceName = workspaceName;
- }
-
- /**
- * Returns the original value of multi-db parameter of workspace from which backup was
performed.
- *
- * @return multi-db parameter
- */
- public void setMultiDb(boolean isMultiDb)
- {
- this.isMultiDb = isMultiDb;
- }
-
- /**
- * Returns the original table name of items from which backup was performed.
- *
- * @return table name
- */
- public void setItemTableName(String itemTableName)
- {
- this.itemTableName = itemTableName;
- }
-
- /**
- * Returns the original table name of values from which backup was performed.
- *
- * @return table name
- */
- public void setValueTableName(String valueTableName)
- {
- this.valueTableName = valueTableName;
- }
-
- /**
- * Returns the original table name of referenceable data from which backup was
performed.
- *
- * @return table name
- */
- public void setRefTableName(String refTableName)
- {
- this.refTableName = refTableName;
- }
-
- /**
- * Returns the original table names of lock data from which backup was performed.
- *
- * @return list of table names
- */
- public void setLockTableNames(List<String> lockTableNames)
- {
- this.lockTableNames.clear();
- this.lockTableNames.addAll(lockTableNames);
- }
-
- /**
- * Write backup information into file.
- *
- * @throws IOException
- * if any error occurred
- */
- public void write() throws IOException
- {
- ObjectWriter backupInfoWriter =
- new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(new File(dir,
RDBMSBackupInfoReader.BACKUP_INFO)));
-
- try
- {
- backupInfoWriter.writeString(repositoryName);
- backupInfoWriter.writeString(workspaceName);
- backupInfoWriter.writeBoolean(isMultiDb);
- backupInfoWriter.writeString(itemTableName);
- backupInfoWriter.writeString(valueTableName);
- backupInfoWriter.writeString(refTableName);
-
- backupInfoWriter.writeInt(lockTableNames.size());
- for (int i = 0; i < lockTableNames.size(); i++)
- {
- backupInfoWriter.writeString(lockTableNames.get(i));
- }
- }
- finally
- {
- backupInfoWriter.close();
- }
- }
-}
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java 2011-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -19,10 +19,8 @@
package org.exoplatform.services.jcr.ext.backup.impl.rdbms;
import org.exoplatform.commons.utils.PrivilegedFileHelper;
-import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.services.jcr.RepositoryService;
import org.exoplatform.services.jcr.access.AccessManager;
-import org.exoplatform.services.jcr.config.LockManagerEntry;
import org.exoplatform.services.jcr.config.QueryHandlerParams;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.RepositoryEntry;
@@ -30,7 +28,6 @@
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.core.WorkspaceContainerFacade;
-import org.exoplatform.services.jcr.dataflow.serialization.ObjectReader;
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.ext.backup.impl.IndexCleanHelper;
import org.exoplatform.services.jcr.ext.backup.impl.ValueStorageCleanHelper;
@@ -39,14 +36,12 @@
import org.exoplatform.services.jcr.impl.core.LocationFactory;
import org.exoplatform.services.jcr.impl.core.NamespaceRegistryImpl;
import org.exoplatform.services.jcr.impl.core.SessionRegistry;
-import
org.exoplatform.services.jcr.impl.core.lock.cacheable.AbstractCacheableLockManager;
import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeManagerImpl;
import org.exoplatform.services.jcr.impl.core.query.SystemSearchManager;
import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
import
org.exoplatform.services.jcr.impl.dataflow.persistent.CacheableWorkspaceDataManager;
-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.storage.jdbc.backup.Backupable;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.RestoreException;
import org.exoplatform.services.jcr.impl.storage.value.fs.FileValueStorage;
import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
import org.exoplatform.services.jcr.impl.util.jdbc.cleaner.DBCleanerException;
@@ -54,31 +49,14 @@
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.security.PrivilegedExceptionAction;
-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.HashSet;
import java.util.List;
-import java.util.Set;
import java.util.zip.ZipInputStream;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
-import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-import javax.sql.DataSource;
/**
* @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy
Bazko</a>
@@ -96,10 +74,6 @@
*/
protected final RepositoryService repositoryService;
- /**
- * List of temporary files.
- */
- protected List<File> spoolFileList = new ArrayList<File>();
/**
* Constructor RdbmsWorkspaceInitializer.
@@ -168,55 +142,35 @@
*/
protected void fullRdbmsRestore() throws RepositoryException
{
- Connection jdbcConn = null;
+ ManageableRepository repository = null;
try
{
- String dsName =
workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
- if (dsName == null)
- {
- throw new RepositoryConfigurationException("Data source name not found
in workspace configuration "
- + workspaceName);
- }
+ repository = repositoryService.getRepository(repositoryEntry.getName());
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ throw new RepositoryException(e);
+ }
- String multiDb =
workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB);
- if (multiDb == null)
+ List<Backupable> backupableComponents =
+
repository.getWorkspaceContainer(workspaceName).getComponentInstancesOfType(Backupable.class);
+
+ try
+ {
+ // restore all components
+ for (Backupable component : backupableComponents)
{
- throw new
RepositoryConfigurationException(JDBCWorkspaceDataContainer.MULTIDB
- + " parameter not found in workspace " + workspaceName + "
configuration");
+ component.restore(new File(restorePath));
}
- boolean isMultiDb = Boolean.parseBoolean(multiDb);
- final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
- if (ds == null)
- {
- throw new NameNotFoundException("Data source " + dsName + "
not found");
- }
-
- jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new
PrivilegedExceptionAction<Connection>()
- {
- public Connection run() throws Exception
- {
- return ds.getConnection();
-
- }
- });
-
- int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
- jdbcConn.setAutoCommit(false);
-
- RDBMSBackupInfoReader backupInfo = new RDBMSBackupInfoReader(restorePath);
-
- restoreJCRTables(jdbcConn, dialect, isMultiDb, backupInfo);
- restoreLockTables(jdbcConn, isMultiDb, backupInfo);
-
restoreValueStorage();
restoreIndex();
}
- catch (RepositoryConfigurationException e)
+ catch (RestoreException e)
{
throw new RepositoryException(e);
}
- catch (NamingException e)
+ catch (RepositoryConfigurationException e)
{
throw new RepositoryException(e);
}
@@ -224,146 +178,9 @@
{
throw new RepositoryException(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 RepositoryException(msg, e);
- }
- finally
- {
- if (jdbcConn != null)
- {
- try
- {
- jdbcConn.close();
- }
- catch (SQLException e)
- {
- throw new RepositoryException(e);
- }
- }
- }
}
/**
- * Restore JCR tables.
- */
- protected void restoreJCRTables(Connection jdbcConn, int dialect, boolean isMultiDb,
RDBMSBackupInfoReader backupInfo)
- throws IOException, SQLException
- {
- Statement st = null;
- try
- {
- Integer[] tableTypes =
- new Integer[]{RestoreTableHelper.ITEM_TABLE, RestoreTableHelper.VALUE_TABLE,
RestoreTableHelper.REF_TABLE};
-
- for (Integer tableType : tableTypes)
- {
- RestoreTableHelper helper = new RestoreTableHelper(tableType, isMultiDb,
backupInfo);
-
- if (!PrivilegedFileHelper.exists(helper.getContentFile()))
- {
- throw new IOException("File " +
PrivilegedFileHelper.getCanonicalPath(helper.getContentFile())
- + " not found");
- }
-
- if (tableType == RestoreTableHelper.ITEM_TABLE && dialect !=
FullBackupJob.DB_DIALECT_MYSQL
- && dialect != FullBackupJob.DB_DIALECT_MYSQL_UTF8)
- {
- // resolve constraint name depends on database
- String constraintName;
- if (dialect == FullBackupJob.DB_DIALECT_DB2 || dialect ==
FullBackupJob.DB_DIALECT_DB2V8)
- {
- constraintName = "JCR_FK_" + (isMultiDb ? "M" :
"S") + "ITEM_PAREN";
- }
- else
- {
- constraintName = "JCR_FK_" + (isMultiDb ? "M" :
"S") + "ITEM_PARENT";
- }
- String constraint =
- "CONSTRAINT " + constraintName + " FOREIGN
KEY(PARENT_ID) REFERENCES " + helper.getTableName()
- + "(ID)";
-
- // drop constraint
- st = jdbcConn.createStatement();
- st.execute("ALTER TABLE " + helper.getTableName() + " DROP
CONSTRAINT " + constraintName);
- jdbcConn.commit();
-
- restoreTable(jdbcConn, helper);
-
- // add constraint
- st = jdbcConn.createStatement();
- st.execute("ALTER TABLE " + helper.getTableName() + " ADD
" + constraint);
- jdbcConn.commit();
- }
- else
- {
- restoreTable(jdbcConn, helper);
- }
- }
- }
- finally
- {
- if (st != null)
- {
- st.close();
- }
- }
- }
-
- /**
- * Restore JCR Lock tables.
- */
- protected void restoreLockTables(Connection jdbcConn, boolean isMultiDb,
RDBMSBackupInfoReader backupInfo)
- throws IOException, SQLException, RepositoryException
- {
- LockManagerEntry lockEntry = workspaceEntry.getLockManager();
- if (lockEntry != null)
- {
- List<String> existedLockTablesNames =
AbstractCacheableLockManager.getLockTableNames(lockEntry);
- if (existedLockTablesNames.size() != backupInfo.getLockTableNames().size())
- {
- throw new RepositoryException("The amount of existed lock tables differs
from backup");
- }
-
- for (int i = 0; i < backupInfo.getLockTableNames().size(); i++)
- {
- RestoreTableHelper helper = new
RestoreTableHelper(RestoreTableHelper.LOCK_TABLE, isMultiDb, backupInfo);
-
- helper.setContentFile(new File(restorePath,
backupInfo.getLockTableNames().get(i)
- + FullBackupJob.CONTENT_FILE_SUFFIX));
- helper.setContentLenFile(new File(restorePath,
backupInfo.getLockTableNames().get(i)
- + FullBackupJob.CONTENT_LEN_FILE_SUFFIX));
- helper.setTableName(existedLockTablesNames.get(i));
-
- if (PrivilegedFileHelper.exists(helper.contentFile))
- {
- restoreTable(jdbcConn, helper);
- }
- else
- {
- throw new IOException("File " +
PrivilegedFileHelper.getCanonicalPath(helper.contentFile) + " not found");
- }
- }
- }
- else if (backupInfo.getLockTableNames().size() != 0)
- {
- throw new RepositoryException("There are no lock tables for new workspace
configuration [" + workspaceName
- + "] but backup lock data exist");
- }
- }
-
- /**
* Restore index from backup.
*/
protected void restoreIndex() throws RepositoryConfigurationException, IOException
@@ -573,593 +390,4 @@
}
}
}
-
- /**
- * Restore table.
- */
- protected void restoreTable(Connection jdbcConn, RestoreTableHelper helper)
- throws IOException, SQLException
- {
- ObjectZipReaderImpl contentReader = null;
- ObjectZipReaderImpl contentLenReader = null;
-
- PreparedStatement insertNode = null;
- ResultSet tableMetaData = null;
-
- int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
-
- try
- {
- contentReader = new
ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(helper.getContentFile()));
- contentReader.getNextEntry();
-
- contentLenReader = new
ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(helper.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());
- }
-
- // collect information about target table
- List<Integer> newColumnType = new ArrayList<Integer>();
- List<String> newColumnName = new ArrayList<String>();
-
- tableMetaData = jdbcConn.getMetaData().getColumns(null, null, helper.tableName,
"%");
- while (tableMetaData.next())
- {
- newColumnName.add(tableMetaData.getString("COLUMN_NAME"));
- newColumnType.add(tableMetaData.getInt("DATA_TYPE"));
- }
-
- int targetColumnCount = sourceColumnCount;
- if (helper.getDeleteColumnIndex() != null)
- {
- targetColumnCount--;
- }
- else if (helper.getNewColumnIndex() != null)
- {
- targetColumnCount++;
- columnType.add(helper.getNewColumnIndex(),
newColumnType.get((helper.getNewColumnIndex())));
- }
-
- // construct statement
- String names = "";
- String parameters = "";
- for (int i = 0; i < targetColumnCount; i++)
- {
- if (helper.getSkipColumnIndex() != null &&
helper.getSkipColumnIndex() == i)
- {
- continue;
- }
- names += newColumnName.get(i) + (i == targetColumnCount - 1 ? "" :
",");
- parameters += "?" + (i == targetColumnCount - 1 ? "" :
",");
- }
- insertNode =
- jdbcConn.prepareStatement("INSERT INTO " + helper.getTableName() +
" (" + names + ") VALUES(" + parameters
- + ")");
-
- // set data
- outer : while (true)
- {
- for (int i = 0, targetIndex = 0; i < columnType.size(); i++,
targetIndex++)
- {
- InputStream stream;
- long len;
-
- if (helper.getNewColumnIndex() != null &&
helper.getNewColumnIndex() == i)
- {
- stream = new
ByteArrayInputStream(workspaceName.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 (helper.getSkipColumnIndex() != null &&
helper.getSkipColumnIndex() == i)
- {
- targetIndex--;
- continue;
- }
- else if (helper.getDeleteColumnIndex() != null &&
helper.getDeleteColumnIndex() == i)
- {
- targetIndex--;
- continue;
- }
-
- // set
- if (stream != null)
- {
- if (helper.getConvertColumnIndexes().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 (helper.isMultiDb)
- {
- if (!helper.isBackupMutliDb())
- {
- stream =
- new ByteArrayInputStream(new String(readBuffer,
Constants.DEFAULT_ENCODING).substring(
-
helper.getBackupWorkspaceName().length()).getBytes());
- }
- }
- else
- {
- if (helper.isBackupMutliDb())
- {
- StringBuilder builder = new StringBuilder();
- builder.append(workspaceName);
- builder.append(currentValue);
-
- stream = new
ByteArrayInputStream(builder.toString().getBytes());
- }
- else
- {
- StringBuilder builder = new StringBuilder();
- builder.append(workspaceName);
- builder.append(new String(readBuffer,
Constants.DEFAULT_ENCODING).substring(helper
- .getBackupWorkspaceName().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 == FullBackupJob.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 (dialect == FullBackupJob.DB_DIALECT_HSQLDB)
- {
- if (columnType.get(i) == Types.VARBINARY)
- {
- 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.setBinaryStream(targetIndex + 1, stream, (int)len);
- }
- }
- }
- else
- {
- insertNode.setNull(targetIndex + 1, columnType.get(i));
- }
- }
- insertNode.addBatch();
-
- }
-
- insertNode.executeBatch();
- jdbcConn.commit();
- }
- 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)
- {
- 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);
- }
- }
- }
-
- /**
- * Class which helps to restore data.
- */
- protected class RestoreTableHelper
- {
- public static final int ITEM_TABLE = 0;
-
- public static final int VALUE_TABLE = 1;
-
- public static final int REF_TABLE = 2;
-
- public static final int LOCK_TABLE = 3;
-
- private String tableName;
-
- private File contentFile;
-
- private File contentLenFile;
-
- private Integer deleteColumnIndex = null;
-
- private Integer skipColumnIndex = null;
-
- private Integer newColumnIndex = null;
-
- private Set<Integer> convertColumnIndex = new HashSet<Integer>();
-
- private final boolean isMultiDb;
-
- private final RDBMSBackupInfoReader backupInfo;
-
- public RestoreTableHelper(int tableType, boolean isMultiDb, RDBMSBackupInfoReader
backupInfo)
- throws IOException
- {
- this.backupInfo = backupInfo;
- this.isMultiDb = isMultiDb;
-
- if (tableType == ITEM_TABLE)
- {
- contentFile = new File(restorePath, backupInfo.getItemTableName() +
FullBackupJob.CONTENT_FILE_SUFFIX);
- contentLenFile =
- new File(restorePath, backupInfo.getItemTableName() +
FullBackupJob.CONTENT_LEN_FILE_SUFFIX);
-
- tableName = "JCR_" + (isMultiDb ? "M" : "S") +
"ITEM";
-
- if (isMultiDb)
- {
- tableName = "JCR_MITEM";
-
- if (!backupInfo.isMultiDb())
- {
- // CONTAINER_NAME column index
- deleteColumnIndex = 4;
-
- // ID and PARENT_ID column indexes
- convertColumnIndex.add(0);
- convertColumnIndex.add(1);
- }
- }
- else
- {
- tableName = "JCR_SITEM";
-
- if (backupInfo.isMultiDb())
- {
- // CONTAINER_NAME column index
- newColumnIndex = 4;
-
- // ID and PARENT_ID column indexes
- convertColumnIndex.add(0);
- convertColumnIndex.add(1);
- }
- else
- {
- // ID and PARENT_ID and CONTAINER_NAME column indexes
- convertColumnIndex.add(0);
- convertColumnIndex.add(1);
- convertColumnIndex.add(4);
- }
- }
- }
- else if (tableType == VALUE_TABLE)
- {
- contentFile = new File(restorePath, backupInfo.getValueTableName() +
FullBackupJob.CONTENT_FILE_SUFFIX);
- contentLenFile =
- new File(restorePath, backupInfo.getValueTableName() +
FullBackupJob.CONTENT_LEN_FILE_SUFFIX);
-
- tableName = "JCR_" + (isMultiDb ? "M" : "S") +
"VALUE";
-
- // auto increment ID column
- skipColumnIndex = 0;
-
- if (!isMultiDb || !backupInfo.isMultiDb())
- {
- // PROPERTY_ID column index
- convertColumnIndex.add(3);
- }
- }
- else if (tableType == REF_TABLE)
- {
- contentFile = new File(restorePath, backupInfo.getRefTableName() +
FullBackupJob.CONTENT_FILE_SUFFIX);
- contentLenFile =
- new File(restorePath, backupInfo.getRefTableName() +
FullBackupJob.CONTENT_LEN_FILE_SUFFIX);
-
- tableName = "JCR_" + (isMultiDb ? "M" : "S") +
"REF";
-
- if (!isMultiDb || !backupInfo.isMultiDb())
- {
- // NODE_ID and PROPERTY_ID column indexes
- convertColumnIndex.add(0);
- convertColumnIndex.add(1);
- }
- }
- }
-
- /**
- * Returns the table name for restore.
- *
- * @return table name
- */
- public String getTableName()
- {
- return tableName;
- }
-
- /**
- * Returns the content file for restore.
- *
- * @return file
- */
- public File getContentFile()
- {
- return contentFile;
- }
-
- /**
- * Returns the content length file for restore.
- *
- * @return file
- */
- public File getContentLenFile()
- {
- return contentLenFile;
- }
-
- /**
- * Set table name for restore.
- */
- public void setTableName(String tableName)
- {
- this.tableName = tableName;
- }
-
- /**
- * Set content file for restore.
- */
- public void setContentFile(File file)
- {
- this.contentFile = file;
- }
-
- /**
- * Set content length file for restore.
- */
- public void setContentLenFile(File file)
- {
- this.contentLenFile = file;
- }
-
- /**
- * Returns index of column which should be skipped during restore.
- *
- * @return Integer
- */
- public Integer getSkipColumnIndex()
- {
- return skipColumnIndex;
- }
-
- /**
- * Returns index of column which should be skipped during restore.
- *
- * @return Integer
- */
- public Integer getDeleteColumnIndex()
- {
- return deleteColumnIndex;
- }
-
-
- /**
- * Returns index of column which should be added during restore.
- *
- * @return Integer
- */
- public Integer getNewColumnIndex()
- {
- return newColumnIndex;
- }
-
- /**
- * Returns indexes of columns which should be converted during restore.
- *
- * @return Integer
- */
- public Set<Integer> getConvertColumnIndexes()
- {
- return convertColumnIndex;
- }
-
- /**
- * Returns the target workspace name for restore.
- *
- * @return workspace name
- */
- public boolean isMultiDb()
- {
- return isMultiDb;
- }
-
- /**
- * Returns the original workspace name where backup was performed.
- *
- * @return workspace name
- */
- public String getBackupWorkspaceName()
- {
- return backupInfo.getWorkspaceName();
- }
-
- /**
- * Returns the original value of multi-db parameter of workspace from which backup
was performed.
- *
- * @return multi-db parameter
- */
- public boolean isBackupMutliDb()
- {
- return backupInfo.isMultiDb();
- }
- }
}
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRDBMSBackupManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRDBMSBackupManager.java 2011-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRDBMSBackupManager.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -28,8 +28,7 @@
* @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex
Reshetnyak</a>
* @version $Id$
*/
-public class TestRDBMSBackupManager
- extends AbstractBackupUseCasesTest
+public class TestRDBMSBackupManager extends AbstractBackupUseCasesTest
{
@Override
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsFullBackupJob.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsFullBackupJob.java 2011-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsFullBackupJob.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -61,14 +61,14 @@
indexesDir = new File(url.getFile(), FullBackupJob.SYSTEM_INDEX_DIR);
assertTrue(indexesDir.exists());
- assertTrue(new File(url.getFile(), "JCR_MITEM" +
FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MITEM" +
FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MITEM.dump").exists());
+ assertTrue(new File(url.getFile(), "JCR_MITEM.len").exists());
- assertTrue(new File(url.getFile(), "JCR_MVALUE" +
FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MVALUE" +
FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MVALUE.dump").exists());
+ assertTrue(new File(url.getFile(), "JCR_MVALUE.len").exists());
- assertTrue(new File(url.getFile(), "JCR_MREF" +
FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MREF" +
FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MREF.dump").exists());
+ assertTrue(new File(url.getFile(), "JCR_MREF.len").exists());
}
@@ -97,14 +97,14 @@
indexesDir = new File(url.getFile(), FullBackupJob.SYSTEM_INDEX_DIR);
assertFalse(indexesDir.exists());
- assertTrue(new File(url.getFile(), "JCR_MITEM" +
FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MITEM" +
FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MITEM.dump").exists());
+ assertTrue(new File(url.getFile(), "JCR_MITEM.len").exists());
- assertTrue(new File(url.getFile(), "JCR_MVALUE" +
FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MVALUE" +
FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MVALUE.dump").exists());
+ assertTrue(new File(url.getFile(), "JCR_MVALUE.len").exists());
- assertTrue(new File(url.getFile(), "JCR_MREF" +
FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MREF" +
FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MREF.dump").exists());
+ assertTrue(new File(url.getFile(), "JCR_MREF.len").exists());
}
}
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java 2011-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -33,15 +33,10 @@
import java.io.File;
import java.net.URL;
-import java.sql.Connection;
-import java.sql.Statement;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
-import javax.naming.InitialContext;
-import javax.sql.DataSource;
-
/**
* @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy
Bazko</a>
* @version $Id: TestFullBackupJob.java 34360 2009-07-22 23:58:59Z tolusha $
@@ -145,8 +140,8 @@
TesterRdbmsWorkspaceInitializer initializer =
new TesterRdbmsWorkspaceInitializer(newEntry,
repositoryService.getRepository("db1").getConfiguration(),
- cacheableDataManager, null, null, null,
- (ValueFactoryImpl) valueFactory, null, repositoryService,
new FileCleanerHolder());
+ cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory,
null, repositoryService,
+ new FileCleanerHolder());
initializer.restoreValueFiles();
assertFalse(new File(newValueStoragePath).exists());
@@ -182,26 +177,11 @@
String newIndexPath = "target/temp/index/" +
IdGenerator.generate();
String dsName = helper.getNewDataSource("");
- DataSource ds = (DataSource)new InitialContext().lookup(dsName);
- Connection conn = ds.getConnection();
- Statement st = conn.createStatement();
- st.execute("CREATE TABLE JCR_MITEM(ID VARCHAR(96) NOT NULL,PARENT_ID
VARCHAR(96) NOT NULL,NAME VARCHAR(512) NOT NULL,VERSION INTEGER NOT NULL,I_CLASS INTEGER
NOT NULL,I_INDEX INTEGER NOT NULL,N_ORDER_NUM INTEGER,P_TYPE INTEGER,P_MULTIVALUED
BOOLEAN,CONSTRAINT JCR_PK_MITEM PRIMARY KEY(ID))");
- conn.commit();
-
- st.execute("INSERT INTO JCR_MITEM VALUES(' ','
','__root_parent',0,0,0,0,NULL,NULL)");
- conn.commit();
-
- st.execute("CREATE TABLE JCR_MVALUE(ID BIGINT generated by default as
identity (START WITH 2, INCREMENT BY 1) NOT NULL, DATA VARBINARY(65535),ORDER_NUM INTEGER
NOT NULL,PROPERTY_ID VARCHAR(96) NOT NULL,STORAGE_DESC VARCHAR(512),CONSTRAINT
JCR_PK_MVALUE PRIMARY KEY(ID),CONSTRAINT JCR_FK_MVALUE_PROPERTY FOREIGN KEY(PROPERTY_ID)
REFERENCES JCR_MITEM(ID))");
- conn.commit();
-
- st.execute("CREATE TABLE JCR_MREF(NODE_ID VARCHAR(96) NOT NULL,
PROPERTY_ID VARCHAR(96) NOT NULL, ORDER_NUM INTEGER NOT NULL, CONSTRAINT JCR_PK_MREF
PRIMARY KEY(NODE_ID, PROPERTY_ID, ORDER_NUM))");
- conn.commit();
-
// set the initializer
WorkspaceEntry newEntry =
- helper.getNewWs("ws1", true, dsName, newValueStoragePath,
newIndexPath, workspaceEntry.getContainer(),
- workspaceEntry.getContainer().getValueStorages());
+ helper.getNewWs("ws" + System.currentTimeMillis(), true, dsName,
newValueStoragePath, newIndexPath,
+ workspaceEntry.getContainer(),
workspaceEntry.getContainer().getValueStorages());
WorkspaceInitializerEntry wiEntry = new WorkspaceInitializerEntry();
wiEntry.setType(RdbmsWorkspaceInitializer.class.getCanonicalName());
@@ -214,39 +194,18 @@
newEntry.setInitializer(wiEntry);
- TesterRdbmsWorkspaceInitializer initializer =
- new TesterRdbmsWorkspaceInitializer(newEntry,
repositoryService.getRepository("db1").getConfiguration(),
- cacheableDataManager, null, null, null,
- (ValueFactoryImpl) valueFactory, null, repositoryService,
new FileCleanerHolder());
+ repositoryService.getRepository("db1").configWorkspace(newEntry);
+
repositoryService.getRepository("db1").createWorkspace(newEntry.getName());
- // restore multi -> multi
- initializer.restoreTables(conn, 0, true, workspaceEntry.getLockManager(),
url.getFile());
- initializer.restoreTables(conn, 1, true, workspaceEntry.getLockManager(),
url.getFile());
- initializer.restoreTables(conn, 2, true, workspaceEntry.getLockManager(),
url.getFile());
-
- st.execute("ALTER TABLE JCR_MITEM ADD CONSTRAINT JCR_FK_MITEM_PARENT
FOREIGN KEY(PARENT_ID) REFERENCES JCR_MITEM(ID)");
- conn.commit();
-
dsName = helper.getNewDataSource("");
- ds = (DataSource)new InitialContext().lookup(dsName);
- conn = ds.getConnection();
- st = conn.createStatement();
- st.execute("CREATE TABLE JCR_SITEM(ID VARCHAR(96) NOT NULL,PARENT_ID
VARCHAR(96) NOT NULL,NAME VARCHAR(512) NOT NULL,VERSION INTEGER NOT NULL,CONTAINER_NAME
VARCHAR(96) NOT NULL,I_CLASS INTEGER NOT NULL,I_INDEX INTEGER NOT NULL,N_ORDER_NUM
INTEGER,P_TYPE INTEGER,P_MULTIVALUED BOOLEAN,CONSTRAINT JCR_PK_SITEM PRIMARY
KEY(ID))");
- conn.commit();
+ newValueStoragePath = "target/temp/values/" +
IdGenerator.generate();
+ newIndexPath = "target/temp/index/" + IdGenerator.generate();
- st.execute("INSERT INTO JCR_SITEM VALUES(' ','
','__root_parent',0,'__root_parent_container',0,0,0,NULL,NULL)");
- conn.commit();
-
- st.execute("CREATE TABLE JCR_SVALUE(ID BIGINT generated by default as
identity (START WITH 2, INCREMENT BY 1) NOT NULL, DATA VARBINARY(65535),ORDER_NUM INTEGER
NOT NULL,PROPERTY_ID VARCHAR(96) NOT NULL,STORAGE_DESC VARCHAR(512),CONSTRAINT
JCR_PK_MVALUE PRIMARY KEY(ID),CONSTRAINT JCR_FK_SVALUE_PROPERTY FOREIGN KEY(PROPERTY_ID)
REFERENCES JCR_SITEM(ID))");
- conn.commit();
-
- st.execute("CREATE TABLE JCR_SREF(NODE_ID VARCHAR(96) NOT NULL,
PROPERTY_ID VARCHAR(96) NOT NULL, ORDER_NUM INTEGER NOT NULL, CONSTRAINT JCR_PK_SREF
PRIMARY KEY(NODE_ID, PROPERTY_ID, ORDER_NUM))");
- conn.commit();
-
// set the initializer
newEntry =
- helper.getNewWs("ws1", true, dsName, newValueStoragePath,
newIndexPath, workspaceEntry.getContainer(),
+ helper.getNewWs("ws" + System.currentTimeMillis(), true, dsName,
newValueStoragePath, newIndexPath,
+ workspaceEntry.getContainer(),
workspaceEntry.getContainer().getValueStorages());
wiEntry = new WorkspaceInitializerEntry();
@@ -260,19 +219,11 @@
newEntry.setInitializer(wiEntry);
- initializer =
- new TesterRdbmsWorkspaceInitializer(newEntry,
repositoryService.getRepository("db1").getConfiguration(),
- cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory,
null, repositoryService, new FileCleanerHolder());
-
- // restore multi -> single
- initializer.restoreTables(conn, 0, false, workspaceEntry.getLockManager(),
url.getFile());
- initializer.restoreTables(conn, 1, false, workspaceEntry.getLockManager(),
url.getFile());
- initializer.restoreTables(conn, 2, false, workspaceEntry.getLockManager(),
url.getFile());
-
- st.execute("ALTER TABLE JCR_SITEM ADD CONSTRAINT JCR_FK_SITEM_PARENT
FOREIGN KEY(PARENT_ID) REFERENCES JCR_SITEM(ID)");
- conn.commit();
-
+ repositoryService.getRepository("db1").configWorkspace(newEntry);
+
repositoryService.getRepository("db1").createWorkspace(newEntry.getName());
}
+
+ break;
}
}
@@ -286,40 +237,25 @@
Calendar calendar = Calendar.getInstance();
- job.init(repositoryService.getRepository("db3"), "ws", config,
calendar);
+ job.init(repositoryService.getRepository("db7"), "ws1", config,
calendar);
job.run();
URL url = job.getStorageURL();
- for (WorkspaceEntry workspaceEntry :
repositoryService.getRepository("db3").getConfiguration()
+ for (WorkspaceEntry workspaceEntry :
repositoryService.getRepository("db7").getConfiguration()
.getWorkspaceEntries())
{
- if (workspaceEntry.getName().equals("ws"))
+ if (workspaceEntry.getName().equals("ws1"))
{
String newValueStoragePath = "target/temp/values/" +
IdGenerator.generate();
String newIndexPath = "target/temp/index/" +
IdGenerator.generate();
String dsName = helper.getNewDataSource("");
- DataSource ds = (DataSource)new InitialContext().lookup(dsName);
- Connection conn = ds.getConnection();
- Statement st = conn.createStatement();
- st.execute("CREATE TABLE JCR_MITEM(ID VARCHAR(96) NOT NULL,PARENT_ID
VARCHAR(96) NOT NULL,NAME VARCHAR(512) NOT NULL,VERSION INTEGER NOT NULL,I_CLASS INTEGER
NOT NULL,I_INDEX INTEGER NOT NULL,N_ORDER_NUM INTEGER,P_TYPE INTEGER,P_MULTIVALUED
BOOLEAN,CONSTRAINT JCR_PK_MITEM PRIMARY KEY(ID))");
- conn.commit();
-
- st.execute("INSERT INTO JCR_MITEM VALUES(' ','
','__root_parent',0,0,0,0,NULL,NULL)");
- conn.commit();
-
- st.execute("CREATE TABLE JCR_MVALUE(ID BIGINT generated by default as
identity (START WITH 2, INCREMENT BY 1) NOT NULL, DATA VARBINARY(65535),ORDER_NUM INTEGER
NOT NULL,PROPERTY_ID VARCHAR(96) NOT NULL,STORAGE_DESC VARCHAR(512),CONSTRAINT
JCR_PK_MVALUE PRIMARY KEY(ID),CONSTRAINT JCR_FK_MVALUE_PROPERTY FOREIGN KEY(PROPERTY_ID)
REFERENCES JCR_MITEM(ID))");
- conn.commit();
-
- st.execute("CREATE TABLE JCR_MREF(NODE_ID VARCHAR(96) NOT NULL,
PROPERTY_ID VARCHAR(96) NOT NULL, ORDER_NUM INTEGER NOT NULL, CONSTRAINT JCR_PK_MREF
PRIMARY KEY(NODE_ID, PROPERTY_ID, ORDER_NUM))");
- conn.commit();
-
// set the initializer
WorkspaceEntry newEntry =
- helper.getNewWs("ws", true, dsName, newValueStoragePath,
newIndexPath, workspaceEntry.getContainer(),
- workspaceEntry.getContainer().getValueStorages());
+ helper.getNewWs("ws" + System.currentTimeMillis(), true, dsName,
newValueStoragePath, newIndexPath,
+ workspaceEntry.getContainer(),
workspaceEntry.getContainer().getValueStorages());
WorkspaceInitializerEntry wiEntry = new WorkspaceInitializerEntry();
wiEntry.setType(RdbmsWorkspaceInitializer.class.getCanonicalName());
@@ -337,34 +273,18 @@
cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory,
null, repositoryService, new FileCleanerHolder());
// restore single -> multi
- initializer.restoreTables(conn, 0, true, workspaceEntry.getLockManager(),
url.getFile());
- initializer.restoreTables(conn, 1, true, workspaceEntry.getLockManager(),
url.getFile());
- initializer.restoreTables(conn, 2, true, workspaceEntry.getLockManager(),
url.getFile());
+ repositoryService.getRepository("db1").configWorkspace(newEntry);
+
repositoryService.getRepository("db1").createWorkspace(newEntry.getName());
- st.execute("ALTER TABLE JCR_MITEM ADD CONSTRAINT JCR_FK_MITEM_PARENT
FOREIGN KEY(PARENT_ID) REFERENCES JCR_MITEM(ID)");
- conn.commit();
-
dsName = helper.getNewDataSource("");
- ds = (DataSource)new InitialContext().lookup(dsName);
- conn = ds.getConnection();
- st = conn.createStatement();
- st.execute("CREATE TABLE JCR_SITEM(ID VARCHAR(96) NOT NULL,PARENT_ID
VARCHAR(96) NOT NULL,NAME VARCHAR(512) NOT NULL,VERSION INTEGER NOT NULL,CONTAINER_NAME
VARCHAR(96) NOT NULL,I_CLASS INTEGER NOT NULL,I_INDEX INTEGER NOT NULL,N_ORDER_NUM
INTEGER,P_TYPE INTEGER,P_MULTIVALUED BOOLEAN,CONSTRAINT JCR_PK_SITEM PRIMARY
KEY(ID))");
- conn.commit();
+ newValueStoragePath = "target/temp/values/" +
IdGenerator.generate();
+ newIndexPath = "target/temp/index/" + IdGenerator.generate();
- st.execute("INSERT INTO JCR_SITEM VALUES(' ','
','__root_parent',0,'__root_parent_container',0,0,0,NULL,NULL)");
- conn.commit();
-
- st.execute("CREATE TABLE JCR_SVALUE(ID BIGINT generated by default as
identity (START WITH 2, INCREMENT BY 1) NOT NULL, DATA VARBINARY(65535),ORDER_NUM INTEGER
NOT NULL,PROPERTY_ID VARCHAR(96) NOT NULL,STORAGE_DESC VARCHAR(512),CONSTRAINT
JCR_PK_MVALUE PRIMARY KEY(ID),CONSTRAINT JCR_FK_SVALUE_PROPERTY FOREIGN KEY(PROPERTY_ID)
REFERENCES JCR_SITEM(ID))");
- conn.commit();
-
- st.execute("CREATE TABLE JCR_SREF(NODE_ID VARCHAR(96) NOT NULL,
PROPERTY_ID VARCHAR(96) NOT NULL, ORDER_NUM INTEGER NOT NULL, CONSTRAINT JCR_PK_SREF
PRIMARY KEY(NODE_ID, PROPERTY_ID, ORDER_NUM))");
- conn.commit();
-
// set the initializer
newEntry =
- helper.getNewWs("ws", true, dsName, newValueStoragePath,
newIndexPath, workspaceEntry.getContainer(),
- workspaceEntry.getContainer().getValueStorages());
+ helper.getNewWs("ws" + System.currentTimeMillis(), true, dsName,
newValueStoragePath, newIndexPath,
+ workspaceEntry.getContainer(),
workspaceEntry.getContainer().getValueStorages());
wiEntry = new WorkspaceInitializerEntry();
wiEntry.setType(RdbmsWorkspaceInitializer.class.getCanonicalName());
@@ -377,18 +297,11 @@
newEntry.setInitializer(wiEntry);
- initializer =
- new TesterRdbmsWorkspaceInitializer(newEntry,
repositoryService.getRepository("db3").getConfiguration(),
- cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory,
null, repositoryService, new FileCleanerHolder());
-
- // restore single -> single
- initializer.restoreTables(conn, 0, false, workspaceEntry.getLockManager(),
url.getFile());
- initializer.restoreTables(conn, 1, false, workspaceEntry.getLockManager(),
url.getFile());
- initializer.restoreTables(conn, 2, false, workspaceEntry.getLockManager(),
url.getFile());
-
- st.execute("ALTER TABLE JCR_SITEM ADD CONSTRAINT JCR_FK_SITEM_PARENT
FOREIGN KEY(PARENT_ID) REFERENCES JCR_SITEM(ID)");
- conn.commit();
+ repositoryService.getRepository("db1").configWorkspace(newEntry);
+
repositoryService.getRepository("db1").createWorkspace(newEntry.getName());
}
+
+ break;
}
}
}
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/TesterRdbmsWorkspaceInitializer.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/TesterRdbmsWorkspaceInitializer.java 2011-01-10
14:57:58 UTC (rev 3788)
+++
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/TesterRdbmsWorkspaceInitializer.java 2011-01-11
12:13:15 UTC (rev 3789)
@@ -20,11 +20,9 @@
import org.exoplatform.services.jcr.RepositoryService;
import org.exoplatform.services.jcr.access.AccessManager;
-import org.exoplatform.services.jcr.config.LockManagerEntry;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.RepositoryEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.ext.backup.impl.rdbms.RDBMSBackupInfoReader;
import org.exoplatform.services.jcr.ext.backup.impl.rdbms.RdbmsWorkspaceInitializer;
import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeManagerImpl;
import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
@@ -32,8 +30,6 @@
import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
import java.io.IOException;
-import java.sql.Connection;
-import java.sql.SQLException;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
@@ -72,13 +68,10 @@
super.restoreIndex();
}
- public void restoreTables(Connection jdbcConn, int tableType, boolean isMultiDB,
LockManagerEntry lockManagerEntry,
- String storageDir) throws RepositoryConfigurationException, IOException,
SQLException
+ @Override
+ public void fullRdbmsRestore() throws RepositoryException
{
- RDBMSBackupInfoReader backupInfo = new RDBMSBackupInfoReader(storageDir);
- RestoreTableHelper helper = new RestoreTableHelper(tableType, isMultiDB,
backupInfo);
-
- super.restoreTable(jdbcConn, helper);
+ super.fullRdbmsRestore();
}
}
Modified: jcr/trunk/exo.jcr.component.ext/src/test/resources/test.policy
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/resources/test.policy 2011-01-10 14:57:58 UTC
(rev 3788)
+++ jcr/trunk/exo.jcr.component.ext/src/test/resources/test.policy 2011-01-11 12:13:15 UTC
(rev 3789)
@@ -11,6 +11,7 @@
permission java.lang.RuntimePermission "manageRepository";
permission java.lang.RuntimePermission "invokeInternalAPI";
permission java.lang.RuntimePermission "accessRPCService";
+ permission java.lang.RuntimePermission "backupRestoreOperations";
permission java.lang.RuntimePermission "modifyConversationState";
};