exo-jcr SVN: r5467 - jcr/branches/1.14-RSYNC/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2012-01-17 07:46:53 -0500 (Tue, 17 Jan 2012)
New Revision: 5467
Modified:
jcr/branches/1.14-RSYNC/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java
jcr/branches/1.14-RSYNC/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/RsyncIndexInfos.java
Log:
EXOJCR-1709 : Added Authentication options, added Std and Err stream support.
Modified: jcr/branches/1.14-RSYNC/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java
===================================================================
--- jcr/branches/1.14-RSYNC/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java 2012-01-17 12:12:18 UTC (rev 5466)
+++ jcr/branches/1.14-RSYNC/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java 2012-01-17 12:46:53 UTC (rev 5467)
@@ -219,13 +219,15 @@
// read RSYNC configuration
String rsyncEntryName = config.getParameterValue(PARAM_RSYNC_ENTRY_NAME, null);
String rsyncEntryPath = config.getParameterValue(PARAM_RSYNC_ENTRY_PATH, null);
+ String rsyncUserName = config.getParameterValue(PARAM_RSYNC_USER, null);
+ String rsyncPassword = config.getParameterValue(PARAM_RSYNC_PASSWORD, null);
int rsyncPort = config.getParameterInteger(PARAM_RSYNC_PORT, PARAM_RSYNC_PORT_DEFAULT);
// rsync configured
if (rsyncEntryName != null)
{
return new RsyncIndexInfos(rootFqn, cache, system, modeHandler, ((SearchIndex)handler).getContext()
- .getIndexDirectory(), rsyncPort, rsyncEntryName, rsyncEntryPath);
+ .getIndexDirectory(), rsyncPort, rsyncEntryName, rsyncEntryPath, rsyncUserName, rsyncPassword);
}
else
{
Modified: jcr/branches/1.14-RSYNC/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/RsyncIndexInfos.java
===================================================================
--- jcr/branches/1.14-RSYNC/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/RsyncIndexInfos.java 2012-01-17 12:12:18 UTC (rev 5466)
+++ jcr/branches/1.14-RSYNC/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/RsyncIndexInfos.java 2012-01-17 12:46:53 UTC (rev 5467)
@@ -27,8 +27,11 @@
import org.jboss.cache.notifications.annotation.CacheListener;
import org.jgroups.stack.IpAddress;
+import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.Serializable;
import java.util.Set;
@@ -48,11 +51,17 @@
private final String urlFormatString;
+ private final String rsyncUserName;
+
+ private final String rsyncPassword;
+
public RsyncIndexInfos(Fqn<String> rootFqn, Cache<Serializable, Object> cache, boolean system,
- IndexerIoModeHandler modeHandler, String indexPath, int rsyncPort, String rsyncEntryName, String rsyncEntryPath)
- throws RepositoryConfigurationException
+ IndexerIoModeHandler modeHandler, String indexPath, int rsyncPort, String rsyncEntryName, String rsyncEntryPath,
+ String rsyncUserName, String rsyncPassword) throws RepositoryConfigurationException
{
super(rootFqn, cache, system, modeHandler);
+ this.rsyncUserName = rsyncUserName;
+ this.rsyncPassword = rsyncPassword;
String absoluteRsyncEntryPath;
try
@@ -128,7 +137,8 @@
String address =
((IpAddress)((CacheSPI<Serializable, Object>)cache).getRPCManager().getCoordinator()).getIpAddress()
.getHostAddress();
- RSyncJob rSyncJob = new RSyncJob(String.format(urlFormatString, address), indexPath);
+ RSyncJob rSyncJob =
+ new RSyncJob(String.format(urlFormatString, address), indexPath, rsyncUserName, rsyncPassword);
try
{
synchronized (this)
@@ -146,16 +156,26 @@
private class RSyncJob
{
+ private final static String RSYNC_USER_SYSTEM_PROPERTY = "USER";
+
+ private final static String RSYNC_PASSWORD_SYSTEM_PROPERTY = "RSYNC_PASSWORD";
+
private Process process;
- private String src;
+ private final String src;
- private String dst;
+ private final String dst;
- public RSyncJob(String src, String dst)
+ private String userName;
+
+ private String password;
+
+ public RSyncJob(String src, String dst, String userName, String password)
{
this.src = src.endsWith(File.separator) ? src : src + File.separator;
this.dst = dst;
+ this.userName = userName;
+ this.password = password;
}
// TODO : Use JNI and librsync library? or handle err stream
@@ -166,8 +186,42 @@
{
String command = "rsync -rv --delete " + src + " " + dst;
log.info("Rsync job started: " + command);
- process = run.exec(command);
+ if (userName != null && password != null)
+ {
+ String[] envProperties =
+ new String[]{RSYNC_USER_SYSTEM_PROPERTY + "=" + userName,
+ RSYNC_PASSWORD_SYSTEM_PROPERTY + "=" + password};
+ process = run.exec(command, envProperties);
+ }
+ else
+ {
+ process = run.exec(command);
+ }
+ // Handle process Standard and Error output
+ InputStream stderr = process.getErrorStream();
+ InputStreamReader isrErr = new InputStreamReader(stderr);
+ BufferedReader brErr = new BufferedReader(isrErr);
+
+ InputStream stdout = process.getInputStream();
+ InputStreamReader isrStd = new InputStreamReader(stdout);
+ BufferedReader brStd = new BufferedReader(isrStd);
+
+ String val = null;
+ StringBuilder stringBuilderErr = new StringBuilder();
+ StringBuilder stringBuilderStd = new StringBuilder();
+ while ((val = brStd.readLine()) != null)
+ {
+ stringBuilderStd.append(val);
+ stringBuilderStd.append('\n');
+ }
+
+ while ((val = brErr.readLine()) != null)
+ {
+ stringBuilderErr.append(val);
+ stringBuilderErr.append('\n');
+ }
+
Integer returnCode = null;
// wait for thread
while (returnCode == null)
@@ -181,10 +235,12 @@
// oops, this can happen sometimes
}
}
- log.info("Rsync job finished: " + returnCode);
+ log.info("Rsync job finished: " + returnCode + ". Error stream output \n" + stringBuilderErr.toString()
+ + " Standard stream output \n" + stringBuilderStd.toString());
if (returnCode != 0)
{
- throw new IOException("RSync job finished with exit code is " + returnCode);
+ throw new IOException("RSync job finished with exit code is " + returnCode + ". Error stream output: \n"
+ + stringBuilderErr.toString());
}
}
finally
14 years, 3 months
exo-jcr SVN: r5466 - jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs.
by do-not-reply@jboss.org
Author: trang_vu
Date: 2012-01-17 07:12:18 -0500 (Tue, 17 Jan 2012)
New Revision: 5466
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/TestRemoveFromValueStorage.java
Log:
JCR-1695: Update TestRemoveFromValueStorage for value-storage-disable profile
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/TestRemoveFromValueStorage.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/TestRemoveFromValueStorage.java 2012-01-17 11:11:32 UTC (rev 5465)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/TestRemoveFromValueStorage.java 2012-01-17 12:12:18 UTC (rev 5466)
@@ -139,7 +139,7 @@
}
}
- for (int i = 0; i < count; i++)
+ for (int i = 0; i < channels.size(); i++)
{
try
{
@@ -155,7 +155,7 @@
mySession.save();
// checking whether values are still in value storage.
- for (int i = 0; i < count; i++)
+ for (int i = 0; i < channels.size(); i++)
{
try
{
14 years, 3 months
exo-jcr SVN: r5465 - in jcr/branches/1.15.x/applications: product-patches/as/jonas/bin/nt and 1 other directory.
by do-not-reply@jboss.org
Author: andrew.plotnikov
Date: 2012-01-17 06:11:32 -0500 (Tue, 17 Jan 2012)
New Revision: 5465
Modified:
jcr/branches/1.15.x/applications/exo.jcr.applications.jonas/pom.xml
jcr/branches/1.15.x/applications/product-patches/as/jonas/bin/nt/jonas.bat
Log:
EXOJCR-1718: Jonas starup failed
Modified: jcr/branches/1.15.x/applications/exo.jcr.applications.jonas/pom.xml
===================================================================
--- jcr/branches/1.15.x/applications/exo.jcr.applications.jonas/pom.xml 2012-01-17 10:49:17 UTC (rev 5464)
+++ jcr/branches/1.15.x/applications/exo.jcr.applications.jonas/pom.xml 2012-01-17 11:11:32 UTC (rev 5465)
@@ -177,6 +177,8 @@
<include name="**/hsqldb*.jar" />
</fileset>
</copy>
+
+ <delete file="${exo.projects.directory.working}/exo-jonas/externals/commons/jonas/carol/jgroups-all.jar" />
</tasks>
</configuration>
<dependencies>
Modified: jcr/branches/1.15.x/applications/product-patches/as/jonas/bin/nt/jonas.bat
===================================================================
--- jcr/branches/1.15.x/applications/product-patches/as/jonas/bin/nt/jonas.bat 2012-01-17 10:49:17 UTC (rev 5464)
+++ jcr/branches/1.15.x/applications/product-patches/as/jonas/bin/nt/jonas.bat 2012-01-17 11:11:32 UTC (rev 5465)
@@ -80,7 +80,7 @@
Rem ----------------------- Begin eXo configuration ----------------------------
cd %JONAS_ROOT%/bin
-
+
set EXO_PROFILES=-Dexo.profiles=
if ""%1"" == ""jbc"" goto profile
if ""%1"" == ""ispn"" goto profile
@@ -97,9 +97,8 @@
:endif
set JONAS_OPTS=%JONAS_OPTS% -Dorg.exoplatform.services.log.Log=org.apache.commons.logging.impl.SimpleLog -Djava.awt.headless=true %EXO_PROFILES% -Djava.net.preferIPv4Stack=true -Dexo.jcr.parent.dir=../..
-set JAVA_OPTS=%JAVA_OPTS% -Xmx512M
-
+
Rem ------------------------ End eXo configuration -----------------------------
Rem ---------------------------------------------
14 years, 3 months
exo-jcr SVN: r5464 - in jcr/branches/1.15.x: exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/faq and 1 other directory.
by do-not-reply@jboss.org
Author: andrew.plotnikov
Date: 2012-01-17 05:49:17 -0500 (Tue, 17 Jan 2012)
New Revision: 5464
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/developer-notes.txt
jcr/branches/1.15.x/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/faq/jcr-faq.xml
Log:
EXOJCR-821: Added throw an exception if session is logged out
Modified: jcr/branches/1.15.x/exo.jcr.component.core/developer-notes.txt
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/developer-notes.txt 2012-01-17 10:34:00 UTC (rev 5463)
+++ jcr/branches/1.15.x/exo.jcr.component.core/developer-notes.txt 2012-01-17 10:49:17 UTC (rev 5464)
@@ -6,3 +6,4 @@
* If lock manager is not configured we will have RepositoryConfigurationException at startup
* Index JCR_XITEM_PARENT_NAME removed (JCR_IDX_MITEM_PN - for DB2)
* Index JCR_IDX_XITEM_PARENT_N_ORDER_NUM from MySQL scripts.
+* We will have RepositoryException when use Session or Node after session.logout
\ No newline at end of file
Modified: jcr/branches/1.15.x/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/faq/jcr-faq.xml
===================================================================
--- jcr/branches/1.15.x/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/faq/jcr-faq.xml 2012-01-17 10:34:00 UTC (rev 5463)
+++ jcr/branches/1.15.x/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/faq/jcr-faq.xml 2012-01-17 10:49:17 UTC (rev 5464)
@@ -240,8 +240,8 @@
<title>Can I use Session after loging out?</title>
<para>No. Any instance of Session or Node (acquired through session)
- shouldn't be used after loging out anymore. At least, it is highly
- recommended not to use.</para>
+ shouldn't be used after loging out anymore. If you use Session or Node
+ after logging out then you get an exception.</para>
</section>
<section>
14 years, 3 months
exo-jcr SVN: r5463 - jcr/branches/1.12.x/patch/1.12.12-GA/JCR-1704.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2012-01-17 05:34:00 -0500 (Tue, 17 Jan 2012)
New Revision: 5463
Modified:
jcr/branches/1.12.x/patch/1.12.12-GA/JCR-1704/JCR-1704.patch
Log:
JCR-1704: fixed patch added
Modified: jcr/branches/1.12.x/patch/1.12.12-GA/JCR-1704/JCR-1704.patch
===================================================================
--- jcr/branches/1.12.x/patch/1.12.12-GA/JCR-1704/JCR-1704.patch 2012-01-17 10:17:25 UTC (rev 5462)
+++ jcr/branches/1.12.x/patch/1.12.12-GA/JCR-1704/JCR-1704.patch 2012-01-17 10:34:00 UTC (rev 5463)
@@ -116,22 +116,19 @@
* The list of allowed methods.
*/
private static final String ALLOW;
-@@ -300,6 +311,14 @@
+@@ -300,6 +311,11 @@
}
+ ValuesParam pReadOnlyMimeTypes = params.getValuesParam(READ_ONLY_MIME_TYPES);
+ if (pReadOnlyMimeTypes != null)
+ {
-+ for (String mimeType : (List<String>)pReadOnlyMimeTypes.getValues())
-+ {
-+ readOnlyMimeTypes.add(mimeType);
-+ }
++ readOnlyMimeTypes.addAll((List<String>)pReadOnlyMimeTypes.getValues());
+ }
}
/**
-@@ -1038,7 +1057,8 @@
+@@ -1038,7 +1054,8 @@
NodeType nodeType = ntm.getNodeType(contentNodeType);
NodeTypeUtil.checkContentResourceType(nodeType);
14 years, 3 months
exo-jcr SVN: r5462 - jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/scripts.
by do-not-reply@jboss.org
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;
+ }
+
+}
14 years, 3 months
exo-jcr SVN: r5461 - in jcr/branches/1.15.x: exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms and 4 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2012-01-17 05:16:32 -0500 (Tue, 17 Jan 2012)
New Revision: 5461
Added:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanException.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/
Removed:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleaner.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DummyDBCleaner.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/core/lock/cacheable/AbstractCacheableLockManager.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
jcr/branches/1.15.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingRepositorySameConfigRestore.java
jcr/branches/1.15.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/usecase/TestBackupRestore.java
Log:
EXOJCR-1707: Refactoring DBCleanService
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 10:14:22 UTC (rev 5460)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestore.java 2012-01-17 10:16:32 UTC (rev 5461)
@@ -29,7 +29,8 @@
import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.backup.BackupException;
import org.exoplatform.services.jcr.impl.backup.DataRestore;
-import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleaner;
+import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanException;
+import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanerTool;
import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectZipReaderImpl;
import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
@@ -113,7 +114,7 @@
/**
* Database cleaner.
*/
- private final DBCleaner dbCleaner;
+ private final DBCleanerTool dbCleaner;
/**
* Database dialect.
@@ -133,7 +134,7 @@
* @throws RepositoryConfigurationException
*/
public DBRestore(File storageDir, Connection jdbcConn, Map<String, RestoreTableRule> tables,
- WorkspaceEntry wsConfig, FileCleaner fileCleaner, DBCleaner dbCleaner) throws NamingException,
+ WorkspaceEntry wsConfig, FileCleaner fileCleaner, DBCleanerTool dbCleaner) throws NamingException,
SQLException, RepositoryConfigurationException
{
this.jdbcConn = jdbcConn;
@@ -155,9 +156,9 @@
{
try
{
- dbCleaner.executeCleanScripts();
+ dbCleaner.clean();
}
- catch (SQLException e)
+ catch (DBCleanException e)
{
throw new BackupException(e);
}
@@ -195,14 +196,17 @@
{
try
{
- dbCleaner.executeCommitScripts();
-
+ dbCleaner.commit();
jdbcConn.commit();
}
catch (SQLException e)
{
throw new BackupException(e);
}
+ catch (DBCleanException e)
+ {
+ throw new BackupException(e);
+ }
}
/**
@@ -214,13 +218,17 @@
{
jdbcConn.rollback();
- dbCleaner.executeRollbackScripts();
+ dbCleaner.rollback();
jdbcConn.commit();
}
catch (SQLException e)
{
throw new BackupException(e);
}
+ catch (DBCleanException e)
+ {
+ throw new BackupException(e);
+ }
}
/**
Added: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanException.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanException.java (rev 0)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanException.java 2012-01-17 10:16:32 UTC (rev 5461)
@@ -0,0 +1,62 @@
+/*
+ * 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;
+
+/**
+ * @author <a href="abazko(a)exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: DBCleanException.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class DBCleanException extends Exception
+{
+
+ /**
+ * DBCleanException constructor.
+ *
+ * @param message
+ * the message to display.
+ */
+ public DBCleanException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * DBCleanException constructor.
+ *
+ * @param cause
+ * the caused exception
+ */
+ public DBCleanException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * DBCleanException constructor.
+ *
+ * @param message
+ * the message to display.
+ * @param cause
+ * the caused exception
+ */
+ public DBCleanException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
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 10:14:22 UTC (rev 5460)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanService.java 2012-01-17 10:16:32 UTC (rev 5461)
@@ -16,30 +16,25 @@
*/
package org.exoplatform.services.jcr.impl.clean.rdbms;
-import org.exoplatform.commons.utils.IOUtil;
-import org.exoplatform.commons.utils.PrivilegedFileHelper;
import org.exoplatform.commons.utils.SecurityHelper;
+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;
import org.exoplatform.services.jcr.config.RepositoryEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
+import org.exoplatform.services.jcr.impl.clean.rdbms.scripts.DBCleaningScripts;
+import org.exoplatform.services.jcr.impl.clean.rdbms.scripts.DBCleaningScriptsFactory;
import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
-import org.exoplatform.services.jcr.impl.util.jdbc.DBInitializerHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import java.io.IOException;
import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import javax.sql.DataSource;
@@ -59,55 +54,42 @@
protected static final Log LOG = ExoLogger.getLogger("exo.jcr.component.core.DBCleanService");
/**
- * Old object suffix. Will using in rename.
- */
- public static final String OLD_OBJECT_SUFFIX = "_OLD";
-
- /**
- * The constraint name is limited by 18 symbols.
- */
- private static final int DB2_CONSTRAINT_NAME_LENGTH_LIMIT = 18;
-
- /**
* Cleans workspace data from database.
*
* @param wsEntry
* workspace configuration
- * @throws RepositoryConfigurationException
- * @throws NamingException
- * @throws SQLException
+ * @throws DBCleanException
*/
- public static void cleanWorkspaceData(WorkspaceEntry wsEntry) throws RepositoryConfigurationException,
- NamingException, SQLException
+ public static void cleanWorkspaceData(WorkspaceEntry wsEntry) throws DBCleanException
{
- // Need privileges to manage repository.
- SecurityManager security = System.getSecurityManager();
- if (security != null)
- {
- security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
- }
+ SecurityHelper
+ .validateSecurityPermissions(new RuntimePermission[]{JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION});
- String dsName = wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
+ Connection jdbcConn = getConnection(wsEntry);
+ boolean autoCommit = DialectConstants.DB_DIALECT_SYBASE.equalsIgnoreCase(resolveDialect(wsEntry));
- final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
- if (ds == null)
+ try
{
- throw new NameNotFoundException("Data source " + dsName + " not found");
- }
+ jdbcConn.setAutoCommit(autoCommit);
- Connection jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
+ DBCleanerTool dbCleaner = getWorkspaceDBCleaner(jdbcConn, wsEntry);
+ doClean(dbCleaner);
+ }
+ catch (SQLException e)
{
- public Connection run() throws Exception
+ throw new DBCleanException(e);
+ }
+ finally
+ {
+ try
{
- return ds.getConnection();
-
+ jdbcConn.close();
}
- });
-
- jdbcConn.setAutoCommit(false);
- DBCleaner dbCleaner = getWorkspaceDBCleaner(jdbcConn, wsEntry);
-
- processingClean(dbCleaner, jdbcConn);
+ catch (SQLException e)
+ {
+ LOG.error("Can not close connection", e);
+ }
+ }
}
/**
@@ -115,844 +97,238 @@
*
* @param rEntry
* the repository configuration
- * @throws RepositoryConfigurationException
- * @throws NamingException
- * @throws SQLException
+ * @throws DBCleanException
*/
- public static void cleanRepositoryData(RepositoryEntry rEntry) throws RepositoryConfigurationException,
- NamingException, SQLException
+ public static void cleanRepositoryData(RepositoryEntry rEntry) throws DBCleanException
{
- // Need privileges to manage repository.
- SecurityManager security = System.getSecurityManager();
- if (security != null)
- {
- security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
- }
+ SecurityHelper
+ .validateSecurityPermissions(new RuntimePermission[]{JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION});
- if (rEntry.getWorkspaceEntries().size() == 0)
- {
- // nothing to clean
- return;
- }
+ WorkspaceEntry wsEntry = rEntry.getWorkspaceEntries().get(0);
- String dsName =
- rEntry.getWorkspaceEntries().get(0).getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
-
- final DataSource ds = (DataSource)new InitialContext().lookup(dsName);
- if (ds == null)
+ boolean multiDB = getMultiDbParameter(wsEntry);
+ if (multiDB)
{
- throw new NameNotFoundException("Data source " + dsName + " not found");
- }
-
- Connection jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
- {
- public Connection run() throws Exception
+ for (WorkspaceEntry entry : rEntry.getWorkspaceEntries())
{
- return ds.getConnection();
-
+ cleanWorkspaceData(entry);
}
- });
-
- jdbcConn.setAutoCommit(false);
- DBCleaner dbCleaner = getRepositoryDBCleaner(jdbcConn, rEntry);
- if (dbCleaner != null)
- {
- processingClean(dbCleaner, jdbcConn);
}
else
{
- for (WorkspaceEntry wsEntry : rEntry.getWorkspaceEntries())
+ Connection jdbcConn = getConnection(wsEntry);
+ boolean autoCommit = DialectConstants.DB_DIALECT_SYBASE.equalsIgnoreCase(resolveDialect(wsEntry));
+
+ try
{
- cleanWorkspaceData(wsEntry);
+ jdbcConn.setAutoCommit(autoCommit);
+
+ DBCleanerTool dbCleaner = getRepositoryDBCleaner(jdbcConn, rEntry);
+ doClean(dbCleaner);
}
+ catch (SQLException e)
+ {
+ throw new DBCleanException(e);
+ }
+ finally
+ {
+ try
+ {
+ jdbcConn.close();
+ }
+ catch (SQLException e)
+ {
+ LOG.error("Can not close connection", e);
+ }
+ }
}
}
/**
- * Returns database cleaner of repository.
+ * Returns database cleaner for repository.
*
* @param jdbcConn
* database connection which need to use
- * @param wsEntry
- * workspace configuration
- * @return database cleaner or null in case of multi-db configuration
- * @throws SQLException
- * @throws RepositoryConfigurationException
+ * @param rEntry
+ * repository configuration
+ * @return DBCleanerTool
+ * @throws DBCleanException
*/
- public static DBCleaner getRepositoryDBCleaner(Connection jdbcConn, RepositoryEntry repoEntry) throws SQLException,
- RepositoryConfigurationException
+ public static DBCleanerTool getRepositoryDBCleaner(Connection jdbcConn, RepositoryEntry rEntry)
+ throws DBCleanException
{
- // Need privileges to manage repository.
- SecurityManager security = System.getSecurityManager();
- if (security != null)
- {
- security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
- }
+ SecurityHelper
+ .validateSecurityPermissions(new RuntimePermission[]{JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION});
- final boolean isMultiDB =
- Boolean.parseBoolean(repoEntry.getWorkspaceEntries().get(0).getContainer()
- .getParameterValue(JDBCWorkspaceDataContainer.MULTIDB));
+ WorkspaceEntry wsEntry = rEntry.getWorkspaceEntries().get(0);
- if (isMultiDB)
+ boolean multiDb = getMultiDbParameter(wsEntry);
+ if (multiDb)
{
- return null;
+ throw new DBCleanException(
+ "It is not possible to create cleaner with common connection for multi database repository configuration");
}
- String dialect =
- repoEntry.getWorkspaceEntries().get(0).getContainer()
- .getParameterValue(JDBCWorkspaceDataContainer.DB_DIALECT, DBConstants.DB_DIALECT_AUTO);
- if (DBConstants.DB_DIALECT_GENERIC.equalsIgnoreCase(dialect)
- || DBConstants.DB_DIALECT_AUTO.equalsIgnoreCase(dialect))
- {
- dialect = DialectDetecter.detect(jdbcConn.getMetaData());
- }
+ String dialect = resolveDialect(wsEntry);
- if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_DB2)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_DB2V8)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MSSQL)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_PGSQL))
- {
- List<String> dbCleanerScripts = new ArrayList<String>();
- dbCleanerScripts.addAll(getDropTableScripts(isMultiDB, dialect));
- dbCleanerScripts.addAll(getInitializationDBScripts(isMultiDB, dialect));
- dbCleanerScripts.addAll(getRemoveIndexesScripts(isMultiDB, dialect));
+ DBCleaningScripts scripts = DBCleaningScriptsFactory.prepareScripts(dialect, rEntry);
- return new DBCleaner(jdbcConn, dbCleanerScripts, new ArrayList<String>(), getRestoreIndexesScripts(isMultiDB,
- dialect), false);
- }
-
- List<String> dbCleanerScripts = new ArrayList<String>();
- dbCleanerScripts.addAll(getRenameScripts(isMultiDB, dialect));
- dbCleanerScripts.addAll(getInitializationDBScripts(isMultiDB, dialect));
- dbCleanerScripts.addAll(getRemoveIndexesScripts(isMultiDB, dialect));
-
- 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,
- dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE));
+ return new DBCleanerTool(jdbcConn, scripts.getCleaningScripts(), scripts.getCommittingScripts(),
+ scripts.getRollbackingScripts());
}
/**
- * Prepare of restore tables. (Drop constraint, etc...)
+ * Returns database cleaner for workspace.
*
- * @param isMultiDb
- * boolean
- * @param dialect
- * String, dialect of DB
+ * @param jdbcConn
+ * database connection which need to use
+ * @param wsEntry
+ * workspace configuration
+ * @return DBCleanerTool
+ * @throws DBCleanException
*/
- private static List<String> getRemoveIndexesScripts(boolean isMultiDB, String dialect)
+ public static DBCleanerTool getWorkspaceDBCleaner(Connection jdbcConn, WorkspaceEntry wsEntry) throws DBCleanException
{
- ArrayList<String> dropScript = new ArrayList<String>();
+ SecurityHelper
+ .validateSecurityPermissions(new RuntimePermission[]{JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION});
- String multiDb = isMultiDB ? "M" : "S";
- String constraintName;
+ boolean multiDb = getMultiDbParameter(wsEntry);
- if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_UTF8)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_MYISAM)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_MYISAM_UTF8))
- {
- return dropScript;
- }
+ String dialect = resolveDialect(wsEntry);
+
+ DBCleaningScripts scripts = DBCleaningScriptsFactory.prepareScripts(dialect, wsEntry);
- constraintName = validateConstraintName("JCR_FK_" + multiDb + "ITEM_PARENT", dialect);
- dropScript.add("ALTER TABLE JCR_" + multiDb + "ITEM " + dropCommand(false, constraintName, dialect));
-
- if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLE)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLEOCI))
- {
- constraintName = validateConstraintName("JCR_PK_" + multiDb + "VALUE", dialect);
- dropScript.add("ALTER TABLE JCR_" + multiDb + "VALUE " + dropCommand(true, constraintName, dialect));
-
- constraintName = validateConstraintName("JCR_FK_" + multiDb + "VALUE_PROPERTY", dialect);
- dropScript.add("ALTER TABLE JCR_" + multiDb + "VALUE " + dropCommand(false, constraintName, dialect));
-
- constraintName = validateConstraintName("JCR_PK_" + multiDb + "ITEM", dialect);
- dropScript.add("ALTER TABLE JCR_" + multiDb + "ITEM " + dropCommand(true, constraintName, dialect));
-
- constraintName = validateConstraintName("JCR_PK_" + multiDb + "REF", dialect);
- dropScript.add("ALTER TABLE JCR_" + multiDb + "REF " + dropCommand(true, constraintName, dialect));
-
- dropScript.add("DROP INDEX JCR_IDX_" + multiDb + "ITEM_PARENT_FK");
- dropScript.add("DROP INDEX JCR_IDX_" + multiDb + "ITEM_PARENT");
- dropScript.add("DROP INDEX JCR_IDX_" + multiDb + "ITEM_PARENT_ID");
- dropScript.add("DROP INDEX JCR_IDX_" + multiDb + "ITEM_N_ORDER_NUM");
- dropScript.add("DROP INDEX JCR_IDX_" + multiDb + "VALUE_PROPERTY");
- dropScript.add("DROP INDEX JCR_IDX_" + multiDb + "REF_PROPERTY");
- }
- else if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE))
- {
- dropScript.add("ALTER TABLE JCR_" + multiDb + "VALUE DROP CONSTRAINT JCR_FK_" + multiDb + "VALUE_PROPERTY");
- dropScript.add("ALTER TABLE JCR_" + multiDb + "ITEM DROP CONSTRAINT JCR_PK_" + multiDb + "ITEM");
- dropScript.add("ALTER TABLE JCR_" + multiDb + "VALUE DROP CONSTRAINT JCR_PK_" + multiDb + "VALUE");
- dropScript.add("DROP INDEX JCR_" + multiDb + "ITEM.JCR_IDX_" + multiDb + "ITEM_PARENT");
- dropScript.add("DROP INDEX JCR_" + multiDb + "ITEM.JCR_IDX_" + multiDb + "ITEM_PARENT_ID");
- dropScript.add("DROP INDEX JCR_" + multiDb + "ITEM.JCR_IDX_" + multiDb + "ITEM_N_ORDER_NUM");
- dropScript.add("DROP INDEX JCR_" + multiDb + "VALUE.JCR_IDX_" + multiDb + "VALUE_PROPERTY");
- dropScript.add("DROP INDEX JCR_" + multiDb + "REF.JCR_IDX_" + multiDb + "REF_PROPERTY");
- }
-
- return dropScript;
+ return new DBCleanerTool(jdbcConn, scripts.getCleaningScripts(), scripts.getCommittingScripts(),
+ scripts.getRollbackingScripts());
}
/**
- * After of restore tables. (Add constraint, etc...)
+ * Cleaning.
*
- * @param isMultiDb
- * boolean
- * @param dialect
- * String, dialect of DB
+ * @throws SQLException
*/
- private static List<String> getRestoreIndexesScripts(boolean isMultiDB, String dialect)
- throws RepositoryConfigurationException
+ private static void doClean(DBCleanerTool dbCleaner) throws DBCleanException, SQLException
{
- ArrayList<String> addScript = new ArrayList<String>();
-
- String multiDb = isMultiDB ? "M" : "S";
-
- String constraintName;
- String constraint;
-
- if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE))
+ Connection jdbcConn = dbCleaner.getConnection();
+ try
{
- addScript.add("ALTER TABLE JCR_" + multiDb + "ITEM ADD CONSTRAINT JCR_PK_" + multiDb
- + "ITEM PRIMARY KEY(ID)");
- addScript.add("ALTER TABLE JCR_" + multiDb + "VALUE ADD CONSTRAINT JCR_PK_" + multiDb
- + "VALUE PRIMARY KEY(ID)");
+ dbCleaner.clean();
+ dbCleaner.commit();
- constraintName = validateConstraintName("JCR_FK_" + multiDb + "ITEM_PARENT", dialect);
- constraint = "CONSTRAINT " + constraintName + " FOREIGN KEY(PARENT_ID) REFERENCES JCR_" + multiDb + "ITEM(ID)";
- addScript.add("ALTER TABLE JCR_" + multiDb + "ITEM ADD " + constraint);
-
- addScript.add("ALTER TABLE JCR_" + multiDb + "VALUE ADD CONSTRAINT JCR_FK_" + multiDb
- + "VALUE_PROPERTY FOREIGN KEY(PROPERTY_ID) REFERENCES JCR_" + multiDb + "ITEM(ID)");
-
- addScript.add(DBInitializerHelper.getObjectScript("CREATE UNIQUE INDEX JCR_IDX_" + multiDb
- + "ITEM_PARENT ON JCR_" + multiDb + "ITEM", isMultiDB, dialect));
- addScript.add(DBInitializerHelper.getObjectScript("CREATE UNIQUE INDEX JCR_IDX_" + multiDb
- + "ITEM_PARENT_ID ON JCR_" + multiDb + "ITEM", isMultiDB, dialect));
- addScript.add(DBInitializerHelper.getObjectScript("CREATE UNIQUE INDEX JCR_IDX_" + multiDb
- + "ITEM_N_ORDER_NUM ON JCR_" + multiDb + "ITEM", isMultiDB, dialect));
- addScript.add(DBInitializerHelper.getObjectScript("CREATE UNIQUE INDEX JCR_IDX_" + multiDb
- + "VALUE_PROPERTY ON JCR_" + multiDb + "VALUE", isMultiDB, dialect));
- addScript.add(DBInitializerHelper.getObjectScript("CREATE UNIQUE INDEX JCR_IDX_" + multiDb
- + "REF_PROPERTY ON JCR_" + multiDb + "REF", isMultiDB, dialect));
-
- return addScript;
+ jdbcConn.commit();
}
-
- if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_UTF8)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_MYISAM)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_MYISAM_UTF8))
+ catch (SQLException e)
{
- constraintName = validateConstraintName("JCR_FK_" + multiDb + "VALUE_PROPERTY", dialect);
- constraint =
- "CONSTRAINT " + constraintName + " FOREIGN KEY(PROPERTY_ID) REFERENCES JCR_" + multiDb + "ITEM(ID)";
- addScript.add("ALTER TABLE JCR_" + multiDb + "VALUE ADD " + constraint);
- }
+ jdbcConn.rollback();
- if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLE)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLEOCI))
- {
- constraintName = validateConstraintName("JCR_PK_" + multiDb + "VALUE", dialect);
- constraint = "CONSTRAINT " + constraintName + " PRIMARY KEY(ID)";
- addScript.add("ALTER TABLE JCR_" + multiDb + "VALUE ADD " + constraint);
+ dbCleaner.rollback();
- constraintName = validateConstraintName("JCR_PK_" + multiDb + "ITEM", dialect);
- constraint = "CONSTRAINT " + constraintName + " PRIMARY KEY(ID)";
- addScript.add("ALTER TABLE JCR_" + multiDb + "ITEM ADD " + constraint);
-
- constraintName = validateConstraintName("JCR_FK_" + multiDb + "VALUE_PROPERTY", dialect);
- constraint =
- "CONSTRAINT " + constraintName + " FOREIGN KEY(PROPERTY_ID) REFERENCES JCR_" + multiDb + "ITEM(ID)";
- addScript.add("ALTER TABLE JCR_" + multiDb + "VALUE ADD " + constraint);
-
- constraintName = validateConstraintName("JCR_PK_" + multiDb + "REF", dialect);
- constraint = "CONSTRAINT " + constraintName + " PRIMARY KEY(NODE_ID, PROPERTY_ID, ORDER_NUM)";
- addScript.add("ALTER TABLE JCR_" + multiDb + "REF ADD " + constraint);
-
- addScript.add(DBInitializerHelper.getObjectScript("JCR_IDX_" + multiDb + "ITEM_PARENT_FK ON JCR_" + multiDb
- + "ITEM", isMultiDB, dialect));
- addScript.add(DBInitializerHelper.getObjectScript("JCR_IDX_" + multiDb + "ITEM_PARENT ON JCR_" + multiDb
- + "ITEM", isMultiDB, dialect));
- addScript.add(DBInitializerHelper.getObjectScript("JCR_IDX_" + multiDb + "ITEM_PARENT_ID ON JCR_" + multiDb
- + "ITEM", isMultiDB, dialect));
- addScript.add(DBInitializerHelper.getObjectScript("JCR_IDX_" + multiDb + "ITEM_N_ORDER_NUM ON JCR_" + multiDb
- + "ITEM", isMultiDB, dialect));
- addScript.add(DBInitializerHelper.getObjectScript("JCR_IDX_" + multiDb + "VALUE_PROPERTY ON JCR_" + multiDb
- + "VALUE", isMultiDB, dialect));
- addScript.add(DBInitializerHelper.getObjectScript("JCR_IDX_" + multiDb + "REF_PROPERTY ON JCR_" + multiDb
- + "REF", isMultiDB, dialect));
+ jdbcConn.commit();
}
-
- constraintName = validateConstraintName("JCR_FK_" + multiDb + "ITEM_PARENT", dialect);
- constraint = "CONSTRAINT " + constraintName + " FOREIGN KEY(PARENT_ID) REFERENCES JCR_" + multiDb + "ITEM(ID)";
- addScript.add("ALTER TABLE JCR_" + multiDb + "ITEM ADD " + constraint);
-
- return addScript;
}
/**
- * Validate name of constraint. For some DBs constrains name is limited.
- *
- * @param string
- * the constraint name
- * @param dialect
- * String, dialect of DB
- * @return the constraint name accepted for specific DB
+ * Opens connection to database underlying a workspace.
*/
- private static String validateConstraintName(String string, String dialect)
+ private static Connection getConnection(WorkspaceEntry wsEntry) throws DBCleanException
{
- if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_DB2)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_DB2V8))
- {
- return string.substring(0, DB2_CONSTRAINT_NAME_LENGTH_LIMIT);
- }
- else
- {
- return string;
- }
- }
+ String dsName = getSourceNameParameter(wsEntry);
- /**
- * Return the SQL script for drop primary or foreign key.
- *
- * @param isPrimaryKey
- * boolean
- * @param dialect
- * String, dialect of DB
- * @return String
- */
- protected static String dropCommand(boolean isPrimaryKey, String constraintName, String dialect)
- {
- if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_UTF8)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_MYISAM)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_MYISAM_UTF8))
+ DataSource ds;
+ try
{
- return isPrimaryKey == true ? "DROP PRIMARY KEY" : "DROP FOREIGN KEY " + constraintName;
+ ds = (DataSource)new InitialContext().lookup(dsName);
}
- else
+ catch (NamingException e)
{
- return "DROP CONSTRAINT " + constraintName;
+ throw new DBCleanException(e);
}
- }
- /**
- * Create list with queries to drop tables, etc...
- *
- * @param multiDb
- * @return List
- * return list with query
- */
- protected static List<String> getDropTableScripts(boolean multiDb, String dialect)
- {
- final String isMultiDB = (multiDb ? "M" : "S");
-
- List<String> cleanScripts = new ArrayList<String>();
-
- if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLE)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLEOCI))
+ if (ds == null)
{
- cleanScripts.add("DROP TRIGGER BI_JCR_" + isMultiDB + "VALUE");
- cleanScripts.add("DROP SEQUENCE JCR_" + isMultiDB + "VALUE_SEQ");
+ throw new DBCleanException("Data source " + dsName + " not found");
}
- cleanScripts.add("DROP TABLE JCR_" + isMultiDB + "VALUE");
- cleanScripts.add("DROP TABLE JCR_" + isMultiDB + "ITEM");
- cleanScripts.add("DROP TABLE JCR_" + isMultiDB + "REF");
+ final DataSource dsF = ds;
- return cleanScripts;
- }
-
- /**
- * Create script to rename tables, indexes, etc...
- *
- * @param multiDb
- * boolean
- * @param dialect
- * string
- * @return List
- * return list with query
- */
- protected static List<String> getRenameScripts(boolean multiDb, String dialect)
- {
- final String isMultiDB = (multiDb ? "M" : "S");
-
- List<String> renameScripts = new ArrayList<String>();
-
- if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLE)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLEOCI))
+ Connection jdbcConn;
+ try
{
- // JCR_[S,M]VALUE
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "VALUE RENAME TO JCR_" + isMultiDB + "VALUE"
- + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "VALUE" + OLD_OBJECT_SUFFIX + " RENAME CONSTRAINT JCR_PK_"
- + isMultiDB + "VALUE TO JCR_PK_" + isMultiDB + "VALUE" + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "VALUE" + OLD_OBJECT_SUFFIX + " RENAME CONSTRAINT JCR_FK_"
- + isMultiDB + "VALUE_PROPERTY TO JCR_FK_" + isMultiDB + "VALUE_PROPERTY" + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER INDEX JCR_PK_" + isMultiDB + "VALUE RENAME TO JCR_PK_" + isMultiDB + "VALUE"
- + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "VALUE_PROPERTY RENAME TO JCR_IDX_" + isMultiDB
- + "VALUE_PROPERTY" + OLD_OBJECT_SUFFIX);
-
- renameScripts.add("RENAME JCR_" + isMultiDB + "VALUE_SEQ TO JCR_" + isMultiDB + "VALUE_SEQ"
- + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER TRIGGER BI_JCR_" + isMultiDB + "VALUE RENAME TO BI_JCR_" + isMultiDB + "VALUE"
- + OLD_OBJECT_SUFFIX);
-
- // JCR_[S,M]ITEM
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "ITEM RENAME TO JCR_" + isMultiDB + "ITEM"
- + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "ITEM" + OLD_OBJECT_SUFFIX + " RENAME CONSTRAINT JCR_PK_"
- + isMultiDB + "ITEM TO JCR_PK_" + isMultiDB + "ITEM" + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "ITEM" + OLD_OBJECT_SUFFIX + " RENAME CONSTRAINT JCR_FK_"
- + isMultiDB + "ITEM_PARENT TO JCR_FK_" + isMultiDB + "ITEM_PARENT" + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER INDEX JCR_PK_" + isMultiDB + "ITEM RENAME TO JCR_PK_" + isMultiDB + "ITEM"
- + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "ITEM_PARENT_FK RENAME TO JCR_IDX_" + isMultiDB
- + "ITEM_PARENT_FK" + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "ITEM_PARENT RENAME TO JCR_IDX_" + isMultiDB
- + "ITEM_PARENT" + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "ITEM_PARENT_ID RENAME TO JCR_IDX_" + isMultiDB
- + "ITEM_PARENT_ID" + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "ITEM_N_ORDER_NUM RENAME TO JCR_IDX_" + isMultiDB
- + "ITEM_N_ORDER_NUM" + OLD_OBJECT_SUFFIX);
-
- // JCR_[S,M]REF
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "REF RENAME TO JCR_" + isMultiDB + "REF"
- + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "REF" + OLD_OBJECT_SUFFIX + " RENAME CONSTRAINT JCR_PK_"
- + isMultiDB + "REF TO JCR_PK_" + isMultiDB + "REF" + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER INDEX JCR_PK_" + isMultiDB + "REF RENAME TO JCR_PK_" + isMultiDB + "REF"
- + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "REF_PROPERTY RENAME TO JCR_IDX_" + isMultiDB
- + "REF_PROPERTY" + OLD_OBJECT_SUFFIX);
+ jdbcConn = SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Connection>()
+ {
+ public Connection run() throws Exception
+ {
+ return dsF.getConnection();
+ }
+ });
}
- else if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_UTF8)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_MYISAM)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_MYISAM_UTF8))
+ catch (SQLException e)
{
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "VALUE RENAME TO JCR_" + isMultiDB + "VALUE"
- + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "ITEM RENAME TO JCR_" + isMultiDB + "ITEM"
- + OLD_OBJECT_SUFFIX);
-
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "REF RENAME TO JCR_" + isMultiDB + "REF"
- + OLD_OBJECT_SUFFIX);
+ throw new DBCleanException(e);
}
- else if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE))
- {
- renameScripts.add("sp_rename JCR_" + isMultiDB + "VALUE, JCR_" + isMultiDB + "VALUE" + OLD_OBJECT_SUFFIX);
- renameScripts.add("sp_rename JCR_" + isMultiDB + "ITEM, JCR_" + isMultiDB + "ITEM" + OLD_OBJECT_SUFFIX);
- renameScripts.add("sp_rename JCR_" + isMultiDB + "REF, JCR_" + isMultiDB + "REF" + OLD_OBJECT_SUFFIX);
- renameScripts.add("sp_rename JCR_FK_" + isMultiDB + "VALUE_PROPERTY, JCR_FK_" + isMultiDB + "VALUE_PROPERTY"
- + OLD_OBJECT_SUFFIX);
- renameScripts.add("sp_rename JCR_FK_" + isMultiDB + "ITEM_PARENT, JCR_FK_" + isMultiDB + "ITEM_PARENT_OLD");
- }
- else if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_HSQLDB))
- {
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "VALUE RENAME TO JCR_" + isMultiDB + "VALUE"
- + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "ITEM RENAME TO JCR_" + isMultiDB + "ITEM"
- + OLD_OBJECT_SUFFIX);
- renameScripts
- .add("ALTER TABLE JCR_" + isMultiDB + "REF RENAME TO JCR_" + isMultiDB + "REF" + OLD_OBJECT_SUFFIX);
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "VALUE" + OLD_OBJECT_SUFFIX + " DROP CONSTRAINT JCR_FK_"
- + isMultiDB + "VALUE_PROPERTY");
-
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "ITEM" + OLD_OBJECT_SUFFIX + " DROP CONSTRAINT JCR_FK_"
- + isMultiDB + "ITEM_PARENT");
-
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "ITEM" + OLD_OBJECT_SUFFIX + " DROP CONSTRAINT JCR_PK_"
- + isMultiDB + "ITEM");
-
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "VALUE" + OLD_OBJECT_SUFFIX + " DROP CONSTRAINT JCR_PK_"
- + isMultiDB + "VALUE");
-
- renameScripts.add("ALTER TABLE JCR_" + isMultiDB + "REF" + OLD_OBJECT_SUFFIX + " DROP CONSTRAINT JCR_PK_"
- + isMultiDB + "REF");
-
- renameScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "ITEM_PARENT RENAME TO JCR_IDX_" + isMultiDB
- + "ITEM_PARENT" + OLD_OBJECT_SUFFIX);
-
- renameScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "ITEM_PARENT_ID RENAME TO JCR_IDX_" + isMultiDB
- + "ITEM_PARENT_ID" + OLD_OBJECT_SUFFIX);
-
- renameScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "ITEM_N_ORDER_NUM RENAME TO JCR_IDX_" + isMultiDB
- + "ITEM_N_ORDER_NUM" + OLD_OBJECT_SUFFIX);
-
- renameScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "VALUE_PROPERTY RENAME TO JCR_IDX_" + isMultiDB
- + "VALUE_PROPERTY" + OLD_OBJECT_SUFFIX);
-
- renameScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "REF_PROPERTY RENAME TO JCR_IDX_" + isMultiDB
- + "REF_PROPERTY" + OLD_OBJECT_SUFFIX);
- }
-
- return renameScripts;
+ return jdbcConn;
}
/**
- * Create script to rollback changes after rename.
- *
- * @param multiDb
- * boolean
- * @param dialect
- * string
- * @return List
- * return list with query
- * @throws RepositoryConfigurationException
+ * Return {@link JDBCWorkspaceDataContainer#SOURCE_NAME} parameter from workspace configuration.
*/
- protected static List<String> getRollbackScripts(boolean multiDb, String dialect)
- throws RepositoryConfigurationException
+ private static String getSourceNameParameter(WorkspaceEntry wsEntry) throws DBCleanException
{
- final String isMultiDB = (multiDb ? "M" : "S");
-
- List<String> rollbackScripts = new ArrayList<String>();
-
- rollbackScripts.addAll(getDropTableScripts(multiDb, dialect));
-
- if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLE)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_ORACLEOCI))
+ try
{
- // JCR_[S,M]VALUE
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "VALUE" + OLD_OBJECT_SUFFIX + " RENAME TO JCR_" + isMultiDB
- + "VALUE");
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "VALUE RENAME CONSTRAINT JCR_PK_" + isMultiDB
- + "VALUE" + OLD_OBJECT_SUFFIX + " TO JCR_PK_" + isMultiDB + "VALUE");
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "VALUE RENAME CONSTRAINT JCR_FK_" + isMultiDB
- + "VALUE_PROPERTY" + OLD_OBJECT_SUFFIX + " TO JCR_FK_" + isMultiDB + "VALUE_PROPERTY");
- rollbackScripts.add("ALTER INDEX JCR_PK_" + isMultiDB + "VALUE" + OLD_OBJECT_SUFFIX + " RENAME TO JCR_PK_"
- + isMultiDB + "VALUE");
- rollbackScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "VALUE_PROPERTY" + OLD_OBJECT_SUFFIX
- + " RENAME TO JCR_IDX_" + isMultiDB + "VALUE_PROPERTY");
-
- rollbackScripts.add("RENAME JCR_" + isMultiDB + "VALUE_SEQ" + OLD_OBJECT_SUFFIX + " TO JCR_" + isMultiDB
- + "VALUE_SEQ");
- rollbackScripts.add("ALTER TRIGGER BI_JCR_" + isMultiDB + "VALUE" + OLD_OBJECT_SUFFIX + " RENAME TO BI_JCR_"
- + isMultiDB + "VALUE");
-
- // JCR_[S,M]ITEM
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "ITEM" + OLD_OBJECT_SUFFIX + " RENAME TO JCR_" + isMultiDB
- + "ITEM");
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "ITEM RENAME CONSTRAINT JCR_PK_" + isMultiDB
- + "ITEM" + OLD_OBJECT_SUFFIX + " TO JCR_PK_" + isMultiDB + "ITEM");
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "ITEM RENAME CONSTRAINT JCR_FK_" + isMultiDB
- + "ITEM_PARENT" + OLD_OBJECT_SUFFIX + " TO JCR_FK_" + isMultiDB + "ITEM_PARENT");
- rollbackScripts.add("ALTER INDEX JCR_PK_" + isMultiDB + "ITEM" + OLD_OBJECT_SUFFIX + " RENAME TO JCR_PK_"
- + isMultiDB + "ITEM");
- rollbackScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "ITEM_PARENT_FK" + OLD_OBJECT_SUFFIX
- + " RENAME TO JCR_IDX_" + isMultiDB + "ITEM_PARENT_FK");
- rollbackScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "ITEM_PARENT" + OLD_OBJECT_SUFFIX
- + " RENAME TO JCR_IDX_" + isMultiDB + "ITEM_PARENT");
- rollbackScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "ITEM_PARENT_ID" + OLD_OBJECT_SUFFIX
- + " RENAME TO JCR_IDX_" + isMultiDB + "ITEM_PARENT_ID");
- rollbackScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "ITEM_N_ORDER_NUM" + OLD_OBJECT_SUFFIX
- + " RENAME TO JCR_IDX_" + isMultiDB + "ITEM_N_ORDER_NUM");
-
- // JCR_[S,M]REF
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "REF" + OLD_OBJECT_SUFFIX + " RENAME TO JCR_" + isMultiDB
- + "REF");
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "REF RENAME CONSTRAINT JCR_PK_" + isMultiDB
- + "REF" + OLD_OBJECT_SUFFIX + " TO JCR_PK_" + isMultiDB + "REF");
- rollbackScripts.add("ALTER INDEX JCR_PK_" + isMultiDB + "REF" + OLD_OBJECT_SUFFIX + " RENAME TO JCR_PK_"
- + isMultiDB + "REF");
- rollbackScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "REF_PROPERTY" + OLD_OBJECT_SUFFIX
- + " RENAME TO JCR_IDX_" + isMultiDB + "REF_PROPERTY");
+ return wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);
}
- else if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_UTF8)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_MYISAM)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_MYISAM_UTF8))
+ catch (RepositoryConfigurationException e)
{
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "ITEM" + OLD_OBJECT_SUFFIX + " RENAME TO JCR_"
- + isMultiDB + "ITEM");
-
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "VALUE" + OLD_OBJECT_SUFFIX + " RENAME TO JCR_"
- + isMultiDB + "VALUE");
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "REF" + OLD_OBJECT_SUFFIX + " RENAME TO JCR_" + isMultiDB
- + "REF");
+ throw new DBCleanException(e);
}
- else if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE))
- {
- rollbackScripts.add("sp_rename JCR_" + isMultiDB + "VALUE" + OLD_OBJECT_SUFFIX + ", JCR_" + isMultiDB
- + "VALUE");
- rollbackScripts.add("sp_rename JCR_" + isMultiDB + "ITEM" + OLD_OBJECT_SUFFIX + ", JCR_" + isMultiDB + "ITEM");
- rollbackScripts.add("sp_rename JCR_" + isMultiDB + "REF" + OLD_OBJECT_SUFFIX + ", JCR_" + isMultiDB + "REF");
-
- rollbackScripts.add("sp_rename JCR_FK_" + isMultiDB + "VALUE_PROPERTY" + OLD_OBJECT_SUFFIX + ", JCR_FK_"
- + isMultiDB + "VALUE_PROPERTY");
-
- rollbackScripts.add("sp_rename JCR_FK_" + isMultiDB + "ITEM_PARENT" + OLD_OBJECT_SUFFIX + ", JCR_FK_"
- + isMultiDB + "ITEM_PARENT");
- }
- else if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_HSQLDB))
- {
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "VALUE" + OLD_OBJECT_SUFFIX + " RENAME TO JCR_"
- + isMultiDB + "VALUE");
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "ITEM" + OLD_OBJECT_SUFFIX + " RENAME TO JCR_"
- + isMultiDB + "ITEM");
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "REF" + OLD_OBJECT_SUFFIX + " RENAME TO JCR_" + isMultiDB
- + "REF");
-
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "ITEM ADD CONSTRAINT JCR_PK_" + isMultiDB
- + "ITEM PRIMARY KEY(ID)");
-
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "VALUE ADD CONSTRAINT JCR_FK_" + isMultiDB
- + "VALUE_PROPERTY FOREIGN KEY(PROPERTY_ID) REFERENCES JCR_" + isMultiDB + "ITEM(ID)");
-
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "ITEM ADD CONSTRAINT JCR_FK_" + isMultiDB
- + "ITEM_PARENT FOREIGN KEY(PARENT_ID) REFERENCES JCR_" + isMultiDB + "ITEM(ID)");
-
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "VALUE ADD CONSTRAINT JCR_PK_" + isMultiDB
- + "VALUE PRIMARY KEY(ID)");
-
- rollbackScripts.add("ALTER TABLE JCR_" + isMultiDB + "REF ADD CONSTRAINT JCR_PK_" + isMultiDB
- + "REF PRIMARY KEY(NODE_ID, PROPERTY_ID, ORDER_NUM)");
-
- rollbackScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "ITEM_PARENT" + OLD_OBJECT_SUFFIX
- + " RENAME TO JCR_IDX_" + isMultiDB + "ITEM_PARENT");
-
- rollbackScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "ITEM_PARENT_ID" + OLD_OBJECT_SUFFIX
- + " RENAME TO JCR_IDX_" + isMultiDB + "ITEM_PARENT_ID");
-
- rollbackScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "ITEM_N_ORDER_NUM" + OLD_OBJECT_SUFFIX
- + " RENAME TO JCR_IDX_" + isMultiDB + "ITEM_N_ORDER_NUM");
-
- rollbackScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "VALUE_PROPERTY" + OLD_OBJECT_SUFFIX
- + " RENAME TO JCR_IDX_" + isMultiDB + "VALUE_PROPERTY");
-
- rollbackScripts.add("ALTER INDEX JCR_IDX_" + isMultiDB + "REF_PROPERTY" + OLD_OBJECT_SUFFIX
- + " RENAME TO JCR_IDX_" + isMultiDB + "REF_PROPERTY");
- }
-
- return rollbackScripts;
}
/**
- * Create script to drop old tables, indexes, etc...after successful restore DB.
- *
- * @param multiDb
- * boolean
- * @param dialect
- * string
- * @return List
- * return list with query
+ * Return {@link JDBCWorkspaceDataContainer#MULTIDB} parameter from workspace configuration.
*/
- protected static List<String> getRemoveOldObjectsScripts(boolean multiDb, String dialect)
+ private static boolean getMultiDbParameter(WorkspaceEntry wsEntry) throws DBCleanException
{
- List<String> afterRetoreScripts = new ArrayList<String>();
-
- for (String query : getDropTableScripts(multiDb, dialect))
- {
- afterRetoreScripts.add(query + OLD_OBJECT_SUFFIX);
- }
-
- return afterRetoreScripts;
- }
-
- /**
- * Create list with queries to initialization database.
- *
- * @param isMultiDb
- * @param dialect
- * @return
- * @throws RepositoryConfigurationException
- */
- protected static List<String> getInitializationDBScripts(boolean isMultiDb, String dialect)
- throws RepositoryConfigurationException
- {
- String multiDb = isMultiDb ? "M" : "S";
-
- String scriptsPath = DBInitializerHelper.scriptPath(dialect, isMultiDb);
- String script;
try
{
- script = IOUtil.getStreamContentAsString(PrivilegedFileHelper.getResourceAsStream(scriptsPath));
+ return Boolean.parseBoolean(wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB));
}
- catch (IOException e)
+ catch (RepositoryConfigurationException e)
{
- throw new RepositoryConfigurationException("Can not read script file " + scriptsPath, e);
+ throw new DBCleanException(e);
}
-
- List<String> scripts = new ArrayList<String>();
- for (String query : JDBCUtils.splitWithSQLDelimiter(script))
- {
- // Skip creation JCR_S(M)CONTAINER TABLE
- if (!query.contains("CREATE TABLE JCR_" + multiDb + "CONTAINER"))
- {
- scripts.add(JDBCUtils.cleanWhitespaces(query));
- }
- }
-
- scripts.add(DBInitializerHelper.getRootNodeInitializeScript(isMultiDb));
-
- // Filter scripts
- if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_UTF8)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_MYISAM)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MYSQL_MYISAM_UTF8))
- {
- for (int i = 0; i < scripts.size(); i++)
- {
- String query = scripts.get(i);
- if (query.contains("JCR_PK_" + multiDb + "ITEM PRIMARY KEY(ID),"))
- {
- // removing foreign key creation from initialization scripts for table JCR_S(M)ITEM
- // it is not possible to create table with such foreign key if the same key exists in
- // another table of database
- query =
- query.replace("JCR_PK_" + multiDb + "ITEM PRIMARY KEY(ID),", "JCR_PK_" + multiDb
- + "ITEM PRIMARY KEY(ID)");
- query =
- query.replace("CONSTRAINT JCR_FK_" + multiDb + "ITEM_PARENT FOREIGN KEY(PARENT_ID) REFERENCES JCR_"
- + multiDb + "ITEM(ID)", "");
- scripts.set(i, query);
- }
- else if (query.contains("CONSTRAINT JCR_PK_" + multiDb + "VALUE PRIMARY KEY(ID),"))
- {
- // removing foreign key creation for table 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
- query =
- query.replace("CONSTRAINT JCR_PK_" + multiDb + "VALUE PRIMARY KEY(ID),", "CONSTRAINT JCR_PK_"
- + multiDb + "VALUE PRIMARY KEY(ID)");
- query =
- query.replace("CONSTRAINT JCR_FK_" + multiDb
- + "VALUE_PROPERTY FOREIGN KEY(PROPERTY_ID) REFERENCES JCR_" + multiDb + "ITEM(ID)", "");
- scripts.set(i, query);
- }
- }
- }
-
- return scripts;
}
/**
- * Returns database cleaner of workspace.
+ * Resolves dialect which it is used in workspace configuration. First of all,
+ * method will try to get parameter {@link JDBCWorkspaceDataContainer#DB_DIALECT} from
+ * a configuration. And only then method will try to detect dialect using {@link DialectDetecter} in case
+ * if dialect is set as {@link DialectConstants#DB_DIALECT_AUTO}.
*
- * @param jdbcConn
- * database connection which need to use
* @param wsEntry
* workspace configuration
- * @return
- * @throws SQLException
- * @throws RepositoryConfigurationException
+ * @return dialect
+ * @throws DBCleanException
*/
- public static DBCleaner getWorkspaceDBCleaner(Connection jdbcConn, WorkspaceEntry wsEntry) throws SQLException,
- RepositoryConfigurationException
+ private static String resolveDialect(WorkspaceEntry wsEntry) throws DBCleanException
{
- // Need privileges to manage repository.
- SecurityManager security = System.getSecurityManager();
- if (security != null)
- {
- security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
- }
-
- boolean isMultiDB =
- Boolean.parseBoolean(wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB));
-
String dialect =
wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.DB_DIALECT, DBConstants.DB_DIALECT_AUTO);
- if (DBConstants.DB_DIALECT_GENERIC.equalsIgnoreCase(dialect)
- || DBConstants.DB_DIALECT_AUTO.equalsIgnoreCase(dialect))
- {
- dialect = DialectDetecter.detect(jdbcConn.getMetaData());
- }
- if (!isMultiDB)
+ if (DBConstants.DB_DIALECT_AUTO.equalsIgnoreCase(dialect))
{
- String containerName = wsEntry.getName();
- String multiDb = isMultiDB ? "M" : "S";
-
- List<String> cleanScripts = new ArrayList<String>();
- List<String> commitScripts = new ArrayList<String>();
- List<String> rollbackScripts = new ArrayList<String>();
-
- String constraintName = validateConstraintName("JCR_FK_" + multiDb + "ITEM_PARENT", dialect);
- cleanScripts.add("ALTER TABLE JCR_" + multiDb + "ITEM " + dropCommand(false, constraintName, dialect));
-
- String constraint =
- "CONSTRAINT " + constraintName + " FOREIGN KEY(PARENT_ID) REFERENCES JCR_" + multiDb + "ITEM(ID)";
- commitScripts.add("ALTER TABLE JCR_" + multiDb + "ITEM ADD " + constraint);
-
- // PostgreSQL, DB2 and MSSQL on connection.rollback() will restore all removed constrains
- if (!dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_PGSQL)
- && !dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_DB2)
- && !dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_DB2V8)
- && !dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MSSQL))
+ try
{
- rollbackScripts.add("ALTER TABLE JCR_" + multiDb + "ITEM ADD " + constraint);
+ Connection jdbcConn = getConnection(wsEntry);
+ dialect = DialectDetecter.detect(jdbcConn.getMetaData());
}
-
- cleanScripts
- .add("delete from JCR_SVALUE where PROPERTY_ID IN (select ID from JCR_SITEM where CONTAINER_NAME='"
- + containerName + "')");
- cleanScripts.add("delete from JCR_SREF where PROPERTY_ID IN (select ID from JCR_SITEM where CONTAINER_NAME='"
- + containerName + "')");
- cleanScripts.add("delete from JCR_SITEM where CONTAINER_NAME='" + containerName + "'");
-
- return new DBCleaner(jdbcConn, cleanScripts, rollbackScripts, commitScripts,
- dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE));
- }
- else
- {
- // PostgreSQL, DB2 and MSSQL on connection.rollback() will restore all removed tables
- if (dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_DB2)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_DB2V8)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_MSSQL)
- || dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_PGSQL))
+ catch (SQLException e)
{
- List<String> cleanScripts = new ArrayList<String>();
-
- cleanScripts.addAll(getDropTableScripts(isMultiDB, dialect));
- cleanScripts.addAll(getInitializationDBScripts(isMultiDB, dialect));
- cleanScripts.addAll(getRemoveIndexesScripts(isMultiDB, dialect));
-
- return new DBCleaner(jdbcConn, cleanScripts, new ArrayList<String>(), getRestoreIndexesScripts(isMultiDB,
- dialect), false);
+ throw new DBCleanException(e);
}
- else
- {
- ArrayList<String> cleanScripts = new ArrayList<String>();
- cleanScripts.addAll(getRenameScripts(isMultiDB, dialect));
- cleanScripts.addAll(getInitializationDBScripts(isMultiDB, dialect));
- cleanScripts.addAll(getRemoveIndexesScripts(isMultiDB, dialect));
-
- ArrayList<String> commitScript = new ArrayList<String>();
- commitScript.addAll(getRemoveOldObjectsScripts(isMultiDB, dialect));
- commitScript.addAll(getRestoreIndexesScripts(isMultiDB, dialect));
-
- return new DBCleaner(jdbcConn, cleanScripts, getRollbackScripts(isMultiDB, dialect), commitScript,
- dialect.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE));
- }
}
- }
- private static void processingClean(DBCleaner dbCleaner, Connection jdbcConn) throws SQLException
- {
- try
- {
- dbCleaner.executeCleanScripts();
- dbCleaner.executeCommitScripts();
-
- jdbcConn.commit();
- }
- catch (SQLException e)
- {
- jdbcConn.rollback();
-
- dbCleaner.executeRollbackScripts();
- jdbcConn.commit();
- }
- finally
- {
- jdbcConn.close();
- }
+ return dialect;
}
}
Deleted: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleaner.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleaner.java 2012-01-17 10:14:22 UTC (rev 5460)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleaner.java 2012-01-17 10:16:32 UTC (rev 5461)
@@ -1,202 +0,0 @@
-/*
- * Copyright (C) 2003-2010 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see<http://www.gnu.org/licenses/>.
- */
-package org.exoplatform.services.jcr.impl.clean.rdbms;
-
-import org.exoplatform.commons.utils.SecurityHelper;
-import org.exoplatform.services.database.utils.JDBCUtils;
-import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
-import java.security.PrivilegedExceptionAction;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * The goal of this class is removing data from database.
- *
- * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
- * @version $Id: DBCleaner.java 3769 2011-01-04 15:36:06Z areshetnyak $
- */
-public class DBCleaner
-{
- /**
- * Logger.
- */
- protected final static Log LOG = ExoLogger.getLogger("exo.jcr.component.core.DBClean");
-
- /**
- * Connection to database.
- */
- protected final Connection connection;
-
- /**
- * Common clean scripts for database.
- */
- protected final List<String> cleanScripts = new ArrayList<String>();
-
- /**
- * Rollback scripts for database.
- */
- protected final List<String> rollbackScripts = new ArrayList<String>();
-
- /**
- * Commit scripts for database.
- */
- protected final List<String> commitScripts = new ArrayList<String>();
-
- /**
- * Idicates if executing scripts should be done in autoCommit mode.
- */
- protected final boolean autoCommit;
-
- /**
- * 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
- * @param commitScripts
- * 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, boolean autoCommit)
- {
- this.connection = connection;
- this.cleanScripts.addAll(cleanScripts);
- this.rollbackScripts.addAll(rollbackScripts);
- this.commitScripts.addAll(commitScripts);
- this.autoCommit = autoCommit;
- }
-
- /**
- * Clean data from database. The method doesn't close connection or perform commit.
- *
- * @throws SQLException
- * if any errors occurred
- */
- public void executeCleanScripts() throws SQLException
- {
- executeScripts(cleanScripts);
- }
-
- /**
- * Rollback changes. The method doesn't close connection or perform commit.
- *
- * @throws SQLException
- * if any errors occurred
- */
- public void executeRollbackScripts() throws SQLException
- {
- executeScripts(rollbackScripts);
- }
-
- /**
- * Cleaning temporary objects. The method doesn't close connection or perform commit.
- *
- * @throws SQLException
- * if any errors occurred
- */
- public void executeCommitScripts() throws SQLException
- {
- executeScripts(commitScripts);
- }
-
- /**
- * Execute script on database.
- *
- * @param scripts
- * the scripts for execution
- * @param isSkipSQLExceprion
- * boolean, skipping SQLException on rollback.
- * @throws SQLException
- * if any exception occurred
- */
- protected void executeScripts(List<String> scripts) throws SQLException
- {
- SecurityManager security = System.getSecurityManager();
- if (security != null)
- {
- 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
- {
- for (String scr : scripts)
- {
- String sql = JDBCUtils.cleanWhitespaces(scr.trim());
- if (sql.length() > 0)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("Execute script: \n[" + sql + "]");
- }
-
- executeQuery(st, sql);
- }
- }
- }
- finally
- {
- try
- {
- st.close();
- }
- catch (SQLException e)
- {
- LOG.error("Can't close the Statement." + e);
- }
-
- // restore previous autoCommit mode
- if (this.autoCommit != autoCommit)
- {
- connection.setAutoCommit(autoCommit);
- }
- }
- }
-
- protected void executeQuery(final Statement statement, final String sql) throws SQLException
- {
- SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- statement.executeUpdate(sql);
- return null;
- }
- });
- }
-}
Added: 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 (rev 0)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanerTool.java 2012-01-17 10:16:32 UTC (rev 5461)
@@ -0,0 +1,200 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.clean.rdbms;
+
+import org.exoplatform.commons.utils.SecurityHelper;
+import org.exoplatform.services.database.utils.JDBCUtils;
+import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.security.PrivilegedExceptionAction;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * The goal of this class is removing data from database.
+ *
+ * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
+ * @version $Id: DBCleanerTool.java 3769 2011-01-04 15:36:06Z areshetnyak $
+ */
+public class DBCleanerTool
+{
+ /**
+ * Logger.
+ */
+ protected final static Log LOG = ExoLogger.getLogger("exo.jcr.component.core.DBCleaner");
+
+ protected final Connection connection;
+
+ protected final List<String> rollbackingScripts = new ArrayList<String>();
+
+ protected final List<String> committingScripts = new ArrayList<String>();
+
+ protected final List<String> cleaningScripts = new ArrayList<String>();
+
+ /**
+ * DBCleanerTool constructor.
+ *
+ * @param connection
+ * connection to database which will be used in cleaning, take in account DBCleanerTool does not
+ * close connection
+ */
+ DBCleanerTool(Connection connection, Collection<String> cleaningScripts, Collection<String> committingScripts,
+ Collection<String> rollbackingScripts)
+ {
+ this.connection = connection;
+
+ this.cleaningScripts.addAll(cleaningScripts);
+ this.committingScripts.addAll(committingScripts);
+ this.rollbackingScripts.addAll(rollbackingScripts);
+ }
+
+ /**
+ * Clean JCR tables, can't contain some indexes or constraints,
+ * should be added on {@link #commit}. It done for possibility to restore
+ * data without any violations.
+ *
+ * <br>
+ * This method does not invoke commit or rollback on {@link Connection}.
+ *
+ * @throws DBCleanException
+ */
+ public void clean() throws DBCleanException
+ {
+ try
+ {
+ execute(cleaningScripts);
+ }
+ catch (SQLException e)
+ {
+ throw new DBCleanException(e);
+ }
+ }
+
+ /**
+ * Executes SQL scripts for finishing clean operations if needed.
+ * It can be adding indexes, constraints, removing temporary objects etc
+ * (related to specific database) or does nothing.
+ *
+ * <br>
+ * This method does not invoke commit or rollback on {@link Connection}.
+ *
+ * @throws DBCleanException
+ */
+ public void commit() throws DBCleanException
+ {
+ try
+ {
+ execute(committingScripts);
+ }
+ catch (SQLException e)
+ {
+ throw new DBCleanException(e);
+ }
+ }
+
+ /**
+ * Tries to restore previous data by renaming tables etc
+ * (related to specific database) or does nothing.
+ *
+ * <br>
+ * This method does not invoke commit or rollback on {@link Connection}.
+ *
+ * @throws DBCleanException
+ */
+ public void rollback() throws DBCleanException
+ {
+ try
+ {
+ execute(rollbackingScripts);
+ }
+ catch (SQLException e)
+ {
+ throw new DBCleanException(e);
+ }
+ }
+
+ /**
+ * Return connection which it is used in cleaner.
+ */
+ public Connection getConnection()
+ {
+ return connection;
+ }
+
+ /**
+ * Execute script on database.
+ *
+ * @param scripts
+ * the scripts for execution
+ * @throws SQLException
+ */
+ protected void execute(List<String> scripts) throws SQLException
+ {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ {
+ security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
+ }
+
+ Statement st = connection.createStatement();
+ try
+ {
+ for (String scr : scripts)
+ {
+ String sql = JDBCUtils.cleanWhitespaces(scr.trim());
+ if (!sql.isEmpty())
+ {
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Execute script: \n[" + sql + "]");
+ }
+
+ executeQuery(st, sql);
+ }
+ }
+ }
+ finally
+ {
+ try
+ {
+ st.close();
+ }
+ catch (SQLException e)
+ {
+ LOG.error("Can't close the Statement." + e);
+ }
+ }
+ }
+
+ protected void executeQuery(final Statement statement, final String sql) throws SQLException
+ {
+ SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ statement.executeUpdate(sql);
+ return null;
+ }
+ });
+ }
+}
Deleted: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DummyDBCleaner.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DummyDBCleaner.java 2012-01-17 10:14:22 UTC (rev 5460)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DummyDBCleaner.java 2012-01-17 10:16:32 UTC (rev 5461)
@@ -1,61 +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.clean.rdbms;
-
-import java.sql.SQLException;
-import java.util.ArrayList;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * <br/>Date: 2011
- *
- * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
- * @version $Id: DummyDBCleaner.java 111 2011-11-11 11:11:11Z rainf0x $
- */
-public class DummyDBCleaner extends DBCleaner
-{
-
- /**
- * DummyDBCleaner constructor.
- */
- public DummyDBCleaner()
- {
- super(null, new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(), false);
- }
-
- /**
- * {@inheritDoc}
- */
- public void executeCleanScripts() throws SQLException
- {
- }
-
- /**
- * {@inheritDoc}
- */
- public void executeCommitScripts() throws SQLException
- {
- }
-
- /**
- * {@inheritDoc}
- */
- public void executeRollbackScripts() throws SQLException
- {
- }
-}
Added: 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 (rev 0)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DummyDBCleanerTool.java 2012-01-17 10:16:32 UTC (rev 5461)
@@ -0,0 +1,60 @@
+/*
+ * 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.clean.rdbms;
+
+import java.util.ArrayList;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2011
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id: DummyDBCleaner.java 111 2011-11-11 11:11:11Z rainf0x $
+ */
+public class DummyDBCleanerTool extends DBCleanerTool
+{
+
+ /**
+ * DummyDBCleanerTool constructor.
+ */
+ public DummyDBCleanerTool()
+ {
+ super(null, new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void clean() throws DBCleanException
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void commit() throws DBCleanException
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void rollback() throws DBCleanException
+ {
+ }
+}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cacheable/AbstractCacheableLockManager.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cacheable/AbstractCacheableLockManager.java 2012-01-17 10:14:22 UTC (rev 5460)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/cacheable/AbstractCacheableLockManager.java 2012-01-17 10:16:32 UTC (rev 5461)
@@ -18,6 +18,7 @@
import org.exoplatform.commons.utils.PrivilegedFileHelper;
import org.exoplatform.commons.utils.PrivilegedSystemHelper;
+import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
@@ -67,6 +68,7 @@
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -925,7 +927,15 @@
*/
public void clean() throws BackupException
{
- actualLocks.addAll(getLockList());
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ actualLocks.addAll(getLockList());
+ return null;
+ }
+ });
+
doClean();
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2012-01-17 10:14:22 UTC (rev 5460)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2012-01-17 10:16:32 UTC (rev 5461)
@@ -39,8 +39,9 @@
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.clean.rdbms.DBCleanException;
import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanService;
-import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleaner;
+import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanerTool;
import org.exoplatform.services.jcr.impl.core.lock.cacheable.AbstractCacheableLockManager;
import org.exoplatform.services.jcr.impl.core.query.NodeDataIndexingIterator;
import org.exoplatform.services.jcr.impl.core.query.Reindexable;
@@ -1032,18 +1033,14 @@
{
throw new BackupException(e);
}
- catch (NamingException e)
+ catch (IOException e)
{
throw new BackupException(e);
}
- catch (SQLException e)
+ catch (DBCleanException e)
{
throw new BackupException(e);
}
- catch (IOException e)
- {
- throw new BackupException(e);
- }
}
/**
@@ -1275,14 +1272,21 @@
}
tables.put(dstTableName, restoreTableRule);
- DBCleaner dbCleaner = null;
+ DBCleanerTool dbCleaner;
if (context.getObject(DataRestoreContext.DB_CLEANER) != null)
{
- dbCleaner = (DBCleaner)context.getObject(DataRestoreContext.DB_CLEANER);
+ dbCleaner = (DBCleanerTool)context.getObject(DataRestoreContext.DB_CLEANER);
}
else
{
- dbCleaner = DBCleanService.getWorkspaceDBCleaner(jdbcConn, wsConfig);
+ try
+ {
+ dbCleaner = DBCleanService.getWorkspaceDBCleaner(jdbcConn, wsConfig);
+ }
+ catch (DBCleanException e)
+ {
+ throw new BackupException(e);
+ }
}
restorers.add(new DBRestore(storageDir, jdbcConn, tables, wsConfig, swapCleaner, dbCleaner));
Modified: jcr/branches/1.15.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingRepositorySameConfigRestore.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingRepositorySameConfigRestore.java 2012-01-17 10:14:22 UTC (rev 5460)
+++ jcr/branches/1.15.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/JobExistingRepositorySameConfigRestore.java 2012-01-17 10:16:32 UTC (rev 5461)
@@ -32,8 +32,8 @@
import org.exoplatform.services.jcr.impl.backup.JCRRestore;
import org.exoplatform.services.jcr.impl.backup.rdbms.DataRestoreContext;
import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanService;
-import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleaner;
-import org.exoplatform.services.jcr.impl.clean.rdbms.DummyDBCleaner;
+import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanerTool;
+import org.exoplatform.services.jcr.impl.clean.rdbms.DummyDBCleanerTool;
import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
import org.exoplatform.services.jcr.impl.util.io.FileCleanerHolder;
@@ -89,7 +89,7 @@
Connection jdbcConn = null;
// define one common database cleaner for all restores for single db case
- DBCleaner dbCleaner = null;
+ DBCleanerTool dbCleaner = null;
Boolean isMultiDb =
Boolean.parseBoolean(wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.MULTIDB));
@@ -143,11 +143,9 @@
if (jdbcConn != null)
{
- if (dbCleaner != null)
+ if (!isMultiDb)
{
- if (isSharedDbCleaner)
- {
- context = new DataRestoreContext(
+ context = new DataRestoreContext(
new String[]{
DataRestoreContext.STORAGE_DIR,
DataRestoreContext.DB_CONNECTION,
@@ -155,22 +153,9 @@
new Object[]{
fullBackupDir,
jdbcConn,
- new DummyDBCleaner()});
- }
- else
- {
- context = new DataRestoreContext(
- new String[]{
- DataRestoreContext.STORAGE_DIR,
- DataRestoreContext.DB_CONNECTION,
- DataRestoreContext.DB_CLEANER},
- new Object[]{
- fullBackupDir,
- jdbcConn,
- dbCleaner});
+ isSharedDbCleaner ? new DummyDBCleanerTool() : dbCleaner});
- isSharedDbCleaner = true;
- }
+ isSharedDbCleaner = true;
}
else
{
Modified: jcr/branches/1.15.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/usecase/TestBackupRestore.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/usecase/TestBackupRestore.java 2012-01-17 10:14:22 UTC (rev 5460)
+++ jcr/branches/1.15.x/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/usecase/TestBackupRestore.java 2012-01-17 10:16:32 UTC (rev 5461)
@@ -39,8 +39,9 @@
import org.exoplatform.services.jcr.ext.backup.impl.JobRepositoryRestore;
import org.exoplatform.services.jcr.ext.backup.impl.JobWorkspaceRestore;
import org.exoplatform.services.jcr.impl.backup.Backupable;
+import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanException;
import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanService;
-import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleaner;
+import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleanerTool;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.exoplatform.services.jcr.impl.core.SessionRegistry;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
@@ -703,28 +704,38 @@
Connection conn = ds.getConnection();
conn.setAutoCommit(false);
- DBCleaner repositoryDBCleaner = DBCleanService.getRepositoryDBCleaner(conn, repository.getConfiguration());
try
{
if (repositoryName.equals("db3"))
{
+ DBCleanerTool repositoryDBCleaner =
+ DBCleanService.getRepositoryDBCleaner(conn, repository.getConfiguration());
+
// clean and rollback first
- repositoryDBCleaner.executeCleanScripts();
+ repositoryDBCleaner.clean();
conn.rollback();
- repositoryDBCleaner.executeRollbackScripts();
+ repositoryDBCleaner.rollback();
conn.commit();
checkConent(repositoryName);
// clean
- repositoryDBCleaner.executeCleanScripts();
- repositoryDBCleaner.executeCommitScripts();
+ repositoryDBCleaner.clean();
+ repositoryDBCleaner.commit();
conn.commit();
}
else
{
- assertNull(repositoryDBCleaner);
+ try
+ {
+ DBCleanerTool repositoryDBCleaner =
+ DBCleanService.getRepositoryDBCleaner(conn, repository.getConfiguration());
+ fail("Exception should be thrown");
+ }
+ catch (DBCleanException e)
+ {
+ }
}
}
finally
@@ -752,22 +763,22 @@
conn = ds.getConnection();
conn.setAutoCommit(false);
- DBCleaner workspaceDBCleaner = DBCleanService.getWorkspaceDBCleaner(conn, wsEntry);
+ DBCleanerTool workspaceDBCleaner = DBCleanService.getWorkspaceDBCleaner(conn, wsEntry);
try
{
// clean and rollback first
- workspaceDBCleaner.executeCleanScripts();
+ workspaceDBCleaner.clean();
conn.rollback();
- workspaceDBCleaner.executeRollbackScripts();
+ workspaceDBCleaner.rollback();
conn.commit();
checkConent(repositoryName);
// clean
- workspaceDBCleaner.executeCleanScripts();
- workspaceDBCleaner.executeCommitScripts();
+ workspaceDBCleaner.clean();
+ workspaceDBCleaner.commit();
conn.commit();
}
finally
14 years, 3 months
exo-jcr SVN: r5460 - kernel/branches/2.4.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils.
by do-not-reply@jboss.org
Author: tolusha
Date: 2012-01-17 05:14:22 -0500 (Tue, 17 Jan 2012)
New Revision: 5460
Modified:
kernel/branches/2.4.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/SecurityHelper.java
Log:
EXOJCR-1707: Refactoring DBCleanService. added method for validation runtime permissions
Modified: kernel/branches/2.4.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/SecurityHelper.java
===================================================================
--- kernel/branches/2.4.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/SecurityHelper.java 2012-01-17 09:20:02 UTC (rev 5459)
+++ kernel/branches/2.4.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/SecurityHelper.java 2012-01-17 10:14:22 UTC (rev 5460)
@@ -22,7 +22,9 @@
import java.io.IOException;
import java.net.MalformedURLException;
+import java.security.AccessControlException;
import java.security.AccessController;
+import java.security.Permission;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
@@ -317,4 +319,21 @@
throw new PrivilegedActionException(e);
}
}
+
+ /**
+ * Validate permissions.
+ *
+ * @throws AccessControlException
+ */
+ public static void validateSecurityPermissions(RuntimePermission... perms)
+ {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ {
+ for (Permission permission : perms)
+ {
+ security.checkPermission(permission);
+ }
+ }
+ }
}
14 years, 3 months
exo-jcr SVN: r5459 - jcr/branches/1.12.x/patch/1.12.12-GA/JCR-1704.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2012-01-17 04:20:02 -0500 (Tue, 17 Jan 2012)
New Revision: 5459
Modified:
jcr/branches/1.12.x/patch/1.12.12-GA/JCR-1704/JCR-1704.patch
Log:
JCR-1704: patch added
Modified: jcr/branches/1.12.x/patch/1.12.12-GA/JCR-1704/JCR-1704.patch
===================================================================
--- jcr/branches/1.12.x/patch/1.12.12-GA/JCR-1704/JCR-1704.patch 2012-01-17 09:09:44 UTC (rev 5458)
+++ jcr/branches/1.12.x/patch/1.12.12-GA/JCR-1704/JCR-1704.patch 2012-01-17 09:20:02 UTC (rev 5459)
@@ -46,33 +46,46 @@
===================================================================
--- exo.jcr.component.webdav/src/test/resources/conf/standalone/test-configuration.xml (revision 5453)
+++ exo.jcr.component.webdav/src/test/resources/conf/standalone/test-configuration.xml (working copy)
-@@ -173,7 +173,16 @@
+@@ -173,7 +173,7 @@
<component>
<type>org.exoplatform.services.jcr.webdav.WebDavServiceImpl</type>
<init-params>
-
+
+ <value-param>
+ <name>auto-mix-lockable</name>
+ <value>false</value>
+@@ -209,6 +209,15 @@
+ <value>/absolute/path/to/file</value>
+ </value-param>
+
+ <!--
+ To test read-only mime-type properties to be correctly fetched and processed during put requests.
+ See more details here: https://jira.exoplatform.org/browse/JCR-1704
+ -->
-+ <value-param>
++ <values-param>
+ <name>read-only-mime-types</name>
+ <value>test/mime-type</value>
-+ </value-param>
-+
- <value-param>
- <name>auto-mix-lockable</name>
- <value>false</value>
++ </values-param>
++
+ </init-params>
+ </component>
+
Index: exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java
===================================================================
--- exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java (revision 5453)
+++ exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java (working copy)
-@@ -75,9 +75,12 @@
- import java.net.URISyntaxException;
+@@ -23,6 +23,7 @@
+ import org.exoplatform.commons.utils.MimeTypeResolver;
+ import org.exoplatform.container.xml.InitParams;
+ import org.exoplatform.container.xml.ValueParam;
++import org.exoplatform.container.xml.ValuesParam;
+ import org.exoplatform.services.jcr.RepositoryService;
+ import org.exoplatform.services.jcr.core.ManageableRepository;
+ import org.exoplatform.services.jcr.ext.app.ThreadLocalSessionProviderService;
+@@ -76,8 +77,10 @@
import java.net.URLEncoder;
import java.util.ArrayList;
-+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
@@ -107,12 +120,12 @@
}
-+ ValueParam pReadOnlyMimeTypes = params.getValueParam(READ_ONLY_MIME_TYPES);
++ ValuesParam pReadOnlyMimeTypes = params.getValuesParam(READ_ONLY_MIME_TYPES);
+ if (pReadOnlyMimeTypes != null)
+ {
-+ for (String mimeType : Arrays.asList(pReadOnlyMimeTypes.getValue().split(",")))
++ for (String mimeType : (List<String>)pReadOnlyMimeTypes.getValues())
+ {
-+ readOnlyMimeTypes.add(mimeType.trim());
++ readOnlyMimeTypes.add(mimeType);
+ }
+ }
}
@@ -178,7 +191,7 @@
* Webdav Put method implementation.
*
* @param session current session
-@@ -205,7 +226,20 @@
+@@ -205,7 +226,23 @@
{
Node content = node.getNode("jcr:content");
@@ -187,11 +200,14 @@
+ /*
+ Workaround created to fix JCR-1704
+
-+ 1. Check if jcr:mimeType property is not set, if it is not set we can set it without worries
-+ 1. Check if jcr:mimeType property is in 'read-only' properties list,
-+ if not we again can set it without worries
++ 1. If readOnlyMimeTypes is not initialized it is okay to set any mime-type you want
++ 2. If readOnlyMimeTypes is empty, it won't be needed to call !content.hasProperty("jcr:mimeType")
++ which represents a potential query, and again it is okay to set any mime-type you want
++ 3. If jcr:mimeType property is not set, we can set it without worries
++ 4. If jcr:mimeType property isn't in 'read-only' properties list,
++ we can set it
+ */
-+ if (!content.hasProperty("jcr:mimeType")
++ if (readOnlyMimeTypes == null || readOnlyMimeTypes.isEmpty() || !content.hasProperty("jcr:mimeType")
+ || !readOnlyMimeTypes.contains(content.getProperty("jcr:mimeType").getString()))
+ {
+ content.setProperty("jcr:mimeType", mimeType);
@@ -204,7 +220,7 @@
===================================================================
--- exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/protocols/webdav.xml (revision 5453)
+++ exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/jcr/protocols/webdav.xml (working copy)
-@@ -1,345 +1,471 @@
+@@ -1,345 +1,470 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<!-- This document was created with Syntext Serna Free. --><!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" []>
-<chapter id="JCR.WebDAV">
@@ -710,12 +726,11 @@
+ This parameter is responsible for definition of read-only mime-type properties.
+ That basically means that all mime-types mentioned here will be set as read-only properties
+ (i. e. you cannot change resource's mime-type after it is set).
-+ Use ',' as a delimeter to separate mime-types.
+ -->
-+ <value-param>
++ <values-param>
+ <name>read-only-mime-types</name>
+ <value>application/vnd.openxmlformats-officedocument.wordprocessingml.document</value>
-+ </value-param>
++ </values-param>
+
+ </init-params>
+</component></programlisting>
14 years, 3 months
exo-jcr SVN: r5458 - in jcr/branches/1.15.x: exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene and 2 other directories.
by do-not-reply@jboss.org
Author: andrew.plotnikov
Date: 2012-01-17 04:09:44 -0500 (Tue, 17 Jan 2012)
New Revision: 5458
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/AbstractIndex.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/ItemDataMergeVisitor.java
jcr/branches/1.15.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupChainImpl.java
Log:
EXOJCR-1687: Fixed new sonar violations in project
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java 2012-01-17 09:08:32 UTC (rev 5457)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java 2012-01-17 09:09:44 UTC (rev 5458)
@@ -18,8 +18,8 @@
*/
package org.exoplatform.services.jcr.impl;
+import org.exoplatform.commons.utils.ClassLoading;
import org.exoplatform.commons.utils.SecurityHelper;
-import org.exoplatform.commons.utils.ClassLoading;
import org.exoplatform.container.ExoContainer;
import org.exoplatform.container.component.ComponentPlugin;
import org.exoplatform.container.jmx.MX4JComponentAdapterFactory;
@@ -289,7 +289,8 @@
workspaceContainer.registerComponentImplementation(StandaloneStoragePluginProvider.class);
try
{
- final Class<?> containerType = ClassLoading.forName(wsConfig.getContainer().getType(), RepositoryContainer.class);
+ final Class<?> containerType =
+ ClassLoading.forName(wsConfig.getContainer().getType(), RepositoryContainer.class);
workspaceContainer.registerComponentImplementation(containerType);
if (isSystem)
{
@@ -309,7 +310,8 @@
String className = wsConfig.getCache().getType();
if (className != null && className.length() > 0)
{
- workspaceContainer.registerComponentImplementation(ClassLoading.forName(className, RepositoryContainer.class));
+ workspaceContainer.registerComponentImplementation(ClassLoading.forName(className,
+ RepositoryContainer.class));
}
else
workspaceContainer.registerComponentImplementation(LinkedWorkspaceStorageCacheImpl.class);
@@ -329,7 +331,8 @@
{
try
{
- final Class<?> lockManagerType = ClassLoading.forName(wsConfig.getLockManager().getType(), RepositoryContainer.class);
+ final Class<?> lockManagerType =
+ ClassLoading.forName(wsConfig.getLockManager().getType(), RepositoryContainer.class);
workspaceContainer.registerComponentImplementation(lockManagerType);
}
catch (ClassNotFoundException e)
@@ -630,7 +633,8 @@
}
try
{
- final Class<?> authenticationPolicyClass = ClassLoading.forName(config.getAuthenticationPolicy(), RepositoryContainer.class);
+ final Class<?> authenticationPolicyClass =
+ ClassLoading.forName(config.getAuthenticationPolicy(), RepositoryContainer.class);
registerComponentImplementation(authenticationPolicyClass);
}
catch (ClassNotFoundException e)
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/AbstractIndex.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/AbstractIndex.java 2012-01-17 09:08:32 UTC (rev 5457)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/AbstractIndex.java 2012-01-17 09:09:44 UTC (rev 5458)
@@ -18,8 +18,6 @@
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-import org.apache.lucene.document.Fieldable;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
@@ -553,80 +551,6 @@
//------------------------------< internal >--------------------------------
/**
- * Returns the index parameter set on <code>f</code>.
- *
- * @param f a lucene field.
- * @return the index parameter on <code>f</code>.
- */
- private Field.Index getIndexParameter(Fieldable f)
- {
- if (!f.isIndexed())
- {
- return Field.Index.NO;
- }
- else if (f.isTokenized())
- {
- return Field.Index.ANALYZED;
- }
- else
- {
- return Field.Index.NOT_ANALYZED;
- }
- }
-
- /**
- * Returns the store parameter set on <code>f</code>.
- *
- * @param f a lucene field.
- * @return the store parameter on <code>f</code>.
- */
- private Field.Store getStoreParameter(Fieldable f)
- {
- if (f.isCompressed())
- {
- return Field.Store.COMPRESS;
- }
- else if (f.isStored())
- {
- return Field.Store.YES;
- }
- else
- {
- return Field.Store.NO;
- }
- }
-
- /**
- * Returns the term vector parameter set on <code>f</code>.
- *
- * @param f a lucene field.
- * @return the term vector parameter on <code>f</code>.
- */
- private Field.TermVector getTermVectorParameter(Fieldable f)
- {
- if (f.isStorePositionWithTermVector() && f.isStoreOffsetWithTermVector())
- {
- return Field.TermVector.WITH_POSITIONS_OFFSETS;
- }
- else if (f.isStorePositionWithTermVector())
- {
- return Field.TermVector.WITH_POSITIONS;
- }
- else if (f.isStoreOffsetWithTermVector())
- {
- return Field.TermVector.WITH_OFFSETS;
- }
- else if (f.isTermVectorStored())
- {
- return Field.TermVector.YES;
- }
- else
- {
- return Field.TermVector.NO;
- }
- }
-
- /**
* Adapter to pipe info messages from lucene into log messages.
*/
private static final class LoggingPrintStream extends PrintStream
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/ItemDataMergeVisitor.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/ItemDataMergeVisitor.java 2012-01-17 09:08:32 UTC (rev 5457)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/ItemDataMergeVisitor.java 2012-01-17 09:09:44 UTC (rev 5458)
@@ -41,7 +41,6 @@
import org.exoplatform.services.log.Log;
import java.io.IOException;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -156,14 +155,6 @@
}
}
- private class VersionableStateComparator implements Comparator<VersionableState>
- {
- public int compare(VersionableState nc1, VersionableState nc2)
- {
- return nc1.getPath().compareTo(nc2.getPath());
- }
- }
-
public ItemDataMergeVisitor(SessionImpl mergeSession, SessionImpl corrSession, Map<String, String> failed,
boolean bestEffort)
{
Modified: jcr/branches/1.15.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupChainImpl.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupChainImpl.java 2012-01-17 09:08:32 UTC (rev 5457)
+++ jcr/branches/1.15.x/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/impl/BackupChainImpl.java 2012-01-17 09:09:44 UTC (rev 5458)
@@ -122,7 +122,8 @@
{
try
{
- this.incrementalBackup = (AbstractIncrementalBackupJob)ClassLoading.forName(incrementalBackupType, this).newInstance();
+ this.incrementalBackup =
+ (AbstractIncrementalBackupJob)ClassLoading.forName(incrementalBackupType, this).newInstance();
}
catch (Exception e)
{
14 years, 3 months