Author: tolusha
Date: 2011-12-02 08:48:01 -0500 (Fri, 02 Dec 2011)
New Revision: 5257
Removed:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/SybaseDBRestore.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestore.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanService.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleaner.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DummyDBCleaner.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/JobExistingRepositorySameConfigRestore.java
Log:
EXOJCR-1603: moved setAutoCommit(true) for Sybase db from DBCleanerService to DBCleaner
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestore.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestore.java 2011-12-02
13:29:16 UTC (rev 5256)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestore.java 2011-12-02
13:48:01 UTC (rev 5257)
@@ -126,15 +126,15 @@
protected List<String> successfulExecuted;
/**
- * Constructor DBRestor.
+ * Constructor DBRestore.
*
* @throws NamingException
* @throws SQLException
* @throws RepositoryConfigurationException
*/
public DBRestore(File storageDir, Connection jdbcConn, Map<String,
RestoreTableRule> tables,
- WorkspaceEntry wsConfig, FileCleaner fileCleaner, DBCleaner dbCleaner) throws
NamingException, SQLException,
- RepositoryConfigurationException
+ WorkspaceEntry wsConfig, FileCleaner fileCleaner, DBCleaner dbCleaner) throws
NamingException,
+ SQLException, RepositoryConfigurationException
{
this.jdbcConn = jdbcConn;
this.fileCleaner = fileCleaner;
@@ -565,6 +565,11 @@
*/
protected void commitBatch() throws SQLException
{
+ // commit every batch for sybase
+ if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE))
+ {
+ jdbcConn.commit();
+ }
}
/**
Deleted:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/SybaseDBRestore.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/SybaseDBRestore.java 2011-12-02
13:29:16 UTC (rev 5256)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/SybaseDBRestore.java 2011-12-02
13:48:01 UTC (rev 5257)
@@ -1,160 +0,0 @@
-/*
- * Copyright (C) 2003-2011 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.backup.rdbms;
-
-import org.exoplatform.services.database.utils.ExceptionManagementHelper;
-import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
-import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.impl.backup.BackupException;
-import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleaner;
-import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
-
-import java.io.File;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.Map;
-
-import javax.naming.NamingException;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * <br/>Date: 2011
- *
- * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex
Reshetnyak</a>
- * @version $Id: SybaseDBRestore.java 111 2011-11-11 11:11:11Z rainf0x $
- */
-public class SybaseDBRestore extends DBRestore
-{
- private final Boolean isMultiDb;
-
- /**
- * Constructor SybaseDBRestore.
- */
- public SybaseDBRestore(File storageDir, Connection jdbcConn, Map<String,
RestoreTableRule> tables,
- WorkspaceEntry wsConfig, FileCleaner fileCleaner, DBCleaner dbCleaner) throws
NamingException, SQLException,
- RepositoryConfigurationException
- {
- super(storageDir, jdbcConn, tables, wsConfig, fileCleaner, dbCleaner);
- this.isMultiDb = tables.entrySet().iterator().next().getValue().getDstMultiDb();
- }
-
- /**
- * {@inheritDoc}
- */
- public void clean() throws BackupException
- {
- try
- {
- // the Sybase is not allowed DDL query (CREATE TABLE, DROP TABLE, etc. ) within
a multi-statement transaction
- if (!jdbcConn.getAutoCommit())
- {
- jdbcConn.setAutoCommit(true);
- }
-
- super.clean();
- }
- catch (SQLException e)
- {
- throw new
BackupException(ExceptionManagementHelper.getFullSQLExceptionMessage(e), e);
- }
- finally
- {
- try
- {
- jdbcConn.setAutoCommit(false);
- }
- catch (SQLException e)
- {
- LOG.warn("Can't set auto commit to \"false\"", e);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void commit() throws BackupException
- {
- try
- {
- // the Sybase is not allowed DDL query (CREATE TABLE, DROP TABLE, etc. ) within
a multi-statement transaction
- if (!jdbcConn.getAutoCommit())
- {
- jdbcConn.setAutoCommit(true);
- }
-
- super.commit();
- }
- catch (SQLException e)
- {
- throw new
BackupException(ExceptionManagementHelper.getFullSQLExceptionMessage(e), e);
- }
- finally
- {
- try
- {
- jdbcConn.setAutoCommit(false);
- }
- catch (SQLException e)
- {
- LOG.warn("Can't set auto commit to \"false\"", e);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void rollback() throws BackupException
- {
- try
- {
- // the Sybase is not allowed DDL query (CREATE TABLE, DROP TABLE, etc. ) within
a multi-statement transaction
- if (!jdbcConn.getAutoCommit())
- {
- jdbcConn.setAutoCommit(true);
- }
-
- super.rollback();
- }
- catch (SQLException e)
- {
- throw new
BackupException(ExceptionManagementHelper.getFullSQLExceptionMessage(e), e);
- }
- finally
- {
- try
- {
- jdbcConn.setAutoCommit(false);
- }
- catch (SQLException e)
- {
- LOG.warn("Can't set auto commit to \"false\"", e);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- protected void commitBatch() throws SQLException
- {
- jdbcConn.commit();
- }
-}
-
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanService.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanService.java 2011-12-02
13:29:16 UTC (rev 5256)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanService.java 2011-12-02
13:48:01 UTC (rev 5257)
@@ -176,15 +176,6 @@
dialect = DialectDetecter.detect(jdbcConn.getMetaData());
}
- // Sybase doesn't allow DDL scripts inside transaction
- if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE))
- {
- if (!jdbcConn.getAutoCommit())
- {
- jdbcConn.setAutoCommit(true);
- }
- }
-
if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLE)
|| dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLEOCI)
|| dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL)
@@ -194,26 +185,26 @@
|| dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE)
|| dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_HSQLDB))
{
- ArrayList<String> dbCleanerScripts = new ArrayList<String>();
+ List<String> dbCleanerScripts = new ArrayList<String>();
dbCleanerScripts.addAll(getRenameScripts(isMultiDB, dialect));
dbCleanerScripts.addAll(getInitializationDBScripts(isMultiDB, dialect));
dbCleanerScripts.addAll(getRemoveIndexesScripts(isMultiDB, dialect));
- ArrayList<String> afterRestoreScript = new ArrayList<String>();
+ List<String> afterRestoreScript = new ArrayList<String>();
afterRestoreScript.addAll(getRemoveOldObjectsScripts(isMultiDB, dialect));
afterRestoreScript.addAll(getRestoreIndexesScripts(isMultiDB, dialect));
- return new DBCleaner(jdbcConn, dbCleanerScripts, getRollbackScripts(isMultiDB,
dialect),
- afterRestoreScript);
+ return new DBCleaner(jdbcConn, dbCleanerScripts, getRollbackScripts(isMultiDB,
dialect), afterRestoreScript,
+ dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE));
}
- ArrayList<String> dbCleanerScripts = new ArrayList<String>();
+ List<String> dbCleanerScripts = new ArrayList<String>();
dbCleanerScripts.addAll(getDropTableScripts(isMultiDB, dialect));
dbCleanerScripts.addAll(getInitializationDBScripts(isMultiDB, dialect));
dbCleanerScripts.addAll(getRemoveIndexesScripts(isMultiDB, dialect));
return new DBCleaner(jdbcConn, dbCleanerScripts, new ArrayList<String>(),
getRestoreIndexesScripts(isMultiDB,
- dialect));
+ dialect), dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE));
}
@@ -847,15 +838,6 @@
dialect = DialectDetecter.detect(jdbcConn.getMetaData());
}
- // Sybase doesn't allow DDL scripts inside transaction
- if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE))
- {
- if (!jdbcConn.getAutoCommit())
- {
- jdbcConn.setAutoCommit(true);
- }
- }
-
if (!isMultiDB)
{
boolean cleanWithHelper = false;
@@ -923,12 +905,13 @@
String deleteItems =
"delete from JCR_SITEM where I_CLASS=1 and CONTAINER_NAME='"
+ containerName + "' and PARENT_ID=?";
- return new DBCleaner(jdbcConn, cleanScripts, rollbackScripts, commitScripts,
- new RecursiveDBCleanHelper(jdbcConn, selectItems, deleteItems));
+ return new DBCleaner(jdbcConn, cleanScripts, rollbackScripts, commitScripts,
new RecursiveDBCleanHelper(
+ jdbcConn, selectItems, deleteItems),
dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE));
}
cleanScripts.add("delete from JCR_SITEM where CONTAINER_NAME='" +
containerName + "'");
- return new DBCleaner(jdbcConn, cleanScripts, rollbackScripts, commitScripts);
+ return new DBCleaner(jdbcConn, cleanScripts, rollbackScripts, commitScripts,
+ dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE));
}
else
{
@@ -949,7 +932,8 @@
commitScript.addAll(getRemoveOldObjectsScripts(isMultiDB, dialect));
commitScript.addAll(getRestoreIndexesScripts(isMultiDB, dialect));
- return new DBCleaner(jdbcConn, cleanScripts, getRollbackScripts(isMultiDB,
dialect), commitScript);
+ return new DBCleaner(jdbcConn, cleanScripts, getRollbackScripts(isMultiDB,
dialect), commitScript,
+ dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE));
}
else
{
@@ -960,7 +944,7 @@
cleanScripts.addAll(getRemoveIndexesScripts(isMultiDB, dialect));
return new DBCleaner(jdbcConn, cleanScripts, new ArrayList<String>(),
getRestoreIndexesScripts(isMultiDB,
- dialect));
+ dialect), dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE));
}
}
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleaner.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleaner.java 2011-12-02
13:29:16 UTC (rev 5256)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleaner.java 2011-12-02
13:48:01 UTC (rev 5257)
@@ -18,7 +18,6 @@
import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
-import org.exoplatform.services.jcr.impl.util.jdbc.DBInitializer;
import org.exoplatform.services.jcr.impl.util.jdbc.DBInitializerHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -29,7 +28,6 @@
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
-import java.util.regex.Pattern;
/**
* The goal of this class is removing workspace data from database.
@@ -50,11 +48,6 @@
protected final Connection connection;
/**
- * Pattern for JCR tables.
- */
- protected final Pattern dbObjectNamePattern;
-
- /**
* Common clean scripts for database.
*/
protected final List<String> cleanScripts = new ArrayList<String>();
@@ -75,17 +68,9 @@
protected final DBCleanHelper dbCleanHelper;
/**
- * DBCleaner constructor.
- *
- * @param connection
- * connection to database where workspace tables is placed
- * @param cleanScripts
- * scripts for cleaning database
+ * Idicates if executing scripts should be done in autoCommit mode.
*/
- public DBCleaner(Connection connection, List<String> cleanScripts)
- {
- this(connection, cleanScripts, null);
- }
+ protected final boolean autoCommit;
/**
* DBCleaner constructor.
@@ -93,24 +78,6 @@
* @param connection
* connection to database where workspace tables is placed
* @param cleanScripts
- * scripts for cleaning database
- * @param dbCleanHelper
- * class which help to clean database by executing special queries
- */
- public DBCleaner(Connection connection, List<String> cleanScripts, DBCleanHelper
dbCleanHelper)
- {
- this.dbObjectNamePattern = Pattern.compile(DBInitializer.SQL_OBJECTNAME,
Pattern.CASE_INSENSITIVE);
- this.connection = connection;
- this.cleanScripts.addAll(cleanScripts);
- this.dbCleanHelper = dbCleanHelper;
- }
-
- /**
- * DBCleaner constructor.
- *
- * @param connection
- * connection to database where workspace tables is placed
- * @param cleanScripts
* scripts for cleaning database
* @param rollbackScripts
* scripts for execution when something failed
@@ -118,13 +85,18 @@
* scripts for removing temporary objects
* @param dbCleanHelper
* class which help to clean database by executing special queries
+ * @param autoCommit
+ * indicates if executing scripts should be done in autoCommit mode
*/
public DBCleaner(Connection connection, List<String> cleanScripts,
List<String> rollbackScripts,
- List<String> commitScripts, DBCleanHelper cleanHelper)
+ List<String> commitScripts, DBCleanHelper dbCleanHelper, boolean autoCommit)
{
- this(connection, cleanScripts, cleanHelper);
+ this.connection = connection;
+ this.cleanScripts.addAll(cleanScripts);
this.rollbackScripts.addAll(rollbackScripts);
this.commitScripts.addAll(commitScripts);
+ this.dbCleanHelper = dbCleanHelper;
+ this.autoCommit = autoCommit;
}
/**
@@ -137,12 +109,14 @@
* @param rollbackScripts
* scripts for execution when something failed
* @param commitScripts
- * scripts for removing temporary objects
+ * scripts for removing temporary objects
+ * @param autoCommit
+ * indicates if executing scripts should be done in autoCommit mode
*/
public DBCleaner(Connection connection, List<String> cleanScripts,
List<String> rollbackScripts,
- List<String> commitScripts)
+ List<String> commitScripts, boolean autoCommit)
{
- this(connection, cleanScripts, rollbackScripts, commitScripts, null);
+ this(connection, cleanScripts, rollbackScripts, commitScripts, null, autoCommit);
}
/**
@@ -201,6 +175,14 @@
security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
}
+ // set the new autoCommit mode if need
+ // for example, the Sybase is not allowed DDL query (CREATE TABLE, DROP TABLE, etc.
) within a multi-statement transaction
+ boolean autoCommit = connection.getAutoCommit();
+ if (this.autoCommit != autoCommit)
+ {
+ connection.setAutoCommit(this.autoCommit);
+ }
+
Statement st = connection.createStatement();
try
{
@@ -228,6 +210,12 @@
{
LOG.error("Can't close the Statement." + e);
}
+
+ // restore previous autoCommit mode
+ if (this.autoCommit != autoCommit)
+ {
+ connection.setAutoCommit(autoCommit);
+ }
}
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DummyDBCleaner.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DummyDBCleaner.java 2011-12-02
13:29:16 UTC (rev 5256)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DummyDBCleaner.java 2011-12-02
13:48:01 UTC (rev 5257)
@@ -16,9 +16,8 @@
*/
package org.exoplatform.services.jcr.impl.clean.rdbms;
-import java.sql.Connection;
import java.sql.SQLException;
-import java.util.List;
+import java.util.ArrayList;
/**
* Created by The eXo Platform SAS.
@@ -34,20 +33,12 @@
/**
* DummyDBCleaner constructor.
*/
- public DummyDBCleaner(Connection connection, List<String> cleanScripts)
+ public DummyDBCleaner()
{
- super(connection, cleanScripts);
+ super(null, new ArrayList<String>(), new ArrayList<String>(), new
ArrayList<String>(), null, false);
}
/**
- * DummyDBCleaner constructor.
- */
- public DummyDBCleaner(Connection connection, List<String> cleanScripts,
DBCleanHelper dbCleanHelper)
- {
- super(connection, cleanScripts, dbCleanHelper);
- }
-
- /**
* {@inheritDoc}
*/
public void executeCleanScripts() throws SQLException
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-12-02
13:29:16 UTC (rev 5256)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2011-12-02
13:48:01 UTC (rev 5257)
@@ -38,7 +38,6 @@
import org.exoplatform.services.jcr.impl.backup.rdbms.DataRestoreContext;
import org.exoplatform.services.jcr.impl.backup.rdbms.DirectoryRestore;
import org.exoplatform.services.jcr.impl.backup.rdbms.RestoreTableRule;
-import org.exoplatform.services.jcr.impl.backup.rdbms.SybaseDBRestore;
import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanService;
import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleaner;
import
org.exoplatform.services.jcr.impl.core.lock.cacheable.AbstractCacheableLockManager;
@@ -1291,17 +1290,9 @@
dbCleaner = DBCleanService.getWorkspaceDBCleaner(jdbcConn, wsConfig);
}
- if (dbDialect == DBConstants.DB_DIALECT_SYBASE)
- {
- restorers.add(new SybaseDBRestore(storageDir, jdbcConn, tables, wsConfig,
swapCleaner, dbCleaner));
- }
- else
- {
- restorers.add(new DBRestore(storageDir, jdbcConn, tables, wsConfig,
swapCleaner, dbCleaner));
- }
+ restorers.add(new DBRestore(storageDir, jdbcConn, tables, wsConfig, swapCleaner,
dbCleaner));
// prepare value storage restorer
- File backupValueStorageDir = new File(storageDir, "values");
if (wsConfig.getContainer().getValueStorages() != null)
{
List<File> dataDirs = new ArrayList<File>();
Modified:
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingRepositorySameConfigRestore.java
===================================================================
---
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingRepositorySameConfigRestore.java 2011-12-02
13:29:16 UTC (rev 5256)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingRepositorySameConfigRestore.java 2011-12-02
13:48:01 UTC (rev 5257)
@@ -155,7 +155,7 @@
new Object[]{
fullBackupDir,
jdbcConn,
- new DummyDBCleaner(jdbcConn, new
ArrayList<String>())});
+ new DummyDBCleaner()});
}
else
{