|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.wideplay.warp.persist.PersistenceFilter
com.wideplay.warp.persist.jpa.SessionPerRequestInterceptor
@Immutable @ThreadSafe public class SessionPerRequestInterceptor
Struts 2 equivalent for PersistenceFilter
.
Needed because Guice's current (1.0.1) Struts 2 plugin creates the Guice Injector
internally, which means that that injector instance is not available to other filters
before the Struts filter executes. Also see
here.
Do not use this interceptor in combination with the
PersistenceFilter
.
This Interceptor starts the PersistenceService
at creation time.
It is vital that only one instance of this interceptor exists in an application.
Currently Guice can't scope Struts 2 interceptors, so you have to rely on Struts'
behaviour in this regard. Struts 2 interceptors are not true singletons; one instance
exists per <interceptor-ref>
in the XML. To make sure only one instance exists,
create an <interceptor-stack>
with this single interceptor, and then use the resulting
stack in your application. Do not use the interceptor directly.
Example configuration:
<interceptors>
<interceptor name="sessionPerRequestInterceptor"
class="com.wideplay.warp.jpa.SessionPerRequestInterceptor"/>
<!-- Stack with single interceptor because we only want one instance -->
<!-- Interceptors = one instance per interceptor-ref -->
<interceptor-stack name="spriStack">
<interceptor-ref name="sessionPerRequestInterceptor" />
</interceptor-stack>
</interceptors>
Example usage:
<interceptor-stack name="securedStack">
<interceptor-ref name="spriStack" />
<interceptor-ref name="authenticationInterceptor" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
It is likely that this class will be obsolete when Guice 2.0 is released. The hierarchical injectors feature would enable a redesign of Guice's current Struts 2 plugin; you would be able to provide one part of the injector ahead of time and then let the plugin merge your injector with its internal one.
This code originated from the book Google Guice (Apress, 2008, ISBN 978-1590599976).
PersistenceFilter
,
Serialized FormConstructor Summary | |
---|---|
SessionPerRequestInterceptor()
|
Method Summary | |
---|---|
void |
destroy()
Tries to close the EntityManagerFactory . |
void |
init()
Does nothing. |
String |
intercept(com.opensymphony.xwork2.ActionInvocation ai)
Makes sure an EntityManager instance is available while
the current request is being processed. |
Methods inherited from class com.wideplay.warp.persist.PersistenceFilter |
---|
doFilter, init |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SessionPerRequestInterceptor()
Method Detail |
---|
public String intercept(com.opensymphony.xwork2.ActionInvocation ai) throws Exception
EntityManager
instance is available while
the current request is being processed.
intercept
in interface com.opensymphony.xwork2.interceptor.Interceptor
Exception
Interceptor.intercept(com.opensymphony.xwork2.ActionInvocation)
public void init()
init
in interface com.opensymphony.xwork2.interceptor.Interceptor
Interceptor.init()
public void destroy()
EntityManagerFactory
.
destroy
in interface com.opensymphony.xwork2.interceptor.Interceptor
destroy
in interface javax.servlet.Filter
destroy
in class PersistenceFilter
Interceptor.destroy()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |