Author: tolusha
Date: 2012-01-17 05:17:25 -0500 (Tue, 17 Jan 2012)
New Revision: 5462
Added:
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/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/HSQLDBCleaningScipts.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/MSSQLCleaningScipts.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/PgSQLCleaningScipts.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
Added:
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
(rev 0)
+++
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
10:17:25 UTC (rev 5462)
@@ -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(a)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/DBCleaningScripts.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/DBCleaningScripts.java
(rev 0)
+++
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
10:17:25 UTC (rev 5462)
@@ -0,0 +1,316 @@
+/*
+ * 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.commons.utils.IOUtil;
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
+import org.exoplatform.services.database.utils.JDBCUtils;
+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.impl.clean.rdbms.DBCleanException;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.impl.util.jdbc.DBInitializerHelper;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: DBCleanScipts.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public abstract class DBCleaningScripts
+{
+ protected final String tablePrefix;
+
+ protected final String dialect;
+
+ protected final boolean multiDb;
+
+ protected final String workspaceName;
+
+ protected final List<String> cleaningScripts = new ArrayList<String>();
+
+ protected final List<String> committingScripts = new ArrayList<String>();
+
+ protected final List<String> rollbackingScripts = new
ArrayList<String>();
+
+ /**
+ * DBCleaningScripts constructor.
+ *
+ * @throws DBCleanException
+ */
+ DBCleaningScripts(String dialect, RepositoryEntry rEntry) throws DBCleanException
+ {
+ if (getMultiDbParameter(rEntry.getWorkspaceEntries().get(0)))
+ {
+ throw new DBCleanException("Not supported operation.");
+ }
+
+ this.multiDb = false;
+ this.tablePrefix = "S";
+ this.workspaceName = null;
+ this.dialect = dialect;
+ }
+
+ /**
+ * DBCleaningScripts constructor.
+ *
+ * @throws DBCleanException
+ */
+ DBCleaningScripts(String dialect, WorkspaceEntry wsEntry) throws DBCleanException
+ {
+ this.multiDb = getMultiDbParameter(wsEntry);
+ this.tablePrefix = multiDb ? "M" : "S";
+ this.workspaceName = wsEntry.getName();
+ this.dialect = dialect;
+ }
+
+ /**
+ * Returns {@link #cleaningScripts}.
+ */
+ public Collection<String> getCleaningScripts()
+ {
+ return cleaningScripts;
+ }
+
+ /**
+ * Returns {@link #committingScripts}.
+ */
+ public Collection<String> getCommittingScripts()
+ {
+ return committingScripts;
+ }
+
+ /**
+ * Returns {@link #rollbackingScripts}.
+ */
+ public Collection<String> getRollbackingScripts()
+ {
+ return rollbackingScripts;
+ }
+
+ /**
+ * Prepares scripts for renaming approach database cleaning.
+ *
+ * @throws DBCleanException
+ */
+ protected void prepareRenamingApproachScripts() throws DBCleanException
+ {
+ cleaningScripts.addAll(getTablesRenamingScripts());
+ cleaningScripts.addAll(getDBInitializationScripts());
+ cleaningScripts.addAll(getConstraintRemovingScripts());
+ cleaningScripts.addAll(getIndexesDroppingScripts());
+
+ committingScripts.addAll(getOldTablesDroppingScripts());
+ committingScripts.addAll(getIndexesAddingScripts());
+ committingScripts.addAll(getConstraintAddingScripts());
+
+ rollbackingScripts.addAll(getTableDroppingScripts());
+ rollbackingScripts.addAll(getOldTablesRenamingScripts());
+ }
+
+ /**
+ * Prepares scripts for dropping tables approach database cleaning.
+ *
+ * @throws DBCleanException
+ */
+ protected void prepareDroppingTablesApproachScripts() throws DBCleanException
+ {
+ cleaningScripts.addAll(getTableDroppingScripts());
+ cleaningScripts.addAll(getDBInitializationScripts());
+ cleaningScripts.addAll(getConstraintRemovingScripts());
+ cleaningScripts.addAll(getIndexesDroppingScripts());
+
+ committingScripts.addAll(getIndexesAddingScripts());
+ committingScripts.addAll(getConstraintAddingScripts());
+ }
+
+ /**
+ * Prepares scripts for simple cleaning database.
+ */
+ protected void prepareSimpleCleaningApproachScripts()
+ {
+ cleaningScripts.addAll(getConstraintRemovingScripts());
+ cleaningScripts.addAll(getSingleDbWorkspaceCleaningScripts());
+
+ committingScripts.addAll(getConstraintAddingScripts());
+
+ rollbackingScripts.addAll(getConstraintAddingScripts());
+ }
+
+ /**
+ * Returns SQL scripts for renaming new JCR tables to new ones.
+ */
+ protected Collection<String> getOldTablesRenamingScripts()
+ {
+ return new ArrayList<String>();
+ }
+
+ /**
+ * Returns SQL scripts for renaming JCR tables to new ones.
+ */
+ protected Collection<String> getTablesRenamingScripts()
+ {
+ return new ArrayList<String>();
+ }
+
+ /**
+ * Returns SQL scripts for removing indexes.
+ */
+ protected Collection<String> getIndexesDroppingScripts()
+ {
+ return new ArrayList<String>();
+ }
+
+ /**
+ * Returns SQL scripts for adding indexes.
+ *
+ * @throws DBCleanException
+ */
+ protected Collection<String> getIndexesAddingScripts() throws DBCleanException
+ {
+ return new ArrayList<String>();
+ }
+
+ /**
+ * Returns SQL scripts for removing constraint.
+ */
+ protected Collection<String> getConstraintRemovingScripts()
+ {
+ List<String> scripts = new ArrayList<String>();
+
+ String constraintName = "JCR_FK_" + tablePrefix +
"ITEM_PARENT";
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM " +
constraintDroppingSyntax() + " " + constraintName);
+
+ return scripts;
+ }
+
+ /**
+ * Returns SQL scripts for adding constraint.
+ */
+ protected Collection<String> getConstraintAddingScripts()
+ {
+ List<String> scripts = new ArrayList<String>();
+
+ String constraintName =
+ "JCR_FK_" + tablePrefix + "ITEM_PARENT FOREIGN KEY(PARENT_ID)
REFERENCES JCR_" + tablePrefix + "ITEM(ID)";
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM ADD CONSTRAINT
" + constraintName);
+
+ return scripts;
+ }
+
+ /**
+ * Returns SQL scripts for dropping existed old JCR tables.
+ */
+ protected Collection<String> getOldTablesDroppingScripts()
+ {
+ List<String> scripts = new ArrayList<String>();
+
+ scripts.add("DROP TABLE JCR_" + tablePrefix + "VALUE_OLD");
+ scripts.add("DROP TABLE JCR_" + tablePrefix + "ITEM_OLD");
+ scripts.add("DROP TABLE JCR_" + tablePrefix + "REF_OLD");
+
+ return scripts;
+ }
+
+ /**
+ * Returns SQL scripts for dropping existed JCR tables.
+ */
+ protected Collection<String> getTableDroppingScripts()
+ {
+ List<String> scripts = new ArrayList<String>();
+
+ scripts.add("DROP TABLE JCR_" + tablePrefix + "VALUE");
+ scripts.add("DROP TABLE JCR_" + tablePrefix + "ITEM");
+ scripts.add("DROP TABLE JCR_" + tablePrefix + "REF");
+
+ return scripts;
+ }
+
+ /**
+ *
+ * @return
+ */
+ protected Collection<String> getSingleDbWorkspaceCleaningScripts()
+ {
+ List<String> scripts = new ArrayList<String>();
+
+ scripts.add("delete from JCR_SVALUE where PROPERTY_ID IN (select ID from
JCR_SITEM where CONTAINER_NAME='"
+ + workspaceName + "')");
+ scripts.add("delete from JCR_SREF where PROPERTY_ID IN (select ID from
JCR_SITEM where CONTAINER_NAME='"
+ + workspaceName + "')");
+ scripts.add("delete from JCR_SITEM where CONTAINER_NAME='" +
workspaceName + "'");
+
+ return scripts;
+ }
+
+ /**
+ * Returns SQL scripts for database initalization.
+ * @throws DBCleanException
+ */
+ protected Collection<String> getDBInitializationScripts() throws
DBCleanException
+ {
+ String scriptPath = DBInitializerHelper.scriptPath(dialect, multiDb);
+
+ String script;
+ try
+ {
+ script =
IOUtil.getStreamContentAsString(PrivilegedFileHelper.getResourceAsStream(scriptPath));
+ }
+ catch (Throwable e)
+ {
+ throw new DBCleanException(e);
+ }
+
+ List<String> scripts = new ArrayList<String>();
+ for (String query : JDBCUtils.splitWithSQLDelimiter(script))
+ {
+ scripts.add(JDBCUtils.cleanWhitespaces(query));
+ }
+
+ scripts.add(DBInitializerHelper.getRootNodeInitializeScript(multiDb));
+
+ return scripts;
+ }
+
+ /**
+ * Returns the syntax for dropping constraint on database.
+ */
+ protected String constraintDroppingSyntax()
+ {
+ return "DROP CONSTRAINT";
+ }
+
+ /**
+ * Return {@link JDBCWorkspaceDataContainer#MULTIDB} parameter from workspace
configuration.
+ */
+ private boolean getMultiDbParameter(WorkspaceEntry wsEntry) throws DBCleanException
+ {
+ try
+ {
+ return
Boolean.parseBoolean(wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB));
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ throw new DBCleanException(e);
+ }
+ }
+}
Added:
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
(rev 0)
+++
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
10:17:25 UTC (rev 5462)
@@ -0,0 +1,119 @@
+/*
+ * 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.database.utils.DialectConstants;
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanException;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: DBCleaningScriptsFactory.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class DBCleaningScriptsFactory
+{
+ /**
+ * Prepare SQL scripts for cleaning workspace data from database.
+ */
+ public static DBCleaningScripts prepareScripts(String dialect, WorkspaceEntry wsEntry)
throws DBCleanException
+ {
+ if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_MYSQL)
+ || dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_MYSQL_MYISAM)
+ || dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_MYSQL_MYISAM_UTF8)
+ || dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_MYSQL_UTF8))
+ {
+ return new MySQLCleaningScipts(dialect, wsEntry);
+ }
+ else if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_DB2)
+ || dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_DB2V8))
+ {
+ return new DB2CleanScipts(dialect, wsEntry);
+ }
+ else if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_MSSQL))
+ {
+ return new MSSQLCleaningScipts(dialect, wsEntry);
+ }
+ else if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_PGSQL))
+ {
+ return new PgSQLCleaningScipts(dialect, wsEntry);
+ }
+ else if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_SYBASE))
+ {
+ return new SybaseCleaningScipts(dialect, wsEntry);
+ }
+ else if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_HSQLDB))
+ {
+ return new HSQLDBCleaningScipts(dialect, wsEntry);
+ }
+ else if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_ORACLE)
+ || dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_ORACLEOCI))
+ {
+ return new OracleCleaningScipts(dialect, wsEntry);
+ }
+ else
+ {
+ throw new DBCleanException("Unsupported dialect " + dialect);
+ }
+ }
+
+ /**
+ * Prepare SQL scripts for cleaning repository data from database.
+ */
+ public static DBCleaningScripts prepareScripts(String dialect, RepositoryEntry rEntry)
throws DBCleanException
+ {
+ if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_MYSQL)
+ || dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_MYSQL_MYISAM)
+ || dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_MYSQL_MYISAM_UTF8)
+ || dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_MYSQL_UTF8))
+ {
+ return new MySQLCleaningScipts(dialect, rEntry);
+ }
+ else if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_DB2)
+ || dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_DB2V8))
+ {
+ return new DB2CleanScipts(dialect, rEntry);
+ }
+ else if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_MSSQL))
+ {
+ return new MSSQLCleaningScipts(dialect, rEntry);
+ }
+ else if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_PGSQL))
+ {
+ return new PgSQLCleaningScipts(dialect, rEntry);
+ }
+ else if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_SYBASE))
+ {
+ return new SybaseCleaningScipts(dialect, rEntry);
+ }
+ else if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_HSQLDB))
+ {
+ return new HSQLDBCleaningScipts(dialect, rEntry);
+ }
+ else if (dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_ORACLE)
+ || dialect.equalsIgnoreCase(DialectConstants.DB_DIALECT_ORACLEOCI))
+ {
+ return new OracleCleaningScipts(dialect, rEntry);
+ }
+ else
+ {
+ throw new DBCleanException("Unsupported dialect " + dialect);
+ }
+ }
+}
Added:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/HSQLDBCleaningScipts.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/HSQLDBCleaningScipts.java
(rev 0)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/HSQLDBCleaningScipts.java 2012-01-17
10:17:25 UTC (rev 5462)
@@ -0,0 +1,135 @@
+/*
+ * 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;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: HSQLDBCleaningScipts.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class HSQLDBCleaningScipts extends DBCleaningScripts
+{
+ /**
+ * HSQLDBCleanScipts constructor.
+ */
+ public HSQLDBCleaningScipts(String dialect, RepositoryEntry rEntry) throws
DBCleanException
+ {
+ super(dialect, rEntry);
+
+ prepareRenamingApproachScripts();
+ }
+
+ /**
+ * HSQLDBCleanScipts constructor.
+ */
+ public HSQLDBCleaningScipts(String dialect, WorkspaceEntry wEntry) throws
DBCleanException
+ {
+ super(dialect, wEntry);
+
+ if (multiDb)
+ {
+ prepareRenamingApproachScripts();
+ }
+ else
+ {
+ prepareSimpleCleaningApproachScripts();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Collection<String> getTablesRenamingScripts()
+ {
+ Collection<String> scripts = new ArrayList<String>();
+
+ // renaming tables
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE RENAME TO
JCR_" + tablePrefix + "VALUE_OLD");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM RENAME TO
JCR_" + tablePrefix + "ITEM_OLD");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "REF RENAME TO
JCR_" + tablePrefix + "REF_OLD");
+
+ // droping constraints
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE_OLD DROP
CONSTRAINT JCR_FK_" + tablePrefix
+ + "VALUE_PROPERTY");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM_OLD DROP
CONSTRAINT JCR_FK_" + tablePrefix + "ITEM_PARENT");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM_OLD DROP
CONSTRAINT JCR_PK_" + tablePrefix + "ITEM");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE_OLD DROP
CONSTRAINT JCR_PK_" + tablePrefix + "VALUE");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "REF_OLD DROP
CONSTRAINT JCR_PK_" + tablePrefix + "REF");
+
+ // renaming indexes
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix + "ITEM_PARENT
RENAME TO JCR_IDX_" + tablePrefix
+ + "ITEM_PARENT_OLD");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix + "ITEM_PARENT_ID
RENAME TO JCR_IDX_" + tablePrefix
+ + "ITEM_PARENT_ID_OLD");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix +
"ITEM_N_ORDER_NUM RENAME TO JCR_IDX_" + tablePrefix
+ + "ITEM_N_ORDER_NUM_OLD");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix + "VALUE_PROPERTY
RENAME TO JCR_IDX_" + tablePrefix
+ + "VALUE_PROPERTY_OLD");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix + "REF_PROPERTY
RENAME TO JCR_IDX_" + tablePrefix
+ + "REF_PROPERTY_OLD");
+
+ return scripts;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Collection<String> getOldTablesRenamingScripts()
+ {
+ Collection<String> scripts = new ArrayList<String>();
+
+ // renaming tables
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE_OLD RENAME TO
JCR_" + tablePrefix + "VALUE");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM_OLD RENAME TO
JCR_" + tablePrefix + "ITEM");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "REF_OLD RENAME TO
JCR_" + tablePrefix + "REF");
+
+ // creating constraints
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM ADD CONSTRAINT
JCR_PK_" + tablePrefix
+ + "ITEM PRIMARY KEY(ID)");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE ADD
CONSTRAINT JCR_FK_" + tablePrefix
+ + "VALUE_PROPERTY FOREIGN KEY(PROPERTY_ID) REFERENCES JCR_" +
tablePrefix + "ITEM(ID)");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM ADD CONSTRAINT
JCR_FK_" + tablePrefix
+ + "ITEM_PARENT FOREIGN KEY(PARENT_ID) REFERENCES JCR_" + tablePrefix +
"ITEM(ID)");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE ADD
CONSTRAINT JCR_PK_" + tablePrefix
+ + "VALUE PRIMARY KEY(ID)");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "REF ADD CONSTRAINT
JCR_PK_" + tablePrefix
+ + "REF PRIMARY KEY(NODE_ID, PROPERTY_ID, ORDER_NUM)");
+
+ // renaming indexes
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix + "ITEM_PARENT_OLD
RENAME TO JCR_IDX_" + tablePrefix
+ + "ITEM_PARENT");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix +
"ITEM_PARENT_ID_OLD RENAME TO JCR_IDX_" + tablePrefix
+ + "ITEM_PARENT_ID");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix +
"ITEM_N_ORDER_NUM_OLD RENAME TO JCR_IDX_" + tablePrefix
+ + "ITEM_N_ORDER_NUM");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix +
"VALUE_PROPERTY_OLD RENAME TO JCR_IDX_" + tablePrefix
+ + "VALUE_PROPERTY");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix +
"REF_PROPERTY_OLD RENAME TO JCR_IDX_" + tablePrefix
+ + "REF_PROPERTY");
+
+ return scripts;
+ }
+
+}
Added:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/MSSQLCleaningScipts.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/MSSQLCleaningScipts.java
(rev 0)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/MSSQLCleaningScipts.java 2012-01-17
10:17:25 UTC (rev 5462)
@@ -0,0 +1,69 @@
+/*
+ * 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;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: MSSQLCleaningScipts.java 34360 2009-07-22 23:58:59Z tolusha $
+ *
+ */
+public class MSSQLCleaningScipts extends DBCleaningScripts
+{
+
+ /**
+ * MSSQLCleaningScipts constructor.
+ */
+ public MSSQLCleaningScipts(String dialect, RepositoryEntry rEntry) throws
DBCleanException
+ {
+ super(dialect, rEntry);
+
+ prepareDroppingTablesApproachScripts();
+ }
+
+ /**
+ * MSSQLCleaningScipts constructor.
+ */
+ public MSSQLCleaningScipts(String dialect, WorkspaceEntry wEntry) throws
DBCleanException
+ {
+ super(dialect, wEntry);
+
+ if (multiDb)
+ {
+ prepareDroppingTablesApproachScripts();
+ }
+ else
+ {
+ prepareSimpleCleaningApproachScripts();
+ }
+ }
+
+ /**
+ * {@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/MySQLCleaningScipts.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/MySQLCleaningScipts.java
(rev 0)
+++
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
10:17:25 UTC (rev 5462)
@@ -0,0 +1,165 @@
+/*
+ * 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;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: MySQLCleaningScipts.java 34360 2009-07-22 23:58:59Z tolusha $
+ *
+ */
+public class MySQLCleaningScipts extends DBCleaningScripts
+{
+
+ /**
+ * MySQLCleaningScipts constructor.
+ */
+ public MySQLCleaningScipts(String dialect, RepositoryEntry rEntry) throws
DBCleanException
+ {
+ super(dialect, rEntry);
+
+ prepareRenamingApproachScripts();
+ }
+
+ /**
+ * MySQLCleaningScipts constructor.
+ */
+ public MySQLCleaningScipts(String dialect, WorkspaceEntry wEntry) throws
DBCleanException
+ {
+ super(dialect, wEntry);
+
+ if (multiDb)
+ {
+ prepareRenamingApproachScripts();
+ }
+ else
+ {
+ prepareSimpleCleaningApproachScripts();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void prepareRenamingApproachScripts() throws DBCleanException
+ {
+ super.prepareRenamingApproachScripts();
+
+ // constraints already removed in {@link #getDBInitializationScripts()}
+ cleaningScripts.clear();
+ cleaningScripts.addAll(getTablesRenamingScripts());
+ cleaningScripts.addAll(getDBInitializationScripts());
+ 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);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected String constraintDroppingSyntax()
+ {
+ return "DROP FOREIGN KEY";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Collection<String> getDBInitializationScripts() throws
DBCleanException
+ {
+ Collection<String> scripts = super.getDBInitializationScripts();
+
+ return filter(scripts);
+ }
+
+ /**
+ * Removing foreign key creation from initialization scripts for table JCR_S(M)ITEM
+ * and JCR_S(M)VALUE. It is not possible to create table with such foreign key if the
same key
+ * exists in another table of database
+ */
+ private Collection<String> filter(Collection<String> scripts)
+ {
+ String JCR_ITEM_PRIMARY_KEY = "CONSTRAINT JCR_PK_" + tablePrefix +
"ITEM PRIMARY KEY(ID)";
+ String JCR_ITEM_FOREIGN_KEY =
+ "CONSTRAINT JCR_FK_" + tablePrefix + "ITEM_PARENT FOREIGN
KEY(PARENT_ID) REFERENCES JCR_" + tablePrefix
+ + "ITEM(ID)";
+
+ String JCR_VALUE_PRIMARY_KEY = "CONSTRAINT JCR_PK_" + tablePrefix +
"VALUE PRIMARY KEY(ID)";
+ String JCR_VALUE_FOREIGN_KEY =
+ "CONSTRAINT JCR_FK_" + tablePrefix + "VALUE_PROPERTY FOREIGN
KEY(PROPERTY_ID) REFERENCES JCR_" + tablePrefix
+ + "ITEM(ID)";
+
+ Collection<String> filteredScripts = new ArrayList<String>();
+
+ for (String script : scripts)
+ {
+ if (script.contains(JCR_ITEM_PRIMARY_KEY + ","))
+ {
+ script = script.replace(JCR_ITEM_PRIMARY_KEY + ",",
JCR_ITEM_PRIMARY_KEY);
+ script = script.replace(JCR_ITEM_FOREIGN_KEY, "");
+ }
+ else if (script.contains(JCR_VALUE_PRIMARY_KEY + ","))
+ {
+ script = script.replace(JCR_VALUE_PRIMARY_KEY + ",",
JCR_VALUE_PRIMARY_KEY);
+ script = script.replace(JCR_VALUE_FOREIGN_KEY, "");
+ }
+
+ filteredScripts.add(script);
+ }
+
+ return filteredScripts;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Collection<String> getTablesRenamingScripts()
+ {
+ Collection<String> scripts = new ArrayList<String>();
+
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE RENAME TO
JCR_" + tablePrefix + "VALUE_OLD");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM RENAME TO
JCR_" + tablePrefix + "ITEM_OLD");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "REF RENAME TO
JCR_" + tablePrefix + "REF_OLD");
+
+ return scripts;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Collection<String> getOldTablesRenamingScripts()
+ {
+ Collection<String> scripts = new ArrayList<String>();
+
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM_OLD RENAME TO
JCR_" + tablePrefix + "ITEM");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE_OLD RENAME TO
JCR_" + tablePrefix + "VALUE");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "REF_OLD RENAME TO
JCR_" + tablePrefix + "REF");
+
+ return scripts;
+ }
+
+}
Added:
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
(rev 0)
+++
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
10:17:25 UTC (rev 5462)
@@ -0,0 +1,258 @@
+/*
+ * 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.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanException;
+import org.exoplatform.services.jcr.impl.util.jdbc.DBInitializerHelper;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: OracleDBCleanScipts.java 34360 2009-07-22 23:58:59Z tolusha $
+ *
+ */
+public class OracleCleaningScipts extends DBCleaningScripts
+{
+
+ /**
+ * OracleCleanScipts constructor.
+ */
+ public OracleCleaningScipts(String dialect, RepositoryEntry rEntry) throws
DBCleanException
+ {
+ super(dialect, rEntry);
+
+ prepareRenamingApproachScripts();
+ }
+
+ /**
+ * OracleCleanScipts constructor.
+ */
+ public OracleCleaningScipts(String dialect, WorkspaceEntry wEntry) throws
DBCleanException
+ {
+ super(dialect, wEntry);
+
+ if (multiDb)
+ {
+ prepareRenamingApproachScripts();
+ }
+ else
+ {
+ prepareSimpleCleaningApproachScripts();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void prepareRenamingApproachScripts() throws DBCleanException
+ {
+ super.prepareRenamingApproachScripts();
+
+ String constraintName = "JCR_PK_" + tablePrefix + "VALUE";
+ cleaningScripts.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);
+
+ constraintName = "JCR_PK_" + tablePrefix + "ITEM";
+ cleaningScripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM DROP
CONSTRAINT " + constraintName);
+
+ constraintName = "JCR_PK_" + tablePrefix + "REF";
+ cleaningScripts.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);
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Collection<String> getIndexesDroppingScripts()
+ {
+ Collection<String> scripts = new ArrayList<String>();
+
+ scripts.add("DROP INDEX JCR_IDX_" + tablePrefix +
"ITEM_PARENT_FK");
+ scripts.add("DROP INDEX JCR_IDX_" + tablePrefix +
"ITEM_PARENT");
+ scripts.add("DROP INDEX JCR_IDX_" + tablePrefix +
"ITEM_PARENT_ID");
+ scripts.add("DROP INDEX JCR_IDX_" + tablePrefix +
"ITEM_N_ORDER_NUM");
+ scripts.add("DROP INDEX JCR_IDX_" + tablePrefix +
"VALUE_PROPERTY");
+ scripts.add("DROP INDEX JCR_IDX_" + tablePrefix +
"REF_PROPERTY");
+
+ return scripts;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Collection<String> getIndexesAddingScripts() throws DBCleanException
+ {
+ Collection<String> scripts = new ArrayList<String>();
+
+ try
+ {
+ scripts.add(DBInitializerHelper.getObjectScript("JCR_IDX_" +
tablePrefix + "ITEM_PARENT_FK ON JCR_"
+ + tablePrefix + "ITEM", multiDb, dialect));
+ scripts.add(DBInitializerHelper.getObjectScript("JCR_IDX_" +
tablePrefix + "ITEM_PARENT ON JCR_" + tablePrefix
+ + "ITEM", multiDb, dialect));
+ scripts.add(DBInitializerHelper.getObjectScript("JCR_IDX_" +
tablePrefix + "ITEM_PARENT_ID ON JCR_"
+ + tablePrefix + "ITEM", multiDb, dialect));
+ scripts.add(DBInitializerHelper.getObjectScript("JCR_IDX_" +
tablePrefix + "ITEM_N_ORDER_NUM ON JCR_"
+ + tablePrefix + "ITEM", multiDb, dialect));
+ scripts.add(DBInitializerHelper.getObjectScript("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)
+ {
+ throw new DBCleanException(e);
+ }
+
+ return scripts;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Collection<String> getTableDroppingScripts()
+ {
+ Collection<String> scripts = super.getTableDroppingScripts();
+
+ scripts.add("DROP TRIGGER BI_JCR_" + tablePrefix + "VALUE");
+ scripts.add("DROP SEQUENCE JCR_" + tablePrefix + "VALUE_SEQ");
+
+ return scripts;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Collection<String> getTablesRenamingScripts()
+ {
+ Collection<String> scripts = super.getTableDroppingScripts();
+
+ // JCR_VALUE
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE RENAME TO
JCR_" + tablePrefix + "VALUE_OLD");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE_OLD" +
" RENAME CONSTRAINT JCR_PK_" + tablePrefix
+ + "VALUE TO JCR_PK_" + tablePrefix + "VALUE_OLD");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE_OLD" +
" RENAME CONSTRAINT JCR_FK_" + tablePrefix
+ + "VALUE_PROPERTY TO JCR_FK_" + tablePrefix +
"VALUE_PROPERTY_OLD");
+
+ scripts.add("ALTER INDEX JCR_PK_" + tablePrefix + "VALUE RENAME TO
JCR_PK_" + tablePrefix + "VALUE_OLD");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix + "VALUE_PROPERTY
RENAME TO JCR_IDX_" + tablePrefix
+ + "VALUE_PROPERTY_OLD");
+
+ // TRIGGER and SEQ
+ scripts.add("RENAME JCR_" + tablePrefix + "VALUE_SEQ TO JCR_" +
tablePrefix + "VALUE_SEQ_OLD");
+ scripts.add("ALTER TRIGGER BI_JCR_" + tablePrefix + "VALUE RENAME TO
BI_JCR_" + tablePrefix + "VALUE_OLD");
+
+ // JCR_ITEM
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM RENAME TO
JCR_" + tablePrefix + "ITEM_OLD");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM_OLD RENAME
CONSTRAINT JCR_PK_" + tablePrefix
+ + "ITEM TO JCR_PK_" + tablePrefix + "ITEM_OLD");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM_OLD RENAME
CONSTRAINT JCR_FK_" + tablePrefix
+ + "ITEM_PARENT TO JCR_FK_" + tablePrefix +
"ITEM_PARENT_OLD");
+
+ scripts.add("ALTER INDEX JCR_PK_" + tablePrefix + "ITEM RENAME TO
JCR_PK_" + tablePrefix + "ITEM_OLD");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix + "ITEM_PARENT_FK
RENAME TO JCR_IDX_" + tablePrefix
+ + "ITEM_PARENT_FK_OLD");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix + "ITEM_PARENT
RENAME TO JCR_IDX_" + tablePrefix
+ + "ITEM_PARENT_OLD");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix + "ITEM_PARENT_ID
RENAME TO JCR_IDX_" + tablePrefix
+ + "ITEM_PARENT_ID_OLD");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix + "ITEM_N_ORDER_NUM
RENAME TO JCR_IDX_" + tablePrefix
+ + "ITEM_N_ORDER_NUM_OLD");
+
+ // JCR_REF
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "REF RENAME TO
JCR_" + tablePrefix + "REF_OLD");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "REF_OLD RENAME
CONSTRAINT JCR_PK_" + tablePrefix
+ + "REF TO JCR_PK_" + tablePrefix + "REF_OLD");
+
+ scripts.add("ALTER INDEX JCR_PK_" + tablePrefix + "REF RENAME TO
JCR_PK_" + tablePrefix + "REF_OLD");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix + "REF_PROPERTY
RENAME TO JCR_IDX_" + tablePrefix
+ + "REF_PROPERTY_OLD");
+
+ return scripts;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Collection<String> getOldTablesRenamingScripts()
+ {
+ Collection<String> scripts = new ArrayList<String>();
+
+ // VALUE
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE_OLD RENAME TO
JCR_" + tablePrefix + "VALUE");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE RENAME
CONSTRAINT JCR_PK_" + tablePrefix
+ + "VALUE_OLD TO JCR_PK_" + tablePrefix + "VALUE");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE RENAME
CONSTRAINT JCR_FK_" + tablePrefix
+ + "VALUE_PROPERTY_OLD TO JCR_FK_" + tablePrefix +
"VALUE_PROPERTY");
+ scripts.add("ALTER INDEX JCR_PK_" + tablePrefix + "VALUE_OLD RENAME
TO JCR_PK_" + tablePrefix + "VALUE");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix +
"VALUE_PROPERTY_OLD RENAME TO JCR_IDX_" + tablePrefix
+ + "VALUE_PROPERTY");
+
+ // TRIGGER and SEQ
+ scripts.add("RENAME JCR_" + tablePrefix + "VALUE_SEQ_OLD TO
JCR_" + tablePrefix + "VALUE_SEQ");
+ scripts.add("ALTER TRIGGER BI_JCR_" + tablePrefix + "VALUE_OLD
RENAME TO BI_JCR_" + tablePrefix + "VALUE");
+
+ // ITEM
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM_OLD RENAME TO
JCR_" + tablePrefix + "ITEM");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM RENAME
CONSTRAINT JCR_PK_" + tablePrefix
+ + "ITEM_OLD TO JCR_PK_" + tablePrefix + "ITEM");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM RENAME
CONSTRAINT JCR_FK_" + tablePrefix
+ + "ITEM_PARENT_OLD TO JCR_FK_" + tablePrefix +
"ITEM_PARENT");
+ scripts.add("ALTER INDEX JCR_PK_" + tablePrefix + "ITEM_OLD RENAME
TO JCR_PK_" + tablePrefix + "ITEM");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix +
"ITEM_PARENT_FK_OLD RENAME TO JCR_IDX_" + tablePrefix
+ + "ITEM_PARENT_FK");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix + "ITEM_PARENT_OLD
RENAME TO JCR_IDX_" + tablePrefix
+ + "ITEM_PARENT");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix +
"ITEM_PARENT_ID_OLD RENAME TO JCR_IDX_" + tablePrefix
+ + "ITEM_PARENT_ID");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix +
"ITEM_N_ORDER_NUM_OLD RENAME TO JCR_IDX_" + tablePrefix
+ + "ITEM_N_ORDER_NUM");
+
+ // REF
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "REF_OLD RENAME TO
JCR_" + tablePrefix + "REF");
+ scripts.add("ALTER TABLE JCR_" + tablePrefix + "REF RENAME
CONSTRAINT JCR_PK_" + tablePrefix
+ + "REF_OLD TO JCR_PK_" + tablePrefix + "REF");
+ scripts.add("ALTER INDEX JCR_PK_" + tablePrefix + "REF_OLD RENAME TO
JCR_PK_" + tablePrefix + "REF");
+ scripts.add("ALTER INDEX JCR_IDX_" + tablePrefix + "REF_PROPERTY_OLD
RENAME TO JCR_IDX_" + tablePrefix
+ + "REF_PROPERTY");
+
+ return scripts;
+ }
+
+}
Added:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/PgSQLCleaningScipts.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/PgSQLCleaningScipts.java
(rev 0)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/PgSQLCleaningScipts.java 2012-01-17
10:17:25 UTC (rev 5462)
@@ -0,0 +1,69 @@
+/*
+ * 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;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: PgSQLCleaningScipts.java 34360 2009-07-22 23:58:59Z tolusha $
+ *
+ */
+public class PgSQLCleaningScipts extends DBCleaningScripts
+{
+
+ /**
+ * PgSQLCleaningScipts constructor.
+ */
+ public PgSQLCleaningScipts(String dialect, RepositoryEntry rEntry) throws
DBCleanException
+ {
+ super(dialect, rEntry);
+
+ prepareDroppingTablesApproachScripts();
+ }
+
+ /**
+ * PgSQLCleaningScipts constructor.
+ */
+ public PgSQLCleaningScipts(String dialect, WorkspaceEntry wEntry) throws
DBCleanException
+ {
+ super(dialect, wEntry);
+
+ if (multiDb)
+ {
+ prepareDroppingTablesApproachScripts();
+ }
+ else
+ {
+ prepareSimpleCleaningApproachScripts();
+ }
+ }
+
+ /**
+ * {@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/SybaseCleaningScipts.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts/SybaseCleaningScipts.java
(rev 0)
+++
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
10:17:25 UTC (rev 5462)
@@ -0,0 +1,170 @@
+/*
+ * 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.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanException;
+import org.exoplatform.services.jcr.impl.util.jdbc.DBInitializerHelper;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: SybaseCleaningScipts.java 34360 2009-07-22 23:58:59Z tolusha $
+ *
+ */
+public class SybaseCleaningScipts extends DBCleaningScripts
+{
+
+ /**
+ * SybaseCleaningScipts constructor.
+ */
+ public SybaseCleaningScipts(String dialect, RepositoryEntry rEntry) throws
DBCleanException
+ {
+ super(dialect, rEntry);
+
+ prepareRenamingApproachScripts();
+ }
+
+ /**
+ * SybaseCleaningScipts constructor.
+ */
+ public SybaseCleaningScipts(String dialect, WorkspaceEntry wEntry) throws
DBCleanException
+ {
+ super(dialect, wEntry);
+
+ if (multiDb)
+ {
+ prepareRenamingApproachScripts();
+ }
+ else
+ {
+ prepareSimpleCleaningApproachScripts();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void prepareRenamingApproachScripts() throws DBCleanException
+ {
+ super.prepareRenamingApproachScripts();
+
+ String constraintName = "JCR_FK_" + tablePrefix +
"VALUE_PROPERTY";
+ cleaningScripts.add("ALTER TABLE JCR_" + tablePrefix + "VALUE DROP
CONSTRAINT " + constraintName);
+
+ constraintName = "JCR_PK_" + tablePrefix + "ITEM";
+ cleaningScripts.add("ALTER TABLE JCR_" + tablePrefix + "ITEM DROP
CONSTRAINT " + constraintName);
+
+ constraintName = "JCR_PK_" + tablePrefix + "VALUE";
+ cleaningScripts.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);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Collection<String> getIndexesDroppingScripts()
+ {
+ Collection<String> scripts = new ArrayList<String>();
+
+ scripts.add("DROP INDEX JCR_" + tablePrefix + "ITEM.JCR_IDX_" +
tablePrefix + "ITEM_PARENT");
+ scripts.add("DROP INDEX JCR_" + tablePrefix + "ITEM.JCR_IDX_" +
tablePrefix + "ITEM_PARENT_ID");
+ scripts.add("DROP INDEX JCR_" + tablePrefix + "ITEM.JCR_IDX_" +
tablePrefix + "ITEM_N_ORDER_NUM");
+ scripts.add("DROP INDEX JCR_" + tablePrefix + "VALUE.JCR_IDX_"
+ tablePrefix + "VALUE_PROPERTY");
+ scripts.add("DROP INDEX JCR_" + tablePrefix + "REF.JCR_IDX_" +
tablePrefix + "REF_PROPERTY");
+
+ return scripts;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Collection<String> getIndexesAddingScripts() throws DBCleanException
+ {
+ Collection<String> scripts = new ArrayList<String>();
+
+ 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));
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ throw new DBCleanException(e);
+ }
+
+ return scripts;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Collection<String> getTablesRenamingScripts()
+ {
+ Collection<String> scripts = super.getTableDroppingScripts();
+
+ scripts.add("sp_rename JCR_" + tablePrefix + "VALUE, JCR_" +
tablePrefix + "VALUE_OLD");
+ scripts.add("sp_rename JCR_" + tablePrefix + "ITEM, JCR_" +
tablePrefix + "ITEM_OLD");
+ scripts.add("sp_rename JCR_" + tablePrefix + "REF, JCR_" +
tablePrefix + "REF_OLD");
+
+ scripts.add("sp_rename JCR_FK_" + tablePrefix + "VALUE_PROPERTY,
JCR_FK_" + tablePrefix + "VALUE_PROPERTY_OLD");
+ scripts.add("sp_rename JCR_FK_" + tablePrefix + "ITEM_PARENT,
JCR_FK_" + tablePrefix + "ITEM_PARENT_OLD");
+
+ return scripts;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Collection<String> getOldTablesRenamingScripts()
+ {
+ Collection<String> scripts = super.getTableDroppingScripts();
+
+ scripts.add("sp_rename JCR_" + tablePrefix + "VALUE_OLD, JCR_"
+ tablePrefix + "VALUE");
+ scripts.add("sp_rename JCR_" + tablePrefix + "ITEM_OLD, JCR_" +
tablePrefix + "ITEM");
+ scripts.add("sp_rename JCR_" + tablePrefix + "REF_OLD, JCR_" +
tablePrefix + "REF");
+
+ scripts.add("sp_rename JCR_FK_" + tablePrefix + "VALUE_PROPERTY_OLD,
JCR_FK_" + tablePrefix + "VALUE_PROPERTY");
+ scripts.add("sp_rename JCR_FK_" + tablePrefix + "ITEM_PARENT_OLD,
JCR_FK_" + tablePrefix + "ITEM_PARENT");
+
+ return scripts;
+ }
+
+}