[exo-jcr-commits] exo-jcr SVN: r4679 - in core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database: creator and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Jul 26 07:42:02 EDT 2011


Author: areshetnyak
Date: 2011-07-26 07:42:01 -0400 (Tue, 26 Jul 2011)
New Revision: 4679

Added:
   core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/utils/
   core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/utils/ExceptionManagementHelper.java
Modified:
   core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java
   core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/jdbc/DBSchemaCreator.java
Log:
EXOJCR-1287 : Add ExceptionManagementHelper.

Modified: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java
===================================================================
--- core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java	2011-07-25 09:18:04 UTC (rev 4678)
+++ core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java	2011-07-26 11:42:01 UTC (rev 4679)
@@ -25,6 +25,7 @@
 import org.exoplatform.container.xml.InitParams;
 import org.exoplatform.container.xml.PropertiesParam;
 import org.exoplatform.container.xml.Property;
+import org.exoplatform.services.database.utils.ExceptionManagementHelper;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -242,14 +243,7 @@
       }
       catch (SQLException e)
       {
-         String errorTrace = "";
-         while (e != null)
-         {
-            errorTrace += e.getMessage() + "; ";
-            e = e.getNextException();
-         }
-
-         throw new DBCreatorException("Can't execute SQL script " + errorTrace);
+         throw new DBCreatorException("Can't execute SQL script : " + ExceptionManagementHelper.getFullSQLExceptionMessage(e));
       }
       finally
       {

Modified: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/jdbc/DBSchemaCreator.java
===================================================================
--- core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/jdbc/DBSchemaCreator.java	2011-07-25 09:18:04 UTC (rev 4678)
+++ core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/jdbc/DBSchemaCreator.java	2011-07-26 11:42:01 UTC (rev 4679)
@@ -19,6 +19,7 @@
 package org.exoplatform.services.database.jdbc;
 
 import org.exoplatform.container.component.ComponentPlugin;
+import org.exoplatform.services.database.utils.ExceptionManagementHelper;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 import org.exoplatform.services.naming.InitialContextInitializer;
@@ -137,16 +138,8 @@
       }
       catch (SQLException e)
       {
-         SQLException next = e.getNextException();
-         String errorTrace = "";
-         while (next != null)
-         {
-            errorTrace += next.getMessage() + "; ";
-            next = next.getNextException();
-         }
-         Throwable cause = e.getCause();
          log.error("Could not create db schema of DataSource: '" + dsName + "'. Reason: " + e.getMessage() + "; "
-            + errorTrace + (cause != null ? " (Cause: " + cause.getMessage() + ")" : "") + ". Last command: " + sql, e);
+                  + ExceptionManagementHelper.getFullSQLExceptionMessage(e) + ". Last command: " + sql, e);
       }
       finally
       {

Added: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/utils/ExceptionManagementHelper.java
===================================================================
--- core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/utils/ExceptionManagementHelper.java	                        (rev 0)
+++ core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/utils/ExceptionManagementHelper.java	2011-07-26 11:42:01 UTC (rev 4679)
@@ -0,0 +1,53 @@
+/*
+ * 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.database.utils;
+
+import java.sql.SQLException;
+
+/**
+ * Created by The eXo Platform SAS.
+ * 
+ * <br/>Date: 2011
+ *
+ * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a> 
+ * @version $Id: ExceptionManagementHelper.java 111 2011-11-11 11:11:11Z rainf0x $
+ */
+public class ExceptionManagementHelper
+{
+   /**
+    * Prepare message from SQLException.
+    * 
+    * @param e
+    *          SQLException
+    * @return String
+    *           The message form SQLException
+    */
+   public static String getFullSQLExceptionMessage(SQLException e)
+   {
+      SQLException next = e.getNextException();
+      String errorTrace = "";
+      while (next != null)
+      {
+         errorTrace += next.getMessage() + "; ";
+         next = next.getNextException();
+      }
+
+      Throwable cause = e.getCause();
+
+      return errorTrace + (cause != null ? " (Cause: " + cause.getMessage() + ")" : "");
+   }
+}


Property changes on: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/utils/ExceptionManagementHelper.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain



More information about the exo-jcr-commits mailing list