You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by grazia <Gr...@gmail.com> on 2012/03/21 22:28:18 UTC
OSIV with requestCycleListener
Would you recommend using a requestCycleListener to implement the OSIV
pattern and storing the hibernate session in a threadlocal ?
Any comments ? tips ?
public class MyRequestCycleListener extends AbstractRequestCycleListener {
private static final ThreadLocal<Session> requestCycleThread = new
ThreadLocal<Session>();
/** Keys for session factories that have been opened for this request */
//protected static HashSet keys = new HashSet();
public static ThreadLocal<Session> getRequestCycleThread() {
return requestCycleThread;
}
@Override
public void onBeginRequest(RequestCycle cycle) {
if (requestCycleThread.get() == null) {
Session session = MyRequestCycle.getHibernateSession(null);
requestCycleThread.set(session);
}
}
@Override
public void onEndRequest(RequestCycle cycle) {
if (requestCycleThread.get()!= null){
MyRequestCycle.closeHibernateSessions();
requestCycleThread.set(null);
}
}
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/OSIV-with-requestCycleListener-tp4493806p4493806.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: OSIV with requestCycleListener
Posted by grazia <Gr...@gmail.com>.
Thank you for the suggestion, I will try it.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/OSIV-with-requestCycleListener-tp4493806p4493927.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: OSIV with requestCycleListener
Posted by Dan Retzlaff <dr...@gmail.com>.
Grazia,
Those are good lifecycle events, but consider configuring
org.hibernate.context.ManagedSessionContext and using its ThreadLocal. Then
client code can use the more conventional
SessionFactory#getCurrentSession().
Dan
On Wed, Mar 21, 2012 at 2:28 PM, grazia <Gr...@gmail.com>wrote:
> Would you recommend using a requestCycleListener to implement the OSIV
> pattern and storing the hibernate session in a threadlocal ?
> Any comments ? tips ?
>
> public class MyRequestCycleListener extends AbstractRequestCycleListener {
>
> private static final ThreadLocal<Session> requestCycleThread = new
> ThreadLocal<Session>();
>
> /** Keys for session factories that have been opened for this request */
> //protected static HashSet keys = new HashSet();
>
> public static ThreadLocal<Session> getRequestCycleThread() {
> return requestCycleThread;
> }
>
> @Override
> public void onBeginRequest(RequestCycle cycle) {
>
> if (requestCycleThread.get() == null) {
> Session session = MyRequestCycle.getHibernateSession(null);
> requestCycleThread.set(session);
> }
> }
>
> @Override
> public void onEndRequest(RequestCycle cycle) {
> if (requestCycleThread.get()!= null){
> MyRequestCycle.closeHibernateSessions();
> requestCycleThread.set(null);
> }
> }
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/OSIV-with-requestCycleListener-tp4493806p4493806.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>