From 056ecf52fdf1ec47bba26ed8b1a8026c1d568687 Mon Sep 17 00:00:00 2001 From: "A. Abram White" Date: Wed, 3 Jan 2007 00:48:59 +0000 Subject: [PATCH] Exception translation when a managed transaction completion even causes an error. git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@491994 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/openjpa/kernel/BrokerImpl.java | 17 +++++++++++++---- .../persistence/PersistenceExceptions.java | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java index 2632b26c8..daa053424 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java @@ -1757,11 +1757,11 @@ public class BrokerImpl } catch (OpenJPAException ke) { if (_log.isTraceEnabled()) _log.trace(_loc.get("end-trans-error"), ke); - throw ke; + throw translateManagedCompletionException(ke); } catch (RuntimeException re) { if (_log.isTraceEnabled()) _log.trace(_loc.get("end-trans-error"), re); - throw new StoreException(re); + throw translateManagedCompletionException(new StoreException(re)); } finally { endOperation(); } @@ -1789,11 +1789,11 @@ public class BrokerImpl } catch (OpenJPAException ke) { if (_log.isTraceEnabled()) _log.trace(_loc.get("end-trans-error"), ke); - throw ke; + throw translateManagedCompletionException(ke); } catch (RuntimeException re) { if (_log.isTraceEnabled()) _log.trace(_loc.get("end-trans-error"), re); - throw new StoreException(re); + throw translateManagedCompletionException(new StoreException(re)); } finally { _flags &= ~FLAG_ACTIVE; _flags &= ~FLAG_FLUSHED; @@ -1813,6 +1813,15 @@ public class BrokerImpl } } + /** + * If we're in a managed transaction, use our implicit behavior exception + * translator to translate before/afterCompletion callback errors. + */ + private RuntimeException translateManagedCompletionException + (RuntimeException re) { + return (!_managed || _extrans == null) ? re : _extrans.translate(re); + } + /** * Flush safely, catching reentrant calls. */ diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceExceptions.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceExceptions.java index 3db3a3119..2f3b96d89 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceExceptions.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceExceptions.java @@ -48,7 +48,7 @@ public class PersistenceExceptions * and {@link NonUniqueResultException} in accordance with * section 3.7 of the EJB 3.0 specification. */ - static RuntimeExceptionTranslator getRollbackTranslator + public static RuntimeExceptionTranslator getRollbackTranslator (final OpenJPAEntityManager em) { return new RuntimeExceptionTranslator() { private boolean throwing = false;