| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Seam
Revision: 8912
Author: pete.muir@jboss.org
Date: 04 Sep 2008 12:17:19
Changes:ws
Files:| ... | ...@@ -10,47 +10,54 @@ | |
| 10 | 10 | import org.jboss.seam.transaction.Transaction; |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | * Swizzles entity references around each invocation, maintaining | |
| 14 | * referential integrity even across passivation of the stateful | |
| 15 | * bean or Seam-managed extended persistence context, and allowing | |
| 16 | * for more efficient replication. | |
| 13 | * Swizzles entity references around each invocation, maintaining referential | |
| 14 | * integrity even across passivation of the stateful bean or Seam-managed | |
| 15 | * extended persistence context, and allowing for more efficient replication. | |
| 17 | 16 | * |
| 18 | 17 | * @author Gavin King |
| 19 | * | |
| 18 | * | |
| 20 | 19 | */ |
| 21 | @Interceptor(around=BijectionInterceptor.class) | |
| 20 | @Interceptor(around = BijectionInterceptor.class) | |
| 22 | 21 | public class ManagedEntityIdentityInterceptor extends AbstractInterceptor |
| 23 | 22 | { |
| 24 | ||
| 25 | private static ManagedEntityStateManager managedEntityStateManager = new ManagedEntityStateManager(); | |
| 26 | ||
| 27 | private boolean reentrant; | |
| 28 | //TODO: cache the non-ignored fields, probably on Component | |
| 29 | ||
| 30 | public boolean isInterceptorEnabled() | |
| 31 | { | |
| 32 | return getComponent().getScope() == CONVERSATION; | |
| 33 | } | |
| 34 | ||
| 35 | @AroundInvoke | |
| 36 | public Object aroundInvoke(InvocationContext ctx) throws Exception | |
| 37 | { | |
| 38 | if (reentrant) { | |
| 23 | ||
| 24 | private static ManagedEntityStateManager managedEntityStateManager = new ManagedEntityStateManager(); | |
| 25 | ||
| 26 | private boolean reentrant; | |
| 27 | ||
| 28 | // TODO: cache the non-ignored fields, probably on Component | |
| 29 | ||
| 30 | public boolean isInterceptorEnabled() | |
| 31 | { | |
| 32 | return getComponent().getScope() == CONVERSATION; | |
| 33 | } | |
| 34 | ||
| 35 | @AroundInvoke | |
| 36 | public Object aroundInvoke(InvocationContext ctx) throws Exception | |
| 37 | { | |
| 38 | if (reentrant) | |
| 39 | { | |
| 40 | return ctx.proceed(); | |
| 41 | } | |
| 42 | else | |
| 43 | { | |
| 44 | reentrant = true; | |
| 45 | managedEntityStateManager.entityIdsToRefs(ctx.getTarget(), getComponent()); | |
| 46 | try | |
| 47 | { | |
| 39 | 48 | return ctx.proceed(); |
| 40 | } else { | |
| 41 | reentrant = true; | |
| 42 | managedEntityStateManager.entityIdsToRefs(ctx.getTarget(), getComponent()); | |
| 43 | try { | |
| 44 | return ctx.proceed(); | |
| 45 | } finally { | |
| 46 | if (!isTransactionRolledBackOrMarkedRollback()) { | |
| 47 | managedEntityStateManager.entityRefsToIds(ctx.getTarget(), getComponent()); | |
| 48 | reentrant = false; | |
| 49 | } | |
| 49 | } | |
| 50 | finally | |
| 51 | { | |
| 52 | if (!isTransactionRolledBackOrMarkedRollback()) | |
| 53 | { | |
| 54 | managedEntityStateManager.entityRefsToIds(ctx.getTarget(), getComponent()); | |
| 55 | reentrant = false; | |
| 50 | 56 | } |
| 51 | } | |
| 52 | } | |
| 53 | ||
| 57 | } | |
| 58 | } | |
| 59 | } | |
| 60 | ||
| 54 | 61 | private static boolean isTransactionRolledBackOrMarkedRollback() |
| 55 | 62 | { |
| 56 | 63 | try |
| ... | ...@@ -62,6 +69,5 @@ | |
| 62 | 69 | return false; |
| 63 | 70 | } |
| 64 | 71 | } |
| 65 | ||
| 66 | ||
| 72 | ||
| 67 | 73 | } |