Author: rfeng
Date: Fri Oct 19 17:55:13 2007
New Revision: 586650
URL: http://svn.apache.org/viewvc?rev=586650&view=rev
Log:
Add more logic to handle the intent combinations
Added:
incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/IncompatibleIntentException.java
(with props)
incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionIntent.java
(with props)
Modified:
incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionManagerHelper.java
Added:
incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/IncompatibleIntentException.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/IncompatibleIntentException.java?rev=586650&view=auto
==============================================================================
---
incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/IncompatibleIntentException.java
(added)
+++
incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/IncompatibleIntentException.java
Fri Oct 19 17:55:13 2007
@@ -0,0 +1,44 @@
+/*
+ * 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.tuscany.sca.policy.transaction;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IncompatibleIntentException extends Exception {
+ private static final long serialVersionUID = -2993825019200280397L;
+
+ public IncompatibleIntentException() {
+ super();
+ }
+
+ public IncompatibleIntentException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public IncompatibleIntentException(String message) {
+ super(message);
+ }
+
+ public IncompatibleIntentException(Throwable cause) {
+ super(cause);
+ }
+
+}
Propchange:
incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/IncompatibleIntentException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/IncompatibleIntentException.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionIntent.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionIntent.java?rev=586650&view=auto
==============================================================================
---
incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionIntent.java
(added)
+++
incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionIntent.java
Fri Oct 19 17:55:13 2007
@@ -0,0 +1,24 @@
+/*
+ * 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.tuscany.sca.policy.transaction;
+
+public enum TransactionIntent {
+ managedTransactionLocal, managedTransactionGlobal, noManagedTransaction,
propagatesTransacton, suspendsTransaction, transactedOneWay, immediateOneWay
+}
Propchange:
incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionIntent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionIntent.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionManagerHelper.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionManagerHelper.java?rev=586650&r1=586649&r2=586650&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionManagerHelper.java
(original)
+++
incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionManagerHelper.java
Fri Oct 19 17:55:13 2007
@@ -19,6 +19,9 @@
package org.apache.tuscany.sca.policy.transaction;
+import java.lang.reflect.InvocationTargetException;
+import java.security.PrivilegedExceptionAction;
+
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.InvalidTransactionException;
@@ -35,6 +38,7 @@
// private static final Logger logger =
Logger.getLogger(TransactionManagerHelper.class.getName());
private TransactionManager tm;
+
public TransactionManagerHelper(TransactionManager tm) {
super();
this.tm = tm;
@@ -56,57 +60,178 @@
}
}
- public void managedLocalTransactionPreInvoke() {
- //
- }
-
- public Transaction noManagedTransactionPreInvoke() throws SystemException {
+ public Transaction suspendsTransactionPreInvoke() throws SystemException {
if (tm.getTransaction() != null) {
return tm.suspend();
+ } else {
+ return null;
}
- return null;
}
- public void noManagedTransactionPostInvoke(Transaction suspended) throws
InvalidTransactionException,
+ public void suspendsTransactionPostInvoke(Transaction suspended) throws
InvalidTransactionException,
IllegalStateException, SystemException {
if (suspended != null) {
tm.resume(suspended);
}
}
- public void propgatesTransactionPreInvoke() {
+ public TransactionManager getTransactionManager() {
+ return tm;
}
- public Transaction suspendsTransactionPreInvoke() throws SystemException {
- if (tm.getTransaction() != null) {
- return tm.suspend();
- } else {
- return null;
+ public void setTransactionManager(TransactionManager tm) {
+ this.tm = tm;
+ }
+
+ public void validateOneway(TransactionIntent onewayIntent,
TransactionIntent implIntent)
+ throws IncompatibleIntentException {
+ if (onewayIntent == TransactionIntent.transactedOneWay) {
+ if (implIntent != TransactionIntent.managedTransactionGlobal) {
+ throw new IncompatibleIntentException(onewayIntent + "<-X->" +
implIntent);
+ }
}
}
- public void suspendsTransactionPostInvoke(Transaction suspended) throws
InvalidTransactionException,
- IllegalStateException, SystemException {
- if (suspended != null) {
- tm.resume(suspended);
+ public void validateInbound(TransactionIntent serviceIntent,
TransactionIntent implIntent)
+ throws IncompatibleIntentException {
+ if (serviceIntent == TransactionIntent.propagatesTransacton) {
+ if (implIntent != TransactionIntent.managedTransactionGlobal) {
+ throw new IncompatibleIntentException(serviceIntent + "<-X->"
+ implIntent);
+ }
}
}
- public void transactedOnewayPreInvoke() {
- //
+ public void validateOutbound(TransactionIntent referenceIntent,
TransactionIntent implIntent)
+ throws IncompatibleIntentException {
+ if (referenceIntent == TransactionIntent.propagatesTransacton) {
+ if (implIntent != TransactionIntent.managedTransactionGlobal) {
+ throw new IncompatibleIntentException(referenceIntent +
"<-X->" + implIntent);
+ }
+ }
}
- public void immediateOnewayPreInvoke() {
- //
+ public <T> T handlesOutbound(TransactionIntent referenceIntent,
+ TransactionIntent implIntent,
+ PrivilegedExceptionAction<T> action) throws
Exception {
+
+ if (implIntent == null) {
+ implIntent = TransactionIntent.noManagedTransaction;
+ }
+
+ if (referenceIntent == TransactionIntent.propagatesTransacton) {
+ if (implIntent != TransactionIntent.managedTransactionGlobal) {
+ throw new IncompatibleIntentException(referenceIntent +
"<-X->" + implIntent);
+ } else {
+ // propagates the current TX
+ return run(action);
+ }
+ } else if (referenceIntent == TransactionIntent.suspendsTransaction) {
+ Transaction tx = suspendsTransactionPreInvoke();
+ try {
+ return run(action);
+ } finally {
+ suspendsTransactionPostInvoke(tx);
+ }
+ } else {
+ return run(action);
+ }
}
- public TransactionManager getTransactionManager() {
- return tm;
+ private <T> T run(PrivilegedExceptionAction<T> action) throws Exception {
+ try {
+ return action.run();
+ } catch (Exception e) {
+ throw new InvocationTargetException(e);
+ }
}
- public void setTransactionManager(TransactionManager tm) {
- this.tm = tm;
+ public <T> T handlesInbound(TransactionIntent serviceIntent,
+ TransactionIntent implIntent,
+ PrivilegedExceptionAction<T> action) throws
Exception {
+ if (serviceIntent == null && implIntent == null) {
+ return run(action);
+ }
+
+ if (implIntent == null) {
+ implIntent = TransactionIntent.noManagedTransaction;
+ }
+
+ if (serviceIntent == TransactionIntent.propagatesTransacton) {
+ if (implIntent != TransactionIntent.managedTransactionGlobal) {
+ throw new IncompatibleIntentException(serviceIntent + "<-X->"
+ implIntent);
+ } else {
+ // Make sure a global TX is in place
+ Transaction tx = managedGlobalTransactionPreInvoke();
+ try {
+ return run(action);
+ } finally {
+ managedGlobalTransactionPostInvoke(tx);
+ }
+ }
+ } else if (serviceIntent == TransactionIntent.suspendsTransaction) {
+ Transaction tx1 = suspendsTransactionPreInvoke();
+ try {
+ if (implIntent == TransactionIntent.managedTransactionGlobal) {
+ // Start a new TX
+ Transaction tx2 = managedGlobalTransactionPreInvoke();
+ try {
+ return run(action);
+ } finally {
+ // Commit tx2
+ managedGlobalTransactionPostInvoke(tx2);
+ }
+ } else {
+ return run(action);
+ }
+ } finally {
+ suspendsTransactionPostInvoke(tx1);
+ }
+ } else {
+ if (implIntent == TransactionIntent.managedTransactionGlobal) {
+ // Start a new TX
+ Transaction tx2 = managedGlobalTransactionPreInvoke();
+ try {
+ return run(action);
+ } finally {
+ // Commit tx2
+ managedGlobalTransactionPostInvoke(tx2);
+ }
+ } else {
+ return run(action);
+ }
+ }
}
+ public <T> void handlesOneWay(TransactionIntent onewayIntent,
+ TransactionIntent implIntent,
+ PrivilegedExceptionAction<T> action) throws
Exception {
+ if (implIntent == null) {
+ implIntent = TransactionIntent.noManagedTransaction;
+ }
+
+ if (onewayIntent == null) {
+ // Assume transactedOneWay
+ run(action);
+ return;
+ }
+
+ if (onewayIntent == TransactionIntent.transactedOneWay) {
+ if (implIntent != TransactionIntent.managedTransactionGlobal) {
+ throw new IncompatibleIntentException(onewayIntent + "<-X->" +
implIntent);
+ } else {
+ run(action);
+ return;
+ }
+ } else {
+ // TransactionIntent.immediateOneWay
+ Transaction tx = suspendsTransactionPreInvoke();
+ try {
+ run(action);
+ return;
+ } finally {
+ suspendsTransactionPostInvoke(tx);
+ }
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]