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

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Jun 24 05:31:10 EDT 2011


Author: nzamosenchuk
Date: 2011-06-24 05:31:10 -0400 (Fri, 24 Jun 2011)
New Revision: 4566

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/JDBCUtils.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java
Log:
EXOJCR-1374: AutoCommit is set to true when creating DB structrure.

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	2011-06-24 09:26:03 UTC (rev 4565)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/JDBCConfigurationPersister.java	2011-06-24 09:31:10 UTC (rev 4566)
@@ -184,8 +184,9 @@
          configTableName = configTableName.toUpperCase().toLowerCase(); // ingres needs it
          binType = "LONG BYTE";
       }
-      else if (DBConstants.DB_DIALECT_MYSQL.equalsIgnoreCase(dialect) 
-               || DBConstants.DB_DIALECT_MYSQL_UTF8.equalsIgnoreCase(dialect)) {
+      else if (DBConstants.DB_DIALECT_MYSQL.equalsIgnoreCase(dialect)
+         || DBConstants.DB_DIALECT_MYSQL_UTF8.equalsIgnoreCase(dialect))
+      {
          binType = "LONGBLOB";
       }
 
@@ -322,12 +323,16 @@
                   return config.getStream();
                }
                else
+               {
                   throw new ConfigurationNotFoundException("No configuration data is found in database. Source name "
                      + sourceName);
+               }
             }
             else
+            {
                throw new ConfigurationNotInitializedException(
                   "Configuration table not is found in database. Source name " + sourceName);
+            }
 
          }
          finally
@@ -385,12 +390,10 @@
          PreparedStatement ps = null;
          try
          {
-
-            con.setAutoCommit(false);
-
             if (!isDbInitialized(con))
             {
                // init db
+               con.setAutoCommit(true);
                Statement st = con.createStatement();
                st.executeUpdate(sql = initSQL);
                st.close();
@@ -400,8 +403,8 @@
 
                // one new conn
                con = openConnection();
-               con.setAutoCommit(false);
             }
+            con.setAutoCommit(false);
 
             if (isDbInitialized(con))
             {
@@ -425,15 +428,15 @@
                if (ps.executeUpdate() <= 0)
                {
                   LOG.warn("Repository service configuration doesn't stored ok. "
-                           + "No rows was affected in JDBC operation. Datasource " + sourceName + ". SQL: " + sql);
+                     + "No rows was affected in JDBC operation. Datasource " + sourceName + ". SQL: " + sql);
                }
             }
             else
+            {
                throw new ConfigurationNotInitializedException(
                   "Configuration table can not be created in database. Source name " + sourceName + ". SQL: " + sql);
-
+            }
             con.commit();
-
          }
          finally
          {
@@ -448,7 +451,6 @@
                   LOG.error("Can't close the Statement: " + e);
                }
             }
-
             con.close();
          }
       }

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCUtils.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCUtils.java	2011-06-24 09:26:03 UTC (rev 4565)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCUtils.java	2011-06-24 09:31:10 UTC (rev 4566)
@@ -24,7 +24,6 @@
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.sql.Savepoint;
 import java.sql.Statement;
 
 /**
@@ -52,36 +51,14 @@
    {
       Statement stmt = null;
       ResultSet trs = null;
-      Savepoint savePoint = null;
-      Boolean autoCommit = null;
       try
       {
-         // safe get autoCommit value
-         autoCommit = con.getAutoCommit();
-         // set autoCommit to true
-         con.setAutoCommit(false);
-         // make a savepoint (snapshot)
-         savePoint = con.setSavepoint(Thread.currentThread().getName()+System.currentTimeMillis());
          stmt = con.createStatement();
          trs = stmt.executeQuery("SELECT count(*) FROM " + tableName);
          return trs.next();
       }
       catch (SQLException e)
       {
-         if (savePoint != null)
-         {
-            try
-            {
-               // revert state to savePoint after failed query in transaction. This will allow following queries to 
-               // be executed in an ordinary way, like no failed query existed.
-               // Obligatory operation for PostgreSQL.
-               con.rollback(savePoint);
-            }
-            catch (SQLException e1)
-            {
-               LOG.error("Can't rollback to savePoint", e1);
-            }
-         }
          if (LOG.isDebugEnabled())
          {
             LOG.debug("SQLException occurs while checking the table " + tableName, e);
@@ -90,17 +67,6 @@
       }
       finally
       {
-         if (autoCommit != null)
-         {
-            try
-            {
-               con.setAutoCommit(autoCommit);
-            }
-            catch (SQLException e)
-            {
-               LOG.error("Can't set autoCommit value back", e);
-            }
-         }
          if (trs != null)
          {
             try

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java	2011-06-24 09:26:03 UTC (rev 4565)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/jdbc/DBInitializer.java	2011-06-24 09:31:10 UTC (rev 4566)
@@ -182,7 +182,7 @@
          }
       });
    }
- 
+
    protected boolean isSequenceExists(Connection conn, String sequenceName) throws SQLException
    {
       return false;
@@ -247,7 +247,8 @@
                   {
                      if (LOG.isDebugEnabled())
                      {
-                        LOG.debug("The table " + tableName + " already exists so we assume that the index " + indexName + " exists also.");
+                        LOG.debug("The table " + tableName + " already exists so we assume that the index " + indexName
+                           + " exists also.");
                      }
                      return true;
                   }
@@ -295,7 +296,8 @@
             {
                if (LOG.isDebugEnabled())
                {
-                  LOG.debug("At least one table has been created so we assume that the trigger " + triggerName + " exists also");
+                  LOG.debug("At least one table has been created so we assume that the trigger " + triggerName
+                     + " exists also");
                }
                return true;
             }
@@ -346,8 +348,10 @@
       try
       {
          st = connection.createStatement();
-         connection.setAutoCommit(false);
-
+         // all DDL queries executed in separated transactions
+         // Required for SyBase, when checking table existence 
+         // and performing DDLs inside single transaction. 
+         connection.setAutoCommit(true);
          for (String scr : scripts)
          {
             String s = cleanWhitespaces(scr.trim());
@@ -376,20 +380,18 @@
          }
 
          postInit(connection);
-
          connection.commit();
          LOG.info("DB schema of DataSource: '" + containerName + "' initialized succesfully");
       }
       catch (SQLException e)
       {
-         try
+         if (LOG.isDebugEnabled())
          {
-            connection.rollback();
+            LOG.error("Problem creating database structure.", e);
          }
-         catch (SQLException re)
-         {
-            LOG.error("Rollback error " + e, e);
-         }
+         LOG
+            .warn("Some tables were created and not rolled back. Please make sure to drop them manually in datasource : '"
+               + containerName + "'");
 
          boolean isAlreadyCreated = false;
          try



More information about the exo-jcr-commits mailing list