[exo-jcr-commits] exo-jcr SVN: r1592 - in jcr/trunk/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/storage/jdbc and 3 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Jan 27 11:05:42 EST 2010


Author: pnedonosko
Date: 2010-01-27 11:05:42 -0500 (Wed, 27 Jan 2010)
New Revision: 1592

Added:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DialectDetecter.java
Modified:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/JDBCConfigurationPersister.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/cas/JDBCValueContentAddressStorageImpl.java
   jcr/trunk/exo.jcr.component.core/src/main/resources/conf/portal/exo-jcr-config.xml
   jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration-sjdbc.xml
   jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration.xml
   jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config-sjdbc.xml
   jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml
Log:
EXOJCR-310 database dialect detection (and for VCAS and conf persister)

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/JDBCConfigurationPersister.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/JDBCConfigurationPersister.java	2010-01-27 13:37:35 UTC (rev 1591)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/JDBCConfigurationPersister.java	2010-01-27 16:05:42 UTC (rev 1592)
@@ -22,6 +22,7 @@
 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.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 
@@ -34,6 +35,7 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
+import javax.jcr.RepositoryException;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.sql.DataSource;
@@ -119,37 +121,66 @@
                + PARAM_SOURCE_NAME + ") is expected");
          }
       }
-
-      String dialectParam = params.getProperty(PARAM_DIALECT);
-
       this.sourceName = sourceNameParam;
 
-      String binType = "BLOB";
-      if (dialectParam != null)
-         if (dialectParam.equalsIgnoreCase(DBConstants.DB_DIALECT_GENERIC)
-            || dialectParam.equalsIgnoreCase(DBConstants.DB_DIALECT_HSQLDB))
+      String dialect = params.getProperty(PARAM_DIALECT);
+      if (dialect == null)
+      {
+         Connection conn = null;
+         try
          {
-            binType = "VARBINARY(102400)"; // 100Kb
+            conn = openConnection();
+            dialect = DialectDetecter.detect(conn.getMetaData());
          }
-         else if (dialectParam.equalsIgnoreCase(DBConstants.DB_DIALECT_PGSQL))
+         catch (NamingException e)
          {
-            configTableName = configTableName.toUpperCase().toLowerCase(); // postgres needs it
-            binType = "BYTEA";
+            throw new RepositoryConfigurationException(e);
          }
-         else if (dialectParam.equalsIgnoreCase(DBConstants.DB_DIALECT_MSSQL))
+         catch (SQLException e)
          {
-            binType = "VARBINARY(max)";
+            throw new RepositoryConfigurationException(e);
          }
-         else if (dialectParam.equalsIgnoreCase(DBConstants.DB_DIALECT_SYBASE))
+         finally
          {
-            binType = "VARBINARY(255)";
+            if (conn != null)
+            {
+               try
+               {
+                  conn.close();
+               }
+               catch (SQLException e)
+               {
+                  throw new RepositoryConfigurationException(e);
+               }
+            }
          }
-         else if (dialectParam.equalsIgnoreCase(DBConstants.DB_DIALECT_INGRES))
-         {
-            configTableName = configTableName.toUpperCase().toLowerCase(); // ingres needs it
-            binType = "LONG BYTE";
-         }
+      }
 
