I tried looking for how to submit patches via Scarab, but its interface is just plain unusable. Anyway, I figured that I'd try and add usefully error messages to the locations where PersistenceBrokerSQLException. Most of them were already logging some information before throwing the exception, so I just added what they were logging as the PersistenceBrokerSQLException message. Hopefully this is useful.

Armin Waibel wrote:

...
Didn't you get an error log message before the exception was thrown?
I can find 7 classes throwing PersistenceBrokerSQLException most of them do not specify the classname causing the SQLException.
Will add this on my endless todo-list ;-)


regards,
Armin
...


--
   Robert r. Sanders
   Chief Technologist
   iPOV
   www.ipov.net

Index: src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
===================================================================
RCS file: 
/home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java,v
retrieving revision 1.24
diff -U3 -r1.24 JdbcAccessImpl.java
--- src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java      20 Sep 
2004 14:33:14 -0000      1.24
+++ src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java      12 Nov 
2004 14:24:46 -0000
@@ -95,7 +95,7 @@
             if (stmt == null)
             {
                 logger.error("getDeleteStatement returned a null statement");
-                throw new PersistenceBrokerException("getDeleteStatement 
returned a null statement");
+                throw new PersistenceBrokerException("JdbcAccessImpl: 
getDeleteStatement returned a null statement");
             }
 
             broker.serviceStatementManager().bindDelete(stmt, cld, obj);
@@ -130,12 +130,12 @@
         }
         catch (SQLException e)
         {
-            logger.error(
-                "SQLException during the execution of the delete (for a "
-                    + cld.getClassOfObject().getName()
-                    + "): "
-                    + e.getMessage(), e);
-            throw new PersistenceBrokerSQLException(e);
+            String msg = "SQLException during the execution of the delete (for 
a "
+                + cld.getClassOfObject().getName()
+                + "): "
+                + e.getMessage(); 
+            logger.error(msg, e);
+            throw new PersistenceBrokerSQLException("JdbcAccessImpl: " + msg, 
e);
         }
         finally
         {
@@ -167,13 +167,12 @@
         }
         catch (SQLException e)
         {
-            logger.error(
-                "SQLException during the execution of delete by query (for a "
-                    + cld.getClassOfObject().getName()
-                    + "): "
-                    + e.getMessage(),
-                e);
-            throw new PersistenceBrokerSQLException(e);
+            String msg = "SQLException during the execution of delete by query 
(for a "
+                + cld.getClassOfObject().getName()
+                + "): "
+                + e.getMessage();
+            logger.error(msg,e);
+            throw new PersistenceBrokerSQLException(msg, e);
         }
         finally
         {
@@ -312,8 +311,9 @@
         }
         catch (SQLException e)
         {
-            logger.error("SQLException during the execution of the query (for 
a "
-                    + cld.getClassOfObject().getName() + "): " + 
e.getMessage(), e);
+            String msg = "SQLException during the execution of the query (for 
a "
+                + cld.getClassOfObject().getName() + "): " + e.getMessage();
+            logger.error(msg, e);
             /*
                         * MBAIRD: error condition could result in our
                         * ResultSetAndStatement not being returned, and not 
being closed
@@ -324,7 +324,7 @@
             {
                 retval.close();
             }
-            throw new PersistenceBrokerSQLException(e);
+            throw new PersistenceBrokerSQLException(msg, e);
         }
     }
 
@@ -376,7 +376,8 @@
         }
         catch (SQLException e)
         {
-            logger.error("SQLException during the execution of the SQL query: 
" + e.getMessage(), e);
+            String msg = "SQLException during the execution of the SQL query: 
" + e.getMessage();
+            logger.error(msg, e);
             /**
              * MBAIRD: error condition could result in our 
ResultSetAndStatement not being returned, and not being closed
              * since it is opened before the try loop, we should release it if 
there is a problem.
@@ -385,7 +386,7 @@
             {
                 retval.close();
             }
-            throw new PersistenceBrokerSQLException(e);
+            throw new PersistenceBrokerSQLException(msg, e);
         }
     }
 
@@ -427,15 +428,15 @@
         }
         catch (SQLException e)
         {
-            logger.error(
-                "SQLException during the execution of the update SQL query: " 
+ sqlStatement, e);
+            String msg = "SQLException during the execution of the update SQL 
query: " + sqlStatement;
+            logger.error(msg, e);
             if (SQL_STATE_KEY_VIOLATED.equals(e.getSQLState()))
             {
                 throw new KeyConstraintViolatedException(e);
             }
             else
             {
-                throw new PersistenceBrokerSQLException(e);
+                throw new PersistenceBrokerSQLException(msg, e);
             }
         }
         finally
@@ -526,18 +527,17 @@
             // BRJ: restore old locking values
             setLockingValues(cld, obj, oldLockingValues);
 
-            logger.error(
-                "SQLException during the execution of the update (for a "
-                    + cld.getClassOfObject().getName()
-                    + "): "
-                    + e.getMessage(),
-                e);
+            String msg = "SQLException during the execution of the update (for 
a "
+                + cld.getClassOfObject().getName()
+                + "): "
+                + e.getMessage();
+            logger.error(msg,e);
             
             if (SQL_STATE_KEY_VIOLATED.equals(e.getSQLState()))
             {
                 throw new KeyConstraintViolatedException(e);
             }
-            throw new PersistenceBrokerSQLException(e);
+            throw new PersistenceBrokerSQLException(msg, e);
         }
         finally
         {           
@@ -630,13 +630,12 @@
         }
         catch (SQLException e)
         {
-            logger.error(
-                "SQLException during the execution of materializeObject (for a 
"
-                    + cld.getClassOfObject().getName()
-                    + "): "
-                    + e.getMessage(),
-                e);
-            throw new PersistenceBrokerSQLException(e);
+            String msg = "SQLException during the execution of 
materializeObject (for a "
+                + cld.getClassOfObject().getName()
+                + "): "
+                + e.getMessage();
+            logger.error(msg,e);
+            throw new PersistenceBrokerSQLException(msg, e);
         }
         finally
         {
@@ -755,17 +754,16 @@
         }
         catch (SQLException e)
         {
-            logger.error(
-                "SQLException during the execution of harvestReturnValue"
-                    + " class="
-                    + obj.getClass().getName()
-                    + ","
-                    + " field="
-                    + fmd.getAttributeName()
-                    + " : "
-                    + e.getMessage(),
-                e);
-            throw new PersistenceBrokerSQLException(e);
+            String msg = "SQLException during the execution of 
harvestReturnValue"
+                + " class="
+                + obj.getClass().getName()
+                + ","
+                + " field="
+                + fmd.getAttributeName()
+                + " : "
+                + e.getMessage();
+            logger.error(msg,e);
+            throw new PersistenceBrokerSQLException(msg, e);
         }
     }
 }
Index: src/java/org/apache/ojb/broker/accesslayer/PkEnumeration.java
===================================================================
RCS file: 
/home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/accesslayer/PkEnumeration.java,v
retrieving revision 1.17
diff -U3 -r1.17 PkEnumeration.java
--- src/java/org/apache/ojb/broker/accesslayer/PkEnumeration.java       4 Apr 
2004 23:53:31 -0000       1.17
+++ src/java/org/apache/ojb/broker/accesslayer/PkEnumeration.java       12 Nov 
2004 14:24:46 -0000
@@ -81,14 +81,15 @@
         }
         catch (NoSuchMethodException e)
         {
-            LoggerFactory.getDefaultLogger().error(primaryKeyClass.getName()
-                    + " must implement a Constructor with one argument of type 
org.apache.ojb.broker.Identity");
-            throw new PersistenceBrokerException(e);
+            String msg = primaryKeyClass.getName() +
+                " must implement a Constructor with one argument of type 
org.apache.ojb.broker.Identity"
+            LoggerFactory.getDefaultLogger().error(msg);
+            throw new PersistenceBrokerException("PkEnumeration: " + msg, e);
         }
         catch (SecurityException e)
         {
             LoggerFactory.getDefaultLogger().error(e);
-            throw new PersistenceBrokerException(e);
+            throw new PersistenceBrokerException("PkEnumeration: 
SecurityException." , e);
         }
     }
 
Index: src/java/org/apache/ojb/broker/accesslayer/StatementsForClassImpl.java
===================================================================
RCS file: 
/home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementsForClassImpl.java,v
retrieving revision 1.24
diff -U3 -r1.24 StatementsForClassImpl.java
--- src/java/org/apache/ojb/broker/accesslayer/StatementsForClassImpl.java      
14 Sep 2004 16:03:33 -0000      1.24
+++ src/java/org/apache/ojb/broker/accesslayer/StatementsForClassImpl.java      
12 Nov 2004 14:24:46 -0000
@@ -125,7 +125,7 @@
         catch (SQLException ex)
         {
             log.error(ex);
-            throw new PersistenceBrokerSQLException(ex);
+            throw new PersistenceBrokerSQLException("StatementsForClassImpl, 
unable to get Generic Statement due to SQLException.", ex);
         }
         return stmt;
     }
@@ -162,7 +162,7 @@
         catch (java.sql.SQLException ex)
         {
             log.error(ex);
-            throw new PersistenceBrokerSQLException(ex);
+            throw new PersistenceBrokerSQLException("StatementsForClassImpl, 
unable to get Prepared Statement due to SQLException.", ex);
         }
         return stmt;
     }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to