[Registry-dev] svn commit r16079 - trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc

Glen Daniels glen at wso2.com
Wed Apr 23 19:35:23 PDT 2008


Hi Chathura!

Please take a look at this commit - I think this is a much better 
technique for wrapping the call to the transactionalJDBCRegistry.  First 
off, it doesn't involve caching Exception, which is generally a bad idea 
- and it's a REALLY bad idea when you rethrow a different Exception 
object, because you've lost the stack trace and any other info hanging 
out in the original Exception.

The change allows the internal RegistryException to bubble up, avoiding 
the information (and type) loss while still committing/rolling back 
appropriately.

Could we do this for all the Exception catching?

Thanks,
--Glen

svn at wso2.org wrote:
> Author: glen
> Date: Wed Apr 23 19:09:32 2008
> New Revision: 16079
> 
> Log:
> 
> Better transaction / exception managing technique.
> 
> 
> Modified:
>    trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/NonTransactionalJDBCRegistry.java
> 
> Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/NonTransactionalJDBCRegistry.java
> ==============================================================================
> --- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/NonTransactionalJDBCRegistry.java	(original)
> +++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/NonTransactionalJDBCRegistry.java	Wed Apr 23 19:09:32 2008
> @@ -177,26 +177,22 @@
>       *                           registry
>       */
>      public Resource get(String path) throws RegistryException {
> -
> +        boolean success = false;
>          try {
>              beginTransaction();
>  
>              Resource resource = transactionalJDBCRegistry.get(path);
>  
> -            commitTransaction();
> +            success = true;
>  
>              return resource;
>  
> -        } catch (Exception e) {
> -
> -            String msg = "Failed to get the resource " + path + ". " + e.getMessage();
> -            log.error(msg, e);
> -
> -            rollbackTransaction();
> -
> -            if (e instanceof RegistryException) throw (RegistryException)e;
> -
> -            throw new RegistryException(msg, e);
> +        } finally {
> +            if (success) {
> +                commitTransaction();
> +            } else {
> +                rollbackTransaction();
> +            }
>          }
>      }
>  
> 
> _______________________________________________
> Registry-dev mailing list
> Registry-dev at wso2.org
> http://wso2.org/cgi-bin/mailman/listinfo/registry-dev
> 



More information about the Registry-dev mailing list