cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Huss <>
Subject Stateless RequestHandler
Date Fri, 07 Dec 2012 20:22:24 GMT
In Cayenne, there is the SessionContextRequestHandler which creates a
session and binds an ObjectContext to it.  Most of my apps are
*stateless*(no sessions) so I don't use this but instead I have a very
simple request
handler that creates a new ObjectContext for each request.  Is this
something worth adding to the project?

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.cayenne.BaseContext;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.configuration.CayenneRuntime;
import org.apache.cayenne.configuration.server.ServerRuntime;
import org.apache.cayenne.configuration.web.RequestHandler;
import org.apache.cayenne.configuration.web.WebUtil;
import org.apache.cayenne.di.Inject;
import org.apache.cayenne.di.Injector;

 * Stateless implementation of the {@link RequestHandler} that creates a new
 * {@link ObjectContext} for each request and binds it to the request
 * @since 3.2
public class StatelessContextRequestHandler implements RequestHandler {

    // using injector to lookup services instead of injecting them directly
for lazy
    // startup and "late binding"
    private Injector injector;

public void requestStart(ServletRequest request, ServletResponse response) {
ServerRuntime runtime = (ServerRuntime)
ObjectContext context = runtime.getContext();
public void requestEnd(ServletRequest request, ServletResponse response) {

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message