Author: tolusha
Date: 2011-01-12 04:41:40 -0500 (Wed, 12 Jan 2011)
New Revision: 3790
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/BackupTables.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTableRule.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTables.java
Removed:
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/RestoreTable.java
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/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/storage/jdbc/JDBCWorkspaceDataContainer.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java
Log:
EXOJCR-1130: Implement approach using the marker Backupable: remove duplicated code
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-11
12:13:15 UTC (rev 3789)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cacheable/AbstractCacheableLockManager.java 2011-01-12
09:41:40 UTC (rev 3790)
@@ -16,6 +16,7 @@
*/
package org.exoplatform.services.jcr.impl.core.lock.cacheable;
+import org.exoplatform.commons.utils.PrivilegedSystemHelper;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.services.jcr.config.LockManagerEntry;
@@ -47,18 +48,28 @@
import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
import
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
import org.exoplatform.services.jcr.impl.storage.JCRInvalidItemStateException;
+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.RestoreException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.util.BackupTables;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.util.RestoreTableRule;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.util.RestoreTables;
import org.exoplatform.services.jcr.observation.ExtendedEvent;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.security.IdentityConstants;
import org.picocontainer.Startable;
+import java.io.File;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -76,7 +87,8 @@
* @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
* @version $Id: AbstractCacheableLockManagerImpl.java 2806 2010-07-21 08:00:15Z tolusha
$
*/
-public abstract class AbstractCacheableLockManager implements CacheableLockManager,
ItemsPersistenceListener, Startable
+public abstract class AbstractCacheableLockManager implements CacheableLockManager,
ItemsPersistenceListener,
+ Startable, Backupable
{
/**
* The name to property time out.
@@ -825,4 +837,55 @@
{
return "select * from " + tableName;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void backup(File storageDir) throws BackupException
+ {
+ Map<String, String> scripts = new HashMap<String, String>();
+ for (String tableName : getTableNames())
+ {
+ scripts.put(tableName, "SELECT * FROM " + tableName);
+ }
+
+ BackupTables.backup(storageDir, getDatasourceName(), scripts);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void restore(File storageDir) throws RestoreException
+ {
+ Map<String, RestoreTableRule> tables = new LinkedHashMap<String,
RestoreTableRule>();
+ for (String tableName : getTableNames())
+ {
+ RestoreTableRule restoreTableRule = new RestoreTableRule();
+ restoreTableRule.setSrcContainerName(null);
+ restoreTableRule.setSrcMultiDb(null);
+ restoreTableRule.setDstContainerName(null);
+ restoreTableRule.setDstMultiDb(null);
+ restoreTableRule.setSkipColumnIndex(null);
+ restoreTableRule.setDeleteColumnIndex(null);
+ restoreTableRule.setNewColumnIndex(null);
+ restoreTableRule.setConvertColumnIndex(null);
+ restoreTableRule.setContentFile(new File(storageDir, tableName +
BackupTables.CONTENT_FILE_SUFFIX));
+ restoreTableRule.setContentLenFile(new File(storageDir, tableName +
BackupTables.CONTENT_LEN_FILE_SUFFIX));
+
+ tables.put(tableName, restoreTableRule);
+ }
+
+ File tempDir = new
File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
+ int maxBufferSize =
+
config.getContainer().getParameterInteger(JDBCWorkspaceDataContainer.MAXBUFFERSIZE_PROP,
+ JDBCWorkspaceDataContainer.DEF_MAXBUFFERSIZE);
+
+ RestoreTables restoreTable = new RestoreTables(null, tempDir, maxBufferSize);
+ restoreTable.restore(storageDir, getDatasourceName(), tables);
+ }
+
+ protected abstract List<String> getTableNames();
+
+ protected abstract String getDatasourceName();
+
}
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-11
12:13:15 UTC (rev 3789)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNCacheableLockManagerImpl.java 2011-01-12
09:41:40 UTC (rev 3790)
@@ -17,8 +17,6 @@
*/
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;
@@ -35,12 +33,7 @@
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;
@@ -49,8 +42,6 @@
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;
@@ -64,8 +55,6 @@
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;
@@ -412,194 +401,46 @@
/**
* {@inheritDoc}
*/
- public void backup(File storageDir) throws BackupException
+ @Override
+ protected List<String> getTableNames()
{
- Connection jdbcConn = null;
+ List<String> tableNames = new ArrayList<String>();
- try
+ LockManagerEntry lockManagerEntry = config.getLockManager();
+ if (lockManagerEntry != null)
{
- List<String> tableNames = new ArrayList<String>();
- String dsName = null;
-
- LockManagerEntry lockManagerEntry = config.getLockManager();
- if (lockManagerEntry != null)
+ for (SimpleParameterEntry entry : lockManagerEntry.getParameters())
{
- for (SimpleParameterEntry entry : lockManagerEntry.getParameters())
+ if (entry.getName().equals(INFINISPAN_JDBC_TABLE_NAME))
{
- if (entry.getName().equals(INFINISPAN_JDBC_TABLE_NAME))
- {
- tableNames.add(entry.getValue());
- }
- else if (entry.getName().equals(INFINISPAN_JDBC_CL_DATASOURCE))
- {
- dsName = entry.getValue();
- }
- }
- }
+ tableNames.add(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();
-
+ return tableNames;
}
- });
-
- 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);
- }
- }
- }
+
+ return tableNames;
}
/**
* {@inheritDoc}
*/
- public void restore(File storageDir) throws RestoreException
+ @Override
+ protected String getDatasourceName()
{
- Connection jdbcConn = null;
-
- try
+ LockManagerEntry lockManagerEntry = config.getLockManager();
+ if (lockManagerEntry != null)
{
- List<String> tableNames = new ArrayList<String>();
- String dsName = null;
-
- LockManagerEntry lockManagerEntry = config.getLockManager();
- if (lockManagerEntry != null)
+ for (SimpleParameterEntry entry : lockManagerEntry.getParameters())
{
- for (SimpleParameterEntry entry : lockManagerEntry.getParameters())
+ if (entry.getName().equals(INFINISPAN_JDBC_CL_DATASOURCE))
{
- if (entry.getName().equals(INFINISPAN_JDBC_TABLE_NAME))
- {
- tableNames.add(entry.getValue());
- }
- else if (entry.getName().equals(INFINISPAN_JDBC_CL_DATASOURCE))
- {
- dsName = entry.getValue();
- }
+ return 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);
- }
- }
- }
+ return null;
}
-
}
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-11
12:13:15 UTC (rev 3789)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2011-01-12
09:41:40 UTC (rev 3790)
@@ -16,8 +16,6 @@
*/
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;
@@ -34,12 +32,6 @@
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;
@@ -57,8 +49,6 @@
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;
@@ -73,8 +63,6 @@
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;
@@ -88,7 +76,7 @@
*/
@Managed
@NameTemplate(@Property(key = "service", value = "lockmanager"))
-public class CacheableLockManagerImpl extends AbstractCacheableLockManager implements
Backupable
+public class CacheableLockManagerImpl extends AbstractCacheableLockManager
{
public static final String JBOSSCACHE_JDBC_CL_DATASOURCE =
"jbosscache-cl-cache.jdbc.datasource";
@@ -587,196 +575,45 @@
/**
* {@inheritDoc}
*/
- public void backup(File storageDir) throws BackupException
+ protected List<String> getTableNames()
{
- Connection jdbcConn = null;
+ List<String> tableNames = new ArrayList<String>();
- try
+ LockManagerEntry lockManagerEntry = config.getLockManager();
+ if (lockManagerEntry != null)
{
- List<String> tableNames = new ArrayList<String>();
- String dsName = null;
-
- LockManagerEntry lockManagerEntry = config.getLockManager();
- if (lockManagerEntry != null)
+ for (SimpleParameterEntry entry : lockManagerEntry.getParameters())
{
- for (SimpleParameterEntry entry : lockManagerEntry.getParameters())
+ if (entry.getName().equals(JBOSSCACHE_JDBC_TABLE_NAME))
{
- 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");
- }
+ tableNames.add(entry.getValue());
+ tableNames.add(entry.getValue() + "_D");
- jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new
PrivilegedExceptionAction<Connection>()
- {
- public Connection run() throws Exception
- {
- return ds.getConnection();
-
+ return tableNames;
}
- });
-
- 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);
- }
- }
- }
+
+ return tableNames;
}
/**
* {@inheritDoc}
*/
- public void restore(File storageDir) throws RestoreException
+ protected String getDatasourceName()
{
- Connection jdbcConn = null;
-
- try
+ LockManagerEntry lockManagerEntry = config.getLockManager();
+ if (lockManagerEntry != null)
{
- List<String> tableNames = new ArrayList<String>();
- String dsName = null;
-
- LockManagerEntry lockManagerEntry = config.getLockManager();
- if (lockManagerEntry != null)
+ for (SimpleParameterEntry entry : lockManagerEntry.getParameters())
{
- for (SimpleParameterEntry entry : lockManagerEntry.getParameters())
+ if (entry.getName().equals(JBOSSCACHE_JDBC_CL_DATASOURCE))
{
- 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();
- }
+ return 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);
- }
- }
- }
+
+ return null;
}
-
}
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-11
12:13:15 UTC (rev 3789)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2011-01-12
09:41:40 UTC (rev 3790)
@@ -32,9 +32,10 @@
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.backup.util.BackupTables;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.util.RestoreTableRule;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.util.RestoreTables;
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;
@@ -64,13 +65,14 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
-import java.sql.Statement;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
import java.util.Set;
import javax.jcr.RepositoryException;
import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import javax.sql.DataSource;
@@ -1004,7 +1006,6 @@
public void backup(File storageDir) throws BackupException
{
ObjectWriter backupInfo = null;
- Connection jdbcConn = null;
try
{
@@ -1015,72 +1016,36 @@
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");
- }
+ Map<String, String> scripts = new HashMap<String, String>();
- 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"}};
+ scripts.put("JCR_MITEM", "select * from JCR_MITEM where
JCR_MITEM.name <> '" + Constants.ROOT_PARENT_NAME
+ + "'");
+ scripts.put("JCR_MVALUE", "select * from JCR_MVALUE");
+ scripts.put("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 + "')"}};
+ scripts.put("JCR_SITEM", "select * from JCR_SITEM where
CONTAINER_NAME='" + containerName + "'");
+ scripts
+ .put(
+ "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 + "')");
+ scripts
+ .put(
+ "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);
- }
+ BackupTables.backup(storageDir, dbSourceName, scripts);
}
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)
@@ -1094,18 +1059,6 @@
throw new BackupException(e);
}
}
-
- if (jdbcConn != null)
- {
- try
- {
- jdbcConn.close();
- }
- catch (SQLException e)
- {
- throw new BackupException(e);
- }
- }
}
}
@@ -1115,29 +1068,9 @@
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")));
@@ -1145,152 +1078,110 @@
String srcContainerName = backupInfo.readString();
boolean srcMultiDb = backupInfo.readBoolean();
- String[] tablesSuffix = new String[]{"ITEM", "VALUE",
"REF"};
+ Map<String, RestoreTableRule> tables = new LinkedHashMap<String,
RestoreTableRule>();
- File tempDir = new
File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
- RestoreTable restoreTable = new RestoreTable(swapCleaner, tempDir,
maxBufferSize);
+ // ITEM table
+ String dstTableName = "JCR_" + (multiDb ? "M" :
"S") + "ITEM";
+ String srcTableName = "JCR_" + (srcMultiDb ? "M" :
"S") + "ITEM";
- restoreTable.setSrcContainerName(srcContainerName);
- restoreTable.setSrcMultiDb(srcMultiDb);
- restoreTable.setDstContainerName(containerName);
- restoreTable.setDstMultiDb(multiDb);
+ RestoreTableRule restoreTableRule = new RestoreTableRule();
+ restoreTableRule.setSrcContainerName(srcContainerName);
+ restoreTableRule.setSrcMultiDb(srcMultiDb);
+ restoreTableRule.setDstContainerName(containerName);
+ restoreTableRule.setDstMultiDb(multiDb);
+ restoreTableRule.setContentFile(new File(storageDir, srcTableName +
BackupTables.CONTENT_FILE_SUFFIX));
+ restoreTableRule.setContentLenFile(new File(storageDir, srcTableName +
BackupTables.CONTENT_LEN_FILE_SUFFIX));
- for (String tableSuffix : tablesSuffix)
+ if (multiDb)
{
- 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 (!srcMultiDb)
{
- 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)";
+ // CONTAINER_NAME column index
+ restoreTableRule.setDeleteColumnIndex(4);
- // 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);
- }
- }
+ // ID and PARENT_ID column indexes
+ Set<Integer> convertColumnIndex = new HashSet<Integer>();
+ convertColumnIndex.add(0);
+ convertColumnIndex.add(1);
+ restoreTableRule.setConvertColumnIndex(convertColumnIndex);
}
- else if (tableSuffix.equals("VALUE"))
+ }
+ else
+ {
+ if (srcMultiDb)
{
- // auto increment ID column
- restoreTable.setSkipColumnIndex(0);
- restoreTable.setDeleteColumnIndex(null);
- restoreTable.setNewColumnIndex(null);
+ // CONTAINER_NAME column index
+ restoreTableRule.setNewColumnIndex(4);
- if (!multiDb || !srcMultiDb)
- {
- // PROPERTY_ID column index
- Set<Integer> convertColumnIndex = new HashSet<Integer>();
- convertColumnIndex.add(3);
- restoreTable.setConvertColumnIndex(convertColumnIndex);
- }
- else
- {
- restoreTable.setConvertColumnIndex(null);
- }
+ // ID and PARENT_ID column indexes
+ Set<Integer> convertColumnIndex = new HashSet<Integer>();
+ convertColumnIndex.add(0);
+ convertColumnIndex.add(1);
+ restoreTableRule.setConvertColumnIndex(convertColumnIndex);
}
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);
- }
+ // ID and PARENT_ID and CONTAINER_NAME column indexes
+ Set<Integer> convertColumnIndex = new HashSet<Integer>();
+ convertColumnIndex.add(0);
+ convertColumnIndex.add(1);
+ convertColumnIndex.add(4);
+ restoreTableRule.setConvertColumnIndex(convertColumnIndex);
}
+ }
+ tables.put(dstTableName, restoreTableRule);
- restoreTable.restore(jdbcConn, dstTableName, storageDir);
+ // VALUE table
+ dstTableName = "JCR_" + (multiDb ? "M" : "S") +
"VALUE";
+ srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") +
"VALUE";
- if (tableSuffix.equals("ITEM"))
- {
- if (constraint != null)
- {
- // add constraint
- st = jdbcConn.createStatement();
- st.execute("ALTER TABLE " + dstTableName + " ADD "
+ constraint);
- jdbcConn.commit();
- }
- }
+ restoreTableRule = new RestoreTableRule();
+ restoreTableRule.setSrcContainerName(srcContainerName);
+ restoreTableRule.setSrcMultiDb(srcMultiDb);
+ restoreTableRule.setDstContainerName(containerName);
+ restoreTableRule.setDstMultiDb(multiDb);
+ restoreTableRule.setContentFile(new File(storageDir, srcTableName +
BackupTables.CONTENT_FILE_SUFFIX));
+ restoreTableRule.setContentLenFile(new File(storageDir, srcTableName +
BackupTables.CONTENT_LEN_FILE_SUFFIX));
+
+ // auto increment ID column
+ restoreTableRule.setSkipColumnIndex(0);
+
+ if (!multiDb || !srcMultiDb)
+ {
+ // PROPERTY_ID column index
+ Set<Integer> convertColumnIndex = new HashSet<Integer>();
+ convertColumnIndex.add(3);
+ restoreTableRule.setConvertColumnIndex(convertColumnIndex);
}
+ tables.put(dstTableName, restoreTableRule);
+
+ // REF tables
+ dstTableName = "JCR_" + (multiDb ? "M" : "S") +
"REF";
+ srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") +
"REF";
+
+ restoreTableRule = new RestoreTableRule();
+ restoreTableRule.setSrcContainerName(srcContainerName);
+ restoreTableRule.setSrcMultiDb(srcMultiDb);
+ restoreTableRule.setDstContainerName(containerName);
+ restoreTableRule.setDstMultiDb(multiDb);
+ restoreTableRule.setContentFile(new File(storageDir, srcTableName +
BackupTables.CONTENT_FILE_SUFFIX));
+ restoreTableRule.setContentLenFile(new File(storageDir, srcTableName +
BackupTables.CONTENT_LEN_FILE_SUFFIX));
+
+ if (!multiDb || !srcMultiDb)
+ {
+ // NODE_ID and PROPERTY_ID column indexes
+ Set<Integer> convertColumnIndex = new HashSet<Integer>();
+ convertColumnIndex.add(0);
+ convertColumnIndex.add(1);
+ restoreTableRule.setConvertColumnIndex(convertColumnIndex);
+ }
+ tables.put(dstTableName, restoreTableRule);
+
+
+ File tempDir = new
File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
+ RestoreTables restoreTable = new RestoreTables(swapCleaner, tempDir,
maxBufferSize);
+
+ restoreTable.restore(storageDir, dbSourceName, tables);
}
catch (FileNotFoundException e)
{
@@ -1300,25 +1191,6 @@
{
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)
@@ -1332,30 +1204,6 @@
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);
- }
- }
}
}
Deleted:
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 2011-01-11
12:13:15 UTC (rev 3789)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/DumpTable.java 2011-01-12
09:41:40 UTC (rev 3790)
@@ -1,206 +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.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();
- }
- }
- }
-
-}
Deleted:
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 2011-01-11
12:13:15 UTC (rev 3789)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/RestoreTable.java 2011-01-12
09:41:40 UTC (rev 3790)
@@ -1,501 +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.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;
- }
-}
Copied:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/BackupTables.java
(from rev 3789,
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/util/BackupTables.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/BackupTables.java 2011-01-12
09:41:40 UTC (rev 3790)
@@ -0,0 +1,285 @@
+/*
+ * 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.util;
+
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
+import org.exoplatform.commons.utils.SecurityHelper;
+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 org.exoplatform.services.jcr.impl.storage.jdbc.backup.BackupException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Backupable;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+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.Types;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.zip.ZipEntry;
+
+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>
+ * @version $Id: BackupTables 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class BackupTables
+{
+ /**
+ * 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();
+
+ /**
+ * {@inheritDoc}
+ */
+ public static void backup(File storageDir, String dsName, Map<String, String>
scripts) throws BackupException
+ {
+ Connection jdbcConn = null;
+
+ try
+ {
+ 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 (Entry<String, String> entry : scripts.entrySet())
+ {
+ dumpTable(jdbcConn, entry.getKey(), entry.getValue(), 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);
+ }
+ }
+ }
+ }
+
+ /**
+ * Dump table.
+ *
+ * @throws IOException
+ * @throws SQLException
+ */
+ private static void dumpTable(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/util/RestoreTableRule.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTableRule.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTableRule.java 2011-01-12
09:41:40 UTC (rev 3790)
@@ -0,0 +1,150 @@
+/*
+ * 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.util;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy
Bazko</a>
+ * @version $Id: RestoreTableRule.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class RestoreTableRule
+{
+ 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;
+
+ public File getContentFile()
+ {
+ return contentFile;
+ }
+
+ public void setContentFile(File contentFile)
+ {
+ this.contentFile = contentFile;
+ }
+
+ public File getContentLenFile()
+ {
+ return contentLenFile;
+ }
+
+ public void setContentLenFile(File contentLenFile)
+ {
+ this.contentLenFile = contentLenFile;
+ }
+
+ public Integer getDeleteColumnIndex()
+ {
+ return deleteColumnIndex;
+ }
+
+ public void setDeleteColumnIndex(Integer deleteColumnIndex)
+ {
+ this.deleteColumnIndex = deleteColumnIndex;
+ }
+
+ public Integer getSkipColumnIndex()
+ {
+ return skipColumnIndex;
+ }
+
+ public void setSkipColumnIndex(Integer skipColumnIndex)
+ {
+ this.skipColumnIndex = skipColumnIndex;
+ }
+
+ public Integer getNewColumnIndex()
+ {
+ return newColumnIndex;
+ }
+
+ public void setNewColumnIndex(Integer newColumnIndex)
+ {
+ this.newColumnIndex = newColumnIndex;
+ }
+
+ public Set<Integer> getConvertColumnIndex()
+ {
+ return convertColumnIndex;
+ }
+
+ public void setConvertColumnIndex(Set<Integer> convertColumnIndex)
+ {
+ this.convertColumnIndex = convertColumnIndex;
+ }
+
+ public String getSrcContainerName()
+ {
+ return srcContainerName;
+ }
+
+ public void setSrcContainerName(String srcContainerName)
+ {
+ this.srcContainerName = srcContainerName;
+ }
+
+ public String getDstContainerName()
+ {
+ return dstContainerName;
+ }
+
+ public void setDstContainerName(String dstContainerName)
+ {
+ this.dstContainerName = dstContainerName;
+ }
+
+ public Boolean getSrcMultiDb()
+ {
+ return srcMultiDb;
+ }
+
+ public void setSrcMultiDb(Boolean srcMultiDb)
+ {
+ this.srcMultiDb = srcMultiDb;
+ }
+
+ public Boolean getDstMultiDb()
+ {
+ return dstMultiDb;
+ }
+
+ public void setDstMultiDb(Boolean dstMultiDb)
+ {
+ this.dstMultiDb = dstMultiDb;
+ }
+}
Copied:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTables.java
(from rev 3789,
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/util/RestoreTables.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTables.java 2011-01-12
09:41:40 UTC (rev 3790)
@@ -0,0 +1,608 @@
+/*
+ * 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.util;
+
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
+import org.exoplatform.commons.utils.SecurityHelper;
+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.storage.jdbc.backup.Backupable;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.RestoreException;
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+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.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+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>
+ * @version $Id: DumpTable.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class RestoreTables
+{
+ /**
+ * 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;
+
+ /**
+ * Logger.
+ */
+ protected static final Log LOG =
ExoLogger.getLogger("exo.jcr.component.core.JDBCWorkspaceDataContainer");
+
+ /**
+ * Constructor RestoreTable.
+ */
+ public RestoreTables(FileCleaner fileCleaner, File tempDir, int maxBufferSize)
+ {
+ this.fileCleaner = fileCleaner;
+ this.tempDir = tempDir;
+ this.maxBufferSize = maxBufferSize;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void restore(File storageDir, String dsName, Map<String,
RestoreTableRule> tables)
+ throws RestoreException
+ {
+ Connection jdbcConn = null;
+ Statement st = null;
+ RestoreException exc = null;
+
+ try
+ {
+ 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 dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
+
+ for (Entry<String, RestoreTableRule> entry : tables.entrySet())
+ {
+ String tableName = entry.getKey();
+ RestoreTableRule restoreRule = entry.getValue();
+
+ String constraint = null;
+ if (tableName.equals("JCR_SITEM") ||
tableName.equals("JCR_MITEM"))
+ {
+ if (dialect != BackupTables.DB_DIALECT_MYSQL && dialect !=
BackupTables.DB_DIALECT_MYSQL_UTF8)
+ {
+ // resolve constraint name depends on database
+ String constraintName;
+ if (dialect == BackupTables.DB_DIALECT_DB2 || dialect ==
BackupTables.DB_DIALECT_DB2V8)
+ {
+ constraintName = "JCR_FK_" + (restoreRule.getDstMultiDb()
? "M" : "S") + "ITEM_PAREN";
+ }
+ else
+ {
+ constraintName = "JCR_FK_" + (restoreRule.getDstMultiDb()
? "M" : "S") + "ITEM_PARENT";
+ }
+ constraint =
+ "CONSTRAINT " + constraintName + " FOREIGN
KEY(PARENT_ID) REFERENCES " + tableName + "(ID)";
+
+ // drop constraint
+ st = jdbcConn.createStatement();
+ st.execute("ALTER TABLE " + tableName + " DROP
CONSTRAINT " + constraintName);
+ }
+ }
+
+ restore(storageDir, jdbcConn, tableName, restoreRule);
+
+ if (constraint != null)
+ {
+ // add constraint
+ st.execute("ALTER TABLE " + tableName + " ADD " +
constraint);
+ }
+ }
+
+ jdbcConn.commit();
+ }
+ catch (IOException e)
+ {
+ exc = new RestoreException(e);
+ throw exc;
+ }
+ 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() + ")" : "");
+
+ exc = new RestoreException(msg, e);
+ throw exc;
+ }
+ catch (NamingException e)
+ {
+ exc = new RestoreException(e);
+ throw exc;
+ }
+ finally
+ {
+ if (st != null)
+ {
+ try
+ {
+ st.close();
+ }
+ catch (SQLException e)
+ {
+ LOG.warn("Can't close statemnt", e);
+ }
+ }
+
+ if (jdbcConn != null)
+ {
+ try
+ {
+ jdbcConn.rollback();
+ }
+ catch (SQLException e)
+ {
+ if (exc != null)
+ {
+ throw new RestoreException(e);
+ }
+ else
+ {
+ throw new RestoreException("Can't rollback connection",
exc);
+ }
+ }
+ finally
+ {
+ try
+ {
+ jdbcConn.close();
+ }
+ catch (SQLException e)
+ {
+ if (exc != null)
+ {
+ throw new RestoreException(e);
+ }
+ else
+ {
+ throw new RestoreException("Can't close connection",
exc);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Restore table.
+ */
+ private void restore(File storageDir, Connection jdbcConn, String tableName,
RestoreTableRule restoreRule)
+ 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();
+
+ // switch table name to lower case
+ if (dialect == BackupTables.DB_DIALECT_PGSQL)
+ {
+ tableName = tableName.toLowerCase();
+ }
+
+ try
+ {
+ contentReader = new
ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(restoreRule.getContentFile()));
+ contentReader.getNextEntry();
+
+ contentLenReader =
+ new
ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(restoreRule.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, tableName,
"%");
+ while (tableMetaData.next())
+ {
+ newColumnName.add(tableMetaData.getString("COLUMN_NAME"));
+ newColumnType.add(tableMetaData.getInt("DATA_TYPE"));
+ }
+
+ int targetColumnCount = sourceColumnCount;
+ if (restoreRule.getDeleteColumnIndex() != null)
+ {
+ targetColumnCount--;
+ }
+ else if (restoreRule.getNewColumnIndex() != null)
+ {
+ targetColumnCount++;
+ columnType.add(restoreRule.getNewColumnIndex(),
newColumnType.get(restoreRule.getNewColumnIndex()));
+ }
+
+ // construct statement
+ String names = "";
+ String parameters = "";
+ for (int i = 0; i < targetColumnCount; i++)
+ {
+ if (restoreRule.getSkipColumnIndex() != null &&
restoreRule.getSkipColumnIndex() == 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 (restoreRule.getNewColumnIndex() != null &&
restoreRule.getNewColumnIndex() == i)
+ {
+ stream =
+ new
ByteArrayInputStream(restoreRule.getDstContainerName().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 (restoreRule.getSkipColumnIndex() != null &&
restoreRule.getSkipColumnIndex() == i)
+ {
+ targetIndex--;
+ continue;
+ }
+ else if (restoreRule.getDeleteColumnIndex() != null &&
restoreRule.getDeleteColumnIndex() == i)
+ {
+ targetIndex--;
+ continue;
+ }
+
+ // set
+ if (stream != null)
+ {
+ if (restoreRule.getConvertColumnIndex() != null &&
restoreRule.getConvertColumnIndex().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 (restoreRule.getDstMultiDb())
+ {
+ if (!restoreRule.getSrcMultiDb())
+ {
+ stream =
+ new ByteArrayInputStream(new String(readBuffer,
Constants.DEFAULT_ENCODING).substring(
+
restoreRule.getSrcContainerName().length()).getBytes());
+ }
+ }
+ else
+ {
+ if (restoreRule.getSrcMultiDb())
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(restoreRule.getDstContainerName());
+ builder.append(currentValue);
+
+ stream = new
ByteArrayInputStream(builder.toString().getBytes());
+ }
+ else
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(restoreRule.getDstContainerName());
+ builder.append(new String(readBuffer,
Constants.DEFAULT_ENCODING).substring(restoreRule
+ .getSrcContainerName().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 == BackupTables.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 == BackupTables.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.executeUpdate();
+ }
+
+ // insertNode.executeBatch();
+ }
+ 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);
+ }
+ }
+ }
+}
+
+
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java 2011-01-11
12:13:15 UTC (rev 3789)
+++
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/load/TestLoadBackup.java 2011-01-12
09:41:40 UTC (rev 3790)
@@ -196,7 +196,7 @@
System.out.println(" ============ BACKUP FINISHED ============");
// restore
- WorkspaceEntry ws1back = makeWorkspaceEntry("ws1back",
"jdbcrestore");
+ WorkspaceEntry ws1back = makeWorkspaceEntry("ws1back",
"jdbcjcr_to_repository_restore_singel_db");
File backLog = new File(bch.getLogFilePath());
if (backLog.exists())