exo-jcr SVN: r3599 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-03 08:33:47 -0500 (Fri, 03 Dec 2010)
New Revision: 3599
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/HSQLSingleDBCleaner.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MultiDBCleaner.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MySQLSingleDBCleaner.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/SingleDBCleaner.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/WorkspaceDBCleaner.java
Log:
EXOJCR-939: clean JCR_LOCK tables also
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/HSQLSingleDBCleaner.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/HSQLSingleDBCleaner.java 2010-12-03 11:19:01 UTC (rev 3598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/HSQLSingleDBCleaner.java 2010-12-03 13:33:47 UTC (rev 3599)
@@ -17,6 +17,8 @@
package org.exoplatform.services.jcr.impl.util.jdbc.cleaner;
import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
@@ -31,12 +33,17 @@
public HSQLSingleDBCleaner(String containerName, Connection connection)
{
super(containerName, connection, true);
+ }
- this.scripts =
- new String[]{
- "delete from JCR_SVALUE where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SVALUE.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME=?)",
- "delete from JCR_SREF where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SREF.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME=?)",
- "delete from JCR_SITEM where I_CLASS=2 and CONTAINER_NAME=?"};
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected List<String> getDBCleanScripts()
+ {
+ List<String> scripts = new ArrayList<String>(commonSingleDBCleanScripts);
+ scripts.add("delete from JCR_SITEM where I_CLASS=2 and CONTAINER_NAME='" + containerName + "'");
+
+ return scripts;
}
-
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MultiDBCleaner.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MultiDBCleaner.java 2010-12-03 11:19:01 UTC (rev 3598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MultiDBCleaner.java 2010-12-03 13:33:47 UTC (rev 3599)
@@ -17,6 +17,8 @@
package org.exoplatform.services.jcr.impl.util.jdbc.cleaner;
import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
@@ -26,12 +28,30 @@
{
/**
+ * Common clean scripts for multi database.
+ */
+ protected final List<String> commonMutliDBCleanScripts = new ArrayList<String>();
+
+ /**
* MultiDBCleaner constructor.
*/
public MultiDBCleaner(String containerName, Connection connection)
{
super(containerName, connection);
- this.scripts = new String[]{"DROP TABLE JCR_MREF", "DROP TABLE JCR_MVALUE", "DROP TABLE JCR_MITEM"};
+ commonMutliDBCleanScripts.add("drop table JCR_MREF");
+ commonMutliDBCleanScripts.add("drop table JCR_MVALUE");
+ commonMutliDBCleanScripts.add("drop table JCR_MITEM");
+ commonMutliDBCleanScripts.add("drop table JCR_LOCK_" + containerName.toUpperCase());
+ commonMutliDBCleanScripts.add("drop table JCR_LOCK_" + containerName.toUpperCase() + "_D");
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected List<String> getDBCleanScripts()
+ {
+ return commonMutliDBCleanScripts;
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MySQLSingleDBCleaner.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MySQLSingleDBCleaner.java 2010-12-03 11:19:01 UTC (rev 3598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MySQLSingleDBCleaner.java 2010-12-03 13:33:47 UTC (rev 3599)
@@ -17,6 +17,8 @@
package org.exoplatform.services.jcr.impl.util.jdbc.cleaner;
import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
@@ -31,12 +33,17 @@
public MySQLSingleDBCleaner(String containerName, Connection connection)
{
super(containerName, connection, true);
+ }
- this.scripts =
- new String[]{
- "delete from JCR_SVALUE where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SVALUE.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME=?)",
- "delete from JCR_SREF where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SREF.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME=?)",
- "delete from JCR_SITEM where I_CLASS=2 and CONTAINER_NAME=?"};
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected List<String> getDBCleanScripts()
+ {
+ List<String> scripts = new ArrayList<String>(commonSingleDBCleanScripts);
+ scripts.add("delete from JCR_SITEM where I_CLASS=2 and CONTAINER_NAME='" + containerName + "'");
+
+ return scripts;
}
-
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/SingleDBCleaner.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/SingleDBCleaner.java 2010-12-03 11:19:01 UTC (rev 3598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/SingleDBCleaner.java 2010-12-03 13:33:47 UTC (rev 3599)
@@ -17,8 +17,8 @@
package org.exoplatform.services.jcr.impl.util.jdbc.cleaner;
import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
/**
* @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
@@ -28,6 +28,11 @@
{
/**
+ * Common clean scripts for single database.
+ */
+ protected final List<String> commonSingleDBCleanScripts = new ArrayList<String>();
+
+ /**
* Indicates if need to use clean helper.
*/
protected final boolean postHelpClean;
@@ -54,11 +59,15 @@
this.postHelpClean = postHelpClean;
this.dbCleanHelper = new DBCleanHelper(containerName, connection);
- this.scripts =
- new String[]{
- "delete from JCR_SVALUE where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SVALUE.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME=?)",
- "delete from JCR_SREF where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SREF.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME=?)",
- "delete from JCR_SITEM where CONTAINER_NAME=?"};
+
+ commonSingleDBCleanScripts
+ .add("delete from JCR_SVALUE where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SVALUE.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME='"
+ + containerName + "')");
+ commonSingleDBCleanScripts
+ .add("delete from JCR_SVALUE where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SVALUE.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME='"
+ + containerName + "')");
+ commonSingleDBCleanScripts.add("drop table JCR_LOCK_" + containerName.toUpperCase());
+ commonSingleDBCleanScripts.add("drop table JCR_LOCK_" + containerName.toUpperCase() + "_D");
}
/**
@@ -94,9 +103,11 @@
* {@inheritDoc}
*/
@Override
- protected void executeQuery(Statement statement, String sql) throws SQLException
+ protected List<String> getDBCleanScripts()
{
- final String q = (containerName != null) ? sql.replace("?", "'" + containerName + "'") : sql;
- super.executeQuery(statement, q);
+ List<String> scripts = new ArrayList<String>(commonSingleDBCleanScripts);
+ scripts.add("delete from JCR_SITEM where CONTAINER_NAME='" + containerName + "'");
+
+ return scripts;
}
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/WorkspaceDBCleaner.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/WorkspaceDBCleaner.java 2010-12-03 11:19:01 UTC (rev 3598)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/WorkspaceDBCleaner.java 2010-12-03 13:33:47 UTC (rev 3599)
@@ -27,6 +27,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -54,11 +55,6 @@
protected final Connection connection;
/**
- * SQL scripts for data cleaning.
- */
- protected String[] scripts;
-
- /**
* Pattern for JCR tables.
*/
protected final Pattern dbObjectNamePattern;
@@ -99,14 +95,14 @@
{
connection.setAutoCommit(false);
st = connection.createStatement();
- for (String scr : scripts)
+ for (String scr : getDBCleanScripts())
{
String s = cleanWhitespaces(scr.trim());
if (s.length() > 0)
{
if (!canExecuteQuery(sql = s))
{
- // table from query not found , so try drop other
+ // table from query not found, so try drop other
continue;
}
@@ -180,8 +176,7 @@
String tableName = sql.substring(tMatcher.start(), tMatcher.end());
if (!isTableExists(connection, tableName))
{
- LOG.error("Table [" + tableName + "] from query [" + sql
- + "] was not found. So query will not be executed.");
+ LOG.warn("Table [" + tableName + "] from query [" + sql + "] was not found. So query will not be executed.");
return false;
}
}
@@ -251,4 +246,12 @@
return string;
}
+ /**
+ * Get SQL scripts for data cleaning.
+ *
+ * @return
+ * List of sql scripts
+ */
+ abstract List<String> getDBCleanScripts();
+
}
15 years, 6 months
exo-jcr SVN: r3598 - jcr/trunk/exo.jcr.component.core.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-03 06:19:01 -0500 (Fri, 03 Dec 2010)
New Revision: 3598
Modified:
jcr/trunk/exo.jcr.component.core/pom.xml
Log:
EXOJCR-852: add TestDBCleanerService.java to include list
Modified: jcr/trunk/exo.jcr.component.core/pom.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/pom.xml 2010-12-03 10:08:25 UTC (rev 3597)
+++ jcr/trunk/exo.jcr.component.core/pom.xml 2010-12-03 11:19:01 UTC (rev 3598)
@@ -419,7 +419,6 @@
<exclude>org/exoplatform/services/jcr/**/impl/**/TestWorkspaceManagement.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestWorkspaceRestore.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestRepositoryManagement.java</exclude>
- <exclude>org/exoplatform/services/jcr/**/impl/**/TestDBCleanerService.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestSessionCleaner.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/Base*.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestJCRSerializationStream.java</exclude>
@@ -718,7 +717,6 @@
<exclude>org/exoplatform/services/jcr/**/impl/**/TestWorkspaceManagement.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestWorkspaceRestore.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestRepositoryManagement.java</exclude>
- <exclude>org/exoplatform/services/jcr/**/impl/**/TestDBCleanerService.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestSaveConfiguration.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/ValueStoragePluginTest.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestSessionCleaner.java</exclude>
15 years, 6 months
exo-jcr SVN: r3597 - in jcr/trunk/exo.jcr.component.ext/src: test/java/org/exoplatform/services/jcr/ext/backup and 1 other directory.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-03 05:08:25 -0500 (Fri, 03 Dec 2010)
New Revision: 3597
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/test/java/org/exoplatform/services/jcr/ext/backup/TestFullBackupJob.java
Log:
EXOJCR-1078: RDBMS fullBackupJob implementation
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 2010-12-02 15:44:13 UTC (rev 3596)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java 2010-12-03 10:08:25 UTC (rev 3597)
@@ -27,10 +27,14 @@
import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.dataflow.serialization.ObjectWriter;
import org.exoplatform.services.jcr.ext.backup.BackupConfig;
+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.query.SystemSearchManager;
import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectWriterImpl;
+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.value.fs.FileValueStorage;
import org.exoplatform.services.log.ExoLogger;
@@ -42,6 +46,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
@@ -83,11 +88,47 @@
*/
public static final String VALUE_STORAGE_DIR = "values";
- public static final String CONTENT_FILE_SUFFIX = "dump";
+ /**
+ * Suffix for content file.
+ */
+ public static final String CONTENT_FILE_SUFFIX = ".dump";
- public static final String CONTENT_LEN_FILE_SUFFIX = "len";
+ /**
+ * Suffix for content length file.
+ */
+ public static final String CONTENT_LEN_FILE_SUFFIX = ".len";
/**
+ * Content is absent.
+ */
+ public static final byte NULL_LEN = 0;
+
+ /**
+ * Content length value has byte type.
+ */
+ public static final byte BYTE_LEN = 1;
+
+ /**
+ * Content length value has integer type.
+ */
+ public static final byte INT_LEN = 2;
+
+ /**
+ * Content length value has long type.
+ */
+ public static final byte LONG_LEN = 3;
+
+ /**
+ * Indicates the way to get value thru getBinaryStream() method.
+ */
+ public static final int GET_BINARY_STREAM_METHOD = 0;
+
+ /**
+ * Indicates the way to get value thru getString() method.
+ */
+ public static final int GET_STRING_METHOD = 1;
+
+ /**
* {@inheritDoc}
*/
@Override
@@ -134,6 +175,7 @@
notifyListeners();
Connection jdbcConn = null;
+ Integer transactionIsolation = null;
try
{
WorkspaceEntry workspaceEntry = null;
@@ -154,14 +196,14 @@
String dsName = workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
if (dsName == null)
{
- throw new RepositoryConfigurationException("Source name not found in workspace configuration "
+ throw new RepositoryConfigurationException("Data source name not found in workspace configuration "
+ workspaceName);
}
final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
if (ds == null)
{
- throw new NameNotFoundException("Data source name " + dsName + " not found");
+ throw new NameNotFoundException("Data source " + dsName + " not found");
}
jdbcConn =
@@ -174,15 +216,24 @@
}
});
-
+ transactionIsolation = jdbcConn.getTransactionIsolation();
+ jdbcConn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
+
+ String multiDb = workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB);
+ if (multiDb == null)
+ {
+ throw new RepositoryConfigurationException(JDBCWorkspaceDataContainer.MULTIDB
+ + " parameter not found in workspace " + workspaceName + " configuration");
+ }
+
// dump JCR data
- Boolean multiDb = Boolean.parseBoolean(workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB));
-
String[][] scripts;
- if (multiDb)
+ if (Boolean.parseBoolean(multiDb))
{
scripts =
- new String[][]{{"JCR_MVALUE", "select * from JCR_MVALUE"}, {"JCR_MREF", "select * from JCR_MREF"},
+ new String[][]{
+ {"JCR_MVALUE", "select * from JCR_MVALUE"},
+ {"JCR_MREF", "select * from JCR_MREF"},
{"JCR_MITEM", "select * from JCR_MITEM"}};
}
else
@@ -192,12 +243,12 @@
{
"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="
- + workspaceEntry.getName() + ")"},
+ + 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="
- + workspaceEntry.getName() + ")"},
- {"JCR_SITEM", "select from JCR_SITEM where CONTAINER_NAME=" + workspaceEntry.getName()}};
+ + workspaceName + ")"},
+ {"JCR_SITEM", "select from JCR_SITEM where CONTAINER_NAME=" + workspaceName}};
}
for (String script[] : scripts)
@@ -205,42 +256,75 @@
dumpTable(jdbcConn, script[0], script[1]);
}
- // copy value storage directory
- for (ValueStorageEntry valueStorage : workspaceEntry.getContainer().getValueStorages())
+ // dump LOCK data
+ scripts =
+ new String[][]{
+ {"JCR_LOCK_" + workspaceName.toUpperCase(), "select * from JCR_LOCK_" + workspaceName.toUpperCase()},
+ {"JCR_LOCK_" + workspaceName.toUpperCase() + "_D",
+ "select * from JCR_LOCK_" + workspaceName.toUpperCase() + "_D"}};
+
+ for (String script[] : scripts)
{
- File srcDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));
- if (!PrivilegedFileHelper.exists(srcDir))
+ if (jdbcConn.getMetaData().getTables(null, null, script[0], new String[]{"TABLE"}).next())
{
- throw new FileNotFoundException("File or directory " + srcDir.getName() + " doesn't exists");
+ dumpTable(jdbcConn, script[0], script[1]);
}
+ else
+ {
+ log.warn("Table " + script[0] + " doesn't exist");
+ }
+ }
- File destValuesDir = new File(getStorageURL().getFile(), VALUE_STORAGE_DIR);
- File destDir = new File(destValuesDir, valueStorage.getId());
+ // copy value storage directory
+ if (workspaceEntry.getContainer().getValueStorages() != null)
+ {
+ for (ValueStorageEntry valueStorage : workspaceEntry.getContainer().getValueStorages())
+ {
+ File srcDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));
+ if (!PrivilegedFileHelper.exists(srcDir))
+ {
+ log.warn("Can't not backup value storage. Directory " + srcDir.getName() + " doesn't exists");
+ }
+ else
+ {
+ File destValuesDir = new File(getStorageURL().getFile(), VALUE_STORAGE_DIR);
+ File destDir = new File(destValuesDir, valueStorage.getId());
- copyDirectory(srcDir, destDir);
+ copyDirectory(srcDir, destDir);
+ }
+ }
}
// copy index directory
- File srcDir = new File(workspaceEntry.getQueryHandler().getParameterValue(QueryHandlerParams.PARAM_INDEX_DIR));
- if (!PrivilegedFileHelper.exists(srcDir))
+ if (workspaceEntry.getQueryHandler() != null)
{
- throw new FileNotFoundException("File or directory " + srcDir.getName() + " doesn't exists");
- }
-
- File destDir = new File(getStorageURL().getFile(), INDEX_DIR);
- copyDirectory(srcDir, destDir);
-
- if (repository.getConfiguration().getSystemWorkspaceName().equals(workspaceName))
- {
- srcDir = new File(PrivilegedFileHelper.getCanonicalPath(srcDir) + "_" + SystemSearchManager.INDEX_DIR_SUFFIX);
+ File srcDir =
+ new File(workspaceEntry.getQueryHandler().getParameterValue(QueryHandlerParams.PARAM_INDEX_DIR));
if (!PrivilegedFileHelper.exists(srcDir))
{
- throw new FileNotFoundException("File or directory " + srcDir.getName() + " doesn't exists");
+ log.warn("Can't not backup index. Directory " + srcDir.getName() + " doesn't exists");
}
+ else
+ {
+ File destDir = new File(getStorageURL().getFile(), INDEX_DIR);
+ copyDirectory(srcDir, destDir);
+ }
- destDir = new File(getStorageURL().getFile(), SYSTEM_INDEX_DIR);
+ if (repository.getConfiguration().getSystemWorkspaceName().equals(workspaceName))
+ {
+ srcDir =
+ new File(PrivilegedFileHelper.getCanonicalPath(srcDir) + "_" + SystemSearchManager.INDEX_DIR_SUFFIX);
+ if (!PrivilegedFileHelper.exists(srcDir))
+ {
+ log.warn("Can't not backup system index. Directory " + srcDir.getName() + " doesn't exists");
+ }
+ else
+ {
+ File destDir = new File(getStorageURL().getFile(), SYSTEM_INDEX_DIR);
+ copyDirectory(srcDir, destDir);
+ }
+ }
}
- copyDirectory(srcDir, destDir);
}
catch (RepositoryConfigurationException e)
{
@@ -267,12 +351,22 @@
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)
{
try
{
+ if (transactionIsolation != null)
+ {
+ jdbcConn.setTransactionIsolation(transactionIsolation);
+ }
+
jdbcConn.close();
}
catch (SQLException e)
@@ -290,21 +384,31 @@
/**
* Dump table.
*/
- private void dumpTable(Connection jdbcConn, String tableName, String script) throws SQLException, IOException
+ private void dumpTable(Connection jdbcConn, String tableName, String script) throws SQLException, IOException,
+ BackupOperationException
{
+ int getValueMethod = GET_BINARY_STREAM_METHOD;
+
+ String dbDialect = DialectDetecter.detect(jdbcConn.getMetaData());
+ if (dbDialect.equals(DBConstants.DB_DIALECT_HSQLDB))
+ {
+ getValueMethod = GET_STRING_METHOD;
+ }
+
ObjectWriter contentWriter = null;
ObjectWriter contentLenWriter = null;
PreparedStatement stmt = null;
+ ResultSet rs = null;
try
{
- File contentFile = new File(getStorageURL().getFile(), tableName + "." + CONTENT_FILE_SUFFIX);
+ File contentFile = new File(getStorageURL().getFile(), tableName + CONTENT_FILE_SUFFIX);
contentWriter = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(contentFile));
- File contentLenFile = new File(getStorageURL().getFile(), tableName + "." + CONTENT_LEN_FILE_SUFFIX);
+ File contentLenFile = new File(getStorageURL().getFile(), tableName + CONTENT_LEN_FILE_SUFFIX);
contentLenWriter = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(contentLenFile));
stmt = jdbcConn.prepareStatement(script);
- ResultSet rs = stmt.executeQuery();
+ rs = stmt.executeQuery();
ResultSetMetaData metaData = rs.getMetaData();
int columnCount = metaData.getColumnCount();
@@ -320,11 +424,10 @@
{
for (int i = 0; i < columnCount; i++)
{
- String str = rs.getString(i + 1);
- InputStream value = str == null ? null : new ByteArrayInputStream(str.getBytes());
+ InputStream value = getInputStream(rs, i + 1, getValueMethod);
if (value == null)
{
- contentLenWriter.writeByte((byte)0);
+ contentLenWriter.writeByte(NULL_LEN);
}
else
{
@@ -341,7 +444,6 @@
}
}
}
- rs.close();
}
finally
{
@@ -355,6 +457,11 @@
contentLenWriter.close();
}
+ if (rs != null)
+ {
+ rs.close();
+ }
+
if (stmt != null)
{
stmt.close();
@@ -363,23 +470,42 @@
}
/**
- * @throws IOException
+ * Get input stream from value.
*/
+ private InputStream getInputStream(ResultSet rs, int columnIndex, int getValueMethod) throws SQLException,
+ UnsupportedEncodingException, BackupOperationException
+ {
+ if (getValueMethod == GET_STRING_METHOD)
+ {
+ String str = rs.getString(columnIndex);
+ return str == null ? null : new ByteArrayInputStream(str.getBytes(Constants.DEFAULT_ENCODING));
+ }
+ else if (getValueMethod == GET_BINARY_STREAM_METHOD)
+ {
+ return rs.getBinaryStream(columnIndex);
+ }
+
+ throw new BackupOperationException("There is no way get input stream from value");
+ }
+
+ /**
+ * Write content length in output.
+ */
private void writeCompressedContentLen(ObjectWriter out, long len) throws IOException
{
if (len < Byte.MAX_VALUE)
{
- out.writeByte((byte)1);
+ out.writeByte(BYTE_LEN);
out.writeByte((byte)len);
}
else if (len < Integer.MAX_VALUE)
{
- out.writeByte((byte)2);
+ out.writeByte(INT_LEN);
out.writeInt((int)len);
}
else
{
- out.writeByte((byte)3);
+ out.writeByte(LONG_LEN);
out.writeLong(len);
}
}
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFullBackupJob.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFullBackupJob.java 2010-12-02 15:44:13 UTC (rev 3596)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFullBackupJob.java 2010-12-03 10:08:25 UTC (rev 3597)
@@ -31,14 +31,14 @@
public class TestFullBackupJob extends AbstractBackupTestCase
{
- public void testRDBMSFullBackupJob() throws Exception
+ public void testRDBMSFullBackupJobSystemWorkspace() throws Exception
{
FullBackupJob job = new FullBackupJob();
BackupConfig config = new BackupConfig();
config.setRepository("db1");
config.setWorkspace("ws");
config.setBackupDir(new File("target/backup/testJob"));
-
+
Calendar calendar = Calendar.getInstance();
job.init(repositoryService.getRepository("db1"), "ws", config, calendar);
@@ -53,19 +53,57 @@
assertEquals(values.length, 1);
assertTrue(new File(valuesDir, values[0]).isDirectory());
-
+
File indexesDir = new File(url.getFile(), FullBackupJob.INDEX_DIR);
assertTrue(indexesDir.exists());
indexesDir = new File(url.getFile(), FullBackupJob.SYSTEM_INDEX_DIR);
assertTrue(indexesDir.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.dump").exists());
- assertTrue(new File(url.getFile(), "JCR_MVALUE.len").exists());
- assertTrue(new File(url.getFile(), "JCR_MREF.dump").exists());
- assertTrue(new File(url.getFile(), "JCR_MREF.len").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_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_MREF" + FullBackupJob.CONTENT_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MREF" + FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
+
}
+
+ public void testRDBMSFullBackupJob() throws Exception
+ {
+ FullBackupJob job = new FullBackupJob();
+ BackupConfig config = new BackupConfig();
+ config.setRepository("db1");
+ config.setWorkspace("ws1");
+ config.setBackupDir(new File("target/backup/testJob"));
+
+ Calendar calendar = Calendar.getInstance();
+
+ job.init(repositoryService.getRepository("db1"), "ws1", config, calendar);
+ job.run();
+
+ URL url = job.getStorageURL();
+ assertNotNull(url);
+
+ File valuesDir = new File(url.getFile(), FullBackupJob.VALUE_STORAGE_DIR);
+ assertFalse(valuesDir.exists());
+
+ File indexesDir = new File(url.getFile(), FullBackupJob.INDEX_DIR);
+ assertTrue(indexesDir.exists());
+
+ 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_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_MREF" + FullBackupJob.CONTENT_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MREF" + FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
+
+ }
}
15 years, 6 months
exo-jcr SVN: r3596 - in jcr/trunk/exo.jcr.component.ext: src/main/java/org/exoplatform/services/jcr/ext/backup/impl and 3 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-02 10:44:13 -0500 (Thu, 02 Dec 2010)
New Revision: 3596
Added:
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/test/java/org/exoplatform/services/jcr/ext/backup/TestFullBackupJob.java
Modified:
jcr/trunk/exo.jcr.component.ext/pom.xml
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/IndexCleanHelper.java
jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml
Log:
EXOJCR-1078: add RDBMC full backup job
Modified: jcr/trunk/exo.jcr.component.ext/pom.xml
===================================================================
--- jcr/trunk/exo.jcr.component.ext/pom.xml 2010-12-02 14:02:19 UTC (rev 3595)
+++ jcr/trunk/exo.jcr.component.ext/pom.xml 2010-12-02 15:44:13 UTC (rev 3596)
@@ -187,6 +187,7 @@
<include>**/replication/async/**/*.java</include>
<include>**/backup/TestBackupManager.java</include>
<include>**/backup/TestFileNameProduser.java</include>
+ <include>**/**/TestFullBackupJob.java</include>
</includes>
<excludes>
<exclude>**/BaseStandaloneTest.java</exclude>
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/IndexCleanHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/IndexCleanHelper.java 2010-12-02 14:02:19 UTC (rev 3595)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/IndexCleanHelper.java 2010-12-02 15:44:13 UTC (rev 3596)
@@ -20,6 +20,7 @@
import org.exoplatform.services.jcr.config.QueryHandlerParams;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.impl.core.query.SystemSearchManager;
import java.io.File;
import java.io.IOException;
@@ -52,7 +53,7 @@
if (isSystem)
{
- removeFolder(new File(indexDir + "_system"));
+ removeFolder(new File(indexDir + "_" + SystemSearchManager.INDEX_DIR_SUFFIX));
}
}
Added: 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 (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java 2010-12-02 15:44:13 UTC (rev 3596)
@@ -0,0 +1,454 @@
+/*
+ * 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.commons.utils.SecurityHelper;
+import org.exoplatform.services.jcr.config.QueryHandlerParams;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.ValueStorageEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.core.ManageableRepository;
+import org.exoplatform.services.jcr.dataflow.serialization.ObjectWriter;
+import org.exoplatform.services.jcr.ext.backup.BackupConfig;
+import org.exoplatform.services.jcr.ext.backup.impl.AbstractFullBackupJob;
+import org.exoplatform.services.jcr.ext.backup.impl.FileNameProducer;
+import org.exoplatform.services.jcr.impl.core.query.SystemSearchManager;
+import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectWriterImpl;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+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.io.OutputStream;
+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.util.Calendar;
+
+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
+ */
+public class FullBackupJob extends AbstractFullBackupJob
+{
+
+ /**
+ * Logger.
+ */
+ protected static Log log = ExoLogger.getLogger("exo.jcr.component.ext.FullBackupJob");
+
+ /**
+ * Index directory in full backup storage.
+ */
+ public static final String INDEX_DIR = "index";
+
+ /**
+ * System index directory in full backup storage.
+ */
+ public static final String SYSTEM_INDEX_DIR = INDEX_DIR + "_" + SystemSearchManager.INDEX_DIR_SUFFIX;
+
+ /**
+ * Value storage directory in full backup storage.
+ */
+ public static final String VALUE_STORAGE_DIR = "values";
+
+ public static final String CONTENT_FILE_SUFFIX = "dump";
+
+ public static final String CONTENT_LEN_FILE_SUFFIX = "len";
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected URL createStorage() throws FileNotFoundException, IOException
+ {
+ FileNameProducer fnp =
+ new FileNameProducer(config.getRepository(), config.getWorkspace(),
+ PrivilegedFileHelper.getAbsolutePath(config.getBackupDir()), super.timeStamp, true, true);
+
+ return new URL("file:" + PrivilegedFileHelper.getAbsolutePath(fnp.getNextFile()));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void init(ManageableRepository repository, String workspaceName, BackupConfig config, Calendar timeStamp)
+ {
+ this.repository = repository;
+ this.workspaceName = workspaceName;
+ this.config = config;
+ this.timeStamp = timeStamp;
+
+ try
+ {
+ url = createStorage();
+ }
+ catch (FileNotFoundException e)
+ {
+ log.error("Full backup initialization failed ", e);
+ notifyError("Full backup initialization failed ", e);
+ }
+ catch (IOException e)
+ {
+ log.error("Full backup initialization failed ", e);
+ notifyError("Full backup initialization failed ", e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run()
+ {
+ notifyListeners();
+
+ Connection jdbcConn = null;
+ try
+ {
+ WorkspaceEntry workspaceEntry = null;
+ for (WorkspaceEntry entry : repository.getConfiguration().getWorkspaceEntries())
+ {
+ if (entry.getName().equals(workspaceName))
+ {
+ workspaceEntry = entry;
+ 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)
+ {
+ throw new RepositoryConfigurationException("Source name not found in workspace configuration "
+ + workspaceName);
+ }
+
+ final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
+ if (ds == null)
+ {
+ throw new NameNotFoundException("Data source name " + dsName + " not found");
+ }
+
+ jdbcConn =
+ SecurityHelper.doPriviledgedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return ds.getConnection();
+
+ }
+ });
+
+
+ // dump JCR data
+ Boolean multiDb = Boolean.parseBoolean(workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB));
+
+ String[][] scripts;
+ if (multiDb)
+ {
+ scripts =
+ new String[][]{{"JCR_MVALUE", "select * from JCR_MVALUE"}, {"JCR_MREF", "select * from JCR_MREF"},
+ {"JCR_MITEM", "select * from JCR_MITEM"}};
+ }
+ else
+ {
+ scripts =
+ new String[][]{
+ {
+ "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="
+ + workspaceEntry.getName() + ")"},
+ {
+ "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="
+ + workspaceEntry.getName() + ")"},
+ {"JCR_SITEM", "select from JCR_SITEM where CONTAINER_NAME=" + workspaceEntry.getName()}};
+ }
+
+ for (String script[] : scripts)
+ {
+ dumpTable(jdbcConn, script[0], script[1]);
+ }
+
+ // copy value storage directory
+ for (ValueStorageEntry valueStorage : workspaceEntry.getContainer().getValueStorages())
+ {
+ File srcDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));
+ if (!PrivilegedFileHelper.exists(srcDir))
+ {
+ throw new FileNotFoundException("File or directory " + srcDir.getName() + " doesn't exists");
+ }
+
+ File destValuesDir = new File(getStorageURL().getFile(), VALUE_STORAGE_DIR);
+ File destDir = new File(destValuesDir, valueStorage.getId());
+
+ copyDirectory(srcDir, destDir);
+ }
+
+ // copy index directory
+ File srcDir = new File(workspaceEntry.getQueryHandler().getParameterValue(QueryHandlerParams.PARAM_INDEX_DIR));
+ if (!PrivilegedFileHelper.exists(srcDir))
+ {
+ throw new FileNotFoundException("File or directory " + srcDir.getName() + " doesn't exists");
+ }
+
+ File destDir = new File(getStorageURL().getFile(), INDEX_DIR);
+ copyDirectory(srcDir, destDir);
+
+ if (repository.getConfiguration().getSystemWorkspaceName().equals(workspaceName))
+ {
+ srcDir = new File(PrivilegedFileHelper.getCanonicalPath(srcDir) + "_" + SystemSearchManager.INDEX_DIR_SUFFIX);
+ if (!PrivilegedFileHelper.exists(srcDir))
+ {
+ throw new FileNotFoundException("File or directory " + srcDir.getName() + " doesn't exists");
+ }
+
+ destDir = new File(getStorageURL().getFile(), SYSTEM_INDEX_DIR);
+ }
+ copyDirectory(srcDir, destDir);
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ log.error("Full backup failed " + getStorageURL().getPath(), e);
+ notifyError("Full backup failed", e);
+ }
+ catch (NameNotFoundException e)
+ {
+ log.error("Full backup failed " + getStorageURL().getPath(), e);
+ notifyError("Full backup failed", e);
+ }
+ catch (NamingException e)
+ {
+ log.error("Full backup failed " + getStorageURL().getPath(), e);
+ notifyError("Full backup failed", e);
+ }
+ catch (SQLException e)
+ {
+ log.error("Full backup failed " + getStorageURL().getPath(), e);
+ notifyError("Full backup failed", e);
+ }
+ catch (IOException e)
+ {
+ log.error("Full backup failed " + getStorageURL().getPath(), e);
+ notifyError("Full backup failed", e);
+ }
+ finally
+ {
+ if (jdbcConn != null)
+ {
+ try
+ {
+ jdbcConn.close();
+ }
+ catch (SQLException e)
+ {
+ log.error("Full backup failed " + getStorageURL().getPath(), e);
+ notifyError("Full backup failed", e);
+ }
+ }
+ }
+
+ state = FINISHED;
+ notifyListeners();
+ }
+
+ /**
+ * Dump table.
+ */
+ private void dumpTable(Connection jdbcConn, String tableName, String script) throws SQLException, IOException
+ {
+ ObjectWriter contentWriter = null;
+ ObjectWriter contentLenWriter = null;
+ PreparedStatement stmt = null;
+ try
+ {
+ File contentFile = new File(getStorageURL().getFile(), tableName + "." + CONTENT_FILE_SUFFIX);
+ contentWriter = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(contentFile));
+
+ File contentLenFile = new File(getStorageURL().getFile(), tableName + "." + CONTENT_LEN_FILE_SUFFIX);
+ contentLenWriter = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(contentLenFile));
+
+ stmt = jdbcConn.prepareStatement(script);
+ ResultSet rs = stmt.executeQuery();
+ ResultSetMetaData metaData = rs.getMetaData();
+
+ int columnCount = metaData.getColumnCount();
+
+ contentWriter.writeInt(columnCount);
+ for (int i = 0; i < columnCount; i++)
+ {
+ contentWriter.writeInt(metaData.getColumnType(i + 1));
+ }
+
+ // Now we can output the actual data
+ while (rs.next())
+ {
+ for (int i = 0; i < columnCount; i++)
+ {
+ String str = rs.getString(i + 1);
+ InputStream value = str == null ? null : new ByteArrayInputStream(str.getBytes());
+ if (value == null)
+ {
+ contentLenWriter.writeByte((byte)0);
+ }
+ 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;
+ }
+ writeCompressedContentLen(contentLenWriter, len);
+ }
+ }
+ }
+ rs.close();
+ }
+ finally
+ {
+ if (contentWriter != null)
+ {
+ contentWriter.close();
+ }
+
+ if (contentLenWriter != null)
+ {
+ contentLenWriter.close();
+ }
+
+ if (stmt != null)
+ {
+ stmt.close();
+ }
+ }
+ }
+
+ /**
+ * @throws IOException
+ */
+ private void writeCompressedContentLen(ObjectWriter out, long len) throws IOException
+ {
+ if (len < Byte.MAX_VALUE)
+ {
+ out.writeByte((byte)1);
+ out.writeByte((byte)len);
+ }
+ else if (len < Integer.MAX_VALUE)
+ {
+ out.writeByte((byte)2);
+ out.writeInt((int)len);
+ }
+ else
+ {
+ out.writeByte((byte)3);
+ out.writeLong(len);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void stop()
+ {
+ log.info("Stop requested " + getStorageURL().getPath());
+ }
+
+ /**
+ * Copy directory.
+ *
+ * @param srcPath
+ * source path
+ * @param dstPath
+ * destination path
+ * @throws IOException
+ * if any exception occurred
+ */
+ private void copyDirectory(File srcPath, File dstPath) throws IOException
+ {
+ if (PrivilegedFileHelper.isDirectory(srcPath))
+ {
+ if (!PrivilegedFileHelper.exists(dstPath))
+ {
+ PrivilegedFileHelper.mkdirs(dstPath);
+ }
+
+ String files[] = PrivilegedFileHelper.list(srcPath);
+ for (int i = 0; i < files.length; i++)
+ {
+ copyDirectory(new File(srcPath, files[i]), new File(dstPath, files[i]));
+ }
+ }
+ else
+ {
+ InputStream in = null;
+ OutputStream out = null;
+
+ try
+ {
+ in = PrivilegedFileHelper.fileInputStream(srcPath);
+ out = PrivilegedFileHelper.fileOutputStream(dstPath);
+
+ // Transfer bytes from in to out
+ byte[] buf = new byte[2048];
+
+ int len;
+
+ while ((len = in.read(buf)) > 0)
+ {
+ out.write(buf, 0, len);
+ }
+ }
+ finally
+ {
+ if (in != null)
+ {
+ in.close();
+ }
+
+ if (out != null)
+ {
+ out.close();
+ }
+ }
+ }
+ }
+}
Added: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFullBackupJob.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFullBackupJob.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFullBackupJob.java 2010-12-02 15:44:13 UTC (rev 3596)
@@ -0,0 +1,71 @@
+/*
+ * 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;
+
+import org.exoplatform.services.jcr.ext.backup.impl.rdbms.FullBackupJob;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Calendar;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
+ * @version $Id: TestFullBackupJob.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class TestFullBackupJob extends AbstractBackupTestCase
+{
+
+ public void testRDBMSFullBackupJob() throws Exception
+ {
+ FullBackupJob job = new FullBackupJob();
+ BackupConfig config = new BackupConfig();
+ config.setRepository("db1");
+ config.setWorkspace("ws");
+ config.setBackupDir(new File("target/backup/testJob"));
+
+ Calendar calendar = Calendar.getInstance();
+
+ job.init(repositoryService.getRepository("db1"), "ws", config, calendar);
+ job.run();
+
+ URL url = job.getStorageURL();
+ assertNotNull(url);
+
+ File valuesDir = new File(url.getFile(), FullBackupJob.VALUE_STORAGE_DIR);
+ assertTrue(valuesDir.exists());
+ String values[] = valuesDir.list();
+
+ assertEquals(values.length, 1);
+ assertTrue(new File(valuesDir, values[0]).isDirectory());
+
+ File indexesDir = new File(url.getFile(), FullBackupJob.INDEX_DIR);
+ assertTrue(indexesDir.exists());
+
+ indexesDir = new File(url.getFile(), FullBackupJob.SYSTEM_INDEX_DIR);
+ assertTrue(indexesDir.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.dump").exists());
+ assertTrue(new File(url.getFile(), "JCR_MVALUE.len").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/resources/conf/standalone/test-jcr-ext-config.xml
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml 2010-12-02 14:02:19 UTC (rev 3595)
+++ jcr/trunk/exo.jcr.component.ext/src/test/resources/conf/standalone/test-jcr-ext-config.xml 2010-12-02 15:44:13 UTC (rev 3596)
@@ -39,7 +39,7 @@
<value-storages>
<value-storage id="draft" class="org.exoplatform.services.jcr.impl.storage.value.fs.TreeFileValueStorage">
<properties>
- <property name="path" value="../temp/values/backup" />
+ <property name="path" value="target/temp/values/backup" />
</properties>
<filters>
<filter property-type="Binary" />
@@ -367,7 +367,7 @@
<value-storages>
<value-storage id="draft" class="org.exoplatform.services.jcr.impl.storage.value.fs.TreeFileValueStorage">
<properties>
- <property name="path" value="../temp/values/db7_ws" />
+ <property name="path" value="target/temp/values/db7_ws" />
</properties>
<filters>
<filter property-type="Binary" />
@@ -400,7 +400,7 @@
<value-storages>
<value-storage id="draft" class="org.exoplatform.services.jcr.impl.storage.value.fs.TreeFileValueStorage">
<properties>
- <property name="path" value="../temp/values/db7_ws1" />
+ <property name="path" value="target/temp/values/db7_ws1" />
</properties>
<filters>
<filter property-type="Binary" />
@@ -441,7 +441,7 @@
<value-storages>
<value-storage id="draft" class="org.exoplatform.services.jcr.impl.storage.value.fs.TreeFileValueStorage">
<properties>
- <property name="path" value="../temp/values/db8_ws" />
+ <property name="path" value="target/temp/values/db8_ws" />
</properties>
<filters>
<filter property-type="Binary" />
@@ -474,7 +474,7 @@
<value-storages>
<value-storage id="draft" class="org.exoplatform.services.jcr.impl.storage.value.fs.TreeFileValueStorage">
<properties>
- <property name="path" value="../temp/values/db8_ws1" />
+ <property name="path" value="target/temp/values/db8_ws1" />
</properties>
<filters>
<filter property-type="Binary" />
15 years, 6 months
exo-jcr SVN: r3595 - jcr/branches/1.12.x/exo.jcr.component.core/src/main/resources/conf/storage.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2010-12-02 09:02:19 -0500 (Thu, 02 Dec 2010)
New Revision: 3595
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/resources/conf/storage/jcr-mjdbc.mysql-utf8.sql
jcr/branches/1.12.x/exo.jcr.component.core/src/main/resources/conf/storage/jcr-sjdbc.mysql-utf8.sql
Log:
JCR-1532: MySQL-UTF8 dialect collation set to case-sensitive
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/resources/conf/storage/jcr-mjdbc.mysql-utf8.sql
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/resources/conf/storage/jcr-mjdbc.mysql-utf8.sql 2010-12-02 13:52:47 UTC (rev 3594)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/resources/conf/storage/jcr-mjdbc.mysql-utf8.sql 2010-12-02 14:02:19 UTC (rev 3595)
@@ -5,7 +5,7 @@
CREATE TABLE JCR_MITEM(
ID VARCHAR(56) NOT NULL,
PARENT_ID VARCHAR(56) NOT NULL,
- NAME VARCHAR(512) CHARACTER SET utf8 NOT NULL,
+ NAME VARCHAR(512) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
VERSION INTEGER NOT NULL,
I_CLASS INTEGER NOT NULL,
I_INDEX INTEGER NOT NULL,
@@ -36,4 +36,4 @@
ORDER_NUM INTEGER NOT NULL,
CONSTRAINT JCR_PK_MREF PRIMARY KEY(NODE_ID, PROPERTY_ID, ORDER_NUM)
);
-CREATE UNIQUE INDEX JCR_IDX_MREF_PROPERTY ON JCR_MREF(PROPERTY_ID, ORDER_NUM);
\ No newline at end of file
+CREATE UNIQUE INDEX JCR_IDX_MREF_PROPERTY ON JCR_MREF(PROPERTY_ID, ORDER_NUM);
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/resources/conf/storage/jcr-sjdbc.mysql-utf8.sql
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/resources/conf/storage/jcr-sjdbc.mysql-utf8.sql 2010-12-02 13:52:47 UTC (rev 3594)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/resources/conf/storage/jcr-sjdbc.mysql-utf8.sql 2010-12-02 14:02:19 UTC (rev 3595)
@@ -5,7 +5,7 @@
CREATE TABLE JCR_SITEM(
ID VARCHAR(56) NOT NULL,
PARENT_ID VARCHAR(56) NOT NULL,
- NAME VARCHAR(512) CHARACTER SET utf8 NOT NULL,
+ NAME VARCHAR(512) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
VERSION INTEGER NOT NULL,
CONTAINER_NAME VARCHAR(24) NOT NULL,
I_CLASS INTEGER NOT NULL,
@@ -37,4 +37,4 @@
ORDER_NUM INTEGER NOT NULL,
CONSTRAINT JCR_PK_SREF PRIMARY KEY(NODE_ID, PROPERTY_ID, ORDER_NUM)
);
-CREATE UNIQUE INDEX JCR_IDX_SREF_PROPERTY ON JCR_SREF(PROPERTY_ID, ORDER_NUM);
\ No newline at end of file
+CREATE UNIQUE INDEX JCR_IDX_SREF_PROPERTY ON JCR_SREF(PROPERTY_ID, ORDER_NUM);
15 years, 6 months
exo-jcr SVN: r3594 - jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2010-12-02 08:52:47 -0500 (Thu, 02 Dec 2010)
New Revision: 3594
Modified:
jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/jcr-mjdbc.mysql-utf8.sql
jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/jcr-sjdbc.mysql-utf8.sql
Log:
EXOJCR-1087: changed collation to case-sensitive
Modified: jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/jcr-mjdbc.mysql-utf8.sql
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/jcr-mjdbc.mysql-utf8.sql 2010-12-02 13:47:14 UTC (rev 3593)
+++ jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/jcr-mjdbc.mysql-utf8.sql 2010-12-02 13:52:47 UTC (rev 3594)
@@ -5,7 +5,7 @@
CREATE TABLE JCR_MITEM(
ID VARCHAR(56) NOT NULL,
PARENT_ID VARCHAR(56) NOT NULL,
- NAME VARCHAR(512) CHARACTER SET utf8 NOT NULL,
+ NAME VARCHAR(512) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
VERSION INTEGER NOT NULL,
I_CLASS INTEGER NOT NULL,
I_INDEX INTEGER NOT NULL,
Modified: jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/jcr-sjdbc.mysql-utf8.sql
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/jcr-sjdbc.mysql-utf8.sql 2010-12-02 13:47:14 UTC (rev 3593)
+++ jcr/trunk/exo.jcr.component.core/src/main/resources/conf/storage/jcr-sjdbc.mysql-utf8.sql 2010-12-02 13:52:47 UTC (rev 3594)
@@ -5,7 +5,7 @@
CREATE TABLE JCR_SITEM(
ID VARCHAR(56) NOT NULL,
PARENT_ID VARCHAR(56) NOT NULL,
- NAME VARCHAR(512) CHARACTER SET utf8 NOT NULL,
+ NAME VARCHAR(512) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
VERSION INTEGER NOT NULL,
CONTAINER_NAME VARCHAR(24) NOT NULL,
I_CLASS INTEGER NOT NULL,
15 years, 6 months
exo-jcr SVN: r3593 - jcr/trunk/exo.jcr.component.core.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2010-12-02 08:47:14 -0500 (Thu, 02 Dec 2010)
New Revision: 3593
Modified:
jcr/trunk/exo.jcr.component.core/pom.xml
Log:
EXOJCR-852: excluded TestWorkspaceRestore, due to its failing for all db except for hsqldb
Modified: jcr/trunk/exo.jcr.component.core/pom.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/pom.xml 2010-12-02 10:39:21 UTC (rev 3592)
+++ jcr/trunk/exo.jcr.component.core/pom.xml 2010-12-02 13:47:14 UTC (rev 3593)
@@ -417,6 +417,7 @@
<exclude>org/exoplatform/services/jcr/**/TestErrorMultithreading.java</exclude>
<exclude>org/exoplatform/services/jcr/**/api/**/TestVersionRestore.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestWorkspaceManagement.java</exclude>
+ <exclude>org/exoplatform/services/jcr/**/impl/**/TestWorkspaceRestore.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestRepositoryManagement.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestDBCleanerService.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestSessionCleaner.java</exclude>
@@ -715,6 +716,7 @@
<exclude>org/exoplatform/services/jcr/**/api/**/TestSameNameItems.java</exclude>
<exclude>org/exoplatform/services/jcr/**/api/**/TestVersionRestore.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestWorkspaceManagement.java</exclude>
+ <exclude>org/exoplatform/services/jcr/**/impl/**/TestWorkspaceRestore.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestRepositoryManagement.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestDBCleanerService.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestSaveConfiguration.java</exclude>
15 years, 6 months
exo-jcr SVN: r3592 - in jcr/trunk/exo.jcr.component.ext: src/main/java/org/exoplatform/services/jcr/ext/backup/impl and 2 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-02 05:39:21 -0500 (Thu, 02 Dec 2010)
New Revision: 3592
Added:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/FileNameProducer.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/
Removed:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FileNameProducer.java
Modified:
jcr/trunk/exo.jcr.component.ext/pom.xml
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FullBackupJob.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/IncrementalBackupJob.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFileNameProduser.java
Log:
EXOJCR-1078: adopt filename producer
Modified: jcr/trunk/exo.jcr.component.ext/pom.xml
===================================================================
--- jcr/trunk/exo.jcr.component.ext/pom.xml 2010-12-02 07:10:21 UTC (rev 3591)
+++ jcr/trunk/exo.jcr.component.ext/pom.xml 2010-12-02 10:39:21 UTC (rev 3592)
@@ -185,7 +185,8 @@
<include>**/replication/*.java</include>
<include>**/replication/external/*.java</include>
<include>**/replication/async/**/*.java</include>
- <include>**/**/TestBackupManager.java</include>
+ <include>**/backup/TestBackupManager.java</include>
+ <include>**/backup/TestFileNameProduser.java</include>
</includes>
<excludes>
<exclude>**/BaseStandaloneTest.java</exclude>
Copied: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/FileNameProducer.java (from rev 3591, jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FileNameProducer.java)
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/FileNameProducer.java (rev 0)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/FileNameProducer.java 2010-12-02 10:39:21 UTC (rev 3592)
@@ -0,0 +1,228 @@
+/*
+ * 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;
+
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Calendar;
+
+/**
+ * Created by The eXo Platform SARL Author : Alex Reshetnyak alex.reshetnyak(a)exoplatform.com.ua Nov
+ * 20, 2007
+ */
+public class FileNameProducer
+{
+ /**
+ * Backup set name.
+ */
+ private final String backupSetName;
+
+ /**
+ * Backup set directory.
+ */
+ private final File backupSetDir;
+
+ /**
+ * Indicates is full backup or not.
+ */
+ private boolean isFullBackup;
+
+ /**
+ * Indicates that need to create a directory for full backup otherwise is will be the single file.
+ */
+ private final boolean isDirectoryForFullBackup;
+
+ /**
+ * Constructor FileNameProducer.
+ *
+ * @param backupSetName
+ * backup set name
+ * @param backupDir
+ * backup directory
+ * @param timeStamp
+ * time stamp for creation unique backup set directory
+ * @param isFullBackup
+ * indicates is full backup or not
+ * @param isDirectory
+ * indicates that need to create a directory for full backup otherwise is will be the single file
+ */
+ public FileNameProducer(String backupSetName, String backupDir, Calendar timeStamp, boolean isFullBackup,
+ boolean isDirectory)
+ {
+ this.backupSetName = backupSetName;
+ this.isFullBackup = isFullBackup;
+ this.isDirectoryForFullBackup = isDirectory;
+
+ String sTime = "-" + getStrDate(timeStamp) + "_" + getStrTime(timeStamp);
+ this.backupSetDir = new File(backupDir + File.separator + backupSetName + sTime);
+
+ if (!PrivilegedFileHelper.exists(backupSetDir))
+ {
+ PrivilegedFileHelper.mkdirs(backupSetDir);
+ }
+ }
+
+ /**
+ * Constructor FileNameProducer.
+ *
+ * @param repositoryName
+ * repository name for creation backup set name
+ * @param workspaceName
+ * workspace name for creation backup set name
+ * @param backupDir
+ * backup directory
+ * @param timeStamp
+ * time stamp for creation unique backup set directory
+ * @param isFullBackup
+ * indicates is full backup or not
+ * @param isDirectory
+ * indicates that need to create a directory for full backup otherwise is will be the single file
+ */
+ public FileNameProducer(String repositoryName, String workspaceName, String backupDir, Calendar timeStamp,
+ boolean isFullBackup, boolean isDirectory)
+ {
+ this(repositoryName + "_" + workspaceName, backupDir, timeStamp, isFullBackup, isDirectory);
+ }
+
+ /**
+ * Constructor FileNameProducer.
+ *
+ * @param repositoryName
+ * repository name for creation backup set name
+ * @param workspaceName
+ * workspace name for creation backup set name
+ * @param backupDir
+ * backup directory
+ * @param timeStamp
+ * time stamp for creation unique backup set directory
+ * @param isFullBackup
+ * indicates is full backup or not
+ */
+ public FileNameProducer(String repositoryName, String workspaceName, String backupDir, Calendar timeStamp,
+ boolean isFullBackup)
+ {
+ this(repositoryName + "_" + workspaceName, backupDir, timeStamp, isFullBackup, false);
+ }
+
+ /**
+ * Get next file in backup set.
+ *
+ * @return
+ * file
+ */
+ public File getNextFile()
+ {
+ File nextFile = null;
+
+ try
+ {
+ String sNextName = generateName();
+
+ nextFile = new File(backupSetDir.getAbsoluteFile() + File.separator + sNextName);
+ if (isFullBackup && isDirectoryForFullBackup)
+ {
+ if (!PrivilegedFileHelper.exists(nextFile))
+ {
+ PrivilegedFileHelper.mkdirs(nextFile);
+ }
+ }
+ else
+ {
+ PrivilegedFileHelper.createNewFile(nextFile);
+ }
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+
+ return nextFile;
+ }
+
+ /**
+ * Generate name for backup file (directory) based on backup set name and current time.
+ */
+ private String generateName()
+ {
+
+ Calendar date = Calendar.getInstance();
+
+ String sDate = getStrDate(date);
+ String sTime = getStrTime(date);
+
+ String fileName = backupSetName + "-" + sDate + "_" + sTime + ".";
+
+ if (isFullBackup)
+ {
+ fileName += "0";
+ }
+ else
+ {
+ fileName += getNextSufix();
+ }
+
+ return fileName;
+ }
+
+ private String getNextSufix()
+ {
+
+ String[] fileList = PrivilegedFileHelper.list(backupSetDir);
+
+ int sufix = 0;
+
+ for (int i = 0; i < fileList.length; i++)
+ {
+ String[] stringArray = fileList[i].split("[.]");
+
+ int currentSufix = Integer.valueOf(stringArray[stringArray.length - 1]).intValue();
+
+ if (currentSufix > sufix)
+ {
+ sufix = currentSufix;
+ }
+ }
+
+ return String.valueOf(++sufix);
+ }
+
+ /**
+ * Returns date as String in format YYYYMMDD.
+ */
+ private String getStrDate(Calendar c)
+ {
+ int m = c.get(Calendar.MONTH) + 1;
+ int d = c.get(Calendar.DATE);
+ return "" + c.get(Calendar.YEAR) + (m < 10 ? "0" + m : m) + (d < 10 ? "0" + d : d);
+ }
+
+ /**
+ * Returns time as String in format HHMMSS.
+ */
+ private String getStrTime(Calendar c)
+ {
+ int h = c.get(Calendar.HOUR);
+ int m = c.get(Calendar.MINUTE);
+ int s = c.get(Calendar.SECOND);
+ return "" + (h < 10 ? "0" + h : h) + (m < 10 ? "0" + m : m) + (s < 10 ? "0" + s : s);
+ }
+
+}
Deleted: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FileNameProducer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FileNameProducer.java 2010-12-02 07:10:21 UTC (rev 3591)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FileNameProducer.java 2010-12-02 10:39:21 UTC (rev 3592)
@@ -1,145 +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.fs;
-
-import org.exoplatform.commons.utils.PrivilegedFileHelper;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Calendar;
-
-/**
- * Created by The eXo Platform SARL Author : Alex Reshetnyak alex.reshetnyak(a)exoplatform.com.ua Nov
- * 20, 2007
- */
-public class FileNameProducer
-{
- private String serviceDir;
-
- private String backupSetName;
-
- private File backupSetDir;
-
- private boolean isFullBackup;
-
- private Calendar timeStamp;
-
- public FileNameProducer(String backupSetName, String serviceDir, Calendar timeStamp, boolean isFullBackup)
- {
- this.backupSetName = backupSetName;
- this.serviceDir = serviceDir;
- this.isFullBackup = isFullBackup;
- this.timeStamp = timeStamp;
- }
-
- public FileNameProducer(String repositoryName, String workspaceName, String serviceDir, Calendar timeStamp,
- boolean isFullBackup)
- {
- this.backupSetName = repositoryName + "_" + workspaceName;
- this.serviceDir = serviceDir;
- this.isFullBackup = isFullBackup;
- this.timeStamp = timeStamp;
- }
-
- public File getNextFile()
- {
- File nextFile = null;
-
- try
- {
- // TODO use SimpleDateFormat
- // String sTime = "-" + new SimpleDateFormat("yyyyMMdd_hhmmss").fprmat(timeStamp);
- String sTime = "-" + getStrDate(timeStamp) + "_" + getStrTime(timeStamp);
-
- backupSetDir = new File(serviceDir + File.separator + backupSetName + sTime);
-
- if (!PrivilegedFileHelper.exists(backupSetDir))
- {
- PrivilegedFileHelper.mkdirs(backupSetDir);
- }
-
- String sNextName = generateName();
-
- nextFile = new File(backupSetDir.getAbsoluteFile() + File.separator + sNextName);
- PrivilegedFileHelper.createNewFile(nextFile);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
-
- return nextFile;
- }
-
- private String generateName()
- {
-
- Calendar date = Calendar.getInstance();
-
- String sDate = getStrDate(date);
- String sTime = getStrTime(date);
-
- String fileName = backupSetName + "-" + sDate + "_" + sTime + ".";
-
- if (isFullBackup)
- fileName += "0";
- else
- fileName += getNextSufix();
-
- return fileName;
- }
-
- private String getNextSufix()
- {
-
- String[] fileList = PrivilegedFileHelper.list(backupSetDir);
-
- int sufix = 0;
-
- for (int i = 0; i < fileList.length; i++)
- {
- String[] stringArray = fileList[i].split("[.]");
-
- int currentSufix = Integer.valueOf(stringArray[stringArray.length - 1]).intValue();
-
- if (currentSufix > sufix)
- sufix = currentSufix;
- }
-
- return String.valueOf(++sufix);
- }
-
- public static String getStrDate(Calendar c)
- {
- // Returns as a String (YYYYMMDD) a Calendar date
- int m = c.get(Calendar.MONTH) + 1;
- int d = c.get(Calendar.DATE);
- return "" + c.get(Calendar.YEAR) + (m < 10 ? "0" + m : m) + (d < 10 ? "0" + d : d);
- }
-
- public static String getStrTime(Calendar c)
- {
- // Returns as a String (YYYYMMDD) a Calendar date
- int h = c.get(Calendar.HOUR);
- int m = c.get(Calendar.MINUTE);
- int s = c.get(Calendar.SECOND);
- return "" + (h < 10 ? "0" + h : h) + (m < 10 ? "0" + m : m) + (s < 10 ? "0" + s : s);
- }
-
-}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FullBackupJob.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FullBackupJob.java 2010-12-02 07:10:21 UTC (rev 3591)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/FullBackupJob.java 2010-12-02 10:39:21 UTC (rev 3592)
@@ -22,6 +22,7 @@
import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.ext.backup.BackupConfig;
import org.exoplatform.services.jcr.ext.backup.impl.AbstractFullBackupJob;
+import org.exoplatform.services.jcr.ext.backup.impl.FileNameProducer;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -51,8 +52,7 @@
FileNameProducer fnp =
new FileNameProducer(config.getRepository(), config.getWorkspace(),
- PrivilegedFileHelper.getAbsolutePath(config.getBackupDir()),
- super.timeStamp, true);
+ PrivilegedFileHelper.getAbsolutePath(config.getBackupDir()), super.timeStamp, true);
return new URL("file:" + PrivilegedFileHelper.getAbsolutePath(fnp.getNextFile()));
}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/IncrementalBackupJob.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/IncrementalBackupJob.java 2010-12-02 07:10:21 UTC (rev 3591)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/fs/IncrementalBackupJob.java 2010-12-02 10:39:21 UTC (rev 3592)
@@ -25,6 +25,7 @@
import org.exoplatform.services.jcr.dataflow.TransactionChangesLog;
import org.exoplatform.services.jcr.ext.backup.BackupConfig;
import org.exoplatform.services.jcr.ext.backup.impl.AbstractIncrementalBackupJob;
+import org.exoplatform.services.jcr.ext.backup.impl.FileNameProducer;
import org.exoplatform.services.jcr.ext.backup.impl.PendingChangesLog;
import org.exoplatform.services.jcr.ext.replication.FixupStream;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFileNameProduser.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFileNameProduser.java 2010-12-02 07:10:21 UTC (rev 3591)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestFileNameProduser.java 2010-12-02 10:39:21 UTC (rev 3592)
@@ -20,7 +20,7 @@
import junit.framework.TestCase;
-import org.exoplatform.services.jcr.ext.backup.impl.fs.FileNameProducer;
+import org.exoplatform.services.jcr.ext.backup.impl.FileNameProducer;
import java.io.File;
import java.util.Calendar;
@@ -31,36 +31,56 @@
*/
public class TestFileNameProduser extends TestCase
{
- FileNameProducer nameProducer;
+ private File tempDir;
- File tempDir;
+ private String backupsetName;
- String backupsetName;
+ private Calendar calendar;
- public void testGetNextName() throws Exception
+ @Override
+ public void setUp() throws Exception
{
+ super.setUp();
+
tempDir = new File("target" + File.separator + "temp" + File.separator + "fileProduser");
tempDir.mkdirs();
-
backupsetName = String.valueOf(System.currentTimeMillis());
+ calendar = Calendar.getInstance();
+ }
- nextName(true);
- nextName(false);
- nextName(false);
- nextName(false);
- nextName(false);
- nextName(false);
+ public void testGetNextNameJCRBackup() throws Exception
+ {
+ FileNameProducer nameProducer =
+ new FileNameProducer(backupsetName, tempDir.getAbsolutePath(), calendar, true, false);
+ File file = nameProducer.getNextFile();
- assertEquals(1, 1);
+ assertTrue(file.isFile());
+ assertTrue(file.getName().endsWith(".0"));
+
+ nameProducer = new FileNameProducer(backupsetName, tempDir.getAbsolutePath(), calendar, false, false);
+ file = nameProducer.getNextFile();
+
+ assertTrue(file.isFile());
+ assertTrue(file.getName().endsWith(".1"));
+ assertTrue(nameProducer.getNextFile().getName().endsWith(".2"));
+ assertTrue(nameProducer.getNextFile().getName().endsWith(".3"));
}
- private void nextName(boolean isFullBackup) throws InterruptedException
+ public void testGetNextNameRDBMSBackup() throws Exception
{
- // nameProducer = new FileNameProducer("reposytory", "production", tempDir.getAbsolutePath(),
- // isFullBackup);
- Thread.sleep(100);
- nameProducer =
- new FileNameProducer(backupsetName, tempDir.getAbsolutePath(), Calendar.getInstance(), isFullBackup);
- System.out.println(nameProducer.getNextFile().getName());
+ FileNameProducer nameProducer =
+ new FileNameProducer(backupsetName, tempDir.getAbsolutePath(), calendar, true, true);
+ File file = nameProducer.getNextFile();
+
+ assertTrue(file.isDirectory());
+ assertTrue(file.getName().endsWith(".0"));
+
+ nameProducer = new FileNameProducer(backupsetName, tempDir.getAbsolutePath(), calendar, false, false);
+ file = nameProducer.getNextFile();
+
+ assertTrue(file.isFile());
+ assertTrue(file.getName().endsWith(".1"));
+ assertTrue(nameProducer.getNextFile().getName().endsWith(".2"));
+ assertTrue(nameProducer.getNextFile().getName().endsWith(".3"));
}
}
15 years, 6 months
exo-jcr SVN: r3591 - jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-02 02:10:21 -0500 (Thu, 02 Dec 2010)
New Revision: 3591
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java
Log:
EXOJCR-852: fix test
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java 2010-12-02 07:06:27 UTC (rev 3590)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestBackupManager.java 2010-12-02 07:10:21 UTC (rev 3591)
@@ -1091,7 +1091,7 @@
final RepositoryBackupChain bch = backup.startBackup(config);
- Thread.sleep(30000);
+ Thread.sleep(40000);
assertTrue(bch.isFinished());
15 years, 6 months
exo-jcr SVN: r3590 - jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-12-02 02:06:27 -0500 (Thu, 02 Dec 2010)
New Revision: 3590
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/RepositoryCreationServiceImpl.java
Log:
EXOJCR-929: fix stop method. check if rpcService exists or not
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/RepositoryCreationServiceImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/RepositoryCreationServiceImpl.java 2010-12-01 16:16:32 UTC (rev 3589)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/repository/creation/RepositoryCreationServiceImpl.java 2010-12-02 07:06:27 UTC (rev 3590)
@@ -639,8 +639,11 @@
*/
public void stop()
{
- this.rpcService.unregisterCommand(reserveRepositoryName);
- this.rpcService.unregisterCommand(createRepository);
- this.rpcService.unregisterCommand(startRepository);
+ if (this.rpcService != null)
+ {
+ this.rpcService.unregisterCommand(reserveRepositoryName);
+ this.rpcService.unregisterCommand(createRepository);
+ this.rpcService.unregisterCommand(startRepository);
+ }
}
}
15 years, 6 months