Author: tolusha
Date: 2012-01-06 04:44:12 -0500 (Fri, 06 Jan 2012)
New Revision: 5427
Removed:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DialectDetecter.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCUtils.java
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBBackup.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestore.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanService.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleaner.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/JDBCConfigurationPersister.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JDBCCacheLoader.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.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.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/cas/JDBCValueContentAddressStorageImpl.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializerHelper.java
Log:
EXOJCR-968: Move DBInitalizer and DBCleaner common code into separated class
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBBackup.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBBackup.java 2012-01-06
09:43:10 UTC (rev 5426)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBBackup.java 2012-01-06
09:44:12 UTC (rev 5427)
@@ -19,7 +19,7 @@
package org.exoplatform.services.jcr.impl.backup.rdbms;
import org.exoplatform.commons.utils.PrivilegedFileHelper;
-import org.exoplatform.services.database.utils.ExceptionManagementHelper;
+import org.exoplatform.services.database.utils.JDBCUtils;
import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.backup.BackupException;
@@ -114,7 +114,7 @@
catch (SQLException e)
{
exc = e;
- throw new BackupException("SQL Exception: " +
ExceptionManagementHelper.getFullSQLExceptionMessage(e), e);
+ throw new BackupException("SQL Exception: " +
JDBCUtils.getFullMessage(e), e);
}
finally
{
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-06
09:43:10 UTC (rev 5426)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DBRestore.java 2012-01-06
09:44:12 UTC (rev 5427)
@@ -20,7 +20,8 @@
import org.exoplatform.commons.utils.PrivilegedFileHelper;
import org.exoplatform.commons.utils.PrivilegedSystemHelper;
-import org.exoplatform.services.database.utils.ExceptionManagementHelper;
+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.WorkspaceEntry;
import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
@@ -31,7 +32,6 @@
import org.exoplatform.services.jcr.impl.clean.rdbms.DBCleaner;
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.DialectDetecter;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.log.ExoLogger;
@@ -184,7 +184,7 @@
}
catch (SQLException e)
{
- throw new BackupException("SQL Exception: " +
ExceptionManagementHelper.getFullSQLExceptionMessage(e), e);
+ throw new BackupException("SQL Exception: " +
JDBCUtils.getFullMessage(e), e);
}
}
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanService.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanService.java 2012-01-06
09:43:10 UTC (rev 5426)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleanService.java 2012-01-06
09:44:12 UTC (rev 5427)
@@ -16,13 +16,16 @@
*/
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.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.storage.jdbc.DBConstants;
-import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
import org.exoplatform.services.jcr.impl.util.jdbc.DBInitializerHelper;
import org.exoplatform.services.log.ExoLogger;
@@ -772,7 +775,7 @@
String script;
try
{
- script = DBInitializerHelper.readScriptResource(scriptsPath);
+ script =
IOUtil.getStreamContentAsString(PrivilegedFileHelper.getResourceAsStream(scriptsPath));
}
catch (IOException e)
{
@@ -780,12 +783,12 @@
}
List<String> scripts = new ArrayList<String>();
- for (String query : DBInitializerHelper.scripts(script))
+ for (String query : JDBCUtils.splitWithSQLDelimiter(script))
{
// Skip creation JCR_S(M)CONTAINER TABLE
if (!query.contains("CREATE TABLE JCR_" + multiDb +
"CONTAINER"))
{
- scripts.add(DBInitializerHelper.cleanWhitespaces(query));
+ scripts.add(JDBCUtils.cleanWhitespaces(query));
}
}
Modified:
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-06
09:43:10 UTC (rev 5426)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/clean/rdbms/DBCleaner.java 2012-01-06
09:44:12 UTC (rev 5427)
@@ -17,8 +17,8 @@
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.jcr.impl.util.jdbc.DBInitializerHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -188,7 +188,7 @@
{
for (String scr : scripts)
{
- String sql = DBInitializerHelper.cleanWhitespaces(scr.trim());
+ String sql = JDBCUtils.cleanWhitespaces(scr.trim());
if (sql.length() > 0)
{
if (LOG.isDebugEnabled())
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/JDBCConfigurationPersister.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/JDBCConfigurationPersister.java 2012-01-06
09:43:10 UTC (rev 5426)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/JDBCConfigurationPersister.java 2012-01-06
09:44:12 UTC (rev 5427)
@@ -20,11 +20,11 @@
import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.container.xml.PropertiesParam;
+import org.exoplatform.services.database.utils.DialectDetecter;
+import org.exoplatform.services.database.utils.JDBCUtils;
import org.exoplatform.services.jcr.config.ConfigurationPersister;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
-import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
-import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCUtils;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2012-01-06
09:43:10 UTC (rev 5426)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2012-01-06
09:44:12 UTC (rev 5427)
@@ -22,6 +22,7 @@
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.jmx.annotations.NameTemplate;
import org.exoplatform.management.jmx.annotations.Property;
+import org.exoplatform.services.database.utils.DialectDetecter;
import org.exoplatform.services.jcr.config.MappedParametrizedObjectEntry;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
@@ -31,7 +32,6 @@
import org.exoplatform.services.jcr.impl.core.lock.cacheable.LockData;
import
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
-import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory;
import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory.CacheType;
import org.exoplatform.services.jcr.jbosscache.PrivilegedJBossCacheHelper;
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JDBCCacheLoader.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JDBCCacheLoader.java 2012-01-06
09:43:10 UTC (rev 5426)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/JDBCCacheLoader.java 2012-01-06
09:44:12 UTC (rev 5427)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.jcr.impl.core.lock.jbosscache;
-import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCUtils;
+import org.exoplatform.services.database.utils.JDBCUtils;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.loader.AdjListJDBCCacheLoaderConfig;
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2012-01-06
09:43:10 UTC (rev 5426)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java 2012-01-06
09:44:12 UTC (rev 5427)
@@ -18,14 +18,15 @@
*/
package org.exoplatform.services.jcr.impl.storage.jdbc;
+import org.exoplatform.services.database.utils.DialectConstants;
+
/**
* Created by The eXo Platform SAS.
*
* @author Gennady Azarenkov
* @version $Id: DBConstants.java 34801 2009-07-31 15:44:50Z dkatayev $
*/
-
-public class DBConstants
+public class DBConstants extends DialectConstants
{
// ======================== Error constants ========================
/**
@@ -261,98 +262,4 @@
*/
protected static final String COLUMN_VSTORAGE_DESC = "STORAGE_DESC";
- // Dialects
- /**
- * DB_DIALECT_AUTO.
- */
- public final static String DB_DIALECT_AUTO = "Auto".intern();
-
- /**
- * DB_DIALECT_GENERIC.
- */
- public final static String DB_DIALECT_GENERIC = "Generic".intern();
-
- /**
- * DB_DIALECT_ORACLE.
- */
- public final static String DB_DIALECT_ORACLE = "Oracle".intern();
-
- /**
- * DB_DIALECT_ORACLEOCI.
- */
- public final static String DB_DIALECT_ORACLEOCI = "Oracle-OCI".intern();
-
- /**
- * DB_DIALECT_PGSQL.
- */
- public final static String DB_DIALECT_PGSQL = "PgSQL".intern();
-
- /**
- * DB_DIALECT_MYSQL.
- */
- public final static String DB_DIALECT_MYSQL = "MySQL".intern();
-
- /**
- * DB_DIALECT_MYSQL_UTF8.
- */
- public final static String DB_DIALECT_MYSQL_UTF8 = "MySQL-UTF8".intern();
-
- /**
- * DB_DIALECT_MYSQL_MYISAM.
- */
- public final static String DB_DIALECT_MYSQL_MYISAM =
"MySQL-MyISAM".intern();
-
- /**
- * DB_DIALECT_MYSQL_MYISAM_UTF8.
- */
- public final static String DB_DIALECT_MYSQL_MYISAM_UTF8 =
"MySQL-MyISAM-UTF8".intern();
-
- /**
- * DB_DIALECT_HSQLDB.
- */
- public final static String DB_DIALECT_HSQLDB = "HSQLDB".intern();
-
- /**
- * DB_DIALECT_DB2.
- */
- public final static String DB_DIALECT_DB2 = "DB2".intern();
-
- /**
- * DB_DIALECT_DB2V8.
- */
- public final static String DB_DIALECT_DB2V8 = "DB2V8".intern();
-
- /**
- * DB_DIALECT_MSSQL.
- */
- public final static String DB_DIALECT_MSSQL = "MSSQL".intern();
-
- /**
- * DB_DIALECT_SYBASE.
- */
- public final static String DB_DIALECT_SYBASE = "Sybase".intern();
-
- /**
- * DB_DIALECT_DERBY.
- */
- public final static String DB_DIALECT_DERBY = "Derby".intern();
-
- /**
- * DB_DIALECT_INGRES.
- */
- public final static String DB_DIALECT_INGRES = "Ingres".intern();
-
- /**
- * DB_DIALECT_H2.
- */
- public final static String DB_DIALECT_H2 = "H2".intern();
-
- /**
- * DB_DIALECTS.
- */
- public final static String[] DB_DIALECTS = {DB_DIALECT_GENERIC, DB_DIALECT_ORACLE,
DB_DIALECT_ORACLEOCI,
- DB_DIALECT_PGSQL, DB_DIALECT_MYSQL, DB_DIALECT_HSQLDB, DB_DIALECT_DB2,
DB_DIALECT_DB2V8, DB_DIALECT_MSSQL,
- DB_DIALECT_SYBASE, DB_DIALECT_DERBY, DB_DIALECT_MYSQL_UTF8, DB_DIALECT_INGRES,
DB_DIALECT_H2,
- DB_DIALECT_MYSQL_MYISAM, DB_DIALECT_MYSQL_MYISAM_UTF8};
-
}
Deleted:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DialectDetecter.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DialectDetecter.java 2012-01-06
09:43:10 UTC (rev 5426)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DialectDetecter.java 2012-01-06
09:44:12 UTC (rev 5427)
@@ -1,129 +0,0 @@
-/*
- * Copyright (C) 2010 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.exoplatform.services.jcr.impl.storage.jdbc;
-
-import org.exoplatform.commons.utils.SecurityHelper;
-
-import java.security.PrivilegedExceptionAction;
-import java.sql.DatabaseMetaData;
-import java.sql.SQLException;
-
-/**
- * JDBC dialect detecter based on database metadata and vendor product name.
- *
- * @author <a href="mailto:peter.nedonosko@exoplatform.com">Peter
Nedonosko</a>
- * @version $Id:DialectDetecter.java 1111 2010-01-01 00:00:01Z pnedonosko $
- *
- */
-public class DialectDetecter
-{
-
- /**
- * Detect databse dialect using JDBC metadata. Based on code of
- *
http://svn.jboss.org/repos/hibernate/core/trunk/core/src/main/java/org/hi...
- * dialect/resolver/StandardDialectResolver.java
- *
- * @param jdbcConn Connection
- * @return String
- * @throws SQLException if error occurs
- */
- public static String detect(final DatabaseMetaData metaData) throws SQLException
- {
- final String databaseName =
- SecurityHelper.doPrivilegedSQLExceptionAction(new
PrivilegedExceptionAction<String>()
- {
- public String run() throws Exception
- {
- return metaData.getDatabaseProductName();
- }
- });
-
- if ("HSQL Database Engine".equals(databaseName))
- {
- return DBConstants.DB_DIALECT_HSQLDB;
- }
-
- if ("H2".equals(databaseName))
- {
- return DBConstants.DB_DIALECT_H2;
- }
-
- if ("MySQL".equals(databaseName))
- {
- return DBConstants.DB_DIALECT_MYSQL;
- }
-
- if ("PostgreSQL".equals(databaseName))
- {
- return DBConstants.DB_DIALECT_PGSQL;
- }
-
- if ("Apache Derby".equals(databaseName))
- {
- return DBConstants.DB_DIALECT_DERBY;
- }
-
- if ("ingres".equalsIgnoreCase(databaseName))
- {
- return DBConstants.DB_DIALECT_INGRES;
- }
-
- if (databaseName.startsWith("Microsoft SQL Server"))
- {
- return DBConstants.DB_DIALECT_MSSQL;
- }
-
- if ("Sybase SQL Server".equals(databaseName) || "Adaptive Server
Enterprise".equals(databaseName))
- {
- return DBConstants.DB_DIALECT_SYBASE;
- }
-
- if (databaseName.startsWith("Adaptive Server Anywhere"))
- {
- return DBConstants.DB_DIALECT_SYBASE;
- }
-
- if (databaseName.startsWith("DB2/"))
- {
- return DBConstants.DB_DIALECT_DB2;
- }
-
- if ("Oracle".equals(databaseName))
- {
- return DBConstants.DB_DIALECT_ORACLE;
-
- // int databaseMajorVersion = metaData.getDatabaseMajorVersion();
- // switch ( databaseMajorVersion ) {
- // case 11:
- // log.warn( "Oracle 11g is not yet fully supported; using
10g dialect" );
- // return new Oracle10gDialect();
- // case 10:
- // return new Oracle10gDialect();
- // case 9:
- // return new Oracle9iDialect();
- // case 8:
- // return new Oracle8iDialect();
- // default:
- // log.warn( "unknown Oracle major version [" +
databaseMajorVersion + "]" );
- // }
- }
-
- return DBConstants.DB_DIALECT_GENERIC;
- }
-}
Deleted:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCUtils.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCUtils.java 2012-01-06
09:43:10 UTC (rev 5426)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCUtils.java 2012-01-06
09:44:12 UTC (rev 5427)
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2011 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.exoplatform.services.jcr.impl.storage.jdbc;
-
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-/**
- * This class provides JDBC tools
- *
- * @author <a href="mailto:nfilotto@exoplatform.com">Nicolas
Filotto</a>
- * @version $Id$
- *
- */
-public class JDBCUtils
-{
- private static final Log LOG =
ExoLogger.getLogger("exo.jcr.component.core.JDBCUtils");
-
- private JDBCUtils()
- {
- }
-
- /**
- * Indicates whether or not a given table exists
- * @param tableName the name of the table to check
- * @param con the connection to use
- * @return <code>true</code> if it exists, <code>false</code>
otherwise
- */
- public static boolean tableExists(String tableName, Connection con)
- {
- Statement stmt = null;
- ResultSet trs = null;
- try
- {
- stmt = con.createStatement();
- trs = stmt.executeQuery("SELECT count(*) FROM " + tableName);
- return trs.next();
- }
- catch (SQLException e)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug("SQLException occurs while checking the table " +
tableName, e);
- }
- return false;
- }
- finally
- {
- if (trs != null)
- {
- try
- {
- trs.close();
- }
- catch (SQLException e)
- {
- LOG.error("Can't close the ResultSet: " + e);
- }
- }
- if (stmt != null)
- {
- try
- {
- stmt.close();
- }
- catch (SQLException e)
- {
- LOG.error("Can't close the Statement: " + e);
- }
- }
- }
- }
-}
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-06
09:43:10 UTC (rev 5426)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2012-01-06
09:44:12 UTC (rev 5427)
@@ -21,7 +21,8 @@
import org.exoplatform.commons.utils.PrivilegedFileHelper;
import org.exoplatform.commons.utils.PrivilegedSystemHelper;
import org.exoplatform.commons.utils.SecurityHelper;
-import org.exoplatform.services.database.utils.ExceptionManagementHelper;
+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.ValueStorageEntry;
@@ -273,7 +274,7 @@
String pDbDialect = null;
try
{
- pDbDialect =
DBInitializerHelper.validateDialect(wsConfig.getContainer().getParameterValue(DB_DIALECT));
+ pDbDialect =
validateDialect(wsConfig.getContainer().getParameterValue(DB_DIALECT));
}
catch (RepositoryConfigurationException e)
{
@@ -915,8 +916,7 @@
}
catch (SQLException e)
{
- LOG.error(
- "Can't remove lock properties because of " +
ExceptionManagementHelper.getFullSQLExceptionMessage(e), e);
+ LOG.error("Can't remove lock properties because of " +
JDBCUtils.getFullMessage(e), e);
}
catch (RepositoryException e)
{
@@ -1398,4 +1398,26 @@
throw new RepositoryException("Datasource '" + dbSourceName +
"' is not bound in this context.", e);
}
}
+
+ /**
+ * Validate dialect.
+ *
+ * @param confParam
+ * String, dialect from configuration.
+ * @return String
+ * return dialect. By default return DB_DIALECT_GENERIC.
+ *
+ */
+ private String validateDialect(String confParam)
+ {
+ for (String dbType : DBConstants.DB_DIALECTS)
+ {
+ if (dbType.equalsIgnoreCase(confParam))
+ {
+ return dbType;
+ }
+ }
+
+ return DBConstants.DB_DIALECT_GENERIC; // by default
+ }
}
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/cas/JDBCValueContentAddressStorageImpl.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/cas/JDBCValueContentAddressStorageImpl.java 2012-01-06
09:43:10 UTC (rev 5426)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/cas/JDBCValueContentAddressStorageImpl.java 2012-01-06
09:44:12 UTC (rev 5427)
@@ -19,10 +19,10 @@
package org.exoplatform.services.jcr.impl.storage.value.cas;
import org.exoplatform.commons.utils.SecurityHelper;
+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.impl.storage.jdbc.DBConstants;
-import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
-import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCUtils;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java 2012-01-06
09:43:10 UTC (rev 5426)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java 2012-01-06
09:44:12 UTC (rev 5427)
@@ -18,9 +18,10 @@
*/
package org.exoplatform.services.jcr.impl.util.jdbc;
+import org.exoplatform.commons.utils.IOUtil;
+import org.exoplatform.commons.utils.PrivilegedFileHelper;
import org.exoplatform.commons.utils.SecurityHelper;
-import org.exoplatform.services.database.utils.ExceptionManagementHelper;
-import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCUtils;
+import org.exoplatform.services.database.utils.JDBCUtils;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -89,8 +90,7 @@
{
this.connection = connection;
this.containerName = containerName;
- this.script = script(scriptPath);
-
+ this.script =
IOUtil.getStreamContentAsString(PrivilegedFileHelper.getResourceAsStream(scriptPath));
this.creatTablePattern = Pattern.compile(SQL_CREATETABLE,
Pattern.CASE_INSENSITIVE);
this.creatViewPattern = Pattern.compile(SQL_CREATEVIEW, Pattern.CASE_INSENSITIVE);
this.dbObjectNamePattern = Pattern.compile(SQL_OBJECTNAME,
Pattern.CASE_INSENSITIVE);
@@ -101,11 +101,6 @@
this.dbTriggerNamePattern = Pattern.compile(SQL_TRIGGERNAME,
Pattern.CASE_INSENSITIVE);
}
- protected String script(String scriptPath) throws IOException
- {
- return DBInitializerHelper.readScriptResource(scriptPath);
- }
-
protected boolean isTableExists(final Connection conn, final String tableName) throws
SQLException
{
return SecurityHelper.doPrivilegedAction(new PrivilegedAction<Boolean>()
@@ -250,7 +245,7 @@
public void init() throws DBInitializerException
{
- String[] scripts = DBInitializerHelper.scripts(script);
+ String[] scripts = JDBCUtils.splitWithSQLDelimiter(script);
String sql = null;
Statement st = null;
Set<String> existingTables = new HashSet<String>();
@@ -263,7 +258,7 @@
connection.setAutoCommit(true);
for (String scr : scripts)
{
- String s = DBInitializerHelper.cleanWhitespaces(scr.trim());
+ String s = JDBCUtils.cleanWhitespaces(scr.trim());
if (s.length() > 0)
{
if (isObjectExists(connection, sql = s, existingTables))
@@ -319,8 +314,8 @@
else
{
String msg =
- "Could not create db schema of DataSource: '" +
containerName + "'. Reason: " + e.getMessage() + "; "
- + ExceptionManagementHelper.getFullSQLExceptionMessage(e) +
". Last command: " + sql;
+ "Could not create db schema of DataSource: '" +
containerName + "'. Reason: " + e.getMessage() + "; "
+ + JDBCUtils.getFullMessage(e) + ". Last command: " + sql;
throw new DBInitializerException(msg, e);
}
@@ -355,6 +350,5 @@
*/
protected void postInit(Connection connection) throws SQLException
{
-
}
}
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializerHelper.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializerHelper.java 2012-01-06
09:43:10 UTC (rev 5426)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializerHelper.java 2012-01-06
09:44:12 UTC (rev 5427)
@@ -16,7 +16,9 @@
*/
package org.exoplatform.services.jcr.impl.util.jdbc;
-import org.exoplatform.commons.utils.SecurityHelper;
+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.impl.Constants;
import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
@@ -24,9 +26,6 @@
import org.exoplatform.services.log.Log;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.security.PrivilegedAction;
/**
* Created by The eXo Platform SAS.
@@ -42,18 +41,8 @@
* Logger.
*/
protected final static Log LOG =
ExoLogger.getLogger("exo.jcr.component.core.DBInitializerHelper");
-
- /**
- * Default SQL delimiter.
- */
- static public String SQL_DELIMITER = ";";
/**
- * SQL delimiter comment prefix.
- */
- static public String SQL_DELIMITER_COMMENT_PREFIX = "/*$DELIMITER:";
-
- /**
* Getting path to initialization by specific dialect and multidb.
*
* @param dbDialect
@@ -131,119 +120,6 @@
}
/**
- * Validate dialect.
- *
- * @param confParam
- * String, dialect from configuration.
- * @return String
- * return dialect. By default return DB_DIALECT_GENERIC.
- *
- */
- public static String validateDialect(String confParam)
- {
- for (String dbType : DBConstants.DB_DIALECTS)
- {
- if (dbType.equalsIgnoreCase(confParam))
- {
- return dbType;
- }
- }
-
- return DBConstants.DB_DIALECT_GENERIC; // by default
- }
-
- /**
- * Read DB initialization script as string.
- *
- * @param path
- * String, path to DB initialization script.
- * @return String,
- * DB initialization script as string.
- * @throws IOException
- * Will throw IOException if file with DB initialization script is not
exists.
- */
- public static String readScriptResource(final String path) throws IOException
- {
- PrivilegedAction<InputStream> action = new
PrivilegedAction<InputStream>()
- {
- public InputStream run()
- {
- return this.getClass().getResourceAsStream(path);
- }
- };
- final InputStream is = SecurityHelper.doPrivilegedAction(action);
-
- PrivilegedAction<InputStreamReader> actionGetReader = new
PrivilegedAction<InputStreamReader>()
- {
- public InputStreamReader run()
- {
- return new InputStreamReader(is);
- }
- };
- InputStreamReader isr = SecurityHelper.doPrivilegedAction(actionGetReader);
-
- try
- {
- StringBuilder sbuff = new StringBuilder();
- char[] buff = new char[is.available()];
- int r = 0;
- while ((r = isr.read(buff)) > 0)
- {
- sbuff.append(buff, 0, r);
- }
-
- return sbuff.toString();
- }
- finally
- {
- try
- {
- is.close();
- }
- catch (IOException e)
- {
- }
- }
- }
-
- /**
- * Determinate DB initialization script by separate query.
- *
- * @param script
- * String, DB initialization script as String.
- * @return String[]
- * Queries to DB initialization.
- */
- public static String[] scripts(String script)
- {
- if (script.startsWith(SQL_DELIMITER_COMMENT_PREFIX))
- {
- // read custom prefix
- try
- {
- String s = script.substring(SQL_DELIMITER_COMMENT_PREFIX.length());
- int endOfDelimIndex = s.indexOf("*/");
- String delim = s.substring(0, endOfDelimIndex).trim();
- s = s.substring(endOfDelimIndex + 2).trim();
- return s.split(delim);
- }
- catch (IndexOutOfBoundsException e)
- {
- LOG.warn("Error of parse SQL-script file. Invalid DELIMITER
configuration. Valid format is '"
- + SQL_DELIMITER_COMMENT_PREFIX
- + "XXX*/' at begin of the SQL-script file, where XXX -
DELIMITER string."
- + " Spaces will be trimed. ", e);
- LOG.info("Using DELIMITER:[" + SQL_DELIMITER + "]");
- return script.split(SQL_DELIMITER);
- }
- }
- else
- {
- return script.split(SQL_DELIMITER);
- }
- }
-
- /**
* Initialization script for root node.
*
* @param multiDb
@@ -259,26 +135,6 @@
}
/**
- * Cleans redundant whitespaces from query.
- */
- public static String cleanWhitespaces(String string)
- {
- if (string != null)
- {
- char[] cc = string.toCharArray();
- for (int ci = cc.length - 1; ci > 0; ci--)
- {
- if (Character.isWhitespace(cc[ci]))
- {
- cc[ci] = ' ';
- }
- }
- return new String(cc);
- }
- return string;
- }
-
- /**
* Get script for creating object (index, etc...)
* @throws RepositoryConfigurationException
*/
@@ -289,7 +145,7 @@
String script;
try
{
- script = DBInitializerHelper.readScriptResource(scriptsPath);
+ script =
IOUtil.getStreamContentAsString(PrivilegedFileHelper.getResourceAsStream(scriptsPath));
}
catch (IOException e)
{
@@ -297,9 +153,9 @@
}
String sql = null;
- for (String query : DBInitializerHelper.scripts(script))
+ for (String query : JDBCUtils.splitWithSQLDelimiter(script))
{
- String q = DBInitializerHelper.cleanWhitespaces(query);
+ String q = JDBCUtils.cleanWhitespaces(query);
if (q.contains(objectName))
{
if (sql != null)