> maybe I'm missing something, but there is no trace of implementation of
> afterBegin() callback of the SessionSynchronization interface.
> Anyone knows something about it ? NYI on purpose or a TODO ?
My company encountered this problem in a project. The attached patch works
for us.
Note that:
- I do not know if we should lock the context when invoking afterBegin() on
the bean.
- I made the internal class static because it doesn't need to hold an
implicit reference to the enclosing class
- I removed the Transaction variable in InstanceSynchronization (unused)
- We should probably look up the methods on SessionSynchronization only
once, instead of doing it everytime
---
jboss-2.1/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceInterceptor.
java Thu Mar 1 21:13:52 2001
+++
jboss-2.1-modif/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceInterc
eptor.java Fri Mar 2 18:12:51 2001
@@ -114,7 +114,7 @@
private void register(EnterpriseContext ctx, Transaction tx)
{
// Create a new synchronization
- InstanceSynchronization synch = new InstanceSynchronization(tx, ctx);
+ InstanceSynchronization synch = new
InstanceSynchronization(ctx);
try {
// OSH: An extra check to avoid warning.
@@ -128,6 +128,9 @@
// We want to be notified when the transaction commits
tx.registerSynchronization(synch);
+ // As per EJB 1.1 spec 6.5.3, call afterBegin()
+ synch.afterBegin();
+
} catch (RollbackException e) {
} catch (Exception e) {
@@ -266,7 +269,7 @@
// Inner classes -------------------------------------------------
- private class InstanceSynchronization
+ private static class InstanceSynchronization
implements Synchronization
{
/**
@@ -283,15 +286,14 @@
boolean notifySession = false;
// Utility methods for the notifications
- Method beforeCompletion, afterCompletion;
+ Method afterBegin, beforeCompletion, afterCompletion;
/**
* Create a new instance synchronization instance.
*/
- InstanceSynchronization(Transaction tx, EnterpriseContext ctx)
+ InstanceSynchronization(EnterpriseContext ctx)
{
- this.tx = tx;
this.ctx = ctx;
// Let's compute it now
@@ -304,6 +306,8 @@
Class sync = Class.forName("javax.ejb.SessionSynchronization");
// Lookup the methods on it
+ afterBegin =
sync.getMethod("afterBegin", new Class[0]);
+
beforeCompletion = sync.getMethod("beforeCompletion", new Class[0]);
afterCompletion = sync.getMethod("afterCompletion", new Class[]
{boolean.class});
@@ -314,6 +318,20 @@
// Synchronization implementation -----------------------------
+ public void afterBegin()
+ {
+ // DEBUG Logger.debug("afterBegin called");
+
+ // do we need to lock() the context here?
+ if (notifySession) {
+ try {
+
+ afterBegin.invoke(ctx.getInstance(),
new Object[0]);
+ }
+ catch (Exception e) { Logger.exception(e);}
+ }
+ }
+
public void beforeCompletion()
{
// DEBUG Logger.debug("beforeCompletion called");