Created
August 28, 2012 21:16
-
-
Save lucascs/3504425 to your computer and use it in GitHub Desktop.
SessionCreator for Spring environments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
@RequestScoped | |
public class SessionCreator implements ComponentFactory<Session> { | |
private final SessionFactory factory; | |
private final Proxifier proxifier; | |
private Session session; | |
public SessionCreator(SessionFactory factory, Proxifier proxifier) { | |
this.factory = factory; | |
this.proxifier = proxifier; | |
} | |
@PostConstruct | |
public void abre() { | |
this.session = proxifier.proxify(Session.class, | |
new MethodInvocation<Session>() { | |
public Object intercept(Session proxy, Method method, | |
Object[] args, SuperMethod superMethod) { | |
Session sessionDoSpring = SessionFactoryUtils.doGetSession(factory, true); | |
return new Mirror().on(sessionDoSpring).invoke().method(method).withArgs(args); | |
} | |
}); | |
} | |
public Session getInstance() { | |
return this.session; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment