exo-jcr SVN: r3796 - jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2011-01-13 02:40:37 -0500 (Thu, 13 Jan 2011)
New Revision: 3796
Modified:
jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd
jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh
Log:
EXOJCR-1151: The problem with form authentication on Platform 3.0.2 was fixed.
Modified: jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd
===================================================================
--- jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd 2011-01-12 16:06:25 UTC (rev 3795)
+++ jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd 2011-01-13 07:40:37 UTC (rev 3796)
@@ -53,7 +53,7 @@
jcrbackup http://%user%:%pass%@%host%/rest/private %comm%
)
if "%auth%" == "-f" (
-jcrbackup http://%host%/%context%/rest form POST /portal/login?initialURI=/%context%/private^^^&username=%user%^^^&password=%pass% %comm%
+jcrbackup http://%host%/%context%/rest form POST /%context%/login?initialURI=/%context%/private^^^&username=%user%^^^&password=%pass% %comm%
)
Modified: jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh
===================================================================
--- jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh 2011-01-12 16:06:25 UTC (rev 3795)
+++ jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh 2011-01-13 07:40:37 UTC (rev 3796)
@@ -51,11 +51,11 @@
then
context="$7"
host=${8#*"http://"}
- newargs="http://$host/$context/rest form POST /portal/login?initialURI=/$context/private&username=$user&password=$pass ${args[@]:8}"
+ newargs="http://$host/$context/rest form POST /$context/login?initialURI=/$context/private&username=$user&password=$pass ${args[@]:8}"
else
context="portal"
host=${6#*"http://"}
- newargs="http://$host/$context/rest form POST /portal/login?initialURI=/$context/private&username=$user&password=$pass ${args[@]:6}"
+ newargs="http://$host/$context/rest form POST /$context/login?initialURI=/$context/private&username=$user&password=$pass ${args[@]:6}"
fi
else
13 years, 5 months
exo-jcr SVN: r3795 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-01-12 11:06:25 -0500 (Wed, 12 Jan 2011)
New Revision: 3795
Modified:
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/RestoreTables.java
Log:
EXOJCR-1096: Test on all supported database: db2
Modified: 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/BackupTables.java 2011-01-12 15:48:51 UTC (rev 3794)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/BackupTables.java 2011-01-12 16:06:25 UTC (rev 3795)
@@ -224,9 +224,11 @@
for (int i = 0; i < columnCount; i++)
{
InputStream value;
- if (dialect == DB_DIALECT_HSQLDB || dialect == DB_DIALECT_SYBASE)
+ if (dialect == DB_DIALECT_HSQLDB || dialect == DB_DIALECT_SYBASE || dialect == DB_DIALECT_DB2
+ || dialect == DB_DIALECT_DB2V8)
{
- if (columnType[i] == Types.VARBINARY || columnType[i] == Types.LONGVARBINARY)
+ if (columnType[i] == Types.VARBINARY || columnType[i] == Types.LONGVARBINARY
+ || columnType[i] == Types.BLOB)
{
value = rs.getBinaryStream(i + 1);
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTables.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTables.java 2011-01-12 15:48:51 UTC (rev 3794)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTables.java 2011-01-12 16:06:25 UTC (rev 3795)
@@ -248,8 +248,7 @@
/**
* Restore table.
*/
- private void restore(File storageDir, Connection jdbcConn, String tableName,
- RestoreTableRule restoreRule)
+ private void restore(File storageDir, Connection jdbcConn, String tableName, RestoreTableRule restoreRule)
throws IOException, SQLException
{
// Need privileges
@@ -465,9 +464,11 @@
}
else
{
- if (dialect == BackupTables.DB_DIALECT_HSQLDB || dialect == BackupTables.DB_DIALECT_SYBASE)
+ if (dialect == BackupTables.DB_DIALECT_HSQLDB || dialect == BackupTables.DB_DIALECT_SYBASE
+ || dialect == BackupTables.DB_DIALECT_DB2 || dialect == BackupTables.DB_DIALECT_DB2V8)
{
- if (columnType.get(i) == Types.VARBINARY || columnType.get(i) == Types.LONGVARBINARY)
+ if (columnType.get(i) == Types.VARBINARY || columnType.get(i) == Types.LONGVARBINARY
+ || columnType.get(i) == Types.BLOB)
{
insertNode.setBinaryStream(targetIndex + 1, stream, (int)len);
}
13 years, 5 months
exo-jcr SVN: r3794 - in jcr/trunk: applications/exo.jcr.applications.backupconsole.dist/bin and 2 other directories.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2011-01-12 10:48:51 -0500 (Wed, 12 Jan 2011)
New Revision: 3794
Modified:
jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd
jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh
jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/src/main/doc/readme.txt
jcr/trunk/applications/exo.jcr.applications.backupconsole/src/main/java/org/exoplatform/jcr/backupconsole/BackupClientImpl.java
jcr/trunk/applications/exo.jcr.applications.backupconsole/src/main/java/org/exoplatform/jcr/backupconsole/BackupConsole.java
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/backup-client.xml
Log:
EXOJCR-1151: The problem with form authentication on Platform 3.0.2 was fixed.
Modified: jcr/trunk/applications/exo.jcr.applications.backupconsole/src/main/java/org/exoplatform/jcr/backupconsole/BackupClientImpl.java
===================================================================
--- jcr/trunk/applications/exo.jcr.applications.backupconsole/src/main/java/org/exoplatform/jcr/backupconsole/BackupClientImpl.java 2011-01-12 15:19:34 UTC (rev 3793)
+++ jcr/trunk/applications/exo.jcr.applications.backupconsole/src/main/java/org/exoplatform/jcr/backupconsole/BackupClientImpl.java 2011-01-12 15:48:51 UTC (rev 3794)
@@ -696,8 +696,7 @@
String result =
"\nThe backup service information : \n" + "\tfull backup type : "
- + info.getFullBackupType()
- + "\n" + "\tincremental backup type : "
+ + info.getFullBackupType() + "\n" + "\tincremental backup type : "
+ info.getIncrementalBackupType() + "\n" + "\tbackup log folder : "
+ info.getBackupLogDir() + "\n" + "\tdefault incremental job period : "
+ info.getDefaultIncrementalJobPeriod() + "\n\n";
Modified: jcr/trunk/applications/exo.jcr.applications.backupconsole/src/main/java/org/exoplatform/jcr/backupconsole/BackupConsole.java
===================================================================
--- jcr/trunk/applications/exo.jcr.applications.backupconsole/src/main/java/org/exoplatform/jcr/backupconsole/BackupConsole.java 2011-01-12 15:19:34 UTC (rev 3793)
+++ jcr/trunk/applications/exo.jcr.applications.backupconsole/src/main/java/org/exoplatform/jcr/backupconsole/BackupConsole.java 2011-01-12 15:48:51 UTC (rev 3794)
@@ -65,7 +65,7 @@
+ " <form auth parm> : form <method> <form path>\n"
+ " <method> : POST or GET\n"
+ " <form path> : /path/path?<paramName1>=<paramValue1>&<paramName2>=<paramValue2>...\n"
- + " Example to <url form authentication> : http://127.0.0.1:8080/portal/rest form POST \"/portal/login?username=root&password=gtn\"\n\n"
+ + " Example to <url form authentication> : http://127.0.0.1:8080/portal/rest form POST \"/portal/login?initialURI=/portal/private&username=root&password=gtn\"\n\n"
+ " <cmd> : start <repo[/ws]> <backup_dir> [<incr>] \n"
+ " stop <backup_id> \n"
Modified: jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd
===================================================================
--- jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd 2011-01-12 15:19:34 UTC (rev 3793)
+++ jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.cmd 2011-01-12 15:48:51 UTC (rev 3794)
@@ -1,6 +1,7 @@
@echo off
set auth=-b
+set context=portal
if NOT "%1" == "-u" goto :help
shift
@@ -17,6 +18,12 @@
set auth=%1
shift
)
+if "%1" == "-c" (
+shift
+set context=%2
+shift
+)
+
if "%1" == "-b" (
shift
)
@@ -46,7 +53,7 @@
jcrbackup http://%user%:%pass%@%host%/rest/private %comm%
)
if "%auth%" == "-f" (
-jcrbackup http://%host%/portal/rest form POST /portal/login?username=%user%^^^&password=%pass% %comm%
+jcrbackup http://%host%/%context%/rest form POST /portal/login?initialURI=/%context%/private^^^&username=%user%^^^&password=%pass% %comm%
)
@@ -55,8 +62,10 @@
echo -u ^<user^> -p ^<password^> [form_of_authentication] ^<host:port^> ^<command^>
echo.
echo [form_of_authentication] : -b - is used for basic authentication
-echo -f - is used for form authentication
+echo : -f [-c ^<context^>] - is used for form authentication with context portal
+echo if parameter context not specified
echo if no authentication set basic authentication is used
+echo -c ^<context^> : context, by default context is portal
echo.
echo ^<command^> : start ^<repo[/ws]^> ^<backup_dir^> [^<incr^>]
echo stop ^<backup_id^>
Modified: jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh
===================================================================
--- jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh 2011-01-12 15:19:34 UTC (rev 3793)
+++ jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/bin/exobackup.sh 2011-01-12 15:48:51 UTC (rev 3794)
@@ -7,8 +7,9 @@
echo " -u <user> -p <password> [form_of_authentication] <host:port> <command> "
echo " "
echo " [form_of_authentication] : -b - is used for basic authentication "
-echo " -f - is used for form authentication "
+echo " -f [-c <context>] - is used for form authentication with context portal if parameter context not specified "
echo " if no authentication set basic authentication is used"
+echo " -c <context> : context, by default context is portal"
echo " <command> : start <repo[/ws]> <backup_dir> [<incr>] "
echo " stop <backup_id> "
echo " status <backup_id> "
@@ -45,8 +46,18 @@
if [ "$5" = "-f" ]
then
- host=${6#*"http://"}
- newargs="http://$host/portal/rest form POST /portal/login?username=$user&password=$pass ${args[@]:6}"
+
+ if [ "$6" = "-c" ]
+ then
+ context="$7"
+ host=${8#*"http://"}
+ newargs="http://$host/$context/rest form POST /portal/login?initialURI=/$context/private&username=$user&password=$pass ${args[@]:8}"
+ else
+ context="portal"
+ host=${6#*"http://"}
+ newargs="http://$host/$context/rest form POST /portal/login?initialURI=/$context/private&username=$user&password=$pass ${args[@]:6}"
+ fi
+
else
if [ "$5" = "-b" ]
then
Modified: jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/src/main/doc/readme.txt
===================================================================
--- jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/src/main/doc/readme.txt 2011-01-12 15:19:34 UTC (rev 3793)
+++ jcr/trunk/applications/exo.jcr.applications.backupconsole.dist/src/main/doc/readme.txt 2011-01-12 15:48:51 UTC (rev 3794)
@@ -9,7 +9,7 @@
<method> : POST or GET
<form_path> : /path/path?<paramName1>=<paramValue1>&<paramName2>=<paramValue2>...
- Example of <url_form_authentication> - http://127.0.0.1:8080/portal/rest form POST "/portal/login?username=root&password=gtn"
+ Example of <url_form_authentication> - http://127.0.0.1:8080/portal/rest form POST "/portal/login?initialURI=/portal/private&username=root&password=gtn"
<command> : start <repo[/ws]> <backup_dir> [<incr>]
stop <backup_id>
@@ -46,8 +46,9 @@
-u <user> -p <password> [form_of_authentication] <host:port> <command>
<form_of_authentication> : -b - is used for basic authentication
- -f - is used for form authentication
+ -f [-c <context>] - is used for form authentication with context portal if parameter context not specified
if no authentication set basic authentication is used
+ -c <context> : context, by default context is portal
<command> : start <repo[/ws]> <backup_dir> [<incr>]
stop <backup_id>
Modified: jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/backup-client.xml
===================================================================
--- jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/backup-client.xml 2011-01-12 15:19:34 UTC (rev 3793)
+++ jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/backup/backup-client.xml 2011-01-12 15:48:51 UTC (rev 3794)
@@ -982,7 +982,8 @@
command "info" with form authentication to GateIn :</para>
<para>./jcrbackup.sh http://127.0.0.1:8080/portal/rest form POST
- "/portal/login?username=root&password=gtn" info</para>
+ "/portal/login?initialURI=/portal/private&username=root&password=gtn"
+ info</para>
</highlights>
<para>Backup client is console application.</para>
@@ -999,7 +1000,7 @@
<form auth parm> : form <method> <form path>
<method> : POST or GET
<form path> : /path/path?<paramName1>=<paramValue1>&<paramName2>=<paramValue2>...
- Example to <url form authentication> : http://127.0.0.1:8080/portal/rest form POST "/portal/login?username=root&password=gtn"
+ Example to <url form authentication> : http://127.0.0.1:8080/portal/rest form POST "/portal/login?initialURI=/portal/private&username=root&password=gtn"
<cmd> : start <repo[/ws]> <backup_dir> [<incr>]
stop <backup_id>
@@ -1281,7 +1282,7 @@
</section>
<section>
- <title>Restoring workspace with original configuation </title>
+ <title>Restoring workspace with original configuation</title>
<para>Restore to workspace "backup" with original configuration of
workspace (the original configuration was stored in backup set), for
13 years, 5 months
exo-jcr SVN: r3793 - jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-01-12 10:19:34 -0500 (Wed, 12 Jan 2011)
New Revision: 3793
Removed:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MySQLSingleDBCleaner.java
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java
Log:
JCR-1570: DB clean on MySQL should not use iterating over all db
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java 2011-01-12 13:54:37 UTC (rev 3792)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java 2011-01-12 15:19:34 UTC (rev 3793)
@@ -188,10 +188,6 @@
{
dbCleaner = new HSQLSingleDBCleaner(wsEntry, conn);
}
- else if (dbDialect == DBConstants.DB_DIALECT_MYSQL || dbDialect == DBConstants.DB_DIALECT_MYSQL_UTF8)
- {
- dbCleaner = new MySQLSingleDBCleaner(wsEntry, conn);
- }
else
{
dbCleaner = new SingleDBCleaner(wsEntry, conn);
Deleted: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MySQLSingleDBCleaner.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MySQLSingleDBCleaner.java 2011-01-12 13:54:37 UTC (rev 3792)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MySQLSingleDBCleaner.java 2011-01-12 15:19:34 UTC (rev 3793)
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2003-2010 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see<http://www.gnu.org/licenses/>.
- */
-package org.exoplatform.services.jcr.impl.util.jdbc.cleaner;
-
-import org.exoplatform.services.jcr.config.WorkspaceEntry;
-
-import java.sql.Connection;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
- * @version $Id: MySQLSingleDBCleaner.java 3655 2010-12-10 08:25:41Z tolusha $
- */
-public class MySQLSingleDBCleaner extends SingleDBCleaner
-{
-
- /**
- * MySQLSingleDBCleaner constructor.
- */
- public MySQLSingleDBCleaner(WorkspaceEntry wsEntry, Connection connection)
- {
- super(wsEntry, connection, true);
- }
-
- /**
- * {@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;
- }
-}
13 years, 5 months
exo-jcr SVN: r3792 - 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: 2011-01-12 08:54:37 -0500 (Wed, 12 Jan 2011)
New Revision: 3792
Removed:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MySQLSingleDBCleaner.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java
Log:
EXOJCR-1150: DB clean on MySQL should not use iterating over all db
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java 2011-01-12 13:42:15 UTC (rev 3791)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/DBCleanerService.java 2011-01-12 13:54:37 UTC (rev 3792)
@@ -207,10 +207,6 @@
{
dbCleaner = new HSQLSingleDBCleaner(wsEntry, conn);
}
- else if (dbDialect == DBConstants.DB_DIALECT_MYSQL || dbDialect == DBConstants.DB_DIALECT_MYSQL_UTF8)
- {
- dbCleaner = new MySQLSingleDBCleaner(wsEntry, conn);
- }
else
{
dbCleaner = new SingleDBCleaner(wsEntry, conn);
Deleted: 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 2011-01-12 13:42:15 UTC (rev 3791)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/cleaner/MySQLSingleDBCleaner.java 2011-01-12 13:54:37 UTC (rev 3792)
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2003-2010 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see<http://www.gnu.org/licenses/>.
- */
-package org.exoplatform.services.jcr.impl.util.jdbc.cleaner;
-
-import org.exoplatform.services.jcr.config.WorkspaceEntry;
-
-import java.sql.Connection;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
- * @version $Id$
- */
-public class MySQLSingleDBCleaner extends SingleDBCleaner
-{
-
- /**
- * MySQLSingleDBCleaner constructor.
- */
- public MySQLSingleDBCleaner(WorkspaceEntry wsEntry, Connection connection)
- {
- super(wsEntry, connection, true);
- }
-
- /**
- * {@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;
- }
-}
13 years, 5 months
exo-jcr SVN: r3791 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc: backup/util and 1 other directory.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-01-12 08:42:15 -0500 (Wed, 12 Jan 2011)
New Revision: 3791
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/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
Log:
EXOJCR-1096: Test on all supported database: sybase
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-12 09:41:40 UTC (rev 3790)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2011-01-12 13:42:15 UTC (rev 3791)
@@ -65,6 +65,7 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
+import java.sql.Types;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
@@ -1112,6 +1113,8 @@
{
// CONTAINER_NAME column index
restoreTableRule.setNewColumnIndex(4);
+ restoreTableRule.setNewColumnName("CONTAINER_NAME");
+ restoreTableRule.setNewColumnType(Types.VARCHAR);
// ID and PARENT_ID column indexes
Set<Integer> convertColumnIndex = new HashSet<Integer>();
Modified: 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/BackupTables.java 2011-01-12 09:41:40 UTC (rev 3790)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/BackupTables.java 2011-01-12 13:42:15 UTC (rev 3791)
@@ -99,6 +99,11 @@
public static final int DB_DIALECT_PGSQL = DBConstants.DB_DIALECT_PGSQL.hashCode();
/**
+ * SYBASE dialect.
+ */
+ public static final int DB_DIALECT_SYBASE = DBConstants.DB_DIALECT_SYBASE.hashCode();
+
+ /**
* {@inheritDoc}
*/
public static void backup(File storageDir, String dsName, Map<String, String> scripts) throws BackupException
@@ -219,9 +224,9 @@
for (int i = 0; i < columnCount; i++)
{
InputStream value;
- if (dialect == DB_DIALECT_HSQLDB)
+ if (dialect == DB_DIALECT_HSQLDB || dialect == DB_DIALECT_SYBASE)
{
- if (columnType[i] == Types.VARBINARY)
+ if (columnType[i] == Types.VARBINARY || columnType[i] == Types.LONGVARBINARY)
{
value = rs.getBinaryStream(i + 1);
}
Modified: 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 2011-01-12 09:41:40 UTC (rev 3790)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTableRule.java 2011-01-12 13:42:15 UTC (rev 3791)
@@ -38,15 +38,19 @@
private Integer newColumnIndex = null;
+ private String newColumnName = null;
+
+ private Integer newColumnType = null;
+
private Set<Integer> convertColumnIndex = new HashSet<Integer>();
- private String srcContainerName;
+ private String srcContainerName = null;
- private String dstContainerName;
+ private String dstContainerName = null;
- private Boolean srcMultiDb;
+ private Boolean srcMultiDb = null;
- private Boolean dstMultiDb;
+ private Boolean dstMultiDb = null;
public File getContentFile()
{
@@ -147,4 +151,25 @@
{
this.dstMultiDb = dstMultiDb;
}
+
+ public String getNewColumnName()
+ {
+ return newColumnName;
+ }
+
+ public void setNewColumnName(String newColumnName)
+ {
+ this.newColumnName = newColumnName;
+ }
+
+ public Integer getNewColumnType()
+ {
+ return newColumnType;
+ }
+
+ public void setNewColumnType(Integer newColumnType)
+ {
+ this.newColumnType = newColumnType;
+ }
+
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTables.java
===================================================================
--- 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)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTables.java 2011-01-12 13:42:15 UTC (rev 3791)
@@ -101,6 +101,7 @@
throws RestoreException
{
Connection jdbcConn = null;
+ Connection jdbcConn1 = null;
Statement st = null;
RestoreException exc = null;
@@ -132,7 +133,8 @@
String constraint = null;
if (tableName.equals("JCR_SITEM") || tableName.equals("JCR_MITEM"))
{
- if (dialect != BackupTables.DB_DIALECT_MYSQL && dialect != BackupTables.DB_DIALECT_MYSQL_UTF8)
+ if (dialect != BackupTables.DB_DIALECT_MYSQL && dialect != BackupTables.DB_DIALECT_MYSQL_UTF8
+ && dialect != BackupTables.DB_DIALECT_SYBASE)
{
// resolve constraint name depends on database
String constraintName;
@@ -246,7 +248,8 @@
/**
* Restore table.
*/
- private void restore(File storageDir, Connection jdbcConn, String tableName, RestoreTableRule restoreRule)
+ private void restore(File storageDir, Connection jdbcConn, String tableName,
+ RestoreTableRule restoreRule)
throws IOException, SQLException
{
// Need privileges
@@ -291,17 +294,6 @@
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)
{
@@ -310,7 +302,13 @@
else if (restoreRule.getNewColumnIndex() != null)
{
targetColumnCount++;
- columnType.add(restoreRule.getNewColumnIndex(), newColumnType.get(restoreRule.getNewColumnIndex()));
+
+ columnType.add(restoreRule.getNewColumnIndex(), restoreRule.getNewColumnType());
+
+ String newColumnName =
+ dialect == BackupTables.DB_DIALECT_PGSQL ? restoreRule.getNewColumnName().toLowerCase() : restoreRule
+ .getNewColumnName();
+ columnName.add(restoreRule.getNewColumnIndex(), newColumnName);
}
// construct statement
@@ -322,7 +320,7 @@
{
continue;
}
- names += newColumnName.get(i) + (i == targetColumnCount - 1 ? "" : ",");
+ names += columnName.get(i) + (i == targetColumnCount - 1 ? "" : ",");
parameters += "?" + (i == targetColumnCount - 1 ? "" : ",");
}
insertNode =
@@ -467,9 +465,9 @@
}
else
{
- if (dialect == BackupTables.DB_DIALECT_HSQLDB)
+ if (dialect == BackupTables.DB_DIALECT_HSQLDB || dialect == BackupTables.DB_DIALECT_SYBASE)
{
- if (columnType.get(i) == Types.VARBINARY)
+ if (columnType.get(i) == Types.VARBINARY || columnType.get(i) == Types.LONGVARBINARY)
{
insertNode.setBinaryStream(targetIndex + 1, stream, (int)len);
}
@@ -492,11 +490,10 @@
insertNode.setNull(targetIndex + 1, columnType.get(i));
}
}
- // insertNode.addBatch();
- insertNode.executeUpdate();
+ insertNode.addBatch();
}
- // insertNode.executeBatch();
+ insertNode.executeBatch();
}
finally
{
13 years, 5 months
exo-jcr SVN: r3790 - in jcr/trunk: exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan and 5 other directories.
by do-not-reply@jboss.org
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())
13 years, 5 months
exo-jcr SVN: r3789 - in jcr/trunk: exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/security and 12 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-01-11 07:13:15 -0500 (Tue, 11 Jan 2011)
New Revision: 3789
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/BackupException.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/Backupable.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/DumpTable.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/RestoreException.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/RestoreTable.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/ResumeException.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/SuspendException.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/Suspendable.java
Removed:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoReader.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoWriter.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/WorkspaceContainerFacade.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/security/JCRRuntimePermissions.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cacheable/AbstractCacheableLockManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNCacheableLockManagerImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/WorkspacePersistentDataManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRDBMSBackupManager.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsFullBackupJob.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/TesterRdbmsWorkspaceInitializer.java
jcr/trunk/exo.jcr.component.ext/src/test/resources/test.policy
Log:
EXOJCR-1130: Implement approach using the marker Backupable
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/WorkspaceContainerFacade.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/WorkspaceContainerFacade.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/WorkspaceContainerFacade.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -20,6 +20,8 @@
import org.exoplatform.services.jcr.impl.WorkspaceContainer;
+import java.util.List;
+
/**
* Created by The eXo Platform SAS .<br/> An entry point to the implementation, used for extending
* functionality
@@ -54,6 +56,18 @@
}
/**
+ * Returns list of components of specific type.
+ *
+ * @param componentType
+ * component type
+ * @return List<Object>
+ */
+ public List getComponentInstancesOfType(Class componentType)
+ {
+ return container.getComponentInstancesOfType(componentType);
+ }
+
+ /**
* @param key
* - an internal key of internal component
* @return the component
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/security/JCRRuntimePermissions.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/security/JCRRuntimePermissions.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/core/security/JCRRuntimePermissions.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -31,4 +31,5 @@
public static final RuntimePermission MANAGE_REPOSITORY_PERMISSION = new RuntimePermission("manageRepository");
+
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cacheable/AbstractCacheableLockManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cacheable/AbstractCacheableLockManager.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cacheable/AbstractCacheableLockManager.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -104,6 +104,11 @@
protected LockRemover lockRemover;
/**
+ * Workspace configuration;
+ */
+ protected final WorkspaceEntry config;
+
+ /**
* SessionLockManagers that uses this LockManager.
*/
protected Map<String, CacheableSessionLockManager> sessionLockManagers;
@@ -164,6 +169,7 @@
lockTimeOut = DEFAULT_LOCK_TIMEOUT;
}
+ this.config = config;
this.dataManager = dataManager;
this.sessionLockManagers = new ConcurrentHashMap<String, CacheableSessionLockManager>();
this.tm = transactionManager;
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNCacheableLockManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNCacheableLockManagerImpl.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNCacheableLockManagerImpl.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -17,12 +17,16 @@
*/
package org.exoplatform.services.jcr.impl.core.lock.infinispan;
+import org.exoplatform.commons.utils.PrivilegedSystemHelper;
+import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.jmx.annotations.NameTemplate;
import org.exoplatform.management.jmx.annotations.Property;
+import org.exoplatform.services.jcr.config.LockManagerEntry;
import org.exoplatform.services.jcr.config.MappedParametrizedObjectEntry;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.SimpleParameterEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.impl.core.lock.LockRemoverHolder;
import org.exoplatform.services.jcr.impl.core.lock.cacheable.AbstractCacheableLockManager;
@@ -31,6 +35,12 @@
import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.BackupException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Backupable;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.DumpTable;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.RestoreException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.RestoreTable;
import org.exoplatform.services.jcr.infinispan.ISPNCacheFactory;
import org.exoplatform.services.jcr.infinispan.PrivilegedISPNCacheHelper;
import org.exoplatform.services.log.ExoLogger;
@@ -39,6 +49,8 @@
import org.exoplatform.services.transaction.TransactionService;
import org.infinispan.Cache;
+import java.io.File;
+import java.io.IOException;
import java.io.Serializable;
import java.security.AccessController;
import java.security.PrivilegedActionException;
@@ -52,6 +64,8 @@
import javax.jcr.RepositoryException;
import javax.jcr.lock.LockException;
import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
import javax.sql.DataSource;
import javax.transaction.TransactionManager;
@@ -61,7 +75,7 @@
*/
@Managed
@NameTemplate(@Property(key = "service", value = "lockmanager"))
-public class ISPNCacheableLockManagerImpl extends AbstractCacheableLockManager
+public class ISPNCacheableLockManagerImpl extends AbstractCacheableLockManager implements Backupable
{
/**
@@ -394,4 +408,198 @@
}
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void backup(File storageDir) throws BackupException
+ {
+ Connection jdbcConn = null;
+
+ try
+ {
+ List<String> tableNames = new ArrayList<String>();
+ String dsName = null;
+
+ LockManagerEntry lockManagerEntry = config.getLockManager();
+ if (lockManagerEntry != null)
+ {
+ for (SimpleParameterEntry entry : lockManagerEntry.getParameters())
+ {
+ if (entry.getName().equals(INFINISPAN_JDBC_TABLE_NAME))
+ {
+ tableNames.add(entry.getValue());
+ }
+ else if (entry.getName().equals(INFINISPAN_JDBC_CL_DATASOURCE))
+ {
+ dsName = entry.getValue();
+ }
+ }
+ }
+
+ final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
+ if (ds == null)
+ {
+ throw new NameNotFoundException("Data source " + dsName + " not found");
+ }
+
+ jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return ds.getConnection();
+
+ }
+ });
+
+ for (String table : tableNames)
+ {
+ DumpTable.dump(jdbcConn, table, "SELECT * FROM " + table, storageDir);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new BackupException(e);
+ }
+ catch (SQLException e)
+ {
+ SQLException next = e.getNextException();
+ String errorTrace = "";
+ while (next != null)
+ {
+ errorTrace += next.getMessage() + "; ";
+ next = next.getNextException();
+ }
+
+ Throwable cause = e.getCause();
+ String msg = "SQL Exception: " + errorTrace + (cause != null ? " (Cause: " + cause.getMessage() + ")" : "");
+
+ throw new BackupException(msg, e);
+ }
+ catch (NamingException e)
+ {
+ throw new BackupException(e);
+ }
+ finally
+ {
+ if (jdbcConn != null)
+ {
+ try
+ {
+ jdbcConn.close();
+ }
+ catch (SQLException e)
+ {
+ throw new BackupException(e);
+ }
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void restore(File storageDir) throws RestoreException
+ {
+ Connection jdbcConn = null;
+
+ try
+ {
+ List<String> tableNames = new ArrayList<String>();
+ String dsName = null;
+
+ LockManagerEntry lockManagerEntry = config.getLockManager();
+ if (lockManagerEntry != null)
+ {
+ for (SimpleParameterEntry entry : lockManagerEntry.getParameters())
+ {
+ if (entry.getName().equals(INFINISPAN_JDBC_TABLE_NAME))
+ {
+ tableNames.add(entry.getValue());
+ }
+ else if (entry.getName().equals(INFINISPAN_JDBC_CL_DATASOURCE))
+ {
+ dsName = entry.getValue();
+ }
+ }
+ }
+
+ final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
+ if (ds == null)
+ {
+ throw new NameNotFoundException("Data source " + dsName + " not found");
+ }
+
+ jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return ds.getConnection();
+
+ }
+ });
+ jdbcConn.setAutoCommit(false);
+
+ int maxBufferSize =
+ config.getContainer().getParameterInteger(JDBCWorkspaceDataContainer.MAXBUFFERSIZE_PROP,
+ JDBCWorkspaceDataContainer.DEF_MAXBUFFERSIZE);
+ File tempDir = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
+
+ RestoreTable restoreTable = new RestoreTable(null, tempDir, maxBufferSize);
+ restoreTable.setSrcContainerName(null);
+ restoreTable.setSrcMultiDb(null);
+ restoreTable.setDstContainerName(null);
+ restoreTable.setDstMultiDb(null);
+ restoreTable.setSkipColumnIndex(null);
+ restoreTable.setDeleteColumnIndex(null);
+ restoreTable.setNewColumnIndex(null);
+ restoreTable.setConvertColumnIndex(null);
+
+ for (String table : tableNames)
+ {
+ restoreTable.setContentFile(new File(storageDir, table + DumpTable.CONTENT_FILE_SUFFIX));
+ restoreTable.setContentLenFile(new File(storageDir, table + DumpTable.CONTENT_LEN_FILE_SUFFIX));
+
+ restoreTable.restore(jdbcConn, table, storageDir);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RestoreException(e);
+ }
+ catch (SQLException e)
+ {
+ SQLException next = e.getNextException();
+ String errorTrace = "";
+ while (next != null)
+ {
+ errorTrace += next.getMessage() + "; ";
+ next = next.getNextException();
+ }
+
+ Throwable cause = e.getCause();
+ String msg = "SQL Exception: " + errorTrace + (cause != null ? " (Cause: " + cause.getMessage() + ")" : "");
+
+ throw new RestoreException(msg, e);
+ }
+ catch (NamingException e)
+ {
+ throw new RestoreException(e);
+ }
+ finally
+ {
+ if (jdbcConn != null)
+ {
+ try
+ {
+ jdbcConn.close();
+ }
+ catch (SQLException e)
+ {
+ throw new RestoreException(e);
+ }
+ }
+ }
+ }
+
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -16,12 +16,16 @@
*/
package org.exoplatform.services.jcr.impl.core.lock.jbosscache;
+import org.exoplatform.commons.utils.PrivilegedSystemHelper;
+import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.jmx.annotations.NameTemplate;
import org.exoplatform.management.jmx.annotations.Property;
+import org.exoplatform.services.jcr.config.LockManagerEntry;
import org.exoplatform.services.jcr.config.MappedParametrizedObjectEntry;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.SimpleParameterEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.impl.core.lock.LockRemoverHolder;
import org.exoplatform.services.jcr.impl.core.lock.cacheable.AbstractCacheableLockManager;
@@ -30,9 +34,15 @@
import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.BackupException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Backupable;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.DumpTable;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.RestoreException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.RestoreTable;
import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory;
+import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory.CacheType;
import org.exoplatform.services.jcr.jbosscache.PrivilegedJBossCacheHelper;
-import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory.CacheType;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.naming.InitialContextInitializer;
@@ -47,6 +57,8 @@
import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.lock.TimeoutException;
+import java.io.File;
+import java.io.IOException;
import java.io.Serializable;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -61,6 +73,8 @@
import javax.jcr.RepositoryException;
import javax.jcr.lock.LockException;
import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
import javax.sql.DataSource;
import javax.transaction.TransactionManager;
@@ -74,7 +88,7 @@
*/
@Managed
@NameTemplate(@Property(key = "service", value = "lockmanager"))
-public class CacheableLockManagerImpl extends AbstractCacheableLockManager
+public class CacheableLockManagerImpl extends AbstractCacheableLockManager implements Backupable
{
public static final String JBOSSCACHE_JDBC_CL_DATASOURCE = "jbosscache-cl-cache.jdbc.datasource";
@@ -570,4 +584,199 @@
node.setResident(true);
}
+ /**
+ * {@inheritDoc}
+ */
+ public void backup(File storageDir) throws BackupException
+ {
+ Connection jdbcConn = null;
+
+ try
+ {
+ List<String> tableNames = new ArrayList<String>();
+ String dsName = null;
+
+ LockManagerEntry lockManagerEntry = config.getLockManager();
+ if (lockManagerEntry != null)
+ {
+ for (SimpleParameterEntry entry : lockManagerEntry.getParameters())
+ {
+ if (entry.getName().equals(JBOSSCACHE_JDBC_TABLE_NAME))
+ {
+ tableNames.add(entry.getValue());
+ tableNames.add(entry.getValue() + "_D");
+ }
+ else if (entry.getName().equals(JBOSSCACHE_JDBC_CL_DATASOURCE))
+ {
+ dsName = entry.getValue();
+ }
+ }
+ }
+
+ final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
+ if (ds == null)
+ {
+ throw new NameNotFoundException("Data source " + dsName + " not found");
+ }
+
+ jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return ds.getConnection();
+
+ }
+ });
+
+ for (String table : tableNames)
+ {
+ DumpTable.dump(jdbcConn, table, "SELECT * FROM " + table, storageDir);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new BackupException(e);
+ }
+ catch (SQLException e)
+ {
+ SQLException next = e.getNextException();
+ String errorTrace = "";
+ while (next != null)
+ {
+ errorTrace += next.getMessage() + "; ";
+ next = next.getNextException();
+ }
+
+ Throwable cause = e.getCause();
+ String msg = "SQL Exception: " + errorTrace + (cause != null ? " (Cause: " + cause.getMessage() + ")" : "");
+
+ throw new BackupException(msg, e);
+ }
+ catch (NamingException e)
+ {
+ throw new BackupException(e);
+ }
+ finally
+ {
+ if (jdbcConn != null)
+ {
+ try
+ {
+ jdbcConn.close();
+ }
+ catch (SQLException e)
+ {
+ throw new BackupException(e);
+ }
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void restore(File storageDir) throws RestoreException
+ {
+ Connection jdbcConn = null;
+
+ try
+ {
+ List<String> tableNames = new ArrayList<String>();
+ String dsName = null;
+
+ LockManagerEntry lockManagerEntry = config.getLockManager();
+ if (lockManagerEntry != null)
+ {
+ for (SimpleParameterEntry entry : lockManagerEntry.getParameters())
+ {
+ if (entry.getName().equals(JBOSSCACHE_JDBC_TABLE_NAME))
+ {
+ tableNames.add(entry.getValue());
+ tableNames.add(entry.getValue() + "_D");
+ }
+ else if (entry.getName().equals(JBOSSCACHE_JDBC_CL_DATASOURCE))
+ {
+ dsName = entry.getValue();
+ }
+ }
+ }
+
+ final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
+ if (ds == null)
+ {
+ throw new NameNotFoundException("Data source " + dsName + " not found");
+ }
+
+ jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return ds.getConnection();
+
+ }
+ });
+ jdbcConn.setAutoCommit(false);
+
+ int maxBufferSize =
+ config.getContainer().getParameterInteger(JDBCWorkspaceDataContainer.MAXBUFFERSIZE_PROP,
+ JDBCWorkspaceDataContainer.DEF_MAXBUFFERSIZE);
+ File tempDir = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
+
+ RestoreTable restoreTable = new RestoreTable(null, tempDir, maxBufferSize);
+ restoreTable.setSrcContainerName(null);
+ restoreTable.setSrcMultiDb(null);
+ restoreTable.setDstContainerName(null);
+ restoreTable.setDstMultiDb(null);
+ restoreTable.setSkipColumnIndex(null);
+ restoreTable.setDeleteColumnIndex(null);
+ restoreTable.setNewColumnIndex(null);
+ restoreTable.setConvertColumnIndex(null);
+
+ for (String table : tableNames)
+ {
+ restoreTable.setContentFile(new File(storageDir, table + DumpTable.CONTENT_FILE_SUFFIX));
+ restoreTable.setContentLenFile(new File(storageDir, table + DumpTable.CONTENT_LEN_FILE_SUFFIX));
+
+ restoreTable.restore(jdbcConn, table, storageDir);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RestoreException(e);
+ }
+ catch (SQLException e)
+ {
+ SQLException next = e.getNextException();
+ String errorTrace = "";
+ while (next != null)
+ {
+ errorTrace += next.getMessage() + "; ";
+ next = next.getNextException();
+ }
+
+ Throwable cause = e.getCause();
+ String msg = "SQL Exception: " + errorTrace + (cause != null ? " (Cause: " + cause.getMessage() + ")" : "");
+
+ throw new RestoreException(msg, e);
+ }
+ catch (NamingException e)
+ {
+ throw new RestoreException(e);
+ }
+ finally
+ {
+ if (jdbcConn != null)
+ {
+ try
+ {
+ jdbcConn.close();
+ }
+ catch (SQLException e)
+ {
+ throw new RestoreException(e);
+ }
+ }
+ }
+ }
+
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -18,9 +18,9 @@
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.WildcardQuery;
-import org.apache.lucene.search.BooleanClause.Occur;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.services.document.DocumentReaderService;
import org.exoplatform.services.jcr.config.QueryHandlerEntry;
@@ -52,6 +52,9 @@
import org.exoplatform.services.jcr.impl.core.value.PathValue;
import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.ResumeException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.SuspendException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Suspendable;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.factories.annotations.NonVolatile;
@@ -86,7 +89,7 @@
* @version $Id: SearchManager.java 1008 2009-12-11 15:14:51Z nzamosenchuk $
*/
@NonVolatile
-public class SearchManager implements Startable, MandatoryItemsPersistenceListener
+public class SearchManager implements Startable, MandatoryItemsPersistenceListener, Suspendable
{
/**
@@ -140,7 +143,7 @@
* The unique name of the related workspace
*/
protected final String wsId;
-
+
/**
* Creates a new <code>SearchManager</code>.
*
@@ -854,4 +857,26 @@
return wsId;
}
+ /**
+ * {@inheritDoc}
+ */
+ public void suspend() throws SuspendException
+ {
+ if (handler instanceof Suspendable)
+ {
+ ((Suspendable)handler).suspend();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void resume() throws ResumeException
+ {
+ if (handler instanceof Suspendable)
+ {
+ ((Suspendable)handler).resume();
+ }
+ }
+
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -2576,6 +2576,28 @@
}
/**
+ * Suspends multi index: flush volatile index and stop merger.
+ *
+ * @throws IOException
+ */
+ protected void suspend() throws IOException
+ {
+ flush();
+ merger.dispose();
+ }
+
+ /**
+ * Resume mulit index by starting merger.
+ *
+ * @throws IOException
+ */
+ protected void resume() throws IOException
+ {
+ merger = doInitIndexMerger();
+ merger.start();
+ }
+
+ /**
* Refresh list of indexes. Used to be called asynchronously when list changes. New, actual list is read from
* IndexInfos.
* @throws IOException
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -62,6 +62,9 @@
import org.exoplatform.services.jcr.impl.core.query.SearchIndexConfigurationHelper;
import org.exoplatform.services.jcr.impl.core.query.lucene.directory.DirectoryManager;
import org.exoplatform.services.jcr.impl.core.query.lucene.directory.FSDirectoryManager;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.ResumeException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.SuspendException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Suspendable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
@@ -95,7 +98,7 @@
* Implements a {@link org.apache.jackrabbit.core.query.QueryHandler} using
* Lucene.
*/
-public class SearchIndex extends AbstractQueryHandler implements IndexerIoModeListener
+public class SearchIndex extends AbstractQueryHandler implements IndexerIoModeListener, Suspendable
{
private static final DefaultQueryNodeFactory DEFAULT_QUERY_NODE_FACTORY = new DefaultQueryNodeFactory();
@@ -2806,4 +2809,40 @@
log.error("Can not recover error log.", e);
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void suspend() throws SuspendException
+ {
+ if (modeHandler.getMode() == IndexerIoMode.READ_WRITE)
+ {
+ try
+ {
+ index.suspend();
+ }
+ catch (IOException e)
+ {
+ throw new SuspendException(e);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void resume() throws ResumeException
+ {
+ if (modeHandler.getMode() == IndexerIoMode.READ_WRITE)
+ {
+ try
+ {
+ index.resume();
+ }
+ catch (IOException e)
+ {
+ throw new ResumeException(e);
+ }
+ }
+ }
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/WorkspacePersistentDataManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/WorkspacePersistentDataManager.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/WorkspacePersistentDataManager.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -42,6 +42,9 @@
import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
import org.exoplatform.services.jcr.impl.storage.SystemDataContainerHolder;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.ResumeException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.SuspendException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Suspendable;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
import org.exoplatform.services.log.ExoLogger;
@@ -55,6 +58,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.jcr.InvalidItemStateException;
import javax.jcr.RepositoryException;
@@ -67,7 +71,7 @@
* @author <a href="mailto:gennady.azarenkov@exoplatform.com">Gennady Azarenkov</a>
* @version $Id$
*/
-public abstract class WorkspacePersistentDataManager implements PersistentDataManager
+public abstract class WorkspacePersistentDataManager implements PersistentDataManager, Suspendable
{
/**
@@ -86,10 +90,6 @@
protected final WorkspaceDataContainer systemDataContainer;
/**
- * Value sorages provider (for dest file suggestion on save).
- */
- // TODO protected final ValueStoragePluginProvider valueStorageProvider;
- /**
* Persistent level listeners. This listeners can be filtered by filters from
* <code>liestenerFilters</code> list.
*/
@@ -110,6 +110,8 @@
*/
protected boolean readOnly = false;
+ protected ReentrantReadWriteLock rwl = new ReentrantReadWriteLock(true);
+
/**
* WorkspacePersistentDataManager constructor.
*
@@ -119,12 +121,10 @@
* holder of system workspace data container
*/
public WorkspacePersistentDataManager(WorkspaceDataContainer dataContainer,
- //ValueStoragePluginProvider valueStorageProvider,
SystemDataContainerHolder systemDataContainerHolder)
{
this.dataContainer = dataContainer;
this.systemDataContainer = systemDataContainerHolder.getContainer();
- // this.valueStorageProvider = valueStorageProvider;
this.listeners = new ArrayList<ItemsPersistenceListener>();
this.mandatoryListeners = new ArrayList<MandatoryItemsPersistenceListener>();
@@ -136,6 +136,8 @@
*/
public void save(final ItemStateChangesLog changesLog) throws RepositoryException
{
+ rwl.readLock().lock();
+
// check if this workspace container is not read-only
if (readOnly && !(changesLog instanceof ReadOnlyThroughChanges))
{
@@ -184,6 +186,8 @@
}
notifySaveItems(persistedLog, true);
+
+ rwl.readLock().unlock();
}
class ChangesLogPersister
@@ -838,4 +842,20 @@
this.readOnly = status;
}
+ /**
+ * {@inheritDoc}
+ */
+ public void suspend() throws SuspendException
+ {
+ rwl.writeLock().lock();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void resume() throws ResumeException
+ {
+ rwl.writeLock().unlock();
+ }
+
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -24,7 +24,17 @@
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.RepositoryEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.dataflow.serialization.ObjectReader;
+import org.exoplatform.services.jcr.dataflow.serialization.ObjectWriter;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectReaderImpl;
+import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectWriterImpl;
import org.exoplatform.services.jcr.impl.storage.WorkspaceDataContainerBase;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.BackupException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Backupable;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.DumpTable;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.RestoreException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.RestoreTable;
import org.exoplatform.services.jcr.impl.storage.jdbc.db.GenericConnectionFactory;
import org.exoplatform.services.jcr.impl.storage.jdbc.db.HSQLDBConnectionFactory;
import org.exoplatform.services.jcr.impl.storage.jdbc.db.MySQLConnectionFactory;
@@ -48,14 +58,19 @@
import org.picocontainer.Startable;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashSet;
+import java.util.Set;
import javax.jcr.RepositoryException;
import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import javax.sql.DataSource;
@@ -65,7 +80,7 @@
* @author <a href="mailto:peter.nedonosko@exoplatform.com.ua">Peter Nedonosko</a>
* @version $Id:GenericWorkspaceDataContainer.java 13433 2007-03-15 16:07:23Z peterit $
*/
-public class JDBCWorkspaceDataContainer extends WorkspaceDataContainerBase implements Startable
+public class JDBCWorkspaceDataContainer extends WorkspaceDataContainerBase implements Startable, Backupable
{
protected static final Log LOG = ExoLogger.getLogger("exo.jcr.component.core.JDBCWorkspaceDataContainer");
@@ -983,4 +998,365 @@
return checkSNSNewConnection;
}
+ /**
+ * {@inheritDoc}
+ */
+ public void backup(File storageDir) throws BackupException
+ {
+ ObjectWriter backupInfo = null;
+ Connection jdbcConn = null;
+
+ try
+ {
+ backupInfo =
+ new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(new File(storageDir,
+ "JDBCWorkspaceDataContainer.info")));
+
+ backupInfo.writeString(containerName);
+ backupInfo.writeBoolean(multiDb);
+
+ final DataSource ds = (DataSource)new InitialContext().lookup(dbSourceName);
+ if (ds == null)
+ {
+ throw new NameNotFoundException("Data source " + dbSourceName + " not found");
+ }
+
+ jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return ds.getConnection();
+
+ }
+ });
+
+ String[][] scripts;
+ if (multiDb)
+ {
+ scripts =
+ new String[][]{
+ {"JCR_MITEM", "select * from JCR_MITEM where JCR_MITEM.name <> '" + Constants.ROOT_PARENT_NAME + "'"},
+ {"JCR_MVALUE", "select * from JCR_MVALUE"}, {"JCR_MREF", "select * from JCR_MREF"}};
+ }
+ else
+ {
+ scripts =
+ new String[][]{
+ {"JCR_SITEM", "select * from JCR_SITEM where CONTAINER_NAME='" + containerName + "'"},
+ {
+ "JCR_SVALUE",
+ "select * from JCR_SVALUE where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SVALUE.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME='"
+ + containerName + "')"},
+ {
+ "JCR_SREF",
+ "select * from JCR_SREF where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SREF.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME='"
+ + containerName + "')"}};
+ }
+
+ for (String script[] : scripts)
+ {
+ DumpTable.dump(jdbcConn, script[0], script[1], storageDir);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new BackupException(e);
+ }
+ catch (SQLException e)
+ {
+ SQLException next = e.getNextException();
+ String errorTrace = "";
+ while (next != null)
+ {
+ errorTrace += next.getMessage() + "; ";
+ next = next.getNextException();
+ }
+
+ Throwable cause = e.getCause();
+ String msg = "SQL Exception: " + errorTrace + (cause != null ? " (Cause: " + cause.getMessage() + ")" : "");
+
+ throw new BackupException(msg, e);
+ }
+ catch (NamingException e)
+ {
+ throw new BackupException(e);
+ }
+ finally
+ {
+ if (backupInfo != null)
+ {
+ try
+ {
+ backupInfo.close();
+ }
+ catch (IOException e)
+ {
+ throw new BackupException(e);
+ }
+ }
+
+ if (jdbcConn != null)
+ {
+ try
+ {
+ jdbcConn.close();
+ }
+ catch (SQLException e)
+ {
+ throw new BackupException(e);
+ }
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void restore(File storageDir) throws RestoreException
+ {
+ ObjectReader backupInfo = null;
+ Statement st = null;
+ Connection jdbcConn = null;
+
+ try
+ {
+ final DataSource ds = (DataSource)new InitialContext().lookup(dbSourceName);
+ if (ds == null)
+ {
+ throw new NameNotFoundException("Data source " + dbSourceName + " not found");
+ }
+
+ jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return ds.getConnection();
+
+ }
+ });
+ jdbcConn.setAutoCommit(false);
+
+ int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
+
+ backupInfo =
+ new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(new File(storageDir,
+ "JDBCWorkspaceDataContainer.info")));
+
+ String srcContainerName = backupInfo.readString();
+ boolean srcMultiDb = backupInfo.readBoolean();
+
+ String[] tablesSuffix = new String[]{"ITEM", "VALUE", "REF"};
+
+ File tempDir = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
+ RestoreTable restoreTable = new RestoreTable(swapCleaner, tempDir, maxBufferSize);
+
+ restoreTable.setSrcContainerName(srcContainerName);
+ restoreTable.setSrcMultiDb(srcMultiDb);
+ restoreTable.setDstContainerName(containerName);
+ restoreTable.setDstMultiDb(multiDb);
+
+ for (String tableSuffix : tablesSuffix)
+ {
+ String dstTableName = "JCR_" + (multiDb ? "M" : "S") + tableSuffix;
+ String srcTableName = "JCR_" + (srcMultiDb ? "M" : "S") + tableSuffix;
+
+ restoreTable.setContentFile(new File(storageDir, srcTableName + DumpTable.CONTENT_FILE_SUFFIX));
+ restoreTable.setContentLenFile(new File(storageDir, srcTableName + DumpTable.CONTENT_LEN_FILE_SUFFIX));
+
+ String constraint = null;
+ if (tableSuffix.equals("ITEM"))
+ {
+ if (dialect != DumpTable.DB_DIALECT_MYSQL && dialect != DumpTable.DB_DIALECT_MYSQL_UTF8)
+ {
+ // resolve constraint name depends on database
+ String constraintName;
+ if (dialect == DumpTable.DB_DIALECT_DB2 || dialect == DumpTable.DB_DIALECT_DB2V8)
+ {
+ constraintName = "JCR_FK_" + (multiDb ? "M" : "S") + "ITEM_PAREN";
+ }
+ else
+ {
+ constraintName = "JCR_FK_" + (multiDb ? "M" : "S") + "ITEM_PARENT";
+ }
+ constraint =
+ "CONSTRAINT " + constraintName + " FOREIGN KEY(PARENT_ID) REFERENCES " + dstTableName + "(ID)";
+
+ // drop constraint
+ st = jdbcConn.createStatement();
+ st.execute("ALTER TABLE " + dstTableName + " DROP CONSTRAINT " + constraintName);
+ jdbcConn.commit();
+ }
+
+ if (multiDb)
+ {
+ restoreTable.setSkipColumnIndex(null);
+ restoreTable.setNewColumnIndex(null);
+
+ if (!srcMultiDb)
+ {
+ // CONTAINER_NAME column index
+ restoreTable.setDeleteColumnIndex(4);
+
+ // ID and PARENT_ID column indexes
+ Set<Integer> convertColumnIndex = new HashSet<Integer>();
+ convertColumnIndex.add(0);
+ convertColumnIndex.add(1);
+ restoreTable.setConvertColumnIndex(convertColumnIndex);
+ }
+ else
+ {
+ restoreTable.setDeleteColumnIndex(null);
+ restoreTable.setConvertColumnIndex(null);
+ }
+ }
+ else
+ {
+ if (srcMultiDb)
+ {
+ // CONTAINER_NAME column index
+ restoreTable.setNewColumnIndex(4);
+ restoreTable.setSkipColumnIndex(null);
+ restoreTable.setDeleteColumnIndex(null);
+
+ // ID and PARENT_ID column indexes
+ Set<Integer> convertColumnIndex = new HashSet<Integer>();
+ convertColumnIndex.add(0);
+ convertColumnIndex.add(1);
+ restoreTable.setConvertColumnIndex(convertColumnIndex);
+ }
+ else
+ {
+ restoreTable.setNewColumnIndex(null);
+ restoreTable.setSkipColumnIndex(null);
+ restoreTable.setDeleteColumnIndex(null);
+
+ // ID and PARENT_ID and CONTAINER_NAME column indexes
+ Set<Integer> convertColumnIndex = new HashSet<Integer>();
+ convertColumnIndex.add(0);
+ convertColumnIndex.add(1);
+ convertColumnIndex.add(4);
+ restoreTable.setConvertColumnIndex(convertColumnIndex);
+ }
+ }
+ }
+ else if (tableSuffix.equals("VALUE"))
+ {
+ // auto increment ID column
+ restoreTable.setSkipColumnIndex(0);
+ restoreTable.setDeleteColumnIndex(null);
+ restoreTable.setNewColumnIndex(null);
+
+ if (!multiDb || !srcMultiDb)
+ {
+ // PROPERTY_ID column index
+ Set<Integer> convertColumnIndex = new HashSet<Integer>();
+ convertColumnIndex.add(3);
+ restoreTable.setConvertColumnIndex(convertColumnIndex);
+ }
+ else
+ {
+ restoreTable.setConvertColumnIndex(null);
+ }
+ }
+ else
+ {
+ restoreTable.setSkipColumnIndex(null);
+ restoreTable.setDeleteColumnIndex(null);
+ restoreTable.setNewColumnIndex(null);
+
+ if (!multiDb || !srcMultiDb)
+ {
+ // NODE_ID and PROPERTY_ID column indexes
+ Set<Integer> convertColumnIndex = new HashSet<Integer>();
+ convertColumnIndex.add(0);
+ convertColumnIndex.add(1);
+ restoreTable.setConvertColumnIndex(convertColumnIndex);
+ }
+ else
+ {
+ restoreTable.setConvertColumnIndex(null);
+ }
+ }
+
+ restoreTable.restore(jdbcConn, dstTableName, storageDir);
+
+ if (tableSuffix.equals("ITEM"))
+ {
+ if (constraint != null)
+ {
+ // add constraint
+ st = jdbcConn.createStatement();
+ st.execute("ALTER TABLE " + dstTableName + " ADD " + constraint);
+ jdbcConn.commit();
+ }
+ }
+ }
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new RestoreException(e);
+ }
+ catch (IOException e)
+ {
+ throw new RestoreException(e);
+ }
+ catch (SQLException e)
+ {
+ SQLException next = e.getNextException();
+ String errorTrace = "";
+ while (next != null)
+ {
+ errorTrace += next.getMessage() + "; ";
+ next = next.getNextException();
+ }
+
+ Throwable cause = e.getCause();
+ String msg = "SQL Exception: " + errorTrace + (cause != null ? " (Cause: " + cause.getMessage() + ")" : "");
+
+ throw new RestoreException(msg, e);
+ }
+ catch (NamingException e)
+ {
+ throw new RestoreException(e);
+ }
+ finally
+ {
+ if (backupInfo != null)
+ {
+ try
+ {
+ backupInfo.close();
+ }
+ catch (IOException e)
+ {
+ throw new RestoreException(e);
+ }
+ }
+
+ if (st != null)
+ {
+ try
+ {
+ st.close();
+ }
+ catch (SQLException e)
+ {
+ throw new RestoreException(e);
+ }
+ }
+
+ if (jdbcConn != null)
+ {
+ try
+ {
+ jdbcConn.close();
+ }
+ catch (SQLException e)
+ {
+ throw new RestoreException(e);
+ }
+ }
+ }
+ }
+
}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/BackupException.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/BackupException.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/BackupException.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jdbc.backup;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
+ * @version $Id: BackupException 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class BackupException extends Exception
+{
+ /**
+ * Constructor BackupException.
+ *
+ * @param message
+ * the message
+ */
+ public BackupException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Constructor BackupException.
+ *
+ * @param cause
+ * the cause
+ */
+ public BackupException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * Constructor BackupException.
+ *
+ * @param message
+ * the message
+ * @param cause
+ * the cause
+ */
+ public BackupException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/Backupable.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/Backupable.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/Backupable.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jdbc.backup;
+
+import java.io.File;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
+ * @version $Id: Backupable.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public interface Backupable
+{
+ /**
+ * Runtime permission for backup and restore operations.
+ */
+ public static final RuntimePermission BACKUP_RESTORE_PERMISSION = new RuntimePermission("backupRestoreOperations");
+
+ /**
+ * Backup data.
+ *
+ * @param storageDir
+ * the directory to store backup
+ * @throws BackupException
+ * if any exception occurred
+ */
+ void backup(File storageDir) throws BackupException;
+
+ /**
+ * Restore data.
+ *
+ * @param storageDir
+ * the directory where backup is stored
+ * @throws RestoreException
+ * if any exception occurred
+ */
+ void restore(File storageDir) throws RestoreException;
+
+}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/DumpTable.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/DumpTable.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/DumpTable.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jdbc.backup;
+
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectZipWriterImpl;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.zip.ZipEntry;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
+ * @version $Id: DumpTable.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class DumpTable
+{
+ /**
+ * Suffix for content file.
+ */
+ public static final String CONTENT_FILE_SUFFIX = ".dump";
+
+ /**
+ * Suffix for content length file.
+ */
+ public static final String CONTENT_LEN_FILE_SUFFIX = ".len";
+
+ /**
+ * Generic dialect.
+ */
+ public static final int DB_DIALECT_GENERIC = DBConstants.DB_DIALECT_GENERIC.hashCode();
+
+ /**
+ * HSQLDB dialect.
+ */
+ public static final int DB_DIALECT_HSQLDB = DBConstants.DB_DIALECT_HSQLDB.hashCode();
+
+ /**
+ * MySQL dialect.
+ */
+ public static final int DB_DIALECT_MYSQL = DBConstants.DB_DIALECT_MYSQL.hashCode();
+
+ /**
+ * MySQL-UTF8 dialect.
+ */
+ public static final int DB_DIALECT_MYSQL_UTF8 = DBConstants.DB_DIALECT_MYSQL_UTF8.hashCode();
+
+ /**
+ * DB2 dialect.
+ */
+ public static final int DB_DIALECT_DB2 = DBConstants.DB_DIALECT_DB2.hashCode();
+
+ /**
+ * DB2V8 dialect.
+ */
+ public static final int DB_DIALECT_DB2V8 = DBConstants.DB_DIALECT_DB2V8.hashCode();
+
+ /**
+ * PGSQL dialect.
+ */
+ public static final int DB_DIALECT_PGSQL = DBConstants.DB_DIALECT_PGSQL.hashCode();
+
+ /**
+ * Dump table.
+ *
+ * @throws IOException
+ * @throws SQLException
+ */
+ public static void dump(Connection jdbcConn, String tableName, String script, File storageDir)
+ throws IOException, SQLException
+ {
+ // Need privileges
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ {
+ security.checkPermission(Backupable.BACKUP_RESTORE_PERMISSION);
+ }
+
+ int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
+
+ ObjectZipWriterImpl contentWriter = null;
+ ObjectZipWriterImpl contentLenWriter = null;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try
+ {
+ File contentFile = new File(storageDir, tableName + CONTENT_FILE_SUFFIX);
+ contentWriter = new ObjectZipWriterImpl(PrivilegedFileHelper.zipOutputStream(contentFile));
+ contentWriter.putNextEntry(new ZipEntry(tableName));
+
+ File contentLenFile = new File(storageDir, tableName + CONTENT_LEN_FILE_SUFFIX);
+ contentLenWriter = new ObjectZipWriterImpl(PrivilegedFileHelper.zipOutputStream(contentLenFile));
+ contentLenWriter.putNextEntry(new ZipEntry(tableName));
+
+ stmt = jdbcConn.prepareStatement(script);
+ rs = stmt.executeQuery();
+ ResultSetMetaData metaData = rs.getMetaData();
+
+ int columnCount = metaData.getColumnCount();
+ int[] columnType = new int[columnCount];
+
+ contentWriter.writeInt(columnCount);
+ for (int i = 0; i < columnCount; i++)
+ {
+ columnType[i] = metaData.getColumnType(i + 1);
+ contentWriter.writeInt(columnType[i]);
+ contentWriter.writeString(metaData.getColumnName(i + 1));
+ }
+
+ // Now we can output the actual data
+ while (rs.next())
+ {
+ for (int i = 0; i < columnCount; i++)
+ {
+ InputStream value;
+ if (dialect == DB_DIALECT_HSQLDB)
+ {
+ if (columnType[i] == Types.VARBINARY)
+ {
+ value = rs.getBinaryStream(i + 1);
+ }
+ else
+ {
+ String str = rs.getString(i + 1);
+ value = str == null ? null : new ByteArrayInputStream(str.getBytes(Constants.DEFAULT_ENCODING));
+ }
+ }
+ else
+ {
+ value = rs.getBinaryStream(i + 1);
+ }
+
+ if (value == null)
+ {
+ contentLenWriter.writeLong(-1);
+ }
+ else
+ {
+ long len = 0;
+ int read = 0;
+ byte[] tmpBuff = new byte[2048];
+
+ while ((read = value.read(tmpBuff)) >= 0)
+ {
+ contentWriter.write(tmpBuff, 0, read);
+ len += read;
+ }
+ contentLenWriter.writeLong(len);
+ }
+ }
+ }
+ }
+ finally
+ {
+ if (contentWriter != null)
+ {
+ contentWriter.closeEntry();
+ contentWriter.close();
+ }
+
+ if (contentLenWriter != null)
+ {
+ contentLenWriter.closeEntry();
+ contentLenWriter.close();
+ }
+
+ if (rs != null)
+ {
+ rs.close();
+ }
+
+ if (stmt != null)
+ {
+ stmt.close();
+ }
+ }
+ }
+
+}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/RestoreException.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/RestoreException.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/RestoreException.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jdbc.backup;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
+ * @version $Id: RestoreException.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class RestoreException extends Exception
+{
+ /**
+ * Constructor RestoreException.
+ *
+ * @param message
+ * the message
+ */
+ public RestoreException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Constructor RestoreException.
+ *
+ * @param cause
+ * the cause
+ */
+ public RestoreException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * Constructor RestoreException.
+ *
+ * @param message
+ * the message
+ * @param cause
+ * the cause
+ */
+ public RestoreException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/RestoreTable.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/RestoreTable.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/RestoreTable.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -0,0 +1,501 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jdbc.backup;
+
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
+import org.exoplatform.services.jcr.dataflow.serialization.ObjectReader;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectZipReaderImpl;
+import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+
+import java.io.ByteArrayInputStream;
+import java.io.EOFException;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
+ * @version $Id: DumpTable.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class RestoreTable
+{
+ /**
+ * List of temporary files.
+ */
+ private final List<File> spoolFileList = new ArrayList<File>();
+
+ /**
+ * The file cleaner.
+ */
+ private final FileCleaner fileCleaner;
+
+ /**
+ * Temporary directory.
+ */
+ private final File tempDir;
+
+ /**
+ * Maximum buffer size.
+ */
+ private final int maxBufferSize;
+
+ private File contentFile;
+
+ private File contentLenFile;
+
+ private Integer deleteColumnIndex = null;
+
+ private Integer skipColumnIndex = null;
+
+ private Integer newColumnIndex = null;
+
+ private Set<Integer> convertColumnIndex = new HashSet<Integer>();
+
+ private String srcContainerName;
+
+ private String dstContainerName;
+
+ private Boolean srcMultiDb;
+
+ private Boolean dstMultiDb;
+
+ /**
+ * Constructor RestoreTable.
+ */
+ public RestoreTable(FileCleaner fileCleaner, File tempDir, int maxBufferSize)
+ {
+ this.fileCleaner = fileCleaner;
+ this.tempDir = tempDir;
+ this.maxBufferSize = maxBufferSize;
+ }
+
+ /**
+ * Restore table.
+ */
+ public void restore(Connection jdbcConn, String tableName, File storageDir) throws IOException, SQLException
+ {
+ // Need privileges
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ {
+ security.checkPermission(Backupable.BACKUP_RESTORE_PERMISSION);
+ }
+
+ ObjectZipReaderImpl contentReader = null;
+ ObjectZipReaderImpl contentLenReader = null;
+
+ PreparedStatement insertNode = null;
+ ResultSet tableMetaData = null;
+
+ int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
+
+ try
+ {
+ contentReader = new ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(contentFile));
+ contentReader.getNextEntry();
+
+ contentLenReader = new ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(contentLenFile));
+ contentLenReader.getNextEntry();
+
+ // get information about source table
+ int sourceColumnCount = contentReader.readInt();
+
+ List<Integer> columnType = new ArrayList<Integer>();
+ List<String> columnName = new ArrayList<String>();
+
+ for (int i = 0; i < sourceColumnCount; i++)
+ {
+ columnType.add(contentReader.readInt());
+ columnName.add(contentReader.readString());
+ }
+
+ // collect information about target table
+ List<Integer> newColumnType = new ArrayList<Integer>();
+ List<String> newColumnName = new ArrayList<String>();
+
+ tableMetaData = jdbcConn.getMetaData().getColumns(null, null, tableName, "%");
+ while (tableMetaData.next())
+ {
+ newColumnName.add(tableMetaData.getString("COLUMN_NAME"));
+ newColumnType.add(tableMetaData.getInt("DATA_TYPE"));
+ }
+
+ int targetColumnCount = sourceColumnCount;
+ if (deleteColumnIndex != null)
+ {
+ targetColumnCount--;
+ }
+ else if (newColumnIndex != null)
+ {
+ targetColumnCount++;
+ columnType.add(newColumnIndex, newColumnType.get(newColumnIndex));
+ }
+
+ // construct statement
+ String names = "";
+ String parameters = "";
+ for (int i = 0; i < targetColumnCount; i++)
+ {
+ if (skipColumnIndex != null && skipColumnIndex == i)
+ {
+ continue;
+ }
+ names += newColumnName.get(i) + (i == targetColumnCount - 1 ? "" : ",");
+ parameters += "?" + (i == targetColumnCount - 1 ? "" : ",");
+ }
+ insertNode =
+ jdbcConn.prepareStatement("INSERT INTO " + tableName + " (" + names + ") VALUES(" + parameters + ")");
+
+ // set data
+ outer : while (true)
+ {
+ for (int i = 0, targetIndex = 0; i < columnType.size(); i++, targetIndex++)
+ {
+ InputStream stream;
+ long len;
+
+ if (newColumnIndex != null && newColumnIndex == i)
+ {
+ stream = new ByteArrayInputStream(dstContainerName.getBytes(Constants.DEFAULT_ENCODING));
+ len = ((ByteArrayInputStream)stream).available();
+ }
+ else
+ {
+ try
+ {
+ len = contentLenReader.readLong();
+ }
+ catch (EOFException e)
+ {
+ if (i == 0)
+ {
+ // content length file is empty check content file
+ try
+ {
+ contentReader.readByte();
+ }
+ catch (EOFException e1)
+ {
+ break outer;
+ }
+ }
+
+ throw new IOException("Content length file is empty but content still present", e);
+ }
+ stream = len == -1 ? null : spoolInputStream(contentReader, len);
+ }
+
+ if (skipColumnIndex != null && skipColumnIndex == i)
+ {
+ targetIndex--;
+ continue;
+ }
+ else if (deleteColumnIndex != null && deleteColumnIndex == i)
+ {
+ targetIndex--;
+ continue;
+ }
+
+ // set
+ if (stream != null)
+ {
+ if (convertColumnIndex != null && convertColumnIndex.contains(i))
+ {
+ // convert column value
+ ByteArrayInputStream ba = (ByteArrayInputStream)stream;
+ byte[] readBuffer = new byte[ba.available()];
+ ba.read(readBuffer);
+
+ String currentValue = new String(readBuffer, Constants.DEFAULT_ENCODING);
+ if (currentValue.equals(Constants.ROOT_PARENT_UUID))
+ {
+ stream = new ByteArrayInputStream(Constants.ROOT_PARENT_UUID.getBytes());
+ }
+ else
+ {
+ if (dstMultiDb)
+ {
+ if (!srcMultiDb)
+ {
+ stream =
+ new ByteArrayInputStream(new String(readBuffer, Constants.DEFAULT_ENCODING).substring(
+ srcContainerName.length()).getBytes());
+ }
+ }
+ else
+ {
+ if (srcMultiDb)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(dstContainerName);
+ builder.append(currentValue);
+
+ stream = new ByteArrayInputStream(builder.toString().getBytes());
+ }
+ else
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(dstContainerName);
+ builder.append(new String(readBuffer, Constants.DEFAULT_ENCODING)
+ .substring(srcContainerName.length()));
+
+ stream = new ByteArrayInputStream(builder.toString().getBytes());
+ }
+ }
+ }
+
+ len = ((ByteArrayInputStream)stream).available();
+ }
+
+ if (columnType.get(i) == Types.INTEGER || columnType.get(i) == Types.BIGINT
+ || columnType.get(i) == Types.SMALLINT || columnType.get(i) == Types.TINYINT)
+ {
+ ByteArrayInputStream ba = (ByteArrayInputStream)stream;
+ byte[] readBuffer = new byte[ba.available()];
+ ba.read(readBuffer);
+
+ String value = new String(readBuffer, Constants.DEFAULT_ENCODING);
+ insertNode.setLong(targetIndex + 1, Integer.parseInt(value));
+ }
+ else if (columnType.get(i) == Types.BIT)
+ {
+ ByteArrayInputStream ba = (ByteArrayInputStream)stream;
+ byte[] readBuffer = new byte[ba.available()];
+ ba.read(readBuffer);
+
+ String value = new String(readBuffer);
+ if (dialect == DumpTable.DB_DIALECT_PGSQL)
+ {
+ insertNode.setBoolean(targetIndex + 1, value.equals("t"));
+ }
+ else
+ {
+ insertNode.setBoolean(targetIndex + 1, value.equals("1"));
+ }
+ }
+ else if (columnType.get(i) == Types.BOOLEAN)
+ {
+ ByteArrayInputStream ba = (ByteArrayInputStream)stream;
+ byte[] readBuffer = new byte[ba.available()];
+ ba.read(readBuffer);
+
+ String value = new String(readBuffer);
+ insertNode.setBoolean(targetIndex + 1, value.equals("true"));
+ }
+ else
+ {
+ if (dialect == DumpTable.DB_DIALECT_HSQLDB)
+ {
+ if (columnType.get(i) == Types.VARBINARY)
+ {
+ insertNode.setBinaryStream(targetIndex + 1, stream, (int)len);
+ }
+ else
+ {
+ byte[] readBuffer = new byte[(int)len];
+ stream.read(readBuffer);
+
+ insertNode.setString(targetIndex + 1, new String(readBuffer, Constants.DEFAULT_ENCODING));
+ }
+ }
+ else
+ {
+ insertNode.setBinaryStream(targetIndex + 1, stream, (int)len);
+ }
+ }
+ }
+ else
+ {
+ insertNode.setNull(targetIndex + 1, columnType.get(i));
+ }
+ }
+ insertNode.addBatch();
+ }
+
+ insertNode.executeBatch();
+ jdbcConn.commit();
+ }
+ finally
+ {
+ if (contentReader != null)
+ {
+ contentReader.close();
+ }
+
+ if (contentLenReader != null)
+ {
+ contentLenReader.close();
+ }
+
+ if (insertNode != null)
+ {
+ insertNode.close();
+ }
+
+ // delete all temporary files
+ for (File file : spoolFileList)
+ {
+ if (!PrivilegedFileHelper.delete(file))
+ {
+ fileCleaner.addFile(file);
+ }
+ }
+
+ if (tableMetaData != null)
+ {
+ tableMetaData.close();
+ }
+ }
+ }
+
+ /**
+ * Spool input stream.
+ */
+ private InputStream spoolInputStream(ObjectReader in, long contentLen) throws IOException
+ {
+ byte[] buffer = new byte[0];
+ byte[] tmpBuff;
+ long readLen = 0;
+ File sf = null;
+ OutputStream sfout = null;
+
+ try
+ {
+ while (true)
+ {
+ int needToRead = contentLen - readLen > 2048 ? 2048 : (int)(contentLen - readLen);
+ tmpBuff = new byte[needToRead];
+
+ if (needToRead == 0)
+ {
+ break;
+ }
+
+ in.readFully(tmpBuff);
+
+ if (sfout != null)
+ {
+ sfout.write(tmpBuff);
+ }
+ else if (readLen + needToRead > maxBufferSize && fileCleaner != null)
+ {
+ sf = PrivilegedFileHelper.createTempFile("jcrvd", null, tempDir);
+ sfout = PrivilegedFileHelper.fileOutputStream(sf);
+
+ sfout.write(buffer);
+ sfout.write(tmpBuff);
+ buffer = null;
+ }
+ else
+ {
+ // reallocate new buffer and spool old buffer contents
+ byte[] newBuffer = new byte[(int)(readLen + needToRead)];
+ System.arraycopy(buffer, 0, newBuffer, 0, (int)readLen);
+ System.arraycopy(tmpBuff, 0, newBuffer, (int)readLen, needToRead);
+ buffer = newBuffer;
+ }
+
+ readLen += needToRead;
+ }
+
+ if (buffer != null)
+ {
+ return new ByteArrayInputStream(buffer);
+ }
+ else
+ {
+ return PrivilegedFileHelper.fileInputStream(sf);
+ }
+ }
+ finally
+ {
+ if (sfout != null)
+ {
+ sfout.close();
+ }
+
+ if (sf != null)
+ {
+ spoolFileList.add(sf);
+ }
+ }
+ }
+
+ public void setContentFile(File contentFile)
+ {
+ this.contentFile = contentFile;
+ }
+
+ public void setContentLenFile(File contentLenFile)
+ {
+ this.contentLenFile = contentLenFile;
+ }
+
+ public void setDeleteColumnIndex(Integer deleteColumnIndex)
+ {
+ this.deleteColumnIndex = deleteColumnIndex;
+ }
+
+ public void setSkipColumnIndex(Integer skipColumnIndex)
+ {
+ this.skipColumnIndex = skipColumnIndex;
+ }
+
+ public void setNewColumnIndex(Integer newColumnIndex)
+ {
+ this.newColumnIndex = newColumnIndex;
+ }
+
+ public void setConvertColumnIndex(Set<Integer> convertColumnIndex)
+ {
+ this.convertColumnIndex = convertColumnIndex;
+ }
+
+ public void setSrcContainerName(String srcContainerName)
+ {
+ this.srcContainerName = srcContainerName;
+ }
+
+ public void setDstContainerName(String dstContainerName)
+ {
+ this.dstContainerName = dstContainerName;
+ }
+
+ public void setSrcMultiDb(Boolean srcMultiDb)
+ {
+ this.srcMultiDb = srcMultiDb;
+ }
+
+ public void setDstMultiDb(Boolean dstMultiDb)
+ {
+ this.dstMultiDb = dstMultiDb;
+ }
+}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/ResumeException.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/ResumeException.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/ResumeException.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jdbc.backup;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
+ * @version $Id: ResumeException 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class ResumeException extends Exception
+{
+ /**
+ * Constructor ResumeException.
+ *
+ * @param cause
+ * the cause
+ */
+ public ResumeException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * Constructor ResumeException.
+ *
+ * @param message
+ * the message
+ * @param cause
+ * the cause
+ */
+ public ResumeException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/SuspendException.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/SuspendException.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/SuspendException.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jdbc.backup;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
+ * @version $Id: SuspendException.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class SuspendException extends Exception
+{
+ /**
+ * Constructor SuspendException.
+ *
+ * @param cause
+ * the cause
+ */
+ public SuspendException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * Constructor SuspendException.
+ *
+ * @param message
+ * the message
+ * @param cause
+ * the cause
+ */
+ public SuspendException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/Suspendable.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/Suspendable.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/Suspendable.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jdbc.backup;
+
+/**
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
+ * @version $Id: Suspendable.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public interface Suspendable
+{
+
+ /**
+ * Suspend current operations.
+ *
+ * @throws SuspendException of error occurred
+ */
+ void suspend() throws SuspendException;
+
+ /**
+ * Resume operations.
+ *
+ * @throws ResumeException of error occurred
+ */
+ void resume() throws ResumeException;
+
+}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/FullBackupJob.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -19,8 +19,6 @@
package org.exoplatform.services.jcr.ext.backup.impl.rdbms;
import org.exoplatform.commons.utils.PrivilegedFileHelper;
-import org.exoplatform.commons.utils.SecurityHelper;
-import org.exoplatform.services.jcr.config.LockManagerEntry;
import org.exoplatform.services.jcr.config.QueryHandlerParams;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.ValueStorageEntry;
@@ -30,41 +28,26 @@
import org.exoplatform.services.jcr.ext.backup.BackupOperationException;
import org.exoplatform.services.jcr.ext.backup.impl.AbstractFullBackupJob;
import org.exoplatform.services.jcr.ext.backup.impl.FileNameProducer;
-import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.core.lock.cacheable.AbstractCacheableLockManager;
import org.exoplatform.services.jcr.impl.core.query.SystemSearchManager;
-import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectZipWriterImpl;
-import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
-import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
-import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.BackupException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Backupable;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.ResumeException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.SuspendException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Suspendable;
import org.exoplatform.services.jcr.impl.storage.value.fs.FileValueStorage;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import java.security.PrivilegedExceptionAction;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Types;
import java.util.Calendar;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
-import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-import javax.sql.DataSource;
-
/**
* Created by The eXo Platform SARL Author : Alex Reshetnyak alex.reshetnyak(a)exoplatform.com.ua Nov
* 21, 2007
@@ -87,57 +70,11 @@
public static final String VALUE_STORAGE_DIR = "values";
/**
- * Suffix for content file.
- */
- public static final String CONTENT_FILE_SUFFIX = ".dump";
-
- /**
- * Suffix for content length file.
- */
- public static final String CONTENT_LEN_FILE_SUFFIX = ".len";
-
- /**
* Logger.
*/
protected static Log log = ExoLogger.getLogger("exo.jcr.component.ext.FullBackupJob");
/**
- * Generic dialect.
- */
- public static final int DB_DIALECT_GENERIC = DBConstants.DB_DIALECT_GENERIC.hashCode();
-
- /**
- * HSQLDB dialect.
- */
- public static final int DB_DIALECT_HSQLDB = DBConstants.DB_DIALECT_HSQLDB.hashCode();
-
- /**
- * MySQL dialect.
- */
- public static final int DB_DIALECT_MYSQL = DBConstants.DB_DIALECT_MYSQL.hashCode();
-
- /**
- * MySQL-UTF8 dialect.
- */
- public static final int DB_DIALECT_MYSQL_UTF8 = DBConstants.DB_DIALECT_MYSQL_UTF8.hashCode();
-
- /**
- * DB2 dialect.
- */
- public static final int DB_DIALECT_DB2 = DBConstants.DB_DIALECT_DB2.hashCode();
-
- /**
- * DB2V8 dialect.
- */
- public static final int DB_DIALECT_DB2V8 = DBConstants.DB_DIALECT_DB2V8.hashCode();
-
- /**
- * PGSQL dialect.
- */
- public static final int DB_DIALECT_PGSQL = DBConstants.DB_DIALECT_PGSQL.hashCode();
-
-
- /**
* {@inheritDoc}
*/
@Override
@@ -183,8 +120,12 @@
{
notifyListeners();
- Connection jdbcConn = null;
- Statement lockStatemnt = null;
+ List<Backupable> backupableComponents =
+ repository.getWorkspaceContainer(workspaceName).getComponentInstancesOfType(Backupable.class);
+
+ List<Suspendable> suspendableComponents =
+ repository.getWorkspaceContainer(workspaceName).getComponentInstancesOfType(Suspendable.class);
+
try
{
WorkspaceEntry workspaceEntry = null;
@@ -196,158 +137,44 @@
break;
}
}
+
if (workspaceEntry == null)
{
throw new RepositoryConfigurationException("Workpace name " + workspaceName
+ " not found in repository configuration");
}
- String dsName = workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
- if (dsName == null)
+ // suspend all components
+ for (Suspendable component : suspendableComponents)
{
- throw new RepositoryConfigurationException("Data source name not found in workspace configuration "
- + workspaceName);
+ component.suspend();
}
- String multiDb = workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB);
- if (multiDb == null)
+ // backup all components
+ for (Backupable component : backupableComponents)
{
- throw new RepositoryConfigurationException(JDBCWorkspaceDataContainer.MULTIDB
- + " parameter not found in workspace " + workspaceName + " configuration");
+ component.backup(new File(getStorageURL().getFile()));
}
- boolean isMultiDb = Boolean.parseBoolean(multiDb);
- final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
- if (ds == null)
- {
- throw new NameNotFoundException("Data source " + dsName + " not found");
- }
-
- jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
- {
- public Connection run() throws Exception
- {
- return ds.getConnection();
-
- }
- });
-
- RDBMSBackupInfoWriter backupInfoWriter = new RDBMSBackupInfoWriter(getStorageURL().getFile());
-
- backupInfoWriter.setRepositoryName(repository.getConfiguration().getName());
- backupInfoWriter.setWorkspaceName(workspaceName);
- backupInfoWriter.setMultiDb(isMultiDb);
-
- // dump JCR data
- String[][] scripts;
- if (isMultiDb)
- {
- scripts =
- new String[][]{
- {"JCR_MITEM", "select * from JCR_MITEM where JCR_MITEM.name <> '" + Constants.ROOT_PARENT_NAME + "'"},
- {"JCR_MVALUE", "select * from JCR_MVALUE"}, {"JCR_MREF", "select * from JCR_MREF"}};
- }
- else
- {
- scripts =
- new String[][]{
- {"JCR_SITEM", "select * from JCR_SITEM where CONTAINER_NAME='" + workspaceName + "'"},
- {
- "JCR_SVALUE",
- "select * from JCR_SVALUE where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SVALUE.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME='"
- + workspaceName + "')"},
- {
- "JCR_SREF",
- "select * from JCR_SREF where exists(select * from JCR_SITEM where JCR_SITEM.ID=JCR_SREF.PROPERTY_ID and JCR_SITEM.CONTAINER_NAME='"
- + workspaceName + "')"}};
- }
-
- backupInfoWriter.setItemTableName(scripts[0][0]);
- backupInfoWriter.setValueTableName(scripts[1][0]);
- backupInfoWriter.setRefTableName(scripts[2][0]);
-
-
- // TODO set workspace waiting
-
- // Lock tables
- // ResultSet rs = null;
- // try
- // {
- // DatabaseMetaData metaData = jdbcConn.getMetaData();
- //
- // rs = metaData.getTables(null, null, "%", new String[]{"TABLE"});
- // lockStatemnt = jdbcConn.createStatement();
- // int dialect = DialectDetecter.detect(metaData).hashCode();
- //
- // if (dialect == DB_DIALECT_HSQLDB)
- // {
- // while (rs.next())
- // {
- // lockStatemnt.execute("SET TABLE " + rs.getString("TABLE_NAME") + " READONLY TRUE");
- // }
- // }
- // else if (dialect == DB_DIALECT_MYSQL || dialect == DB_DIALECT_MYSQL_UTF8)
- // {
- // String lock = "";
- // while (rs.next())
- // {
- // lock += rs.getString("TABLE_NAME") + " READ,";
- // }
- // lockStatemnt.execute("LOCK TABLES " + lock.substring(0, lock.length() - 1));
- // }
- // }
- // finally
- // {
- // if (rs != null)
- // {
- // rs.close();
- // }
- // }
-
- // dump JCR data
- for (String script[] : scripts)
- {
- dumpTable(jdbcConn, script[0], script[1]);
- }
-
- // dump JCR LOCK data
- LockManagerEntry lockEntry = workspaceEntry.getLockManager();
- if (lockEntry != null)
- {
- List<String> lockTableNames = AbstractCacheableLockManager.getLockTableNames(lockEntry);
- backupInfoWriter.setLockTableNames(lockTableNames);
-
- for (String tableName : lockTableNames)
- {
- dumpTable(jdbcConn, tableName, AbstractCacheableLockManager.getSelectScript(tableName));
- }
- }
-
backupValueStorage(workspaceEntry);
backupIndex(workspaceEntry);
-
- // write backup information
- backupInfoWriter.write();
-
- // TODO set workspace waiting
-
}
catch (RepositoryConfigurationException e)
{
log.error("Full backup failed " + getStorageURL().getPath(), e);
notifyError("Full backup failed", e);
}
- catch (NameNotFoundException e)
+ catch (SuspendException e)
{
log.error("Full backup failed " + getStorageURL().getPath(), e);
notifyError("Full backup failed", e);
}
- catch (NamingException e)
+ catch (BackupException e)
{
log.error("Full backup failed " + getStorageURL().getPath(), e);
notifyError("Full backup failed", e);
}
- catch (SQLException e)
+ catch (BackupOperationException e)
{
log.error("Full backup failed " + getStorageURL().getPath(), e);
notifyError("Full backup failed", e);
@@ -357,57 +184,15 @@
log.error("Full backup failed " + getStorageURL().getPath(), e);
notifyError("Full backup failed", e);
}
- catch (BackupOperationException e)
- {
- log.error("Full backup failed " + getStorageURL().getPath(), e);
- notifyError("Full backup failed", e);
- }
finally
{
- if (jdbcConn != null)
+ for (Suspendable component : suspendableComponents)
{
try
{
- // unlock tables
- // if (lockStatemnt != null)
- // {
- // ResultSet rs = null;
- // try
- // {
- // DatabaseMetaData metaData = jdbcConn.getMetaData();
- // int dialect = DialectDetecter.detect(metaData).hashCode();
- //
- // if (dialect == DB_DIALECT_HSQLDB)
- // {
- // rs = metaData.getTables(null, null, "%", new String[]{"TABLE"});
- // while (rs.next())
- // {
- // String tableName = rs.getString("TABLE_NAME");
- // lockStatemnt.execute("SET TABLE " + tableName + " READONLY FALSE");
- // }
- // }
- // else
- // {
- // lockStatemnt.execute("UNLOCK TABLES");
- // }
- // }
- // finally
- // {
- // if (rs != null)
- // {
- // rs.close();
- // }
- //
- // if (lockStatemnt != null)
- // {
- // lockStatemnt.close();
- // }
- // }
- // }
-
- jdbcConn.close();
+ component.resume();
}
- catch (SQLException e)
+ catch (ResumeException e)
{
log.error("Full backup failed " + getStorageURL().getPath(), e);
notifyError("Full backup failed", e);
@@ -494,112 +279,6 @@
}
/**
- * Dump table.
- */
- protected void dumpTable(Connection jdbcConn, String tableName, String script) throws SQLException, IOException,
- BackupOperationException
- {
- int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
-
- ObjectZipWriterImpl contentWriter = null;
- ObjectZipWriterImpl contentLenWriter = null;
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try
- {
- File contentFile = new File(getStorageURL().getFile(), tableName + CONTENT_FILE_SUFFIX);
- contentWriter = new ObjectZipWriterImpl(PrivilegedFileHelper.zipOutputStream(contentFile));
- contentWriter.putNextEntry(new ZipEntry(tableName));
-
- File contentLenFile = new File(getStorageURL().getFile(), tableName + CONTENT_LEN_FILE_SUFFIX);
- contentLenWriter = new ObjectZipWriterImpl(PrivilegedFileHelper.zipOutputStream(contentLenFile));
- contentLenWriter.putNextEntry(new ZipEntry(tableName));
-
- stmt = jdbcConn.prepareStatement(script);
- rs = stmt.executeQuery();
- ResultSetMetaData metaData = rs.getMetaData();
-
- int columnCount = metaData.getColumnCount();
- int[] columnType = new int[columnCount];
-
- contentWriter.writeInt(columnCount);
- for (int i = 0; i < columnCount; i++)
- {
- columnType[i] = metaData.getColumnType(i + 1);
- contentWriter.writeInt(columnType[i]);
- contentWriter.writeString(metaData.getColumnName(i + 1));
- }
-
- // Now we can output the actual data
- while (rs.next())
- {
- for (int i = 0; i < columnCount; i++)
- {
- InputStream value;
- if (dialect == DB_DIALECT_HSQLDB)
- {
- if (columnType[i] == Types.VARBINARY)
- {
- value = rs.getBinaryStream(i+1);
- }
- else
- {
- String str = rs.getString(i+1);
- value = str == null ? null : new ByteArrayInputStream(str.getBytes(Constants.DEFAULT_ENCODING));
- }
- }
- else
- {
- value = rs.getBinaryStream(i+1);
- }
-
- if (value == null)
- {
- contentLenWriter.writeLong(-1);
- }
- else
- {
- long len = 0;
- int read = 0;
- byte[] tmpBuff = new byte[2048];
-
- while ((read = value.read(tmpBuff)) >= 0)
- {
- contentWriter.write(tmpBuff, 0, read);
- len += read;
- }
- contentLenWriter.writeLong(len);
- }
- }
- }
- }
- finally
- {
- if (contentWriter != null)
- {
- contentWriter.closeEntry();
- contentWriter.close();
- }
-
- if (contentLenWriter != null)
- {
- contentLenWriter.closeEntry();
- contentLenWriter.close();
- }
-
- if (rs != null)
- {
- rs.close();
- }
-
- if (stmt != null)
- {
- stmt.close();
- }
- }
- }
-
- /**
* {@inheritDoc}
*/
public void stop()
Deleted: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoReader.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoReader.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoReader.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -1,180 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.jcr.ext.backup.impl.rdbms;
-
-import org.exoplatform.commons.utils.PrivilegedFileHelper;
-import org.exoplatform.services.jcr.dataflow.serialization.ObjectReader;
-import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectReaderImpl;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Contains information about performed backup.
- *
- * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
- * @version $Id: RDBMSBackupInfoReader.java 34360 2009-07-22 23:58:59Z tolusha $
- */
-public class RDBMSBackupInfoReader
-{
-
- /**
- * File which contains necessary information about backup.
- */
- public static final String BACKUP_INFO = "backup.info";
-
- /**
- * Workspace name.
- */
- private final String workspaceName;
-
- /**
- * Repository name.
- */
- private final String repositoryName;
-
- /**
- * Is multi-db.
- */
- private final boolean isMultiDb;
-
- /**
- * Table name for items.
- */
- private final String itemTableName;
-
- /**
- * Table name for values.
- */
- private final String valueTableName;
-
- /**
- * Table name for referenceable data.
- */
- private final String refTableName;
-
- /**
- * Lock table names.
- */
- private final List<String> lockTableNames = new ArrayList<String>();
-
- /**
- * Constructor RDBMSBackupInfoReader.java.
- *
- * @param dir
- * The directory where file with backup information was stored.
- */
- public RDBMSBackupInfoReader(String dir) throws IOException
- {
- ObjectReader backupInfoReader =
- new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(new File(dir, BACKUP_INFO)));
-
- try
- {
- this.repositoryName = backupInfoReader.readString();
- this.workspaceName = backupInfoReader.readString();
- this.isMultiDb = backupInfoReader.readBoolean();
- this.itemTableName = backupInfoReader.readString();
- this.valueTableName = backupInfoReader.readString();
- this.refTableName = backupInfoReader.readString();
-
- int lockTablesCount = backupInfoReader.readInt();
- for (int i = 0; i < lockTablesCount; i++)
- {
- lockTableNames.add(backupInfoReader.readString());
- }
- }
- finally
- {
- backupInfoReader.close();
- }
- }
-
- /**
- * Returns the original repository name where backup was performed.
- *
- * @return repository name
- */
- public String getRepositoryName()
- {
- return repositoryName;
- }
-
- /**
- * Returns the original workspace name where backup was performed.
- *
- * @return workspace name
- */
- public String getWorkspaceName()
- {
- return workspaceName;
- }
-
- /**
- * Returns the original value of multi-db parameter of workspace from which backup was performed.
- *
- * @return multi-db parameter
- */
- public boolean isMultiDb()
- {
- return isMultiDb;
- }
-
- /**
- * Returns the original table name of items from which backup was performed.
- *
- * @return table name
- */
- public String getItemTableName()
- {
- return itemTableName;
- }
-
- /**
- * Returns the original table name of values from which backup was performed.
- *
- * @return table name
- */
- public String getValueTableName()
- {
- return valueTableName;
- }
-
- /**
- * Returns the original table name of referenceable data from which backup was performed.
- *
- * @return table name
- */
- public String getRefTableName()
- {
- return refTableName;
- }
-
- /**
- * Returns the original table names of lock data from which backup was performed.
- *
- * @return list of table names
- */
- public List<String> getLockTableNames()
- {
- return lockTableNames;
- }
-}
Deleted: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoWriter.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoWriter.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RDBMSBackupInfoWriter.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -1,192 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.jcr.ext.backup.impl.rdbms;
-
-import org.exoplatform.commons.utils.PrivilegedFileHelper;
-import org.exoplatform.services.jcr.dataflow.serialization.ObjectWriter;
-import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectWriterImpl;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Contains information about performed backup.
- *
- * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
- * @version $Id: RDBMSBackupInfo.java 34360 2009-07-22 23:58:59Z tolusha $
- */
-public class RDBMSBackupInfoWriter
-{
-
- /**
- * Workspace name.
- */
- private String workspaceName;
-
- /**
- * Repository name.
- */
- private String repositoryName;
-
- /**
- * Is multi-db.
- */
- private boolean isMultiDb;
-
- /**
- * Table name for items.
- */
- private String itemTableName;
-
- /**
- * Table name for values.
- */
- private String valueTableName;
-
- /**
- * Table name for referenceable data.
- */
- private String refTableName;
-
- /**
- * Lock table names.
- */
- private List<String> lockTableNames = new ArrayList<String>();
-
- /**
- * The directory where file with backup information will be stored.
- */
- private final String dir;
-
- /**
- * Constructor RDBMSBackupInfoWriter.
- *
- * @param dir
- * The directory where file with backup information was stored.
- */
- public RDBMSBackupInfoWriter(String dir)
- {
- this.dir = dir;
- }
-
- /**
- * Returns the original repository name where backup was performed.
- *
- * @return repository name
- */
- public void setRepositoryName(String repositoryName)
- {
- this.repositoryName = repositoryName;
- }
-
- /**
- * Returns the original workspace name where backup was performed.
- *
- * @return workspace name
- */
- public void setWorkspaceName(String workspaceName)
- {
- this.workspaceName = workspaceName;
- }
-
- /**
- * Returns the original value of multi-db parameter of workspace from which backup was performed.
- *
- * @return multi-db parameter
- */
- public void setMultiDb(boolean isMultiDb)
- {
- this.isMultiDb = isMultiDb;
- }
-
- /**
- * Returns the original table name of items from which backup was performed.
- *
- * @return table name
- */
- public void setItemTableName(String itemTableName)
- {
- this.itemTableName = itemTableName;
- }
-
- /**
- * Returns the original table name of values from which backup was performed.
- *
- * @return table name
- */
- public void setValueTableName(String valueTableName)
- {
- this.valueTableName = valueTableName;
- }
-
- /**
- * Returns the original table name of referenceable data from which backup was performed.
- *
- * @return table name
- */
- public void setRefTableName(String refTableName)
- {
- this.refTableName = refTableName;
- }
-
- /**
- * Returns the original table names of lock data from which backup was performed.
- *
- * @return list of table names
- */
- public void setLockTableNames(List<String> lockTableNames)
- {
- this.lockTableNames.clear();
- this.lockTableNames.addAll(lockTableNames);
- }
-
- /**
- * Write backup information into file.
- *
- * @throws IOException
- * if any error occurred
- */
- public void write() throws IOException
- {
- ObjectWriter backupInfoWriter =
- new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(new File(dir, RDBMSBackupInfoReader.BACKUP_INFO)));
-
- try
- {
- backupInfoWriter.writeString(repositoryName);
- backupInfoWriter.writeString(workspaceName);
- backupInfoWriter.writeBoolean(isMultiDb);
- backupInfoWriter.writeString(itemTableName);
- backupInfoWriter.writeString(valueTableName);
- backupInfoWriter.writeString(refTableName);
-
- backupInfoWriter.writeInt(lockTableNames.size());
- for (int i = 0; i < lockTableNames.size(); i++)
- {
- backupInfoWriter.writeString(lockTableNames.get(i));
- }
- }
- finally
- {
- backupInfoWriter.close();
- }
- }
-}
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/rdbms/RdbmsWorkspaceInitializer.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -19,10 +19,8 @@
package org.exoplatform.services.jcr.ext.backup.impl.rdbms;
import org.exoplatform.commons.utils.PrivilegedFileHelper;
-import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.services.jcr.RepositoryService;
import org.exoplatform.services.jcr.access.AccessManager;
-import org.exoplatform.services.jcr.config.LockManagerEntry;
import org.exoplatform.services.jcr.config.QueryHandlerParams;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.RepositoryEntry;
@@ -30,7 +28,6 @@
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.core.WorkspaceContainerFacade;
-import org.exoplatform.services.jcr.dataflow.serialization.ObjectReader;
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.ext.backup.impl.IndexCleanHelper;
import org.exoplatform.services.jcr.ext.backup.impl.ValueStorageCleanHelper;
@@ -39,14 +36,12 @@
import org.exoplatform.services.jcr.impl.core.LocationFactory;
import org.exoplatform.services.jcr.impl.core.NamespaceRegistryImpl;
import org.exoplatform.services.jcr.impl.core.SessionRegistry;
-import org.exoplatform.services.jcr.impl.core.lock.cacheable.AbstractCacheableLockManager;
import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeManagerImpl;
import org.exoplatform.services.jcr.impl.core.query.SystemSearchManager;
import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
import org.exoplatform.services.jcr.impl.dataflow.persistent.CacheableWorkspaceDataManager;
-import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectZipReaderImpl;
-import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
-import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.Backupable;
+import org.exoplatform.services.jcr.impl.storage.jdbc.backup.RestoreException;
import org.exoplatform.services.jcr.impl.storage.value.fs.FileValueStorage;
import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
import org.exoplatform.services.jcr.impl.util.jdbc.cleaner.DBCleanerException;
@@ -54,31 +49,14 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import java.io.ByteArrayInputStream;
-import java.io.EOFException;
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
-import java.security.PrivilegedExceptionAction;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Types;
-import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import java.util.zip.ZipInputStream;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
-import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-import javax.sql.DataSource;
/**
* @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
@@ -96,10 +74,6 @@
*/
protected final RepositoryService repositoryService;
- /**
- * List of temporary files.
- */
- protected List<File> spoolFileList = new ArrayList<File>();
/**
* Constructor RdbmsWorkspaceInitializer.
@@ -168,55 +142,35 @@
*/
protected void fullRdbmsRestore() throws RepositoryException
{
- Connection jdbcConn = null;
+ ManageableRepository repository = null;
try
{
- String dsName = workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
- if (dsName == null)
- {
- throw new RepositoryConfigurationException("Data source name not found in workspace configuration "
- + workspaceName);
- }
+ repository = repositoryService.getRepository(repositoryEntry.getName());
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ throw new RepositoryException(e);
+ }
- String multiDb = workspaceEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB);
- if (multiDb == null)
+ List<Backupable> backupableComponents =
+ repository.getWorkspaceContainer(workspaceName).getComponentInstancesOfType(Backupable.class);
+
+ try
+ {
+ // restore all components
+ for (Backupable component : backupableComponents)
{
- throw new RepositoryConfigurationException(JDBCWorkspaceDataContainer.MULTIDB
- + " parameter not found in workspace " + workspaceName + " configuration");
+ component.restore(new File(restorePath));
}
- boolean isMultiDb = Boolean.parseBoolean(multiDb);
- final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
- if (ds == null)
- {
- throw new NameNotFoundException("Data source " + dsName + " not found");
- }
-
- jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
- {
- public Connection run() throws Exception
- {
- return ds.getConnection();
-
- }
- });
-
- int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
- jdbcConn.setAutoCommit(false);
-
- RDBMSBackupInfoReader backupInfo = new RDBMSBackupInfoReader(restorePath);
-
- restoreJCRTables(jdbcConn, dialect, isMultiDb, backupInfo);
- restoreLockTables(jdbcConn, isMultiDb, backupInfo);
-
restoreValueStorage();
restoreIndex();
}
- catch (RepositoryConfigurationException e)
+ catch (RestoreException e)
{
throw new RepositoryException(e);
}
- catch (NamingException e)
+ catch (RepositoryConfigurationException e)
{
throw new RepositoryException(e);
}
@@ -224,146 +178,9 @@
{
throw new RepositoryException(e);
}
- catch (SQLException e)
- {
- SQLException next = e.getNextException();
- String errorTrace = "";
- while (next != null)
- {
- errorTrace += next.getMessage() + "; ";
- next = next.getNextException();
- }
-
- Throwable cause = e.getCause();
- String msg = "SQL Exception: " + errorTrace + (cause != null ? " (Cause: " + cause.getMessage() + ")" : "");
-
- throw new RepositoryException(msg, e);
- }
- finally
- {
- if (jdbcConn != null)
- {
- try
- {
- jdbcConn.close();
- }
- catch (SQLException e)
- {
- throw new RepositoryException(e);
- }
- }
- }
}
/**
- * Restore JCR tables.
- */
- protected void restoreJCRTables(Connection jdbcConn, int dialect, boolean isMultiDb, RDBMSBackupInfoReader backupInfo)
- throws IOException, SQLException
- {
- Statement st = null;
- try
- {
- Integer[] tableTypes =
- new Integer[]{RestoreTableHelper.ITEM_TABLE, RestoreTableHelper.VALUE_TABLE, RestoreTableHelper.REF_TABLE};
-
- for (Integer tableType : tableTypes)
- {
- RestoreTableHelper helper = new RestoreTableHelper(tableType, isMultiDb, backupInfo);
-
- if (!PrivilegedFileHelper.exists(helper.getContentFile()))
- {
- throw new IOException("File " + PrivilegedFileHelper.getCanonicalPath(helper.getContentFile())
- + " not found");
- }
-
- if (tableType == RestoreTableHelper.ITEM_TABLE && dialect != FullBackupJob.DB_DIALECT_MYSQL
- && dialect != FullBackupJob.DB_DIALECT_MYSQL_UTF8)
- {
- // resolve constraint name depends on database
- String constraintName;
- if (dialect == FullBackupJob.DB_DIALECT_DB2 || dialect == FullBackupJob.DB_DIALECT_DB2V8)
- {
- constraintName = "JCR_FK_" + (isMultiDb ? "M" : "S") + "ITEM_PAREN";
- }
- else
- {
- constraintName = "JCR_FK_" + (isMultiDb ? "M" : "S") + "ITEM_PARENT";
- }
- String constraint =
- "CONSTRAINT " + constraintName + " FOREIGN KEY(PARENT_ID) REFERENCES " + helper.getTableName()
- + "(ID)";
-
- // drop constraint
- st = jdbcConn.createStatement();
- st.execute("ALTER TABLE " + helper.getTableName() + " DROP CONSTRAINT " + constraintName);
- jdbcConn.commit();
-
- restoreTable(jdbcConn, helper);
-
- // add constraint
- st = jdbcConn.createStatement();
- st.execute("ALTER TABLE " + helper.getTableName() + " ADD " + constraint);
- jdbcConn.commit();
- }
- else
- {
- restoreTable(jdbcConn, helper);
- }
- }
- }
- finally
- {
- if (st != null)
- {
- st.close();
- }
- }
- }
-
- /**
- * Restore JCR Lock tables.
- */
- protected void restoreLockTables(Connection jdbcConn, boolean isMultiDb, RDBMSBackupInfoReader backupInfo)
- throws IOException, SQLException, RepositoryException
- {
- LockManagerEntry lockEntry = workspaceEntry.getLockManager();
- if (lockEntry != null)
- {
- List<String> existedLockTablesNames = AbstractCacheableLockManager.getLockTableNames(lockEntry);
- if (existedLockTablesNames.size() != backupInfo.getLockTableNames().size())
- {
- throw new RepositoryException("The amount of existed lock tables differs from backup");
- }
-
- for (int i = 0; i < backupInfo.getLockTableNames().size(); i++)
- {
- RestoreTableHelper helper = new RestoreTableHelper(RestoreTableHelper.LOCK_TABLE, isMultiDb, backupInfo);
-
- helper.setContentFile(new File(restorePath, backupInfo.getLockTableNames().get(i)
- + FullBackupJob.CONTENT_FILE_SUFFIX));
- helper.setContentLenFile(new File(restorePath, backupInfo.getLockTableNames().get(i)
- + FullBackupJob.CONTENT_LEN_FILE_SUFFIX));
- helper.setTableName(existedLockTablesNames.get(i));
-
- if (PrivilegedFileHelper.exists(helper.contentFile))
- {
- restoreTable(jdbcConn, helper);
- }
- else
- {
- throw new IOException("File " + PrivilegedFileHelper.getCanonicalPath(helper.contentFile) + " not found");
- }
- }
- }
- else if (backupInfo.getLockTableNames().size() != 0)
- {
- throw new RepositoryException("There are no lock tables for new workspace configuration [" + workspaceName
- + "] but backup lock data exist");
- }
- }
-
- /**
* Restore index from backup.
*/
protected void restoreIndex() throws RepositoryConfigurationException, IOException
@@ -573,593 +390,4 @@
}
}
}
-
- /**
- * Restore table.
- */
- protected void restoreTable(Connection jdbcConn, RestoreTableHelper helper)
- throws IOException, SQLException
- {
- ObjectZipReaderImpl contentReader = null;
- ObjectZipReaderImpl contentLenReader = null;
-
- PreparedStatement insertNode = null;
- ResultSet tableMetaData = null;
-
- int dialect = DialectDetecter.detect(jdbcConn.getMetaData()).hashCode();
-
- try
- {
- contentReader = new ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(helper.getContentFile()));
- contentReader.getNextEntry();
-
- contentLenReader = new ObjectZipReaderImpl(PrivilegedFileHelper.zipInputStream(helper.getContentLenFile()));
- contentLenReader.getNextEntry();
-
- // get information about source table
- int sourceColumnCount = contentReader.readInt();
-
- List<Integer> columnType = new ArrayList<Integer>();
- List<String> columnName = new ArrayList<String>();
-
- for (int i = 0; i < sourceColumnCount; i++)
- {
- columnType.add(contentReader.readInt());
- columnName.add(contentReader.readString());
- }
-
- // collect information about target table
- List<Integer> newColumnType = new ArrayList<Integer>();
- List<String> newColumnName = new ArrayList<String>();
-
- tableMetaData = jdbcConn.getMetaData().getColumns(null, null, helper.tableName, "%");
- while (tableMetaData.next())
- {
- newColumnName.add(tableMetaData.getString("COLUMN_NAME"));
- newColumnType.add(tableMetaData.getInt("DATA_TYPE"));
- }
-
- int targetColumnCount = sourceColumnCount;
- if (helper.getDeleteColumnIndex() != null)
- {
- targetColumnCount--;
- }
- else if (helper.getNewColumnIndex() != null)
- {
- targetColumnCount++;
- columnType.add(helper.getNewColumnIndex(), newColumnType.get((helper.getNewColumnIndex())));
- }
-
- // construct statement
- String names = "";
- String parameters = "";
- for (int i = 0; i < targetColumnCount; i++)
- {
- if (helper.getSkipColumnIndex() != null && helper.getSkipColumnIndex() == i)
- {
- continue;
- }
- names += newColumnName.get(i) + (i == targetColumnCount - 1 ? "" : ",");
- parameters += "?" + (i == targetColumnCount - 1 ? "" : ",");
- }
- insertNode =
- jdbcConn.prepareStatement("INSERT INTO " + helper.getTableName() + " (" + names + ") VALUES(" + parameters
- + ")");
-
- // set data
- outer : while (true)
- {
- for (int i = 0, targetIndex = 0; i < columnType.size(); i++, targetIndex++)
- {
- InputStream stream;
- long len;
-
- if (helper.getNewColumnIndex() != null && helper.getNewColumnIndex() == i)
- {
- stream = new ByteArrayInputStream(workspaceName.getBytes(Constants.DEFAULT_ENCODING));
- len = ((ByteArrayInputStream)stream).available();
- }
- else
- {
- try
- {
- len = contentLenReader.readLong();
- }
- catch (EOFException e)
- {
- if (i == 0)
- {
- // content length file is empty check content file
- try
- {
- contentReader.readByte();
- }
- catch (EOFException e1)
- {
- break outer;
- }
- }
-
- throw new IOException("Content length file is empty but content still present", e);
- }
- stream = len == -1 ? null : spoolInputStream(contentReader, len);
- }
-
- if (helper.getSkipColumnIndex() != null && helper.getSkipColumnIndex() == i)
- {
- targetIndex--;
- continue;
- }
- else if (helper.getDeleteColumnIndex() != null && helper.getDeleteColumnIndex() == i)
- {
- targetIndex--;
- continue;
- }
-
- // set
- if (stream != null)
- {
- if (helper.getConvertColumnIndexes().contains(i))
- {
- // convert column value
- ByteArrayInputStream ba = (ByteArrayInputStream)stream;
- byte[] readBuffer = new byte[ba.available()];
- ba.read(readBuffer);
-
- String currentValue = new String(readBuffer, Constants.DEFAULT_ENCODING);
- if (currentValue.equals(Constants.ROOT_PARENT_UUID))
- {
- stream = new ByteArrayInputStream(Constants.ROOT_PARENT_UUID.getBytes());
- }
- else
- {
- if (helper.isMultiDb)
- {
- if (!helper.isBackupMutliDb())
- {
- stream =
- new ByteArrayInputStream(new String(readBuffer, Constants.DEFAULT_ENCODING).substring(
- helper.getBackupWorkspaceName().length()).getBytes());
- }
- }
- else
- {
- if (helper.isBackupMutliDb())
- {
- StringBuilder builder = new StringBuilder();
- builder.append(workspaceName);
- builder.append(currentValue);
-
- stream = new ByteArrayInputStream(builder.toString().getBytes());
- }
- else
- {
- StringBuilder builder = new StringBuilder();
- builder.append(workspaceName);
- builder.append(new String(readBuffer, Constants.DEFAULT_ENCODING).substring(helper
- .getBackupWorkspaceName().length()));
-
- stream = new ByteArrayInputStream(builder.toString().getBytes());
- }
- }
- }
-
- len = ((ByteArrayInputStream)stream).available();
- }
-
- if (columnType.get(i) == Types.INTEGER || columnType.get(i) == Types.BIGINT
- || columnType.get(i) == Types.SMALLINT || columnType.get(i) == Types.TINYINT)
- {
- ByteArrayInputStream ba = (ByteArrayInputStream)stream;
- byte[] readBuffer = new byte[ba.available()];
- ba.read(readBuffer);
-
- String value = new String(readBuffer, Constants.DEFAULT_ENCODING);
- insertNode.setLong(targetIndex + 1, Integer.parseInt(value));
- }
- else if (columnType.get(i) == Types.BIT)
- {
- ByteArrayInputStream ba = (ByteArrayInputStream)stream;
- byte[] readBuffer = new byte[ba.available()];
- ba.read(readBuffer);
-
- String value = new String(readBuffer);
- if (dialect == FullBackupJob.DB_DIALECT_PGSQL)
- {
- insertNode.setBoolean(targetIndex + 1, value.equals("t"));
- }
- else
- {
- insertNode.setBoolean(targetIndex + 1, value.equals("1"));
- }
- }
- else if (columnType.get(i) == Types.BOOLEAN)
- {
- ByteArrayInputStream ba = (ByteArrayInputStream)stream;
- byte[] readBuffer = new byte[ba.available()];
- ba.read(readBuffer);
-
- String value = new String(readBuffer);
- insertNode.setBoolean(targetIndex + 1, value.equals("true"));
- }
- else
- {
- if (dialect == FullBackupJob.DB_DIALECT_HSQLDB)
- {
- if (columnType.get(i) == Types.VARBINARY)
- {
- insertNode.setBinaryStream(targetIndex + 1, stream, (int)len);
- }
- else
- {
- byte[] readBuffer = new byte[(int)len];
- stream.read(readBuffer);
-
- insertNode.setString(targetIndex + 1, new String(readBuffer, Constants.DEFAULT_ENCODING));
- }
- }
- else
- {
- insertNode.setBinaryStream(targetIndex + 1, stream, (int)len);
- }
- }
- }
- else
- {
- insertNode.setNull(targetIndex + 1, columnType.get(i));
- }
- }
- insertNode.addBatch();
-
- }
-
- insertNode.executeBatch();
- jdbcConn.commit();
- }
- finally
- {
- if (contentReader != null)
- {
- contentReader.close();
- }
-
- if (contentLenReader != null)
- {
- contentLenReader.close();
- }
-
- if (insertNode != null)
- {
- insertNode.close();
- }
-
- // delete all temporary files
- for (File file : spoolFileList)
- {
- if (!PrivilegedFileHelper.delete(file))
- {
- fileCleaner.addFile(file);
- }
- }
-
- if (tableMetaData != null)
- {
- tableMetaData.close();
- }
- }
- }
-
- /**
- * Spool input stream.
- */
- private InputStream spoolInputStream(ObjectReader in, long contentLen) throws IOException
- {
- byte[] buffer = new byte[0];
- byte[] tmpBuff;
- long readLen = 0;
- File sf = null;
- OutputStream sfout = null;
-
- try
- {
- while (true)
- {
- int needToRead = contentLen - readLen > 2048 ? 2048 : (int)(contentLen - readLen);
- tmpBuff = new byte[needToRead];
-
- if (needToRead == 0)
- {
- break;
- }
-
- in.readFully(tmpBuff);
-
- if (sfout != null)
- {
- sfout.write(tmpBuff);
- }
- else if (readLen + needToRead > maxBufferSize)
- {
- sf = PrivilegedFileHelper.createTempFile("jcrvd", null, tempDir);
- sfout = PrivilegedFileHelper.fileOutputStream(sf);
-
- sfout.write(buffer);
- sfout.write(tmpBuff);
- buffer = null;
- }
- else
- {
- // reallocate new buffer and spool old buffer contents
- byte[] newBuffer = new byte[(int)(readLen + needToRead)];
- System.arraycopy(buffer, 0, newBuffer, 0, (int)readLen);
- System.arraycopy(tmpBuff, 0, newBuffer, (int)readLen, needToRead);
- buffer = newBuffer;
- }
-
- readLen += needToRead;
- }
-
- if (buffer != null)
- {
- return new ByteArrayInputStream(buffer);
- }
- else
- {
- return PrivilegedFileHelper.fileInputStream(sf);
- }
- }
- finally
- {
- if (sfout != null)
- {
- sfout.close();
- }
-
- if (sf != null)
- {
- spoolFileList.add(sf);
- }
- }
- }
-
- /**
- * Class which helps to restore data.
- */
- protected class RestoreTableHelper
- {
- public static final int ITEM_TABLE = 0;
-
- public static final int VALUE_TABLE = 1;
-
- public static final int REF_TABLE = 2;
-
- public static final int LOCK_TABLE = 3;
-
- private String tableName;
-
- private File contentFile;
-
- private File contentLenFile;
-
- private Integer deleteColumnIndex = null;
-
- private Integer skipColumnIndex = null;
-
- private Integer newColumnIndex = null;
-
- private Set<Integer> convertColumnIndex = new HashSet<Integer>();
-
- private final boolean isMultiDb;
-
- private final RDBMSBackupInfoReader backupInfo;
-
- public RestoreTableHelper(int tableType, boolean isMultiDb, RDBMSBackupInfoReader backupInfo)
- throws IOException
- {
- this.backupInfo = backupInfo;
- this.isMultiDb = isMultiDb;
-
- if (tableType == ITEM_TABLE)
- {
- contentFile = new File(restorePath, backupInfo.getItemTableName() + FullBackupJob.CONTENT_FILE_SUFFIX);
- contentLenFile =
- new File(restorePath, backupInfo.getItemTableName() + FullBackupJob.CONTENT_LEN_FILE_SUFFIX);
-
- tableName = "JCR_" + (isMultiDb ? "M" : "S") + "ITEM";
-
- if (isMultiDb)
- {
- tableName = "JCR_MITEM";
-
- if (!backupInfo.isMultiDb())
- {
- // CONTAINER_NAME column index
- deleteColumnIndex = 4;
-
- // ID and PARENT_ID column indexes
- convertColumnIndex.add(0);
- convertColumnIndex.add(1);
- }
- }
- else
- {
- tableName = "JCR_SITEM";
-
- if (backupInfo.isMultiDb())
- {
- // CONTAINER_NAME column index
- newColumnIndex = 4;
-
- // ID and PARENT_ID column indexes
- convertColumnIndex.add(0);
- convertColumnIndex.add(1);
- }
- else
- {
- // ID and PARENT_ID and CONTAINER_NAME column indexes
- convertColumnIndex.add(0);
- convertColumnIndex.add(1);
- convertColumnIndex.add(4);
- }
- }
- }
- else if (tableType == VALUE_TABLE)
- {
- contentFile = new File(restorePath, backupInfo.getValueTableName() + FullBackupJob.CONTENT_FILE_SUFFIX);
- contentLenFile =
- new File(restorePath, backupInfo.getValueTableName() + FullBackupJob.CONTENT_LEN_FILE_SUFFIX);
-
- tableName = "JCR_" + (isMultiDb ? "M" : "S") + "VALUE";
-
- // auto increment ID column
- skipColumnIndex = 0;
-
- if (!isMultiDb || !backupInfo.isMultiDb())
- {
- // PROPERTY_ID column index
- convertColumnIndex.add(3);
- }
- }
- else if (tableType == REF_TABLE)
- {
- contentFile = new File(restorePath, backupInfo.getRefTableName() + FullBackupJob.CONTENT_FILE_SUFFIX);
- contentLenFile =
- new File(restorePath, backupInfo.getRefTableName() + FullBackupJob.CONTENT_LEN_FILE_SUFFIX);
-
- tableName = "JCR_" + (isMultiDb ? "M" : "S") + "REF";
-
- if (!isMultiDb || !backupInfo.isMultiDb())
- {
- // NODE_ID and PROPERTY_ID column indexes
- convertColumnIndex.add(0);
- convertColumnIndex.add(1);
- }
- }
- }
-
- /**
- * Returns the table name for restore.
- *
- * @return table name
- */
- public String getTableName()
- {
- return tableName;
- }
-
- /**
- * Returns the content file for restore.
- *
- * @return file
- */
- public File getContentFile()
- {
- return contentFile;
- }
-
- /**
- * Returns the content length file for restore.
- *
- * @return file
- */
- public File getContentLenFile()
- {
- return contentLenFile;
- }
-
- /**
- * Set table name for restore.
- */
- public void setTableName(String tableName)
- {
- this.tableName = tableName;
- }
-
- /**
- * Set content file for restore.
- */
- public void setContentFile(File file)
- {
- this.contentFile = file;
- }
-
- /**
- * Set content length file for restore.
- */
- public void setContentLenFile(File file)
- {
- this.contentLenFile = file;
- }
-
- /**
- * Returns index of column which should be skipped during restore.
- *
- * @return Integer
- */
- public Integer getSkipColumnIndex()
- {
- return skipColumnIndex;
- }
-
- /**
- * Returns index of column which should be skipped during restore.
- *
- * @return Integer
- */
- public Integer getDeleteColumnIndex()
- {
- return deleteColumnIndex;
- }
-
-
- /**
- * Returns index of column which should be added during restore.
- *
- * @return Integer
- */
- public Integer getNewColumnIndex()
- {
- return newColumnIndex;
- }
-
- /**
- * Returns indexes of columns which should be converted during restore.
- *
- * @return Integer
- */
- public Set<Integer> getConvertColumnIndexes()
- {
- return convertColumnIndex;
- }
-
- /**
- * Returns the target workspace name for restore.
- *
- * @return workspace name
- */
- public boolean isMultiDb()
- {
- return isMultiDb;
- }
-
- /**
- * Returns the original workspace name where backup was performed.
- *
- * @return workspace name
- */
- public String getBackupWorkspaceName()
- {
- return backupInfo.getWorkspaceName();
- }
-
- /**
- * Returns the original value of multi-db parameter of workspace from which backup was performed.
- *
- * @return multi-db parameter
- */
- public boolean isBackupMutliDb()
- {
- return backupInfo.isMultiDb();
- }
- }
}
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRDBMSBackupManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRDBMSBackupManager.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRDBMSBackupManager.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -28,8 +28,7 @@
* @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
* @version $Id$
*/
-public class TestRDBMSBackupManager
- extends AbstractBackupUseCasesTest
+public class TestRDBMSBackupManager extends AbstractBackupUseCasesTest
{
@Override
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsFullBackupJob.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsFullBackupJob.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsFullBackupJob.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -61,14 +61,14 @@
indexesDir = new File(url.getFile(), FullBackupJob.SYSTEM_INDEX_DIR);
assertTrue(indexesDir.exists());
- assertTrue(new File(url.getFile(), "JCR_MITEM" + FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MITEM" + FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MITEM.dump").exists());
+ assertTrue(new File(url.getFile(), "JCR_MITEM.len").exists());
- assertTrue(new File(url.getFile(), "JCR_MVALUE" + FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MVALUE" + FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MVALUE.dump").exists());
+ assertTrue(new File(url.getFile(), "JCR_MVALUE.len").exists());
- assertTrue(new File(url.getFile(), "JCR_MREF" + FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MREF" + FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MREF.dump").exists());
+ assertTrue(new File(url.getFile(), "JCR_MREF.len").exists());
}
@@ -97,14 +97,14 @@
indexesDir = new File(url.getFile(), FullBackupJob.SYSTEM_INDEX_DIR);
assertFalse(indexesDir.exists());
- assertTrue(new File(url.getFile(), "JCR_MITEM" + FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MITEM" + FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MITEM.dump").exists());
+ assertTrue(new File(url.getFile(), "JCR_MITEM.len").exists());
- assertTrue(new File(url.getFile(), "JCR_MVALUE" + FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MVALUE" + FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MVALUE.dump").exists());
+ assertTrue(new File(url.getFile(), "JCR_MVALUE.len").exists());
- assertTrue(new File(url.getFile(), "JCR_MREF" + FullBackupJob.CONTENT_FILE_SUFFIX).exists());
- assertTrue(new File(url.getFile(), "JCR_MREF" + FullBackupJob.CONTENT_LEN_FILE_SUFFIX).exists());
+ assertTrue(new File(url.getFile(), "JCR_MREF.dump").exists());
+ assertTrue(new File(url.getFile(), "JCR_MREF.len").exists());
}
}
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/TestRdbmsWorkspaceInitializer.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -33,15 +33,10 @@
import java.io.File;
import java.net.URL;
-import java.sql.Connection;
-import java.sql.Statement;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
-import javax.naming.InitialContext;
-import javax.sql.DataSource;
-
/**
* @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
* @version $Id: TestFullBackupJob.java 34360 2009-07-22 23:58:59Z tolusha $
@@ -145,8 +140,8 @@
TesterRdbmsWorkspaceInitializer initializer =
new TesterRdbmsWorkspaceInitializer(newEntry, repositoryService.getRepository("db1").getConfiguration(),
- cacheableDataManager, null, null, null,
- (ValueFactoryImpl) valueFactory, null, repositoryService, new FileCleanerHolder());
+ cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null, repositoryService,
+ new FileCleanerHolder());
initializer.restoreValueFiles();
assertFalse(new File(newValueStoragePath).exists());
@@ -182,26 +177,11 @@
String newIndexPath = "target/temp/index/" + IdGenerator.generate();
String dsName = helper.getNewDataSource("");
- DataSource ds = (DataSource)new InitialContext().lookup(dsName);
- Connection conn = ds.getConnection();
- Statement st = conn.createStatement();
- st.execute("CREATE TABLE JCR_MITEM(ID VARCHAR(96) NOT NULL,PARENT_ID VARCHAR(96) NOT NULL,NAME VARCHAR(512) NOT NULL,VERSION INTEGER NOT NULL,I_CLASS INTEGER NOT NULL,I_INDEX INTEGER NOT NULL,N_ORDER_NUM INTEGER,P_TYPE INTEGER,P_MULTIVALUED BOOLEAN,CONSTRAINT JCR_PK_MITEM PRIMARY KEY(ID))");
- conn.commit();
-
- st.execute("INSERT INTO JCR_MITEM VALUES(' ',' ','__root_parent',0,0,0,0,NULL,NULL)");
- conn.commit();
-
- st.execute("CREATE TABLE JCR_MVALUE(ID BIGINT generated by default as identity (START WITH 2, INCREMENT BY 1) NOT NULL, DATA VARBINARY(65535),ORDER_NUM INTEGER NOT NULL,PROPERTY_ID VARCHAR(96) NOT NULL,STORAGE_DESC VARCHAR(512),CONSTRAINT JCR_PK_MVALUE PRIMARY KEY(ID),CONSTRAINT JCR_FK_MVALUE_PROPERTY FOREIGN KEY(PROPERTY_ID) REFERENCES JCR_MITEM(ID))");
- conn.commit();
-
- st.execute("CREATE TABLE JCR_MREF(NODE_ID VARCHAR(96) NOT NULL, PROPERTY_ID VARCHAR(96) NOT NULL, ORDER_NUM INTEGER NOT NULL, CONSTRAINT JCR_PK_MREF PRIMARY KEY(NODE_ID, PROPERTY_ID, ORDER_NUM))");
- conn.commit();
-
// set the initializer
WorkspaceEntry newEntry =
- helper.getNewWs("ws1", true, dsName, newValueStoragePath, newIndexPath, workspaceEntry.getContainer(),
- workspaceEntry.getContainer().getValueStorages());
+ helper.getNewWs("ws" + System.currentTimeMillis(), true, dsName, newValueStoragePath, newIndexPath,
+ workspaceEntry.getContainer(), workspaceEntry.getContainer().getValueStorages());
WorkspaceInitializerEntry wiEntry = new WorkspaceInitializerEntry();
wiEntry.setType(RdbmsWorkspaceInitializer.class.getCanonicalName());
@@ -214,39 +194,18 @@
newEntry.setInitializer(wiEntry);
- TesterRdbmsWorkspaceInitializer initializer =
- new TesterRdbmsWorkspaceInitializer(newEntry, repositoryService.getRepository("db1").getConfiguration(),
- cacheableDataManager, null, null, null,
- (ValueFactoryImpl) valueFactory, null, repositoryService, new FileCleanerHolder());
+ repositoryService.getRepository("db1").configWorkspace(newEntry);
+ repositoryService.getRepository("db1").createWorkspace(newEntry.getName());
- // restore multi -> multi
- initializer.restoreTables(conn, 0, true, workspaceEntry.getLockManager(), url.getFile());
- initializer.restoreTables(conn, 1, true, workspaceEntry.getLockManager(), url.getFile());
- initializer.restoreTables(conn, 2, true, workspaceEntry.getLockManager(), url.getFile());
-
- st.execute("ALTER TABLE JCR_MITEM ADD CONSTRAINT JCR_FK_MITEM_PARENT FOREIGN KEY(PARENT_ID) REFERENCES JCR_MITEM(ID)");
- conn.commit();
-
dsName = helper.getNewDataSource("");
- ds = (DataSource)new InitialContext().lookup(dsName);
- conn = ds.getConnection();
- st = conn.createStatement();
- st.execute("CREATE TABLE JCR_SITEM(ID VARCHAR(96) NOT NULL,PARENT_ID VARCHAR(96) NOT NULL,NAME VARCHAR(512) NOT NULL,VERSION INTEGER NOT NULL,CONTAINER_NAME VARCHAR(96) NOT NULL,I_CLASS INTEGER NOT NULL,I_INDEX INTEGER NOT NULL,N_ORDER_NUM INTEGER,P_TYPE INTEGER,P_MULTIVALUED BOOLEAN,CONSTRAINT JCR_PK_SITEM PRIMARY KEY(ID))");
- conn.commit();
+ newValueStoragePath = "target/temp/values/" + IdGenerator.generate();
+ newIndexPath = "target/temp/index/" + IdGenerator.generate();
- st.execute("INSERT INTO JCR_SITEM VALUES(' ',' ','__root_parent',0,'__root_parent_container',0,0,0,NULL,NULL)");
- conn.commit();
-
- st.execute("CREATE TABLE JCR_SVALUE(ID BIGINT generated by default as identity (START WITH 2, INCREMENT BY 1) NOT NULL, DATA VARBINARY(65535),ORDER_NUM INTEGER NOT NULL,PROPERTY_ID VARCHAR(96) NOT NULL,STORAGE_DESC VARCHAR(512),CONSTRAINT JCR_PK_MVALUE PRIMARY KEY(ID),CONSTRAINT JCR_FK_SVALUE_PROPERTY FOREIGN KEY(PROPERTY_ID) REFERENCES JCR_SITEM(ID))");
- conn.commit();
-
- st.execute("CREATE TABLE JCR_SREF(NODE_ID VARCHAR(96) NOT NULL, PROPERTY_ID VARCHAR(96) NOT NULL, ORDER_NUM INTEGER NOT NULL, CONSTRAINT JCR_PK_SREF PRIMARY KEY(NODE_ID, PROPERTY_ID, ORDER_NUM))");
- conn.commit();
-
// set the initializer
newEntry =
- helper.getNewWs("ws1", true, dsName, newValueStoragePath, newIndexPath, workspaceEntry.getContainer(),
+ helper.getNewWs("ws" + System.currentTimeMillis(), true, dsName, newValueStoragePath, newIndexPath,
+ workspaceEntry.getContainer(),
workspaceEntry.getContainer().getValueStorages());
wiEntry = new WorkspaceInitializerEntry();
@@ -260,19 +219,11 @@
newEntry.setInitializer(wiEntry);
- initializer =
- new TesterRdbmsWorkspaceInitializer(newEntry, repositoryService.getRepository("db1").getConfiguration(),
- cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null, repositoryService, new FileCleanerHolder());
-
- // restore multi -> single
- initializer.restoreTables(conn, 0, false, workspaceEntry.getLockManager(), url.getFile());
- initializer.restoreTables(conn, 1, false, workspaceEntry.getLockManager(), url.getFile());
- initializer.restoreTables(conn, 2, false, workspaceEntry.getLockManager(), url.getFile());
-
- st.execute("ALTER TABLE JCR_SITEM ADD CONSTRAINT JCR_FK_SITEM_PARENT FOREIGN KEY(PARENT_ID) REFERENCES JCR_SITEM(ID)");
- conn.commit();
-
+ repositoryService.getRepository("db1").configWorkspace(newEntry);
+ repositoryService.getRepository("db1").createWorkspace(newEntry.getName());
}
+
+ break;
}
}
@@ -286,40 +237,25 @@
Calendar calendar = Calendar.getInstance();
- job.init(repositoryService.getRepository("db3"), "ws", config, calendar);
+ job.init(repositoryService.getRepository("db7"), "ws1", config, calendar);
job.run();
URL url = job.getStorageURL();
- for (WorkspaceEntry workspaceEntry : repositoryService.getRepository("db3").getConfiguration()
+ for (WorkspaceEntry workspaceEntry : repositoryService.getRepository("db7").getConfiguration()
.getWorkspaceEntries())
{
- if (workspaceEntry.getName().equals("ws"))
+ if (workspaceEntry.getName().equals("ws1"))
{
String newValueStoragePath = "target/temp/values/" + IdGenerator.generate();
String newIndexPath = "target/temp/index/" + IdGenerator.generate();
String dsName = helper.getNewDataSource("");
- DataSource ds = (DataSource)new InitialContext().lookup(dsName);
- Connection conn = ds.getConnection();
- Statement st = conn.createStatement();
- st.execute("CREATE TABLE JCR_MITEM(ID VARCHAR(96) NOT NULL,PARENT_ID VARCHAR(96) NOT NULL,NAME VARCHAR(512) NOT NULL,VERSION INTEGER NOT NULL,I_CLASS INTEGER NOT NULL,I_INDEX INTEGER NOT NULL,N_ORDER_NUM INTEGER,P_TYPE INTEGER,P_MULTIVALUED BOOLEAN,CONSTRAINT JCR_PK_MITEM PRIMARY KEY(ID))");
- conn.commit();
-
- st.execute("INSERT INTO JCR_MITEM VALUES(' ',' ','__root_parent',0,0,0,0,NULL,NULL)");
- conn.commit();
-
- st.execute("CREATE TABLE JCR_MVALUE(ID BIGINT generated by default as identity (START WITH 2, INCREMENT BY 1) NOT NULL, DATA VARBINARY(65535),ORDER_NUM INTEGER NOT NULL,PROPERTY_ID VARCHAR(96) NOT NULL,STORAGE_DESC VARCHAR(512),CONSTRAINT JCR_PK_MVALUE PRIMARY KEY(ID),CONSTRAINT JCR_FK_MVALUE_PROPERTY FOREIGN KEY(PROPERTY_ID) REFERENCES JCR_MITEM(ID))");
- conn.commit();
-
- st.execute("CREATE TABLE JCR_MREF(NODE_ID VARCHAR(96) NOT NULL, PROPERTY_ID VARCHAR(96) NOT NULL, ORDER_NUM INTEGER NOT NULL, CONSTRAINT JCR_PK_MREF PRIMARY KEY(NODE_ID, PROPERTY_ID, ORDER_NUM))");
- conn.commit();
-
// set the initializer
WorkspaceEntry newEntry =
- helper.getNewWs("ws", true, dsName, newValueStoragePath, newIndexPath, workspaceEntry.getContainer(),
- workspaceEntry.getContainer().getValueStorages());
+ helper.getNewWs("ws" + System.currentTimeMillis(), true, dsName, newValueStoragePath, newIndexPath,
+ workspaceEntry.getContainer(), workspaceEntry.getContainer().getValueStorages());
WorkspaceInitializerEntry wiEntry = new WorkspaceInitializerEntry();
wiEntry.setType(RdbmsWorkspaceInitializer.class.getCanonicalName());
@@ -337,34 +273,18 @@
cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null, repositoryService, new FileCleanerHolder());
// restore single -> multi
- initializer.restoreTables(conn, 0, true, workspaceEntry.getLockManager(), url.getFile());
- initializer.restoreTables(conn, 1, true, workspaceEntry.getLockManager(), url.getFile());
- initializer.restoreTables(conn, 2, true, workspaceEntry.getLockManager(), url.getFile());
+ repositoryService.getRepository("db1").configWorkspace(newEntry);
+ repositoryService.getRepository("db1").createWorkspace(newEntry.getName());
- st.execute("ALTER TABLE JCR_MITEM ADD CONSTRAINT JCR_FK_MITEM_PARENT FOREIGN KEY(PARENT_ID) REFERENCES JCR_MITEM(ID)");
- conn.commit();
-
dsName = helper.getNewDataSource("");
- ds = (DataSource)new InitialContext().lookup(dsName);
- conn = ds.getConnection();
- st = conn.createStatement();
- st.execute("CREATE TABLE JCR_SITEM(ID VARCHAR(96) NOT NULL,PARENT_ID VARCHAR(96) NOT NULL,NAME VARCHAR(512) NOT NULL,VERSION INTEGER NOT NULL,CONTAINER_NAME VARCHAR(96) NOT NULL,I_CLASS INTEGER NOT NULL,I_INDEX INTEGER NOT NULL,N_ORDER_NUM INTEGER,P_TYPE INTEGER,P_MULTIVALUED BOOLEAN,CONSTRAINT JCR_PK_SITEM PRIMARY KEY(ID))");
- conn.commit();
+ newValueStoragePath = "target/temp/values/" + IdGenerator.generate();
+ newIndexPath = "target/temp/index/" + IdGenerator.generate();
- st.execute("INSERT INTO JCR_SITEM VALUES(' ',' ','__root_parent',0,'__root_parent_container',0,0,0,NULL,NULL)");
- conn.commit();
-
- st.execute("CREATE TABLE JCR_SVALUE(ID BIGINT generated by default as identity (START WITH 2, INCREMENT BY 1) NOT NULL, DATA VARBINARY(65535),ORDER_NUM INTEGER NOT NULL,PROPERTY_ID VARCHAR(96) NOT NULL,STORAGE_DESC VARCHAR(512),CONSTRAINT JCR_PK_MVALUE PRIMARY KEY(ID),CONSTRAINT JCR_FK_SVALUE_PROPERTY FOREIGN KEY(PROPERTY_ID) REFERENCES JCR_SITEM(ID))");
- conn.commit();
-
- st.execute("CREATE TABLE JCR_SREF(NODE_ID VARCHAR(96) NOT NULL, PROPERTY_ID VARCHAR(96) NOT NULL, ORDER_NUM INTEGER NOT NULL, CONSTRAINT JCR_PK_SREF PRIMARY KEY(NODE_ID, PROPERTY_ID, ORDER_NUM))");
- conn.commit();
-
// set the initializer
newEntry =
- helper.getNewWs("ws", true, dsName, newValueStoragePath, newIndexPath, workspaceEntry.getContainer(),
- workspaceEntry.getContainer().getValueStorages());
+ helper.getNewWs("ws" + System.currentTimeMillis(), true, dsName, newValueStoragePath, newIndexPath,
+ workspaceEntry.getContainer(), workspaceEntry.getContainer().getValueStorages());
wiEntry = new WorkspaceInitializerEntry();
wiEntry.setType(RdbmsWorkspaceInitializer.class.getCanonicalName());
@@ -377,18 +297,11 @@
newEntry.setInitializer(wiEntry);
- initializer =
- new TesterRdbmsWorkspaceInitializer(newEntry, repositoryService.getRepository("db3").getConfiguration(),
- cacheableDataManager, null, null, null, (ValueFactoryImpl)valueFactory, null, repositoryService, new FileCleanerHolder());
-
- // restore single -> single
- initializer.restoreTables(conn, 0, false, workspaceEntry.getLockManager(), url.getFile());
- initializer.restoreTables(conn, 1, false, workspaceEntry.getLockManager(), url.getFile());
- initializer.restoreTables(conn, 2, false, workspaceEntry.getLockManager(), url.getFile());
-
- st.execute("ALTER TABLE JCR_SITEM ADD CONSTRAINT JCR_FK_SITEM_PARENT FOREIGN KEY(PARENT_ID) REFERENCES JCR_SITEM(ID)");
- conn.commit();
+ repositoryService.getRepository("db1").configWorkspace(newEntry);
+ repositoryService.getRepository("db1").createWorkspace(newEntry.getName());
}
+
+ break;
}
}
}
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/TesterRdbmsWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/TesterRdbmsWorkspaceInitializer.java 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/impl/core/TesterRdbmsWorkspaceInitializer.java 2011-01-11 12:13:15 UTC (rev 3789)
@@ -20,11 +20,9 @@
import org.exoplatform.services.jcr.RepositoryService;
import org.exoplatform.services.jcr.access.AccessManager;
-import org.exoplatform.services.jcr.config.LockManagerEntry;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.RepositoryEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.ext.backup.impl.rdbms.RDBMSBackupInfoReader;
import org.exoplatform.services.jcr.ext.backup.impl.rdbms.RdbmsWorkspaceInitializer;
import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeManagerImpl;
import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
@@ -32,8 +30,6 @@
import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
import java.io.IOException;
-import java.sql.Connection;
-import java.sql.SQLException;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
@@ -72,13 +68,10 @@
super.restoreIndex();
}
- public void restoreTables(Connection jdbcConn, int tableType, boolean isMultiDB, LockManagerEntry lockManagerEntry,
- String storageDir) throws RepositoryConfigurationException, IOException, SQLException
+ @Override
+ public void fullRdbmsRestore() throws RepositoryException
{
- RDBMSBackupInfoReader backupInfo = new RDBMSBackupInfoReader(storageDir);
- RestoreTableHelper helper = new RestoreTableHelper(tableType, isMultiDB, backupInfo);
-
- super.restoreTable(jdbcConn, helper);
+ super.fullRdbmsRestore();
}
}
Modified: jcr/trunk/exo.jcr.component.ext/src/test/resources/test.policy
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/resources/test.policy 2011-01-10 14:57:58 UTC (rev 3788)
+++ jcr/trunk/exo.jcr.component.ext/src/test/resources/test.policy 2011-01-11 12:13:15 UTC (rev 3789)
@@ -11,6 +11,7 @@
permission java.lang.RuntimePermission "manageRepository";
permission java.lang.RuntimePermission "invokeInternalAPI";
permission java.lang.RuntimePermission "accessRPCService";
+ permission java.lang.RuntimePermission "backupRestoreOperations";
permission java.lang.RuntimePermission "modifyConversationState";
};
13 years, 5 months
exo-jcr SVN: r3788 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-01-10 09:57:58 -0500 (Mon, 10 Jan 2011)
New Revision: 3788
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
Log:
EXOJCR-1145: IndexMerger in RO mode is not aware of new indexes
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-01-10 14:25:41 UTC (rev 3787)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-01-10 14:57:58 UTC (rev 3788)
@@ -266,8 +266,38 @@
removeDeletable();
// initialize IndexMerger
- merger = doInitIndexMerger();
+ // initialize IndexMerger
+ IndexMerger merger = new IndexMerger(this);
+ merger.setMaxMergeDocs(handler.getMaxMergeDocs());
+ merger.setMergeFactor(handler.getMergeFactor());
+ merger.setMinMergeDocs(handler.getMinMergeDocs());
+ // copy current index names
+ Set<String> currentNames = new HashSet<String>(indexNames.getNames());
+
+ // open persistent indexes
+ for (String name : currentNames)
+ {
+ // only open if it still exists
+ // it is possible that indexNames still contains a name for
+ // an index that has been deleted, but indexNames has not been
+ // written to disk.
+ if (!directoryManager.hasDirectory(name))
+ {
+ log.debug("index does not exist anymore: " + name);
+ // move on to next index
+ continue;
+ }
+ PersistentIndex index =
+ new PersistentIndex(name, handler.getTextAnalyzer(), handler.getSimilarity(), cache, indexingQueue,
+ directoryManager);
+ index.setMaxFieldLength(handler.getMaxFieldLength());
+ index.setUseCompoundFile(handler.getUseCompoundFile());
+ index.setTermInfosIndexDivisor(handler.getTermInfosIndexDivisor());
+ indexes.add(index);
+ merger.indexAdded(index.getName(), index.getNumDocuments());
+ }
+
// this method is run in privileged mode internally
IndexingQueueStore store = new IndexingQueueStore(indexDir);
@@ -1154,38 +1184,19 @@
// -------------------------< internal >-------------------------------------
+ /**
+ * Initialize IndexMerger.
+ */
private IndexMerger doInitIndexMerger() throws IOException
{
- // initialize IndexMerger
IndexMerger merger = new IndexMerger(this);
merger.setMaxMergeDocs(handler.getMaxMergeDocs());
merger.setMergeFactor(handler.getMergeFactor());
merger.setMinMergeDocs(handler.getMinMergeDocs());
- // copy current index names
- Set<String> currentNames = new HashSet<String>(indexNames.getNames());
-
- // open persistent indexes
- for (String name : currentNames)
+ for (Object index : indexes)
{
- // only open if it still exists
- // it is possible that indexNames still contains a name for
- // an index that has been deleted, but indexNames has not been
- // written to disk.
- if (!directoryManager.hasDirectory(name))
- {
- log.debug("index does not exist anymore: " + name);
- // move on to next index
- continue;
- }
- PersistentIndex index =
- new PersistentIndex(name, handler.getTextAnalyzer(), handler.getSimilarity(), cache, indexingQueue,
- directoryManager);
- index.setMaxFieldLength(handler.getMaxFieldLength());
- index.setUseCompoundFile(handler.getUseCompoundFile());
- index.setTermInfosIndexDivisor(handler.getTermInfosIndexDivisor());
- indexes.add(index);
- merger.indexAdded(index.getName(), index.getNumDocuments());
+ merger.indexAdded(((PersistentIndex)index).getName(), ((PersistentIndex)index).getNumDocuments());
}
return merger;
13 years, 5 months
exo-jcr SVN: r3787 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-01-10 09:25:41 -0500 (Mon, 10 Jan 2011)
New Revision: 3787
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
Log:
EXOJCR-1145: IndexMerger in RO mode is not aware of new indexes
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-01-10 12:38:21 UTC (rev 3786)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-01-10 14:25:41 UTC (rev 3787)
@@ -173,7 +173,7 @@
/**
* The <code>IndexMerger</code> for this <code>MultiIndex</code>.
*/
- private final IndexMerger merger;
+ private IndexMerger merger;
/**
* Timer to schedule flushes of this index after some idle time.
@@ -266,42 +266,14 @@
removeDeletable();
// initialize IndexMerger
- merger = new IndexMerger(this);
- merger.setMaxMergeDocs(handler.getMaxMergeDocs());
- merger.setMergeFactor(handler.getMergeFactor());
- merger.setMinMergeDocs(handler.getMinMergeDocs());
+ merger = doInitIndexMerger();
// this method is run in privileged mode internally
IndexingQueueStore store = new IndexingQueueStore(indexDir);
// initialize indexing queue
this.indexingQueue = new IndexingQueue(store);
- // copy current index names
- Set<String> currentNames = new HashSet<String>(indexNames.getNames());
- // open persistent indexes
- for (String name : currentNames)
- {
- // only open if it still exists
- // it is possible that indexNames still contains a name for
- // an index that has been deleted, but indexNames has not been
- // written to disk.
- if (!directoryManager.hasDirectory(name))
- {
- log.debug("index does not exist anymore: " + name);
- // move on to next index
- continue;
- }
- PersistentIndex index =
- new PersistentIndex(name, handler.getTextAnalyzer(), handler.getSimilarity(), cache, indexingQueue,
- directoryManager);
- index.setMaxFieldLength(handler.getMaxFieldLength());
- index.setUseCompoundFile(handler.getUseCompoundFile());
- index.setTermInfosIndexDivisor(handler.getTermInfosIndexDivisor());
- indexes.add(index);
- merger.indexAdded(index.getName(), index.getNumDocuments());
- }
-
// init volatile index
resetVolatileIndex();
@@ -1180,9 +1152,45 @@
});
}
- // -------------------------< internal
- // >-------------------------------------
+ // -------------------------< internal >-------------------------------------
+ private IndexMerger doInitIndexMerger() throws IOException
+ {
+ // initialize IndexMerger
+ IndexMerger merger = new IndexMerger(this);
+ merger.setMaxMergeDocs(handler.getMaxMergeDocs());
+ merger.setMergeFactor(handler.getMergeFactor());
+ merger.setMinMergeDocs(handler.getMinMergeDocs());
+
+ // copy current index names
+ Set<String> currentNames = new HashSet<String>(indexNames.getNames());
+
+ // open persistent indexes
+ for (String name : currentNames)
+ {
+ // only open if it still exists
+ // it is possible that indexNames still contains a name for
+ // an index that has been deleted, but indexNames has not been
+ // written to disk.
+ if (!directoryManager.hasDirectory(name))
+ {
+ log.debug("index does not exist anymore: " + name);
+ // move on to next index
+ continue;
+ }
+ PersistentIndex index =
+ new PersistentIndex(name, handler.getTextAnalyzer(), handler.getSimilarity(), cache, indexingQueue,
+ directoryManager);
+ index.setMaxFieldLength(handler.getMaxFieldLength());
+ index.setUseCompoundFile(handler.getUseCompoundFile());
+ index.setTermInfosIndexDivisor(handler.getTermInfosIndexDivisor());
+ indexes.add(index);
+ merger.indexAdded(index.getName(), index.getNumDocuments());
+ }
+
+ return merger;
+ }
+
/**
* Enqueues unused segments for deletion in {@link #deletable}. This method
* does not synchronize on {@link #deletable}! A caller must ensure that it
@@ -2501,6 +2509,7 @@
{
// try to stop merger in safe way
merger.dispose();
+
flushTask.cancel();
FLUSH_TIMER.purge();
this.redoLog = null;
@@ -2532,7 +2541,9 @@
attemptDelete();
// now that we are ready, start index merger
+ merger = doInitIndexMerger();
merger.start();
+
if (redoLogApplied)
{
// wait for the index merge to finish pending jobs
13 years, 5 months