db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mka...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer JdbcAccessImpl.java
Date Fri, 04 Mar 2005 22:39:06 GMT
mkalen      2005/03/04 14:39:06

  Modified:    src/java/org/apache/ojb/broker/accesslayer Tag:
                        OJB_1_0_RELEASE JdbcAccessImpl.java
  Log:
  Add check for FK-violation when throwing KeyConstraintViolatedException. Makes PostgeSQL
pass some tests that expect specific broker exception. (Transparent change for other calling
methods since catch-blocks will apply to superclass of exception.)
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.22.2.3  +37 -8     db-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
  
  Index: JdbcAccessImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java,v
  retrieving revision 1.22.2.2
  retrieving revision 1.22.2.3
  diff -u -r1.22.2.2 -r1.22.2.3
  --- JdbcAccessImpl.java	27 Nov 2004 23:38:05 -0000	1.22.2.2
  +++ JdbcAccessImpl.java	4 Mar 2005 22:39:05 -0000	1.22.2.3
  @@ -51,6 +51,17 @@
   public class JdbcAccessImpl implements JdbcAccess
   {
       private static final String SQL_STATE_KEY_VIOLATED = "23000";
  +    private static final String SQL_STATE_FK_VIOLATED = "23505";
  +    /*
  +        X/OPEN codes within class 23:
  +            23000	INTEGRITY CONSTRAINT VIOLATION
  +            23001	RESTRICT VIOLATION
  +            23502	NOT NULL VIOLATION
  +            23503	FOREIGN KEY VIOLATION
  +            23505	UNIQUE VIOLATION
  +            23514	CHECK VIOLATION
  +    */
  +
       /**
        * The logger used.
        */
  @@ -78,7 +89,10 @@
        */
       public void executeDelete(ClassDescriptor cld, Object obj) throws PersistenceBrokerException
       {
  -        if(logger.isDebugEnabled()) logger.safeDebug("executeDelete", obj);
  +        if (logger.isDebugEnabled())
  +        {
  +            logger.debug("executeDelete: " + obj);
  +        }
   
           PreparedStatement stmt = null;
           try
  @@ -141,7 +155,10 @@
        */
       public void executeDelete(Query query, ClassDescriptor cld) throws PersistenceBrokerException
       {
  -        if(logger.isDebugEnabled()) logger.safeDebug("executeDelete (by Query)", query);
  +        if (logger.isDebugEnabled())
  +        {
  +            logger.debug("executeDelete (by Query): " + query);
  +        }
   
           PreparedStatement stmt = null;
   
  @@ -177,7 +194,10 @@
        */
       public void executeInsert(ClassDescriptor cld, Object obj) throws PersistenceBrokerException
       {
  -        if(logger.isDebugEnabled()) logger.safeDebug("executeInsert", obj);
  +        if (logger.isDebugEnabled())
  +        {
  +            logger.debug("executeInsert: " + obj);
  +        }
   
           PreparedStatement stmt = null;
           try
  @@ -212,6 +232,7 @@
           }
           catch (SQLException e)
           {
  +            final String stateCode = e.getSQLState();
               // Build a detailed error message
               StringBuffer msg = new StringBuffer("SQL failure while insert object data for
class ");
               try
  @@ -227,7 +248,8 @@
                               .append(fields[i].getPersistentField().get(obj));
                   }
                   msg.append("], object was " + obj);
  -                msg.append(", exception message is [" + e.getMessage() + "]");
  +                msg.append(", exception message is [").append(e.getMessage()).append("]");
  +                msg.append(", SQL code [").append(stateCode).append("]");
               }
               catch (Exception ignore)
               {
  @@ -237,7 +259,9 @@
               /**
                * throw a specific type of runtime exception for a key constraint.
                */
  -            if (SQL_STATE_KEY_VIOLATED.equals(e.getSQLState()))
  +            if (SQL_STATE_KEY_VIOLATED.equals(stateCode)
  +                ||
  +                SQL_STATE_FK_VIOLATED.equals(stateCode))
               {
                   throw new KeyConstraintViolatedException(msg.toString(), e);
               }
  @@ -260,7 +284,9 @@
       public ResultSetAndStatement executeQuery(Query query, ClassDescriptor cld) throws
PersistenceBrokerException
       {
           if (logger.isDebugEnabled())
  -            logger.safeDebug("executeQuery", query);
  +        {
  +            logger.debug("executeQuery: " + query);
  +        }
           /*
   		 * MBAIRD: we should create a scrollable resultset if the start at
   		 * index or end at index is set
  @@ -455,7 +481,10 @@
        */
       public void executeUpdate(ClassDescriptor cld, Object obj) throws PersistenceBrokerException
       {
  -        if(logger.isDebugEnabled()) logger.safeDebug("executeUpdate", obj);
  +        if (logger.isDebugEnabled())
  +        {
  +            logger.debug("executeUpdate: " + obj);
  +        }
   
           PreparedStatement stmt = null;
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message