+      String binType = "BLOB";
+      if (DBConstants.DB_DIALECT_GENERIC.equalsIgnoreCase(dialect)
+         || DBConstants.DB_DIALECT_HSQLDB.equalsIgnoreCase(dialect))
+      {
+         binType = "VARBINARY(102400)"; // 100Kb
+      }
+      else if (DBConstants.DB_DIALECT_PGSQL.equalsIgnoreCase(dialect))
+      {
+         configTableName = configTableName.toUpperCase().toLowerCase(); // postgres needs it
+         binType = "BYTEA";
+      }
+      else if (DBConstants.DB_DIALECT_MSSQL.equalsIgnoreCase(dialect))
+      {
+         binType = "VARBINARY(max)";
+      }
+      else if (DBConstants.DB_DIALECT_SYBASE.equalsIgnoreCase(dialect))
+      {
+         binType = "VARBINARY(255)";
+      }
+      else if (DBConstants.DB_DIALECT_INGRES.equalsIgnoreCase(dialect))
+      {
+         configTableName = configTableName.toUpperCase().toLowerCase(); // ingres needs it
+         binType = "LONG BYTE";
+      }
+
       this.initSQL =
          "CREATE TABLE " + configTableName + " (" + "NAME VARCHAR(64) NOT NULL, " + "CONFIG " + binType + " NOT NULL, "
             + "CONSTRAINT JCR_CONFIG_PK PRIMARY KEY(NAME))";

Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DialectDetecter.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DialectDetecter.java	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DialectDetecter.java	2010-01-27 16:05:42 UTC (rev 1592)
@@ -0,0 +1,128 @@
+/*
+ * 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 java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+
+/**
+ * JDBC dialect detecter based on database metadata and vendor product name.
+ * 
+ * @author <a href="mailto:peter.nedonosko at 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/hibernate/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 = 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))
+      {
+         // TODO doesn't detect MySQL_UTF8
+         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"))
+      {
+         // TODO not implemented anything special for
+         return DBConstants.DB_DIALECT_SYBASE;
+      }
+
+      // TODO Informix not supported now
+      //if ( "Informix Dynamic Server".equals( databaseName ) ) {
+      //   return new InformixDialect();
+      //}
+
+      if (databaseName.startsWith("DB2/"))
+      {
+         // TODO doesn't detect DB2 v8 
+         return DBConstants.DB_DIALECT_DB2;
+      }
+
+      if ("Oracle".equals(databaseName))
+      {
+         // TODO doesn't detect Oracle OCI (experimental support still)
+         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;
+   }
+
+}


Property changes on: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DialectDetecter.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java	2010-01-27 13:37:35 UTC (rev 1591)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java	2010-01-27 16:05:42 UTC (rev 1592)
@@ -246,7 +246,7 @@
                   dbUserName != null ? DriverManager.getConnection(dbUrl, dbUserName, dbPassword) : DriverManager
                      .getConnection(dbUrl);
 
-               this.dbDialect = detectDialect(jdbcConn.getMetaData());
+               this.dbDialect = DialectDetecter.detect(jdbcConn.getMetaData());
             }
             catch (SQLException e)
             {
@@ -301,7 +301,7 @@
                try
                {
                   jdbcConn = ds.getConnection();
-                  this.dbDialect = detectDialect(jdbcConn.getMetaData());
+                  this.dbDialect = DialectDetecter.detect(jdbcConn.getMetaData());
                }
                catch (SQLException e)
                {
@@ -380,100 +380,6 @@
    }
 
    /**
-    * Detect databse dialect using JDBC metadata. Based on code of 
-    * http://svn.jboss.org/repos/hibernate/core/trunk/core/src/main/java/org/hibernate/dialect/resolver/StandardDialectResolver.java 
-    * 
-    * @param jdbcConn Connection 
-    * @return String
-    * @throws SQLException if error occurs
-    */
-   protected String detectDialect(DatabaseMetaData metaData) throws SQLException
-   {
-      String databaseName = 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))
-      {
-         // TODO doesn't detect MySQL_UTF8
-         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"))
-      {
-         // TODO not implemented anything special for
-         return DBConstants.DB_DIALECT_SYBASE;
-      }
-
-      // TODO Informix not supported now
-      //if ( "Informix Dynamic Server".equals( databaseName ) ) {
-      //   return new InformixDialect();
-      //}
-
-      if (databaseName.startsWith("DB2/"))
-      {
-         // TODO doesn't detect DB2 v8 
-         return DBConstants.DB_DIALECT_DB2;
-      }
-
-      if ("Oracle".equals(databaseName))
-      {
-         // TODO doesn't detect Oracle OCI (experimental support still)
-         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;
-   }
-
-   /**
     * Prepare sefault connection factory.
     * 
     * @return GenericConnectionFactory


Property changes on: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/cas/JDBCValueContentAddressStorageImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/cas/JDBCValueContentAddressStorageImpl.java	2010-01-27 13:37:35 UTC (rev 1591)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/cas/JDBCValueContentAddressStorageImpl.java	2010-01-27 16:05:42 UTC (rev 1592)
@@ -20,10 +20,12 @@
 
 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.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 
 import java.sql.Connection;
+import java.sql.DatabaseMetaData;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -86,8 +88,8 @@
    /**
     * MYSQL_PK_CONSTRAINT_DETECT.
     */
-   private static final Pattern MYSQL_PK_CONSTRAINT_DETECT =
-      Pattern.compile(MYSQL_PK_CONSTRAINT_DETECT_PATTERN, Pattern.CASE_INSENSITIVE);
+   private static final Pattern MYSQL_PK_CONSTRAINT_DETECT = Pattern.compile(MYSQL_PK_CONSTRAINT_DETECT_PATTERN,
+      Pattern.CASE_INSENSITIVE);
 
    protected DataSource dataSource;
 
@@ -118,97 +120,118 @@
     */
    public void init(Properties props) throws RepositoryConfigurationException, VCASException
    {
-      // init database metadata
-      final String tn = props.getProperty(TABLE_NAME_PARAM);
-      if (tn != null)
-         tableName = tn;
-      else
-         tableName = DEFAULT_TABLE_NAME;
+      final String sn = props.getProperty(JDBC_SOURCE_NAME_PARAM);
+      if (sn == null)
+      {
+         throw new RepositoryConfigurationException(JDBC_SOURCE_NAME_PARAM + " parameter expected!");
+      }
 
-      dialect = props.getProperty(JDBC_DIALECT_PARAM, DBConstants.DB_DIALECT_GENERIC);
+      try
+      {
+         dataSource = (DataSource)new InitialContext().lookup(sn);
+         Connection conn = null;
+         try
+         {
+            conn = dataSource.getConnection();
+            DatabaseMetaData dbMetaData = conn.getMetaData();
 
-      sqlConstraintPK = tableName + "_PK";
+            String dialect = props.getProperty(JDBC_DIALECT_PARAM);
+            if (dialect == null)
+            {
+               dialect = DialectDetecter.detect(dbMetaData);
+            }
 
-      sqlVCASIDX = tableName + "_IDX";
+            dialect = props.getProperty(JDBC_DIALECT_PARAM, DBConstants.DB_DIALECT_GENERIC);
 
-      if (DBConstants.DB_DIALECT_PGSQL.equalsIgnoreCase(dialect)
-         || DBConstants.DB_DIALECT_INGRES.equalsIgnoreCase(dialect))
-      {
-         // use lowercase for postgres/ingres metadata.getTable(), HSQLDB wants UPPERCASE
-         // for other seems not matter
-         tableName = tableName.toUpperCase().toLowerCase();
-         sqlConstraintPK = sqlConstraintPK.toUpperCase().toLowerCase();
-         sqlVCASIDX = sqlVCASIDX.toUpperCase().toLowerCase();
-      }
+            // init database metadata
+            final String tn = props.getProperty(TABLE_NAME_PARAM);
+            if (tn != null)
+            {
+               tableName = tn;
+            }
+            else
+            {
+               tableName = DEFAULT_TABLE_NAME;
+            }
 
-      sqlAddRecord = "INSERT INTO " + tableName + " (PROPERTY_ID, ORDER_NUM, CAS_ID) VALUES(?,?,?)";
-      sqlDeleteRecord = "DELETE FROM " + tableName + " WHERE PROPERTY_ID=?";
-      sqlDeleteValueRecord = "DELETE FROM " + tableName + " WHERE PROPERTY_ID=? AND ORDER_NUM=?";
-      sqlSelectRecord = "SELECT CAS_ID FROM " + tableName + " WHERE PROPERTY_ID=? AND ORDER_NUM=?";
-      sqlSelectRecords = "SELECT CAS_ID, ORDER_NUM FROM " + tableName + " WHERE PROPERTY_ID=? ORDER BY ORDER_NUM";
+            sqlConstraintPK = tableName + "_PK";
 
-      sqlSelectOwnRecords =
-         "SELECT P.CAS_ID, P.ORDER_NUM, S.CAS_ID as SHARED_ID " + "FROM " + tableName + " P LEFT JOIN " + tableName
-            + " S ON P.PROPERTY_ID<>S.PROPERTY_ID AND P.CAS_ID=S.CAS_ID "
-            + "WHERE P.PROPERTY_ID=? GROUP BY P.CAS_ID, P.ORDER_NUM, S.CAS_ID ORDER BY P.ORDER_NUM";
+            sqlVCASIDX = tableName + "_IDX";
 
-      sqlSelectSharingProps =
-         "SELECT DISTINCT C.PROPERTY_ID AS PROPERTY_ID FROM " + tableName + " C, " + tableName + " P "
-            + "WHERE C.CAS_ID=P.CAS_ID AND C.PROPERTY_ID<>P.PROPERTY_ID AND P.PROPERTY_ID=?";
+            if (DBConstants.DB_DIALECT_PGSQL.equalsIgnoreCase(dialect)
+               || DBConstants.DB_DIALECT_INGRES.equalsIgnoreCase(dialect))
+            {
+               // use lowercase for postgres/ingres metadata.getTable(), HSQLDB wants UPPERCASE
+               // for other seems not matter
+               tableName = tableName.toUpperCase().toLowerCase();
+               sqlConstraintPK = sqlConstraintPK.toUpperCase().toLowerCase();
+               sqlVCASIDX = sqlVCASIDX.toUpperCase().toLowerCase();
+            }
 
-      // init database objects
-      final String sn = props.getProperty(JDBC_SOURCE_NAME_PARAM);
-      if (sn != null)
-      {
-         try
-         {
-            dataSource = (DataSource)new InitialContext().lookup(sn);
-            try
+            sqlAddRecord = "INSERT INTO " + tableName + " (PROPERTY_ID, ORDER_NUM, CAS_ID) VALUES(?,?,?)";
+            sqlDeleteRecord = "DELETE FROM " + tableName + " WHERE PROPERTY_ID=?";
+            sqlDeleteValueRecord = "DELETE FROM " + tableName + " WHERE PROPERTY_ID=? AND ORDER_NUM=?";
+            sqlSelectRecord = "SELECT CAS_ID FROM " + tableName + " WHERE PROPERTY_ID=? AND ORDER_NUM=?";
+            sqlSelectRecords = "SELECT CAS_ID, ORDER_NUM FROM " + tableName + " WHERE PROPERTY_ID=? ORDER BY ORDER_NUM";
+
+            sqlSelectOwnRecords =
+               "SELECT P.CAS_ID, P.ORDER_NUM, S.CAS_ID as SHARED_ID " + "FROM " + tableName + " P LEFT JOIN "
+                  + tableName + " S ON P.PROPERTY_ID<>S.PROPERTY_ID AND P.CAS_ID=S.CAS_ID "
+                  + "WHERE P.PROPERTY_ID=? GROUP BY P.CAS_ID, P.ORDER_NUM, S.CAS_ID ORDER BY P.ORDER_NUM";
+
+            sqlSelectSharingProps =
+               "SELECT DISTINCT C.PROPERTY_ID AS PROPERTY_ID FROM " + tableName + " C, " + tableName + " P "
+                  + "WHERE C.CAS_ID=P.CAS_ID AND C.PROPERTY_ID<>P.PROPERTY_ID AND P.PROPERTY_ID=?";
+
+            // init database objects
+            ResultSet trs = dbMetaData.getTables(null, null, tableName, null);
+            // check if table already exists
+            if (!trs.next())
             {
-               Connection con = dataSource.getConnection();
-               try
-               {
-                  ResultSet trs = con.getMetaData().getTables(null, null, tableName, null);
-                  // check if table already exists
-                  if (!trs.next())
-                  {
-                     // create table
-                     con
-                        .createStatement()
-                        .executeUpdate(
-                           "CREATE TABLE "
-                              + tableName
-                              + " (PROPERTY_ID VARCHAR(96) NOT NULL, ORDER_NUM INTEGER NOT NULL, CAS_ID VARCHAR(512) NOT NULL, "
-                              + "CONSTRAINT " + sqlConstraintPK + " PRIMARY KEY(PROPERTY_ID, ORDER_NUM))");
+               // create table
+               conn.createStatement().executeUpdate(
+                  "CREATE TABLE " + tableName
+                     + " (PROPERTY_ID VARCHAR(96) NOT NULL, ORDER_NUM INTEGER NOT NULL, CAS_ID VARCHAR(512) NOT NULL, "
+                     + "CONSTRAINT " + sqlConstraintPK + " PRIMARY KEY(PROPERTY_ID, ORDER_NUM))");
 
-                     // create index on hash (CAS_ID)
-                     con.createStatement().executeUpdate(
-                        "CREATE INDEX " + sqlVCASIDX + " ON " + tableName + "(CAS_ID, PROPERTY_ID, ORDER_NUM)");
+               // create index on hash (CAS_ID)
+               conn.createStatement().executeUpdate(
+                  "CREATE INDEX " + sqlVCASIDX + " ON " + tableName + "(CAS_ID, PROPERTY_ID, ORDER_NUM)");
 
-                     if (LOG.isDebugEnabled())
-                        LOG.debug("JDBC Value Content Address Storage initialized in database " + sn);
-                  }
-                  else if (LOG.isDebugEnabled())
-                     LOG.debug("JDBC Value Content Address Storage already initialized in database " + sn);
-               }
-               finally
+               if (LOG.isDebugEnabled())
                {
-                  con.close();
+                  LOG.debug("JDBC Value Content Address Storage initialized in database " + sn);
                }
             }
-            catch (SQLException e)
+            else if (LOG.isDebugEnabled())
             {
-               throw new VCASException("VCAS INIT database error: " + e, e);
+               LOG.debug("JDBC Value Content Address Storage already initialized in database " + sn);
             }
          }
-         catch (final NamingException e)
+         catch (SQLException e)
          {
-            throw new RepositoryConfigurationException("JDBC data source is not available in JNDI with name '" + sn
-               + "'. Error: " + e);
+            throw new VCASException("VCAS INIT database error: " + e, e);
          }
+         finally
+         {
+            if (conn != null)
+            {
+               try
+               {
+                  conn.close();
+               }
+               catch (SQLException e)
+               {
+                  throw new VCASException("VCAS INIT database error on Connection close: " + e, e);
+               }
+            }
+         }
       }
-      else
-         throw new RepositoryConfigurationException(JDBC_SOURCE_NAME_PARAM + " parameter should be set");
+      catch (NamingException e)
+      {
+         throw new RepositoryConfigurationException("JDBC data source is not available in JNDI with name '" + sn
+            + "'. Error: " + e);
+      }
    }
 
    /**
@@ -274,8 +297,10 @@
          return MYSQL_PK_CONSTRAINT_DETECT.matcher(err).find();
       }
       else if (err.toLowerCase().toUpperCase().indexOf(sqlConstraintPK.toLowerCase().toUpperCase()) >= 0)
+      {
          // most of supported dbs prints PK name in exception
          return true;
+      }
 
       // NOTICE! As an additional check we may ask the database for property currently processed in
       // VCAS

Modified: jcr/trunk/exo.jcr.component.core/src/main/resources/conf/portal/exo-jcr-config.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/resources/conf/portal/exo-jcr-config.xml	2010-01-27 13:37:35 UTC (rev 1591)
+++ jcr/trunk/exo.jcr.component.core/src/main/resources/conf/portal/exo-jcr-config.xml	2010-01-27 16:05:42 UTC (rev 1592)
@@ -30,7 +30,6 @@
                <container class="org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer">
                   <properties>
                      <property name="source-name" value="jdbcjcr" />
-                     <property name="dialect" value="hsqldb" />
                      <property name="multi-db" value="false" />
                      <property name="update-storage" value="false" />
                      <property name="max-buffer-size" value="200k" />
@@ -77,7 +76,6 @@
                <container class="org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer">
                   <properties>
                      <property name="source-name" value="jdbcjcr" />
-                     <property name="dialect" value="hsqldb" />
                      <property name="multi-db" value="false" />
                      <property name="update-storage" value="false" />
                      <property name="max-buffer-size" value="200k" />
@@ -116,7 +114,6 @@
                <container class="org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer">
                   <properties>
                      <property name="source-name" value="jdbcjcr" />
-                     <property name="dialect" value="hsqldb" />
                      <property name="multi-db" value="false" />
                      <property name="update-storage" value="false" />
                      <property name="max-buffer-size" value="200k" />

Modified: jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration-sjdbc.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration-sjdbc.xml	2010-01-27 13:37:35 UTC (rev 1591)
+++ jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration-sjdbc.xml	2010-01-27 16:05:42 UTC (rev 1592)
@@ -98,64 +98,65 @@
       </properties-param -->
 
     </init-params>
+  </component>
+  
+  <component>
+     <key>org.exoplatform.services.jcr.RepositoryService</key>
+     <type>org.exoplatform.services.jcr.impl.RepositoryServiceImpl</type>
+     <component-plugins>
+       <component-plugin>
+           <name>add.namespaces</name>
+           <set-method>addPlugin</set-method>
+           <type>org.exoplatform.services.jcr.impl.AddNamespacesPlugin</type>
+           <init-params>
+             <properties-param>
+               <name>namespaces</name>
+               <property name="test" value="http://www.apache.org/jackrabbit/test"/>
+               <property name="exojcrtest" value="http://www.exoplatform.org/jcr/test/1.0"/>
+               <property name="rma" value="http://www.rma.com/jcr/"/>
+               <property name="metadata" value="http://www.exoplatform.com/jcr/metadata/1.1/"/>
+             </properties-param>
+           </init-params>
+       </component-plugin>
+       <component-plugin>
+         <name>add.nodeType</name>
+         <set-method>addPlugin</set-method>
+         <type>org.exoplatform.services.jcr.impl.AddNodeTypePlugin</type>
+         <init-params>
+         <values-param>
+           <name>autoCreatedInNewRepository</name>
+           <description>Node types configuration file</description>
+           <value>jar:/conf/test/nodetypes-tck.xml</value>
+           <value>jar:/conf/test/nodetypes-impl.xml</value>
+           <value>jar:/conf/test/nodetypes-usecase.xml</value>
+           <value>jar:/conf/test/nodetypes-config.xml</value>
+           <value>jar:/conf/test/nodetypes-config-extended.xml</value>    
+         </values-param>
+         <values-param>
+           <name>testInitNodeTypesRepository</name>
+           <description>Node types configuration file for repository with name testInitNodeTypesRepository</description>
+           <value>jar:/conf/test/nodetypes-test.xml</value>
+         </values-param>
+         <values-param>
+           <name>testInitNodeTypesRepositoryTest2</name>
+           <description>Node types configuration file for repository with name testInitNodeTypesRepositoryTest2</description>
+           <value>jar:/conf/test/nodetypes-test2.xml</value>
+         </values-param>
+       </init-params>
+       </component-plugin>
+     </component-plugins>
   </component>
-    <component>
-      <key>org.exoplatform.services.jcr.RepositoryService</key>
-      <type>org.exoplatform.services.jcr.impl.RepositoryServiceImpl</type>
-      <component-plugins>
-        <component-plugin>
-            <name>add.namespaces</name>
-            <set-method>addPlugin</set-method>
-            <type>org.exoplatform.services.jcr.impl.AddNamespacesPlugin</type>
-            <init-params>
-              <properties-param>
-                <name>namespaces</name>
-                <property name="test" value="http://www.apache.org/jackrabbit/test"/>
-                <property name="exojcrtest" value="http://www.exoplatform.org/jcr/test/1.0"/>
-                <property name="rma" value="http://www.rma.com/jcr/"/>
-                <property name="metadata" value="http://www.exoplatform.com/jcr/metadata/1.1/"/>
-              </properties-param>
-            </init-params>
-        </component-plugin>
-        <component-plugin>
-          <name>add.nodeType</name>
-          <set-method>addPlugin</set-method>
-          <type>org.exoplatform.services.jcr.impl.AddNodeTypePlugin</type>
-          <init-params>
-          <values-param>
-            <name>autoCreatedInNewRepository</name>
-            <description>Node types configuration file</description>
-            <value>jar:/conf/test/nodetypes-tck.xml</value>
-            <value>jar:/conf/test/nodetypes-impl.xml</value>
-            <value>jar:/conf/test/nodetypes-usecase.xml</value>
-            <value>jar:/conf/test/nodetypes-config.xml</value>
-            <value>jar:/conf/test/nodetypes-config-extended.xml</value>    
-          </values-param>
-          <values-param>
-            <name>testInitNodeTypesRepository</name>
-            <description>Node types configuration file for repository with name testInitNodeTypesRepository</description>
-            <value>jar:/conf/test/nodetypes-test.xml</value>
-          </values-param>
-          <values-param>
-            <name>testInitNodeTypesRepositoryTest2</name>
-            <description>Node types configuration file for repository with name testInitNodeTypesRepositoryTest2</description>
-            <value>jar:/conf/test/nodetypes-test2.xml</value>
-          </values-param>
-        </init-params>
-        </component-plugin>
-      </component-plugins>
-    </component>
 
-    <component>
-	    <key>org.exoplatform.services.jcr.config.RepositoryServiceConfiguration</key>
-	    <type>org.exoplatform.services.jcr.impl.config.RepositoryServiceConfigurationImpl</type>
-	    <init-params>
-	      <value-param>
-	        <name>conf-path</name>
-	        <description>JCR configuration file</description>
-	        <value>jar:/conf/standalone/test-jcr-config-sjdbc.xml</value>
-	        </value-param>
-	    </init-params>
+  <component>
+    <key>org.exoplatform.services.jcr.config.RepositoryServiceConfiguration</key>
+    <type>org.exoplatform.services.jcr.impl.config.RepositoryServiceConfigurationImpl</type>
+    <init-params>
+      <value-param>
+        <name>conf-path</name>
+        <description>JCR configuration file</description>
+        <value>jar:/conf/standalone/test-jcr-config-sjdbc.xml</value>
+        </value-param>
+    </init-params>
   </component>
 
   <component>

Modified: jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration.xml	2010-01-27 13:37:35 UTC (rev 1591)
+++ jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration.xml	2010-01-27 16:05:42 UTC (rev 1592)
@@ -176,7 +176,6 @@
         <name>working-conf</name>
         <description>working-conf</description>
         <property name="source-name" value="jdbcjcr"/>
-        <property name="dialect" value="hsqldb"/>
         <property name="persister-class-name" value="org.exoplatform.services.jcr.impl.config.JDBCConfigurationPersister"/>
       </properties-param>
     </init-params>

Modified: jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config-sjdbc.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config-sjdbc.xml	2010-01-27 13:37:35 UTC (rev 1591)
+++ jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config-sjdbc.xml	2010-01-27 16:05:42 UTC (rev 1592)
@@ -191,7 +191,6 @@
                            <property name="digest-algo" value="MD5" />
                            <property name="vcas-type" value="org.exoplatform.services.jcr.impl.storage.value.cas.JDBCValueContentAddressStorageImpl" />
                            <property name="jdbc-source-name" value="jdbcjcr" />
-                           <property name="jdbc-dialect" value="hsqldb" />
                         </properties>
                         <filters>
                            <filter property-type="Binary" />

Modified: jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml	2010-01-27 13:37:35 UTC (rev 1591)
+++ jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml	2010-01-27 16:05:42 UTC (rev 1592)
@@ -45,7 +45,6 @@
                            <property name="digest-algo" value="MD5" />
                            <property name="vcas-type" value="org.exoplatform.services.jcr.impl.storage.value.cas.JDBCValueContentAddressStorageImpl" />
                            <property name="jdbc-source-name" value="jdbcjcr" />
-                           <property name="jdbc-dialect" value="hsqldb" />
                         </properties>
                         <filters>
                            <filter property-type="Binary" />
@@ -205,7 +204,6 @@
 									<property name="vcas-type"
 										value="org.exoplatform.services.jcr.impl.storage.value.cas.JDBCValueContentAddressStorageImpl" />
 									<property name="jdbc-source-name" value="jdbcjcr" />
-									<property name="jdbc-dialect" value="hsqldb" />
 								</properties>
 								<filters>
 									<filter property-type="Binary" />



More information about the exo-jcr-commits mailing list