You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by im...@apache.org on 2006/04/30 09:20:16 UTC
svn commit: r398292 - in
/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation:
ConversationContext.java ConversationManager.java
ConversationServletFilter.java PersistenceManager.java
Author: imario
Date: Sun Apr 30 00:20:14 2006
New Revision: 398292
URL: http://svn.apache.org/viewcvs?rev=398292&view=rev
Log:
servlet filter to deal with attach/detach aspects of the underlaying persistence
Added:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationServletFilter.java (with props)
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java?rev=398292&r1=398291&r2=398292&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java Sun Apr 30 00:20:14 2006
@@ -188,4 +188,34 @@
return null;
}
+
+ /**
+ * detach all conversations from their underlaying persistence
+ */
+ public void detachPersistence()
+ {
+ for (int i = conversationStack.size(); i>0; i--)
+ {
+ Conversation conversation = (Conversation) conversationStack.get(i-1);
+ if (conversation.isPersistence())
+ {
+ conversation.getPersistenceManager().detach();
+ }
+ }
+ }
+
+ /**
+ * attach all conversations to their underlaying persistence
+ */
+ public void attachPersistence()
+ {
+ for (int i = conversationStack.size(); i>0; i--)
+ {
+ Conversation conversation = (Conversation) conversationStack.get(i-1);
+ if (conversation.isPersistence())
+ {
+ conversation.getPersistenceManager().attach();
+ }
+ }
+ }
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java?rev=398292&r1=398291&r2=398292&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java Sun Apr 30 00:20:14 2006
@@ -22,6 +22,7 @@
import javax.faces.FacesException;
import javax.faces.context.FacesContext;
+import javax.servlet.http.HttpSession;
import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
@@ -72,6 +73,10 @@
ConversationManager conversationManager = (ConversationManager) context.getExternalContext().getSessionMap().get(CONVERSATION_MANAGER_KEY);
if (conversationManager == null)
{
+ if (!Boolean.TRUE.equals(context.getExternalContext().getRequestMap().get(ConversationServletFilter.CONVERSATION_FILTER_CALLED)))
+ {
+ throw new IllegalStateException("ConversationServletFilter not called. Please configure the filter org.apache.myfaces.custom.conversation.ConversationServletFilter in your web.xml to cover your faces requests.");
+ }
conversationManager = new ConversationManager();
context.getExternalContext().getSessionMap().put(CONVERSATION_MANAGER_KEY, conversationManager);
}
@@ -80,6 +85,18 @@
}
/**
+ * Get the conversation manager from the http session. This will <b>not</b> create a conversation manager if none exists.
+ */
+ public static ConversationManager getInstance(HttpSession session)
+ {
+ if (session == null)
+ {
+ return null;
+ }
+ return (ConversationManager) session.getAttribute(CONVERSATION_MANAGER_KEY);
+ }
+
+ /**
* Get the current, or create a new unique conversationContextId.<br />
* The current conversationContextId will retrieved from the request parameters, if we cant find it there
* a new one will be created. In either case the result will be stored within the request for faster lookup.
@@ -299,5 +316,23 @@
}
return persistenceManagerFactory;
+ }
+
+ protected void attachPersistence()
+ {
+ ConversationContext conversationContext = getConversationContext();
+ if (conversationContext != null)
+ {
+ conversationContext.attachPersistence();
+ }
+ }
+
+ protected void detachPersistence()
+ {
+ ConversationContext conversationContext = getConversationContext();
+ if (conversationContext != null)
+ {
+ conversationContext.detachPersistence();
+ }
}
}
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationServletFilter.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationServletFilter.java?rev=398292&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationServletFilter.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationServletFilter.java Sun Apr 30 00:20:14 2006
@@ -0,0 +1,55 @@
+package org.apache.myfaces.custom.conversation;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+public class ConversationServletFilter implements Filter
+{
+ public final static String CONVERSATION_FILTER_CALLED = "org.apache.myfaces.conversation.ConversationServletFilter.CALLED";
+
+ public void init(FilterConfig arg0) throws ServletException
+ {
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
+ {
+ ConversationManager conversationManager = null;
+
+ if (!Boolean.TRUE.equals(request.getAttribute(CONVERSATION_FILTER_CALLED)))
+ {
+ if (request instanceof HttpServletRequest)
+ {
+ conversationManager = ConversationManager.getInstance(((HttpServletRequest) request).getSession(false));
+ if (conversationManager != null)
+ {
+ conversationManager.attachPersistence();
+ }
+ }
+
+ request.setAttribute(CONVERSATION_FILTER_CALLED, Boolean.TRUE);
+ }
+
+ try
+ {
+ chain.doFilter(request, response);
+ }
+ finally
+ {
+ if (conversationManager != null)
+ {
+ conversationManager.detachPersistence();
+ }
+ }
+ }
+
+ public void destroy()
+ {
+ }
+}
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationServletFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationServletFilter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationServletFilter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java?rev=398292&r1=398291&r2=398292&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java Sun Apr 30 00:20:14 2006
@@ -22,6 +22,23 @@
*/
public interface PersistenceManager
{
+ /**
+ * commit the transaction
+ */
public void commit();
+
+ /**
+ * rollback the transaction
+ */
public void rollback();
+
+ /**
+ * attach to your underlaying persistence
+ */
+ public void attach();
+
+ /**
+ * detach from your underlaying persistence
+ */
+ public void detach();
}