Ok
I'm not sure I understand completely what you need. But here is my first
proposal:
Write your own PersistFilter (see below) and use
EntityManager.setProperty to set the request specific properties.
@Singleton
public final class MyPersistFilter implements Filter {
private final UnitOfWork unitOfWork;
private final Provider<EntityManager> emProvider;
private final PersistService persistService;
@Inject
public PersistFilter(UnitOfWork unitOfWork, Provider<EntityManager>
emProvider, PersistService persistService) {
this.unitOfWork = unitOfWork;
this.emProvider = emProvider;
this.persistService = persistService;
}
public void init(FilterConfig filterConfig) throws ServletException {
persistService.start();
}
public void destroy() {
persistService.stop();
}
public void doFilter(final ServletRequest servletRequest, final
ServletResponse servletResponse, final FilterChain filterChain) throws
IOException, ServletException {
unitOfWork.begin();
try {
final EntityManager em = emProvider.get();
final Map<String, String> props =
getPropertiesForRequest(servletRequest);
for(String key: props.keySet()) {
em.setProperty(key, props.get(key));
}
filterChain.doFilter(servletRequest, servletResponse);
} finally {
unitOfWork.end();
}
}
private Map<String, String> getPropertiesForRequest(final
ServletRequest servletRequest) {
// TODO
return null;
}
}
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.