You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by dl...@apache.org on 2005/01/06 19:36:47 UTC

cvs commit: db-torque/src/generator/src/templates/om Object.vm ObjectWithManager.vm

dlr         2005/01/06 10:36:47

  Modified:    src/generator/src/templates/om Object.vm
                        ObjectWithManager.vm
  Log:
  Fix the Java source code generation failure for OM class whose
  corresponding table lacks a PK.
  
  Observed behavior before this patch:
  
  Compilation error in BaseYourObject.setQueryKey(String) due to throws
  delcaration mismatch between Torque's BaseObject.setPrimaryKey(String)
  method and lack of generated setPrimaryKey(String) method.  Had the
  override been generated, it would've had a throws declaration of
  TorqueException, instead of Exception as declared by BaseObject.
  
    [javac] .../BaseYourObject.java:392:9:392:26: Semantic Error: The
    method "void setPrimaryKey(java.lang.String $1) throws
    java.lang.Exception;" can throw the checked exception
    "java.lang.Exception", so its invocation must be enclosed in a try
    statement that catches the exception, or else this method must be
    declared to throw the exception.
  
  * src/generator/src/templates/om/Object.vm
  * src/generator/src/templates/om/ObjectWithManager.vm
    Wrap the invocation of setPrimaryKey(String) in a try/catch block to
    re-throw Exception as TorqueException in the setQueryKey(String)
    method.
  
  CollabNet-internal issue: PCN33929
  
  Revision  Changes    Path
  1.18      +13 -0     db-torque/src/generator/src/templates/om/Object.vm
  
  Index: Object.vm
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/templates/om/Object.vm,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -u -r1.17 -r1.18
  --- Object.vm	20 Oct 2004 01:28:18 -0000	1.17
  +++ Object.vm	6 Jan 2005 18:36:47 -0000	1.18
  @@ -1424,7 +1424,20 @@
       public void setQueryKey(String key)
           throws TorqueException
       {
  +  ## Work around the fact that BaseObject.setPrimaryKey() declares
  +  ## that it throws Exception instead of TorqueException.
  +  #set ($tableHasPrimaryKey = $table.PrimaryKey.size() > 0)
  +  #if (!$tableHasPrimaryKey)
  +        try
  +        {
  +  #end
           setPrimaryKey(key);
  +  #if (!$tableHasPrimaryKey)
  +        }
  +        catch (Exception e)
  +        {
  +        }
  +  #end
       }
   #end
   
  
  
  
  1.13      +14 -1     db-torque/src/generator/src/templates/om/ObjectWithManager.vm
  
  Index: ObjectWithManager.vm
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/templates/om/ObjectWithManager.vm,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -u -r1.12 -r1.13
  --- ObjectWithManager.vm	20 Oct 2004 01:28:18 -0000	1.12
  +++ ObjectWithManager.vm	6 Jan 2005 18:36:47 -0000	1.13
  @@ -1110,7 +1110,8 @@
                       ${table.JavaName}Peer.doUpdate(($table.JavaName) this, con);
                   }
   
  -  #if ($table.PrimaryKey.size() > 0)
  +  #set ($tableHasPrimaryKey = $table.PrimaryKey.size() > 0)
  +  #if ($tableHasPrimaryKey)
       #set ($interfaceName = $table.JavaName)
       #if ($table.Interface)
         #set ($interfaceName = $table.Interface)
  @@ -1400,7 +1401,19 @@
       public void setQueryKey(String key)
           throws TorqueException
       {
  +  ## Work around the fact that BaseObject.setPrimaryKey() declares
  +  ## that it throws Exception instead of TorqueException.
  +  #if (!$tableHasPrimaryKey)
  +        try
  +        {
  +  #end
           setPrimaryKey(key);
  +  #if (!$tableHasPrimaryKey)
  +        }
  +        catch (Exception e)
  +        {
  +        }
  +  #end
       }
   #end
   
  
  
  

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