cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johnth...@apache.org
Subject svn commit: r1421016 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/
Date Wed, 12 Dec 2012 22:10:30 GMT
Author: johnthuss
Date: Wed Dec 12 22:10:29 2012
New Revision: 1421016

URL: http://svn.apache.org/viewvc?rev=1421016&view=rev
Log:
CAY-1781  Add StatelessContextRequestHandler as an alternative to the Session-based one

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/StatelessContextRequestHandler.java
Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/SessionContextRequestHandler.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=1421016&r1=1421015&r2=1421016&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Wed Dec 12 22:10:29 2012
@@ -38,6 +38,7 @@ CAY-1771 cdbimport improvements: "usePri
 CAY-1772 Real support for DbEntity catalogs
 CAY-1778 TransactionManager to simplify user-managed transactions 
 CAY-1779 Flatten object entities for many to many relationships on reverse engineering 
+CAY-1781 Add StatelessContextRequestHandler as an alternative to the Session-based one
 
 Bug Fixes:
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/SessionContextRequestHandler.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/SessionContextRequestHandler.java?rev=1421016&r1=1421015&r2=1421016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/SessionContextRequestHandler.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/SessionContextRequestHandler.java
Wed Dec 12 22:10:29 2012
@@ -39,6 +39,8 @@ import org.apache.cayenne.di.Injector;
  * <p>
  * User applications in most cases should provide a custom RequestHandler that implements
  * a smarter app-specific strategy for providing ObjectContext.
+ * <p>
+ * For stateless (per request) context creation use {@link StatelessContextRequestHandler}.
  * 
  * @since 3.1
  */

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/StatelessContextRequestHandler.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/StatelessContextRequestHandler.java?rev=1421016&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/StatelessContextRequestHandler.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/StatelessContextRequestHandler.java
Wed Dec 12 22:10:29 2012
@@ -0,0 +1,55 @@
+package org.apache.cayenne.configuration.web;
+
+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.ObjectContextFactory;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.di.Module;
+
+/**
+ * <p>Stateless implementation of {@link RequestHandler} that creates a new
+ * {@link ObjectContext} for each request and binds it to the request thread.
+ * <p>
+ * This is an alternative to the session-based request handler 
+ * {@link SessionContextRequestHandler} which is the default.
+ * <p>
+ * The request handler can be used by injecting it with a custom @{link Module}, like so:
+ * 
+<pre><code>
+import org.apache.cayenne.configuration.web.RequestHandler;
+import org.apache.cayenne.configuration.web.StatelessContextRequestHandler;
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.Module;
+public class AppModule implements Module {
+    public void configure(Binder binder) {
+        binder.bind(RequestHandler.class).to(StatelessContextRequestHandler.class);
+    }
+}
+</code></pre>
+ * 
+ * @since 3.2
+ */
+public class StatelessContextRequestHandler implements RequestHandler {
+
+    // using injector to lookup services instead of injecting them directly for lazy
+    // startup and "late binding"
+    @Inject
+    private Injector injector;
+
+    public void requestStart(ServletRequest request, ServletResponse response) {
+        CayenneRuntime.bindThreadInjector(injector);
+        ObjectContext context = injector.getInstance(ObjectContextFactory.class).createContext();
+        BaseContext.bindThreadObjectContext(context);
+    }
+
+    public void requestEnd(ServletRequest request, ServletResponse response) {
+        CayenneRuntime.bindThreadInjector(null);
+        BaseContext.bindThreadObjectContext(null);
+    }
+
+}



Mime
View raw message