Skip to content

Instantly share code, notes, and snippets.

@lucascs
Created August 28, 2012 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucascs/3504425 to your computer and use it in GitHub Desktop.
Save lucascs/3504425 to your computer and use it in GitHub Desktop.
SessionCreator for Spring environments
@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