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 2007/03/03 11:09:20 UTC

svn commit: r514112 - in /myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples: ballot/backings/BallotVoter.java lib/SpringUtils.java

Author: imario
Date: Sat Mar  3 02:09:19 2007
New Revision: 514112

URL: http://svn.apache.org/viewvc?view=rev&rev=514112
Log:
demonstrate programatic transaction handling

Added:
    myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/lib/SpringUtils.java
Modified:
    myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoter.java

Modified: myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoter.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoter.java?view=diff&rev=514112&r1=514111&r2=514112
==============================================================================
--- myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoter.java (original)
+++ myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoter.java Sat Mar  3 02:09:19 2007
@@ -19,27 +19,40 @@
 package org.apache.myfaces.examples.ballot.backings;
 
 import org.apache.myfaces.examples.ballot.dao.VoterDao;
-import org.apache.myfaces.examples.ballot.model.Voter;
 import org.apache.myfaces.examples.ballot.lib.BallotState;
+import org.apache.myfaces.examples.ballot.model.Voter;
 import org.apache.myfaces.examples.lib.FacesConst;
 import org.apache.myfaces.examples.lib.FacesUtils;
+import org.apache.myfaces.examples.lib.SpringUtils;
 import org.apache.myfaces.fusion.conversation.Conversation;
-import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.PlatformTransactionManager;
 
 import javax.faces.context.FacesContext;
 import javax.servlet.http.HttpServletRequest;
-import java.util.UUID;
-import java.io.StringWriter;
 import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
+import java.util.UUID;
 
 public class BallotVoter
 {
+	private PlatformTransactionManager transactionManager;
+
 	private VoterDao voterDao;
 	private Voter voter;
 	private BallotState ballotState;
 
+	public PlatformTransactionManager getTransactionManager()
+	{
+		return transactionManager;
+	}
+
+	public void setTransactionManager(PlatformTransactionManager transactionManager)
+	{
+		this.transactionManager = transactionManager;
+	}
+
 	public Voter getVoter()
 	{
 		return voter;
@@ -82,7 +95,10 @@
 		}
 	}
 
-	@Transactional
+	/**
+	 * here we use programmatic transaction handling instead of declarative to allow to
+	 * leave the mehtod without exception and without having to flush in case of an failure
+	 */
 	public String saveAction()
 	{
 		boolean isNew = getVoterDao().isNew(getVoter());
@@ -101,6 +117,8 @@
 		getVoterDao().save(getVoter());
 		getBallotState().setVoterEmail(getVoter().getEmail());
 
+		SpringUtils.commit(transactionManager);
+
 		if (isNew)
 		{
 			sendMail();
@@ -167,7 +185,7 @@
 		out.println(url.toString());
 		out.println("");
 		out.println("See you,");
-		out.println("The Apache Software Foundation");
+		out.println("The Voting Machine");
 
 		out.close();
 

Added: myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/lib/SpringUtils.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/lib/SpringUtils.java?view=auto&rev=514112
==============================================================================
--- myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/lib/SpringUtils.java (added)
+++ myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/lib/SpringUtils.java Sat Mar  3 02:09:19 2007
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.myfaces.examples.lib;
+
+import org.springframework.transaction.support.DefaultTransactionDefinition;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.PlatformTransactionManager;
+
+public final class SpringUtils
+{
+	private SpringUtils()
+	{
+	}
+
+	public static void commit(PlatformTransactionManager transactionManager)
+	{
+		/* programmatic commit - should be easier, no?*/
+		
+		DefaultTransactionDefinition def = new DefaultTransactionDefinition();
+		def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
+		TransactionStatus status = transactionManager.getTransaction(def);
+		transactionManager.commit(status);
+	}
+}