this is looking ok so far - I'm assuming that a
given transaction is associated with one thread, however there may
be >1 transaction per thread - eg when calling ejb method that
is @REQUIRES_NEW - which I think is what is happening for thread
w: 21 below.
so - the info I wish to accumulate per transaction needs to know
which transaction it belongs to - eg info added at *a* and *d*
below belong to the outer transaction and those from *c* & *d*
belong to 2 different transactions - but I see no obvious way to
find a 'current transaction id'
so - the id below is just the hashcode of the Session as per the
listener code below. I can keep track of which transaction I
should associate info with by using a threadLocal to hold the
current id changing it as postBegin and postCommit/Rollback events
come into the listener.
3 questions :
is the hashcode() of the session good enough to use as the
transaction id for this?
or am i better off just incrementing/decrementing depth as begin
and commit/rollback events come in ?
any other cunning ideas?
2011-10-24 13:09:38,006 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
20] (SessionListener.java:34) - postCommitTransaction
:1254684283
2011-10-24 13:09:38,012 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
20] (SessionListener.java:47) - postBeginTransaction :1512523073
2011-10-24 13:09:38,016 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
20] (SessionListener.java:34) - postCommitTransaction
:1512523073
2011-10-24 13:09:38,023 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
20] (SessionListener.java:47) - postBeginTransaction :787144669
2011-10-24 13:09:38,026 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
20] (SessionListener.java:34) - postCommitTransaction :787144669
2011-10-24 13:09:38,214 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
20] (SessionListener.java:34) - postCommitTransaction
:1032168624
2011-10-24 13:09:38,475 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
17] (SessionListener.java:47) - postBeginTransaction :1456358112
2011-10-24 13:09:38,482 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
17] (SessionListener.java:34) - postCommitTransaction
:1456358112
2011-10-24 13:09:38,716 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
15] (SessionListener.java:47) - postBeginTransaction :1039139907
2011-10-24 13:09:38,729 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
15] (SessionListener.java:34) - postCommitTransaction
:1039139907
2011-10-24 13:09:38,764 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
21] (SessionListener.java:47) - postBeginTransaction
:1028020992
*a*
2011-10-24 13:09:38,784 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
21] (SessionListener.java:47) - postBeginTransaction :54512809
*b*
2011-10-24 13:09:38,788 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
21] (SessionListener.java:34) - postCommitTransaction
:54512809
*c*
2011-10-24 13:09:38,820 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
21] (SessionListener.java:47) - postBeginTransaction
:1001893012
*d*
2011-10-24 13:09:38,827 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
21] (SessionListener.java:34) - postCommitTransaction
:1001893012
2011-10-24 13:09:38,840 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
21] (SessionListener.java:34) - postCommitTransaction
:1028020992
2011-10-24 13:09:38,852 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
21] (SessionListener.java:47) - postBeginTransaction :376508753
2011-10-24 13:09:38,856 TRACE
biz.wss.jpa.eclipselink.SessionListener [p: thread-pool-1; w:
21] (SessionListener.java:34) - postCommitTransaction :376508753
public class SessionListener extends SessionEventAdapter
{
private static final Log log =
LogFactory.getLog(SessionListener.class);
@Override
public void postCommitTransaction(SessionEvent event) {
log.trace("postCommitTransaction :" +
event.getSession().hashCode() );
super.postCommitTransaction(event);
}
@Override
public void postRollbackTransaction(SessionEvent event) {
log.trace("postRollbackTransaction :" +
event.getSession().hashCode() );
super.postRollbackTransaction(event);
}
@Override
public void postBeginTransaction(SessionEvent event) {
log.trace("postBeginTransaction :" +
event.getSession().hashCode() );
super.postBeginTransaction(event);
}
public class SessionCustomizer implements
org.eclipse.persistence.config.SessionCustomizer {
private static final Log log =
LogFactory.getLog(SessionCustomizer.class);
public SessionCustomizer(){}
public void customize(Session paramSession) throws Exception
{
paramSession.getEventManager().addListener(new
SessionEventAdapter() {
@Override
public void postLogin(SessionEvent event) {
event.getSession().getPlatform().setShouldBindLiterals(false);
log.debug("Registering listener");
event.getSession().getEventManager().addListener(new
SessionListener());
}
});
}
On 20/10/2011 14:29, Tom Ware wrote:
The
best way to configure a SessionEventListener, is in a
SessionCustomizer by using EclipseLink specific code.
-Tom
On 20/10/2011 9:24 AM, Tim Martin wrote:
Before I go down a certain track to far I
just wanted to check if from within
jpa using eclipselink 2.3 it's possible to register a session/
unit of work
listener to these events here
http://wiki.eclipse.org/Introduction_to_EclipseLink_Sessions_(ELUG)#Table_83-3
and act on them once a transaction has commited/ rolled back.
we need to hold some info that is accumulated during a
transaction and then only
if the transaction commits send it on to some other part of the
application for
processing. we have looked at writing the info to db tables and
reading after
the transaction commits or sending to jms where it would get
removed if the
transaction rollsback, but neither of those really meet our
requirements.
I cant find any readily available info on how to register a uow/
session
listener from within jee. I found this here
http://wiki.eclipse.org/Configuring_a_Session_%28ELUG%29#Configuring_Session_Event_Listeners
but how would I get hold of the session from within jpa where i
just have the
SessionContext or EntityManager ? Do I need to use a
SessionCustomizer ?
we can use eclipselink specific code if needed...
Thanks
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
|