[exo-jcr-commits] exo-jcr SVN: r5471 - in jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl: clean/rdbms and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Jan 17 10:19:39 EST 2012
Author: tolusha
Date: 2012-01-17 10:19:38 -0500 (Tue, 17 Jan 2012)
New Revision: 5471
Added:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/DB2CleaningScipts.java
Removed:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/DB2CleanScipts.java
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestore.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanService.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanerTool.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DummyDBCleanerTool.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/DBCleaningScripts.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/DBCleaningScriptsFactory.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/MySQLCleaningScipts.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/OracleCleaningScipts.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/SybaseCleaningScipts.java
Log:
EXOJCR-1707: Refactoring DBCleanService, Fix cleaning scripts
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestore.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestore.java 2012-01-17 14:06:21 UTC (rev 5470)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestore.java 2012-01-17 15:19:38 UTC (rev 5471)
@@ -20,6 +20,7 @@
import org.exoplatform.commons.utils.PrivilegedFileHelper;
import org.exoplatform.commons.utils.PrivilegedSystemHelper;
+import org.exoplatform.services.database.utils.DialectConstants;
import org.exoplatform.services.database.utils.DialectDetecter;
import org.exoplatform.services.database.utils.JDBCUtils;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
@@ -126,6 +127,8 @@
*/
protected List<String> successfulExecuted;
+ protected boolean dbCleanerInAutoCommit;
+
/**
* Constructor DBRestore.
*
@@ -147,6 +150,7 @@
this.tables = tables;
this.dbCleaner = dbCleaner;
this.dialect = DialectDetecter.detect(jdbcConn.getMetaData());
+ this.dbCleanerInAutoCommit = dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_SYBASE);
}
/**
@@ -197,6 +201,7 @@
try
{
dbCleaner.commit();
+
jdbcConn.commit();
}
catch (SQLException e)
@@ -219,6 +224,7 @@
jdbcConn.rollback();
dbCleaner.rollback();
+
jdbcConn.commit();
}
catch (SQLException e)
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanService.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanService.java 2012-01-17 14:06:21 UTC (rev 5470)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanService.java 2012-01-17 15:19:38 UTC (rev 5471)
@@ -170,10 +170,11 @@
}
String dialect = resolveDialect(wsEntry);
+ boolean autoCommit = dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_SYBASE);
DBCleaningScripts scripts = DBCleaningScriptsFactory.prepareScripts(dialect, rEntry);
- return new DBCleanerTool(jdbcConn, scripts.getCleaningScripts(), scripts.getCommittingScripts(),
+ return new DBCleanerTool(jdbcConn, autoCommit, scripts.getCleaningScripts(), scripts.getCommittingScripts(),
scripts.getRollbackingScripts());
}
@@ -195,10 +196,11 @@
boolean multiDb = getMultiDbParameter(wsEntry);
String dialect = resolveDialect(wsEntry);
+ boolean autoCommit = dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_SYBASE);
DBCleaningScripts scripts = DBCleaningScriptsFactory.prepareScripts(dialect, wsEntry);
- return new DBCleanerTool(jdbcConn, scripts.getCleaningScripts(), scripts.getCommittingScripts(),
+ return new DBCleanerTool(jdbcConn, autoCommit, scripts.getCleaningScripts(), scripts.getCommittingScripts(),
scripts.getRollbackingScripts());
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanerTool.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanerTool.java 2012-01-17 14:06:21 UTC (rev 5470)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanerTool.java 2012-01-17 15:19:38 UTC (rev 5471)
@@ -45,6 +45,8 @@
protected final Connection connection;
+ protected final boolean autoCommit;
+
protected final List<String> rollbackingScripts = new ArrayList<String>();
protected final List<String> committingScripts = new ArrayList<String>();
@@ -57,11 +59,14 @@
* @param connection
* connection to database which will be used in cleaning, take in account DBCleanerTool does not
* close connection
+ * @param autoCommit
+ * auto commit mode which will be set during script execution
*/
- DBCleanerTool(Connection connection, Collection<String> cleaningScripts, Collection<String> committingScripts,
- Collection<String> rollbackingScripts)
+ DBCleanerTool(Connection connection, boolean autoCommit, Collection<String> cleaningScripts,
+ Collection<String> committingScripts, Collection<String> rollbackingScripts)
{
this.connection = connection;
+ this.autoCommit = autoCommit;
this.cleaningScripts.addAll(cleaningScripts);
this.committingScripts.addAll(committingScripts);
@@ -86,7 +91,7 @@
}
catch (SQLException e)
{
- throw new DBCleanException(e);
+ throw new DBCleanException(JDBCUtils.getFullMessage(e), e);
}
}
@@ -108,7 +113,7 @@
}
catch (SQLException e)
{
- throw new DBCleanException(e);
+ throw new DBCleanException(JDBCUtils.getFullMessage(e), e);
}
}
@@ -129,7 +134,7 @@
}
catch (SQLException e)
{
- throw new DBCleanException(e);
+ throw new DBCleanException(JDBCUtils.getFullMessage(e), e);
}
}
@@ -142,7 +147,7 @@
}
/**
- * Execute script on database.
+ * Execute script on database. Set auto commit mode if needed.
*
* @param scripts
* the scripts for execution
@@ -150,10 +155,14 @@
*/
protected void execute(List<String> scripts) throws SQLException
{
- SecurityManager security = System.getSecurityManager();
- if (security != null)
+ SecurityHelper
+ .validateSecurityPermissions(new RuntimePermission[]{JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION});
+
+ // set needed auto commit mode
+ boolean autoCommit = connection.getAutoCommit();
+ if (autoCommit != this.autoCommit)
{
- security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
+ connection.setAutoCommit(this.autoCommit);
}
Statement st = connection.createStatement();
@@ -183,18 +192,32 @@
{
LOG.error("Can't close the Statement." + e);
}
+
+ // restore previous auto commit mode
+ if (autoCommit != this.autoCommit)
+ {
+ connection.setAutoCommit(autoCommit);
+ }
}
}
protected void executeQuery(final Statement statement, final String sql) throws SQLException
{
- SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Object>()
+ try
{
- public Object run() throws Exception
+ SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Object>()
{
- statement.executeUpdate(sql);
- return null;
- }
- });
+ public Object run() throws Exception
+ {
+ statement.executeUpdate(sql);
+ return null;
+ }
+ });
+ }
+ catch (SQLException e)
+ {
+ LOG.error("Query execution \"" + sql + "\" failed");
+ throw e;
+ }
}
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DummyDBCleanerTool.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DummyDBCleanerTool.java 2012-01-17 14:06:21 UTC (rev 5470)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DummyDBCleanerTool.java 2012-01-17 15:19:38 UTC (rev 5471)
@@ -34,7 +34,7 @@
*/
public DummyDBCleanerTool()
{
- super(null, new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>());
+ super(null, false, new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>());
}
/**
Deleted: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/DB2CleanScipts.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/DB2CleanScipts.java 2012-01-17 14:06:21 UTC (rev 5470)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/DB2CleanScipts.java 2012-01-17 15:19:38 UTC (rev 5471)
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) 2012 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.clean.rdbms.scripts;
-
-import org.exoplatform.services.jcr.config.RepositoryEntry;
-import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanException;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * @author <a href="abazko at exoplatform.com">Anatoliy Bazko</a>
- * @version $Id: DB2DBCleanScipts.java 34360 2009-07-22 23:58:59Z tolusha $
- */
-public class DB2CleanScipts extends DBCleaningScripts
-{
-
- /**
- * DB2CleanScipts constructor.
- */
- public DB2CleanScipts(String dialect, RepositoryEntry rEntry) throws DBCleanException
- {
- super(dialect, rEntry);
-
- prepareDroppingTablesApproachScripts();
- }
-
- /**
- * DB2CleanScipts constructor.
- */
- public DB2CleanScipts(String dialect, WorkspaceEntry wEntry) throws DBCleanException
- {
- super(dialect, wEntry);
-
- if (multiDb)
- {
- prepareDroppingTablesApproachScripts();
- }
- else
- {
- prepareSimpleCleaningApproachScripts();
- }
- }
-
- /**
- * {@inheritDoc}
- */
- protected Collection<String> getConstraintRemovingScripts()
- {
- List<String> scripts = new ArrayList<String>();
-
- String constraintName = "JCR_FK_" + tablePrefix + "ITEM_PAREN";
- scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM DROP CONSTRAINT " + constraintName);
-
- return scripts;
- }
-
- /**
- * {@inheritDoc}
- */
- protected Collection<String> getConstraintAddingScripts()
- {
- List<String> scripts = new ArrayList<String>();
-
- String constraintName =
- "JCR_FK_" + tablePrefix + "ITEM_PAREN FOREIGN KEY(PARENT_ID) REFERENCES JCR_" + tablePrefix + "ITEM(ID)";
- scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM ADD CONSTRAINT" + constraintName);
-
- return scripts;
- }
-
- /**
- * {@inheritDoc}
- */
- protected void prepareSimpleCleaningApproachScripts()
- {
- super.prepareSimpleCleaningApproachScripts();
-
- rollbackingScripts.clear();
- }
-}
Added: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/DB2CleaningScipts.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/DB2CleaningScipts.java (rev 0)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/DB2CleaningScipts.java 2012-01-17 15:19:38 UTC (rev 5471)
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2012 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.clean.rdbms.scripts;
+
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanException;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author <a href="abazko at exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: DB2DBCleanScipts.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class DB2CleaningScipts extends DBCleaningScripts
+{
+
+ /**
+ * DB2CleaningScipts constructor.
+ */
+ public DB2CleaningScipts(String dialect, RepositoryEntry rEntry) throws DBCleanException
+ {
+ super(dialect, rEntry);
+
+ prepareDroppingTablesApproachScripts();
+ }
+
+ /**
+ * DB2CleaningScipts constructor.
+ */
+ public DB2CleaningScipts(String dialect, WorkspaceEntry wEntry) throws DBCleanException
+ {
+ super(dialect, wEntry);
+
+ if (multiDb)
+ {
+ prepareDroppingTablesApproachScripts();
+ }
+ else
+ {
+ prepareSimpleCleaningApproachScripts();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Collection<String> getFKRemovingScripts()
+ {
+ List<String> scripts = new ArrayList<String>();
+
+ String constraintName = "JCR_FK_" + tablePrefix + "ITEM_PAREN";
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM DROP CONSTRAINT " + constraintName);
+
+ return scripts;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Collection<String> getFKAddingScripts()
+ {
+ List<String> scripts = new ArrayList<String>();
+
+ String constraintName =
+ "JCR_FK_" + tablePrefix + "ITEM_PAREN FOREIGN KEY(PARENT_ID) REFERENCES JCR_" + tablePrefix + "ITEM(ID)";
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM ADD CONSTRAINT " + constraintName);
+
+ return scripts;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void prepareSimpleCleaningApproachScripts()
+ {
+ super.prepareSimpleCleaningApproachScripts();
+
+ rollbackingScripts.clear();
+ }
+}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/DBCleaningScripts.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/DBCleaningScripts.java 2012-01-17 14:06:21 UTC (rev 5470)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/DBCleaningScripts.java 2012-01-17 15:19:38 UTC (rev 5471)
@@ -116,14 +116,16 @@
{
cleaningScripts.addAll(getTablesRenamingScripts());
cleaningScripts.addAll(getDBInitializationScripts());
- cleaningScripts.addAll(getConstraintRemovingScripts());
+ cleaningScripts.addAll(getFKRemovingScripts());
+ cleaningScripts.addAll(getConstraintsRemovingScripts());
cleaningScripts.addAll(getIndexesDroppingScripts());
committingScripts.addAll(getOldTablesDroppingScripts());
committingScripts.addAll(getIndexesAddingScripts());
- committingScripts.addAll(getConstraintAddingScripts());
+ committingScripts.addAll(getConstraintsAddingScripts());
+ committingScripts.addAll(getFKAddingScripts());
- rollbackingScripts.addAll(getTableDroppingScripts());
+ rollbackingScripts.addAll(getTablesDroppingScripts());
rollbackingScripts.addAll(getOldTablesRenamingScripts());
}
@@ -134,13 +136,13 @@
*/
protected void prepareDroppingTablesApproachScripts() throws DBCleanException
{
- cleaningScripts.addAll(getTableDroppingScripts());
+ cleaningScripts.addAll(getTablesDroppingScripts());
cleaningScripts.addAll(getDBInitializationScripts());
- cleaningScripts.addAll(getConstraintRemovingScripts());
+ cleaningScripts.addAll(getFKRemovingScripts());
cleaningScripts.addAll(getIndexesDroppingScripts());
committingScripts.addAll(getIndexesAddingScripts());
- committingScripts.addAll(getConstraintAddingScripts());
+ committingScripts.addAll(getFKAddingScripts());
}
/**
@@ -148,15 +150,31 @@
*/
protected void prepareSimpleCleaningApproachScripts()
{
- cleaningScripts.addAll(getConstraintRemovingScripts());
+ cleaningScripts.addAll(getFKRemovingScripts());
cleaningScripts.addAll(getSingleDbWorkspaceCleaningScripts());
- committingScripts.addAll(getConstraintAddingScripts());
+ committingScripts.addAll(getFKAddingScripts());
- rollbackingScripts.addAll(getConstraintAddingScripts());
+ rollbackingScripts.addAll(getFKAddingScripts());
}
/**
+ * Returns SQL scripts for adding constraints.
+ */
+ protected Collection<String> getConstraintsAddingScripts()
+ {
+ return new ArrayList<String>();
+ }
+
+ /**
+ * Returns SQL scripts for removing constraints.
+ */
+ protected Collection<String> getConstraintsRemovingScripts()
+ {
+ return new ArrayList<String>();
+ }
+
+ /**
* Returns SQL scripts for renaming new JCR tables to new ones.
*/
protected Collection<String> getOldTablesRenamingScripts()
@@ -191,9 +209,9 @@
}
/**
- * Returns SQL scripts for removing constraint.
+ * Returns SQL scripts for removing FK on JCR_ITEM table.
*/
- protected Collection<String> getConstraintRemovingScripts()
+ protected Collection<String> getFKRemovingScripts()
{
List<String> scripts = new ArrayList<String>();
@@ -204,9 +222,9 @@
}
/**
- * Returns SQL scripts for adding constraint.
+ * Returns SQL scripts for adding FK on JCR_ITEM table.
*/
- protected Collection<String> getConstraintAddingScripts()
+ protected Collection<String> getFKAddingScripts()
{
List<String> scripts = new ArrayList<String>();
@@ -234,7 +252,7 @@
/**
* Returns SQL scripts for dropping existed JCR tables.
*/
- protected Collection<String> getTableDroppingScripts()
+ protected Collection<String> getTablesDroppingScripts()
{
List<String> scripts = new ArrayList<String>();
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/DBCleaningScriptsFactory.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/DBCleaningScriptsFactory.java 2012-01-17 14:06:21 UTC (rev 5470)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/DBCleaningScriptsFactory.java 2012-01-17 15:19:38 UTC (rev 5471)
@@ -44,7 +44,7 @@
else if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_DB2)
|| dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_DB2V8))
{
- return new DB2CleanScipts(dialect, wsEntry);
+ return new DB2CleaningScipts(dialect, wsEntry);
}
else if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_MSSQL))
{
@@ -88,7 +88,7 @@
else if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_DB2)
|| dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_DB2V8))
{
- return new DB2CleanScipts(dialect, rEntry);
+ return new DB2CleaningScipts(dialect, rEntry);
}
else if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_MSSQL))
{
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/MySQLCleaningScipts.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/MySQLCleaningScipts.java 2012-01-17 14:06:21 UTC (rev 5470)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/MySQLCleaningScipts.java 2012-01-17 15:19:38 UTC (rev 5471)
@@ -74,8 +74,8 @@
cleaningScripts.addAll(getIndexesDroppingScripts());
String constraintName =
- "JCR_FK_" + tablePrefix + "VALUE_PROPERTY FOREIGN KEY(PROPERTY_ID) REFERENCES JCR_" + multiDb + "ITEM(ID)";
- committingScripts.add("ALTER TABLE JCR_" + multiDb + "VALUE ADD CONSTRAINT " + constraintName);
+ "JCR_FK_" + tablePrefix + "VALUE_PROPERTY FOREIGN KEY(PROPERTY_ID) REFERENCES JCR_" + tablePrefix + "ITEM(ID)";
+ committingScripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE ADD CONSTRAINT " + constraintName);
}
/**
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/OracleCleaningScipts.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/OracleCleaningScipts.java 2012-01-17 14:06:21 UTC (rev 5470)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/OracleCleaningScipts.java 2012-01-17 15:19:38 UTC (rev 5471)
@@ -63,37 +63,48 @@
}
/**
+ * R{@inheritDoc}
+ */
+ protected Collection<String> getConstraintsAddingScripts()
+ {
+ Collection<String> scripts = new ArrayList<String>();
+
+ String constraintName = "JCR_PK_" + tablePrefix + "VALUE PRIMARY KEY(ID)";
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE ADD CONSTRAINT " + constraintName);
+
+ constraintName = "JCR_PK_" + tablePrefix + "ITEM PRIMARY KEY(ID)";
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM ADD CONSTRAINT " + constraintName);
+
+ constraintName =
+ "JCR_FK_" + tablePrefix + "VALUE_PROPERTY FOREIGN KEY(PROPERTY_ID) REFERENCES JCR_" + tablePrefix + "ITEM(ID)";
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE ADD CONSTRAINT " + constraintName);
+
+ constraintName = "JCR_PK_" + tablePrefix + "REF PRIMARY KEY(NODE_ID, PROPERTY_ID, ORDER_NUM)";
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "REF ADD CONSTRAINT " + constraintName);
+
+ return scripts;
+ }
+
+ /**
* {@inheritDoc}
*/
- protected void prepareRenamingApproachScripts() throws DBCleanException
+ protected Collection<String> getConstraintsRemovingScripts()
{
- super.prepareRenamingApproachScripts();
+ Collection<String> scripts = new ArrayList<String>();
String constraintName = "JCR_PK_" + tablePrefix + "VALUE";
- cleaningScripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE DROP CONSTRAINT " + constraintName);
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE DROP CONSTRAINT " + constraintName);
constraintName = "JCR_FK_" + tablePrefix + "VALUE_PROPERTY";
- cleaningScripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE DROP CONSTRAINT " + constraintName);
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE DROP CONSTRAINT " + constraintName);
constraintName = "JCR_PK_" + tablePrefix + "ITEM";
- cleaningScripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM DROP CONSTRAINT " + constraintName);
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM DROP CONSTRAINT " + constraintName);
constraintName = "JCR_PK_" + tablePrefix + "REF";
- cleaningScripts.add("ALTER TABLE JCR_" + tablePrefix + "REF DROP CONSTRAINT " + constraintName);
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "REF DROP CONSTRAINT " + constraintName);
- constraintName = "JCR_PK_" + tablePrefix + "VALUE PRIMARY KEY(ID)";
- committingScripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE ADD CONSTRAINT " + constraintName);
-
- constraintName = "JCR_PK_" + tablePrefix + "ITEM PRIMARY KEY(ID)";
- committingScripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM ADD CONSTRAINT " + constraintName);
-
- constraintName =
- "JCR_FK_" + multiDb + "VALUE_PROPERTY FOREIGN KEY(PROPERTY_ID) REFERENCES JCR_" + tablePrefix + "ITEM(ID)";
- committingScripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE ADD CONSTRAINT " + constraintName);
-
- constraintName = "JCR_PK_" + tablePrefix + "REF PRIMARY KEY(NODE_ID, PROPERTY_ID, ORDER_NUM)";
- committingScripts.add("ALTER TABLE JCR_" + tablePrefix + "REF ADD CONSTRAINT " + constraintName);
-
+ return scripts;
}
/**
@@ -146,22 +157,39 @@
/**
* {@inheritDoc}
*/
- protected Collection<String> getTableDroppingScripts()
+ protected Collection<String> getTablesDroppingScripts()
{
- Collection<String> scripts = super.getTableDroppingScripts();
+ Collection<String> scripts = new ArrayList<String>();
scripts.add("DROP TRIGGER BI_JCR_" + tablePrefix + "VALUE");
scripts.add("DROP SEQUENCE JCR_" + tablePrefix + "VALUE_SEQ");
+ scripts.addAll(super.getTablesDroppingScripts());
+
return scripts;
}
/**
* {@inheritDoc}
*/
+ protected Collection<String> getOldTablesDroppingScripts()
+ {
+ Collection<String> scripts = new ArrayList<String>();
+
+ scripts.add("DROP TRIGGER BI_JCR_" + tablePrefix + "VALUE_OLD");
+ scripts.add("DROP SEQUENCE JCR_" + tablePrefix + "VALUE_SEQ_OLD");
+
+ scripts.addAll(super.getOldTablesDroppingScripts());
+
+ return scripts;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
protected Collection<String> getTablesRenamingScripts()
{
- Collection<String> scripts = super.getTableDroppingScripts();
+ Collection<String> scripts = new ArrayList<String>();
// JCR_VALUE
scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE RENAME TO JCR_" + tablePrefix + "VALUE_OLD");
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/SybaseCleaningScipts.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/SybaseCleaningScipts.java 2012-01-17 14:06:21 UTC (rev 5470)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/SybaseCleaningScipts.java 2012-01-17 15:19:38 UTC (rev 5471)
@@ -65,28 +65,40 @@
/**
* {@inheritDoc}
*/
- protected void prepareRenamingApproachScripts() throws DBCleanException
+ protected Collection<String> getConstraintsAddingScripts()
{
- super.prepareRenamingApproachScripts();
+ Collection<String> scripts = new ArrayList<String>();
+ String constraintName = "JCR_PK_" + tablePrefix + "ITEM PRIMARY KEY(ID)";
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM ADD CONSTRAINT " + constraintName);
+
+ constraintName = "JCR_PK_" + tablePrefix + "VALUE PRIMARY KEY(ID)";
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE ADD CONSTRAINT " + constraintName);
+
+ constraintName =
+ "JCR_FK_" + tablePrefix + "VALUE_PROPERTY FOREIGN KEY(PROPERTY_ID) REFERENCES JCR_" + tablePrefix + "ITEM(ID)";
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE ADD CONSTRAINT " + constraintName);
+
+ return scripts;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Collection<String> getConstraintsRemovingScripts()
+ {
+ Collection<String> scripts = new ArrayList<String>();
+
String constraintName = "JCR_FK_" + tablePrefix + "VALUE_PROPERTY";
- cleaningScripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE DROP CONSTRAINT " + constraintName);
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE DROP CONSTRAINT " + constraintName);
constraintName = "JCR_PK_" + tablePrefix + "ITEM";
- cleaningScripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM DROP CONSTRAINT " + constraintName);
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM DROP CONSTRAINT " + constraintName);
constraintName = "JCR_PK_" + tablePrefix + "VALUE";
- cleaningScripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE DROP CONSTRAINT " + constraintName);
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE DROP CONSTRAINT " + constraintName);
- constraintName = "JCR_PK_" + tablePrefix + "ITEM PRIMARY KEY(ID)";
- committingScripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM ADD CONSTRAINT " + constraintName);
-
- constraintName = "JCR_PK_" + tablePrefix + "VALUE PRIMARY KEY(ID)";
- committingScripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE ADD CONSTRAINT " + constraintName);
-
- constraintName =
- "JCR_FK_" + tablePrefix + "VALUE_PROPERTY FOREIGN KEY(PROPERTY_ID) REFERENCES JCR_" + tablePrefix + "ITEM(ID)";
- committingScripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE ADD CONSTRAINT " + constraintName);
+ return scripts;
}
/**
@@ -114,16 +126,16 @@
try
{
- scripts.add(DBInitializerHelper.getObjectScript("CREATE UNIQUE INDEX JCR_IDX_" + tablePrefix
- + "ITEM_PARENT ON JCR_" + tablePrefix + "ITEM", multiDb, dialect));
- scripts.add(DBInitializerHelper.getObjectScript("CREATE UNIQUE INDEX JCR_IDX_" + multiDb
- + "ITEM_PARENT_ID ON JCR_" + tablePrefix + "ITEM", multiDb, dialect));
- scripts.add(DBInitializerHelper.getObjectScript("CREATE UNIQUE INDEX JCR_IDX_" + multiDb
- + "ITEM_N_ORDER_NUM ON JCR_" + tablePrefix + "ITEM", multiDb, dialect));
- scripts.add(DBInitializerHelper.getObjectScript("CREATE UNIQUE INDEX JCR_IDX_" + multiDb
- + "VALUE_PROPERTY ON JCR_" + tablePrefix + "VALUE", multiDb, dialect));
- scripts.add(DBInitializerHelper.getObjectScript("CREATE UNIQUE INDEX JCR_IDX_" + multiDb
- + "REF_PROPERTY ON JCR_" + tablePrefix + "REF", multiDb, dialect));
+ scripts.add(DBInitializerHelper.getObjectScript("INDEX JCR_IDX_" + tablePrefix + "ITEM_PARENT ON JCR_"
+ + tablePrefix + "ITEM", multiDb, dialect));
+ scripts.add(DBInitializerHelper.getObjectScript("INDEX JCR_IDX_" + tablePrefix + "ITEM_PARENT_ID ON JCR_"
+ + tablePrefix + "ITEM", multiDb, dialect));
+ scripts.add(DBInitializerHelper.getObjectScript("INDEX JCR_IDX_" + tablePrefix + "ITEM_N_ORDER_NUM ON JCR_"
+ + tablePrefix + "ITEM", multiDb, dialect));
+ scripts.add(DBInitializerHelper.getObjectScript("INDEX JCR_IDX_" + tablePrefix + "VALUE_PROPERTY ON JCR_"
+ + tablePrefix + "VALUE", multiDb, dialect));
+ scripts.add(DBInitializerHelper.getObjectScript("JCR_IDX_" + tablePrefix + "REF_PROPERTY ON JCR_"
+ + tablePrefix + "REF", multiDb, dialect));
}
catch (RepositoryConfigurationException e)
{
@@ -138,7 +150,7 @@
*/
protected Collection<String> getTablesRenamingScripts()
{
- Collection<String> scripts = super.getTableDroppingScripts();
+ Collection<String> scripts = new ArrayList<String>();
scripts.add("sp_rename JCR_" + tablePrefix + "VALUE, JCR_" + tablePrefix + "VALUE_OLD");
scripts.add("sp_rename JCR_" + tablePrefix + "ITEM, JCR_" + tablePrefix + "ITEM_OLD");
@@ -155,7 +167,7 @@
*/
protected Collection<String> getOldTablesRenamingScripts()
{
- Collection<String> scripts = super.getTableDroppingScripts();
+ Collection<String> scripts = new ArrayList<String>();
scripts.add("sp_rename JCR_" + tablePrefix + "VALUE_OLD, JCR_" + tablePrefix + "VALUE");
scripts.add("sp_rename JCR_" + tablePrefix + "ITEM_OLD, JCR_" + tablePrefix + "ITEM");
More information about the exo-jcr-commits
mailing list