diff --git a/all/pom.xml b/all/pom.xml
index 56f1e0a827b..eb5965bd35d 100644
--- a/all/pom.xml
+++ b/all/pom.xml
@@ -327,6 +327,11 @@
+
+ io.seata
+ manual-api
+ ${project.version}
+
diff --git a/build/pom.xml b/build/pom.xml
index f3b7f14efed..f0ea057e305 100644
--- a/build/pom.xml
+++ b/build/pom.xml
@@ -63,7 +63,7 @@
- 1.6.0-SNAPSHOT
+ 1.6.66-SNAPSHOT
1.8
diff --git a/common-api/pom.xml b/common-api/pom.xml
new file mode 100644
index 00000000000..ef47668dd5a
--- /dev/null
+++ b/common-api/pom.xml
@@ -0,0 +1,76 @@
+
+
+
+
+ io.seata
+ seata-parent
+ ${revision}
+
+ 4.0.0
+ common-api
+ common-api ${project.version}
+ jar
+
+
+
+
+ ${project.groupId}
+ seata-tm
+ ${project.version}
+
+
+ ${project.groupId}
+ seata-rm-datasource
+ ${project.version}
+
+
+ ${project.groupId}
+ seata-rm
+ ${project.version}
+
+
+ ${project.groupId}
+ seata-serializer-all
+ ${project.version}
+
+
+ ${project.groupId}
+ seata-common
+ ${project.version}
+
+
+
+
+
+ org.springframework
+ spring-context
+
+
+ org.springframework
+ spring-jdbc
+
+
+
+ com.alibaba
+ fastjson
+
+
+
+
+
diff --git a/common-api/src/main/java/io/seata/commonapi/autoproxy/DefaultTransactionAutoProxy.java b/common-api/src/main/java/io/seata/commonapi/autoproxy/DefaultTransactionAutoProxy.java
new file mode 100644
index 00000000000..e170923b976
--- /dev/null
+++ b/common-api/src/main/java/io/seata/commonapi/autoproxy/DefaultTransactionAutoProxy.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 1999-2019 Seata.io Group.
+ *
+ * Licensed 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 io.seata.commonapi.autoproxy;
+
+import io.seata.common.loader.EnhancedServiceLoader;
+import io.seata.common.util.CollectionUtils;
+import io.seata.commonapi.remoting.RemotingDesc;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * the default transaction auto proxy
+ *
+ * @author ruishansun
+ */
+public class DefaultTransactionAutoProxy {
+
+ /**
+ * all the transaction auto proxy
+ */
+ protected static final List ALL_TRANSACTION_AUTO_PROXIES = new ArrayList<>();
+ /**
+ * method interceptor map, beanName -> IsTransactionProxyResult
+ */
+ private static final Map METHOD_INTERCEPTOR_MAP = new ConcurrentHashMap<>();
+
+ private static class SingletonHolder {
+ private static final DefaultTransactionAutoProxy INSTANCE = new DefaultTransactionAutoProxy();
+ }
+
+ /**
+ * Get the default transaction auto proxy
+ *
+ * @return the default transaction auto proxy
+ */
+ public static DefaultTransactionAutoProxy get() {
+ return SingletonHolder.INSTANCE;
+ }
+
+ /**
+ * Instantiates a new default transaction auto proxy
+ */
+ protected DefaultTransactionAutoProxy() {
+ initTransactionAutoProxy();
+ }
+
+ /**
+ * init transaction auto proxy
+ */
+ private void initTransactionAutoProxy() {
+ List proxies = EnhancedServiceLoader.loadAll(TransactionAutoProxy.class);
+ if (CollectionUtils.isNotEmpty(proxies)) {
+ ALL_TRANSACTION_AUTO_PROXIES.addAll(proxies);
+ }
+ }
+
+ /**
+ * whether is transaction auto proxy
+ *
+ * @param beanName the beanName
+ * @param remotingDesc the remotingDesc
+ * @return true or false
+ */
+ public boolean isTransactionAutoProxy(String beanName, RemotingDesc remotingDesc) {
+ for (TransactionAutoProxy proxy : ALL_TRANSACTION_AUTO_PROXIES) {
+ IsTransactionProxyResult result = proxy.isTransactionProxyTargetBean(remotingDesc);
+ if (result.isProxyTargetBean()) {
+ METHOD_INTERCEPTOR_MAP.put(beanName, result);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * get the IsTransactionProxyResult
+ *
+ * @param beanName the beanName
+ * @return the IsTransactionProxyResult
+ */
+ public IsTransactionProxyResult getIsProxyTargetBeanResult(String beanName) {
+ IsTransactionProxyResult result = METHOD_INTERCEPTOR_MAP.get(beanName);
+ return result != null ? result : new IsTransactionProxyResult();
+ }
+}
\ No newline at end of file
diff --git a/common-api/src/main/java/io/seata/commonapi/autoproxy/IsTransactionProxyResult.java b/common-api/src/main/java/io/seata/commonapi/autoproxy/IsTransactionProxyResult.java
new file mode 100644
index 00000000000..c3e6097f7eb
--- /dev/null
+++ b/common-api/src/main/java/io/seata/commonapi/autoproxy/IsTransactionProxyResult.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 1999-2019 Seata.io Group.
+ *
+ * Licensed 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 io.seata.commonapi.autoproxy;
+
+import org.aopalliance.intercept.MethodInterceptor;
+
+/**
+ * whether is the transaction proxy result
+ *
+ * @author ruishansun
+ */
+public class IsTransactionProxyResult {
+
+ /**
+ * whether proxied by transaction bean
+ */
+ private boolean isProxyTargetBean;
+
+ /**
+ * whether used common fence
+ */
+ private boolean useCommonFence;
+
+ /**
+ * transaction proxy method
+ */
+ private MethodInterceptor methodInterceptor;
+
+ private ManualApiExecute manualApiExecute;
+
+ public boolean isProxyTargetBean() {
+ return isProxyTargetBean;
+ }
+
+ public void setProxyTargetBean(boolean proxyTargetBean) {
+ isProxyTargetBean = proxyTargetBean;
+ }
+
+ public boolean isUseCommonFence() {
+ return useCommonFence;
+ }
+
+ public void setUseCommonFence(boolean useCommonFence) {
+ this.useCommonFence = useCommonFence;
+ }
+
+ public MethodInterceptor getMethodInterceptor() {
+ return methodInterceptor;
+ }
+
+ public void setMethodInterceptor(MethodInterceptor methodInterceptor) {
+ this.methodInterceptor = methodInterceptor;
+ }
+
+ public ManualApiExecute getManualApiExecute() {
+ return manualApiExecute;
+ }
+
+ public void setManualApiExecute(ManualApiExecute manualApiExecute) {
+ this.manualApiExecute = manualApiExecute;
+ }
+}
\ No newline at end of file
diff --git a/common-api/src/main/java/io/seata/commonapi/autoproxy/ManualApiExecute.java b/common-api/src/main/java/io/seata/commonapi/autoproxy/ManualApiExecute.java
new file mode 100644
index 00000000000..29046cee633
--- /dev/null
+++ b/common-api/src/main/java/io/seata/commonapi/autoproxy/ManualApiExecute.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright 1999-2019 Seata.io Group.
+ *
+ * Licensed 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 io.seata.commonapi.autoproxy;
+
+import java.lang.reflect.Method;
+
+public interface ManualApiExecute {
+
+ void manualApiBefore(Method method, Object[] arguments) throws Throwable;
+}
diff --git a/common-api/src/main/java/io/seata/commonapi/autoproxy/TransactionAutoProxy.java b/common-api/src/main/java/io/seata/commonapi/autoproxy/TransactionAutoProxy.java
new file mode 100644
index 00000000000..a569f90a639
--- /dev/null
+++ b/common-api/src/main/java/io/seata/commonapi/autoproxy/TransactionAutoProxy.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 1999-2019 Seata.io Group.
+ *
+ * Licensed 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 io.seata.commonapi.autoproxy;
+
+import io.seata.commonapi.remoting.RemotingDesc;
+
+/**
+ * The interface Transaction Auto Proxy. Proxied by tcc/saga with SPI.
+ *
+ * @author ruishansun
+ */
+public interface TransactionAutoProxy {
+
+ /**
+ * Whether it is transaction auto proxy? (tcc or saga)
+ *
+ * @param remotingDesc the remotingDesc
+ * @return the IsTransactionProxyResult
+ */
+ IsTransactionProxyResult isTransactionProxyTargetBean(RemotingDesc remotingDesc);
+}
\ No newline at end of file
diff --git a/tcc/src/main/java/io/seata/rm/tcc/TCCFenceHandler.java b/common-api/src/main/java/io/seata/commonapi/fence/CommonFenceHandler.java
similarity index 72%
rename from tcc/src/main/java/io/seata/rm/tcc/TCCFenceHandler.java
rename to common-api/src/main/java/io/seata/commonapi/fence/CommonFenceHandler.java
index 86222acd60f..492d4ccf72f 100644
--- a/tcc/src/main/java/io/seata/rm/tcc/TCCFenceHandler.java
+++ b/common-api/src/main/java/io/seata/commonapi/fence/CommonFenceHandler.java
@@ -13,48 +13,49 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.rm.tcc;
-
-import java.lang.reflect.Method;
-import java.sql.Connection;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import javax.sql.DataSource;
+package io.seata.commonapi.fence;
import io.seata.common.exception.FrameworkErrorCode;
import io.seata.common.exception.SkipCallbackWrapperException;
import io.seata.common.executor.Callback;
import io.seata.common.thread.NamedThreadFactory;
-import io.seata.rm.tcc.constant.TCCFenceConstant;
-import io.seata.rm.tcc.exception.TCCFenceException;
-import io.seata.rm.tcc.store.TCCFenceDO;
-import io.seata.rm.tcc.store.TCCFenceStore;
-import io.seata.rm.tcc.store.db.TCCFenceStoreDataBaseDAO;
+import io.seata.commonapi.fence.constant.CommonFenceConstant;
+import io.seata.commonapi.fence.exception.CommonFenceException;
+import io.seata.commonapi.fence.store.CommonFenceDO;
+import io.seata.commonapi.fence.store.CommonFenceStore;
+import io.seata.commonapi.fence.store.db.CommonFenceStoreDataBaseDAO;
+import io.seata.commonapi.remoting.TwoPhaseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionTemplate;
+import javax.sql.DataSource;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
/**
- * TCC Fence Handler(idempotent, non_rollback, suspend)
+ * Common Fence Handler(idempotent, non_rollback, suspend)
*
* @author kaka2code
*/
-public class TCCFenceHandler {
+public class CommonFenceHandler {
- private TCCFenceHandler() {
+ private CommonFenceHandler() {
throw new IllegalStateException("Utility class");
}
- private static final Logger LOGGER = LoggerFactory.getLogger(TCCFenceHandler.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(CommonFenceHandler.class);
- private static final TCCFenceStore TCC_FENCE_DAO = TCCFenceStoreDataBaseDAO.getInstance();
+ private static final CommonFenceStore COMMON_FENCE_DAO = CommonFenceStoreDataBaseDAO.getInstance();
private static DataSource dataSource;
@@ -84,19 +85,19 @@ private TCCFenceHandler() {
}
public static DataSource getDataSource() {
- return TCCFenceHandler.dataSource;
+ return CommonFenceHandler.dataSource;
}
public static void setDataSource(DataSource dataSource) {
- TCCFenceHandler.dataSource = dataSource;
+ CommonFenceHandler.dataSource = dataSource;
}
public static void setTransactionTemplate(TransactionTemplate transactionTemplate) {
- TCCFenceHandler.transactionTemplate = transactionTemplate;
+ CommonFenceHandler.transactionTemplate = transactionTemplate;
}
/**
- * tcc prepare method enhanced
+ * common prepare method enhanced
*
* @param xid the global transaction id
* @param branchId the branch transaction id
@@ -108,15 +109,15 @@ public static Object prepareFence(String xid, Long branchId, String actionName,
return transactionTemplate.execute(status -> {
try {
Connection conn = DataSourceUtils.getConnection(dataSource);
- boolean result = insertTCCFenceLog(conn, xid, branchId, actionName, TCCFenceConstant.STATUS_TRIED);
- LOGGER.info("TCC fence prepare result: {}. xid: {}, branchId: {}", result, xid, branchId);
+ boolean result = insertCommonFenceLog(conn, xid, branchId, actionName, CommonFenceConstant.STATUS_TRIED);
+ LOGGER.info("Common fence prepare result: {}. xid: {}, branchId: {}", result, xid, branchId);
if (result) {
return targetCallback.execute();
} else {
- throw new TCCFenceException(String.format("Insert tcc fence record error, prepare fence failed. xid= %s, branchId= %s", xid, branchId),
+ throw new CommonFenceException(String.format("Insert common fence record error, prepare fence failed. xid= %s, branchId= %s", xid, branchId),
FrameworkErrorCode.InsertRecordError);
}
- } catch (TCCFenceException e) {
+ } catch (CommonFenceException e) {
if (e.getErrcode() == FrameworkErrorCode.DuplicateKeyException) {
LOGGER.error("Branch transaction has already rollbacked before,prepare fence failed. xid= {},branchId = {}", xid, branchId);
addToLogCleanQueue(xid, branchId);
@@ -131,10 +132,10 @@ public static Object prepareFence(String xid, Long branchId, String actionName,
}
/**
- * tcc commit method enhanced
+ * common commit method enhanced
*
* @param commitMethod commit method
- * @param targetTCCBean target tcc bean
+ * @param targetTCCBean target common bean
* @param xid the global transaction id
* @param branchId the branch transaction id
* @param args commit method's parameters
@@ -145,22 +146,22 @@ public static boolean commitFence(Method commitMethod, Object targetTCCBean,
return transactionTemplate.execute(status -> {
try {
Connection conn = DataSourceUtils.getConnection(dataSource);
- TCCFenceDO tccFenceDO = TCC_FENCE_DAO.queryTCCFenceDO(conn, xid, branchId);
- if (tccFenceDO == null) {
- throw new TCCFenceException(String.format("TCC fence record not exists, commit fence method failed. xid= %s, branchId= %s", xid, branchId),
+ CommonFenceDO commonFenceDO = COMMON_FENCE_DAO.queryCommonFenceDO(conn, xid, branchId);
+ if (commonFenceDO == null) {
+ throw new CommonFenceException(String.format("Common fence record not exists, commit fence method failed. xid= %s, branchId= %s", xid, branchId),
FrameworkErrorCode.RecordNotExists);
}
- if (TCCFenceConstant.STATUS_COMMITTED == tccFenceDO.getStatus()) {
- LOGGER.info("Branch transaction has already committed before. idempotency rejected. xid: {}, branchId: {}, status: {}", xid, branchId, tccFenceDO.getStatus());
+ if (CommonFenceConstant.STATUS_COMMITTED == commonFenceDO.getStatus()) {
+ LOGGER.info("Branch transaction has already committed before. idempotency rejected. xid: {}, branchId: {}, status: {}", xid, branchId, commonFenceDO.getStatus());
return true;
}
- if (TCCFenceConstant.STATUS_ROLLBACKED == tccFenceDO.getStatus() || TCCFenceConstant.STATUS_SUSPENDED == tccFenceDO.getStatus()) {
+ if (CommonFenceConstant.STATUS_ROLLBACKED == commonFenceDO.getStatus() || CommonFenceConstant.STATUS_SUSPENDED == commonFenceDO.getStatus()) {
if (LOGGER.isWarnEnabled()) {
- LOGGER.warn("Branch transaction status is unexpected. xid: {}, branchId: {}, status: {}", xid, branchId, tccFenceDO.getStatus());
+ LOGGER.warn("Branch transaction status is unexpected. xid: {}, branchId: {}, status: {}", xid, branchId, commonFenceDO.getStatus());
}
return false;
}
- return updateStatusAndInvokeTargetMethod(conn, commitMethod, targetTCCBean, xid, branchId, TCCFenceConstant.STATUS_COMMITTED, status, args);
+ return updateStatusAndInvokeTargetMethod(conn, commitMethod, targetTCCBean, xid, branchId, CommonFenceConstant.STATUS_COMMITTED, status, args);
} catch (Throwable t) {
status.setRollbackOnly();
throw new SkipCallbackWrapperException(t);
@@ -169,7 +170,7 @@ public static boolean commitFence(Method commitMethod, Object targetTCCBean,
}
/**
- * tcc rollback method enhanced
+ * Common rollback method enhanced
*
* @param rollbackMethod rollback method
* @param targetTCCBean target tcc bean
@@ -184,29 +185,29 @@ public static boolean rollbackFence(Method rollbackMethod, Object targetTCCBean,
return transactionTemplate.execute(status -> {
try {
Connection conn = DataSourceUtils.getConnection(dataSource);
- TCCFenceDO tccFenceDO = TCC_FENCE_DAO.queryTCCFenceDO(conn, xid, branchId);
+ CommonFenceDO commonFenceDO = COMMON_FENCE_DAO.queryCommonFenceDO(conn, xid, branchId);
// non_rollback
- if (tccFenceDO == null) {
- boolean result = insertTCCFenceLog(conn, xid, branchId, actionName, TCCFenceConstant.STATUS_SUSPENDED);
- LOGGER.info("Insert tcc fence record result: {}. xid: {}, branchId: {}", result, xid, branchId);
+ if (commonFenceDO == null) {
+ boolean result = insertCommonFenceLog(conn, xid, branchId, actionName, CommonFenceConstant.STATUS_SUSPENDED);
+ LOGGER.info("Insert common fence record result: {}. xid: {}, branchId: {}", result, xid, branchId);
if (!result) {
- throw new TCCFenceException(String.format("Insert tcc fence record error, rollback fence method failed. xid= %s, branchId= %s", xid, branchId),
+ throw new CommonFenceException(String.format("Insert common fence record error, rollback fence method failed. xid= %s, branchId= %s", xid, branchId),
FrameworkErrorCode.InsertRecordError);
}
return true;
} else {
- if (TCCFenceConstant.STATUS_ROLLBACKED == tccFenceDO.getStatus() || TCCFenceConstant.STATUS_SUSPENDED == tccFenceDO.getStatus()) {
- LOGGER.info("Branch transaction had already rollbacked before, idempotency rejected. xid: {}, branchId: {}, status: {}", xid, branchId, tccFenceDO.getStatus());
+ if (CommonFenceConstant.STATUS_ROLLBACKED == commonFenceDO.getStatus() || CommonFenceConstant.STATUS_SUSPENDED == commonFenceDO.getStatus()) {
+ LOGGER.info("Branch transaction had already rollbacked before, idempotency rejected. xid: {}, branchId: {}, status: {}", xid, branchId, commonFenceDO.getStatus());
return true;
}
- if (TCCFenceConstant.STATUS_COMMITTED == tccFenceDO.getStatus()) {
+ if (CommonFenceConstant.STATUS_COMMITTED == commonFenceDO.getStatus()) {
if (LOGGER.isWarnEnabled()) {
- LOGGER.warn("Branch transaction status is unexpected. xid: {}, branchId: {}, status: {}", xid, branchId, tccFenceDO.getStatus());
+ LOGGER.warn("Branch transaction status is unexpected. xid: {}, branchId: {}, status: {}", xid, branchId, commonFenceDO.getStatus());
}
return false;
}
}
- return updateStatusAndInvokeTargetMethod(conn, rollbackMethod, targetTCCBean, xid, branchId, TCCFenceConstant.STATUS_ROLLBACKED, status, args);
+ return updateStatusAndInvokeTargetMethod(conn, rollbackMethod, targetTCCBean, xid, branchId, CommonFenceConstant.STATUS_ROLLBACKED, status, args);
} catch (Throwable t) {
status.setRollbackOnly();
throw new SkipCallbackWrapperException(t);
@@ -215,7 +216,7 @@ public static boolean rollbackFence(Method rollbackMethod, Object targetTCCBean,
}
/**
- * Insert TCC fence log
+ * Insert Common fence log
*
* @param conn the db connection
* @param xid the xid
@@ -223,13 +224,13 @@ public static boolean rollbackFence(Method rollbackMethod, Object targetTCCBean,
* @param status the status
* @return the boolean
*/
- private static boolean insertTCCFenceLog(Connection conn, String xid, Long branchId, String actionName, Integer status) {
- TCCFenceDO tccFenceDO = new TCCFenceDO();
- tccFenceDO.setXid(xid);
- tccFenceDO.setBranchId(branchId);
- tccFenceDO.setActionName(actionName);
- tccFenceDO.setStatus(status);
- return TCC_FENCE_DAO.insertTCCFenceDO(conn, tccFenceDO);
+ private static boolean insertCommonFenceLog(Connection conn, String xid, Long branchId, String actionName, Integer status) {
+ CommonFenceDO commonFenceDO = new CommonFenceDO();
+ commonFenceDO.setXid(xid);
+ commonFenceDO.setBranchId(branchId);
+ commonFenceDO.setActionName(actionName);
+ commonFenceDO.setStatus(status);
+ return COMMON_FENCE_DAO.insertCommonFenceDO(conn, commonFenceDO);
}
/**
@@ -246,7 +247,7 @@ private static boolean updateStatusAndInvokeTargetMethod(Connection conn, Method
String xid, Long branchId, int status,
TransactionStatus transactionStatus,
Object[] args) throws Exception {
- boolean result = TCC_FENCE_DAO.updateTCCFenceDO(conn, xid, branchId, status, TCCFenceConstant.STATUS_TRIED);
+ boolean result = COMMON_FENCE_DAO.updateCommonFenceDO(conn, xid, branchId, status, CommonFenceConstant.STATUS_TRIED);
if (result) {
// invoke two phase method
Object ret = method.invoke(targetTCCBean, args);
@@ -266,7 +267,7 @@ private static boolean updateStatusAndInvokeTargetMethod(Connection conn, Method
}
/**
- * Delete TCC Fence
+ * Delete Common Fence
*
* @param xid the global transaction id
* @param branchId the branch transaction id
@@ -277,7 +278,7 @@ public static boolean deleteFence(String xid, Long branchId) {
boolean ret = false;
try {
Connection conn = DataSourceUtils.getConnection(dataSource);
- ret = TCC_FENCE_DAO.deleteTCCFenceDO(conn, xid, branchId);
+ ret = COMMON_FENCE_DAO.deleteCommonFenceDO(conn, xid, branchId);
} catch (RuntimeException e) {
status.setRollbackOnly();
LOGGER.error("delete fence log failed, xid: {}, branchId: {}", xid, branchId, e);
@@ -288,18 +289,24 @@ public static boolean deleteFence(String xid, Long branchId) {
+ /**
+ * Delete Common Fence By Datetime
+ *
+ * @param datetime datetime
+ * @return the deleted row count
+ */
public static int deleteFenceByDate(Date datetime) {
- DataSource dataSource = TCCFenceHandler.getDataSource();
+ DataSource dataSource = CommonFenceHandler.getDataSource();
Connection connection = null;
int total = 0;
try {
connection = DataSourceUtils.getConnection(dataSource);
while (true) {
- Set xidSet = TCC_FENCE_DAO.queryEndStatusXidsByDate(connection, datetime, LIMIT_DELETE);
+ Set xidSet = COMMON_FENCE_DAO.queryEndStatusXidsByDate(connection, datetime, LIMIT_DELETE);
if (xidSet.isEmpty()) {
break;
}
- total += TCC_FENCE_DAO.deleteTCCFenceDO(connection, new ArrayList<>(xidSet));
+ total += COMMON_FENCE_DAO.deleteTCCFenceDO(connection, new ArrayList<>(xidSet));
}
} catch (RuntimeException e) {
LOGGER.error("delete fence log failed ", e);
@@ -335,7 +342,7 @@ private static void addToLogCleanQueue(final String xid, final long branchId) {
/**
* clean fence log that has the final status runnable.
*
- * @see TCCFenceConstant
+ * @see CommonFenceConstant
*/
private static class FenceLogCleanRunnable implements Runnable {
@Override
@@ -344,7 +351,7 @@ public void run() {
try {
FenceLogIdentity logIdentity = LOG_QUEUE.take();
- boolean ret = TCCFenceHandler.deleteFence(logIdentity.getXid(), logIdentity.getBranchId());
+ boolean ret = CommonFenceHandler.deleteFence(logIdentity.getXid(), logIdentity.getBranchId());
if (!ret) {
LOGGER.error("delete fence log failed, xid: {}, branchId: {}", logIdentity.getXid(), logIdentity.getBranchId());
}
@@ -384,4 +391,4 @@ public void setBranchId(Long branchId) {
this.branchId = branchId;
}
}
-}
+}
\ No newline at end of file
diff --git a/tcc/src/main/java/io/seata/rm/tcc/config/TCCFenceConfig.java b/common-api/src/main/java/io/seata/commonapi/fence/config/CommonFenceConfig.java
similarity index 75%
rename from tcc/src/main/java/io/seata/rm/tcc/config/TCCFenceConfig.java
rename to common-api/src/main/java/io/seata/commonapi/fence/config/CommonFenceConfig.java
index fffc08ab993..5263fb7dc01 100644
--- a/tcc/src/main/java/io/seata/rm/tcc/config/TCCFenceConfig.java
+++ b/common-api/src/main/java/io/seata/commonapi/fence/config/CommonFenceConfig.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.rm.tcc.config;
+package io.seata.commonapi.fence.config;
import java.time.Duration;
import java.util.Date;
@@ -26,10 +26,10 @@
import io.seata.common.DefaultValues;
import io.seata.common.exception.FrameworkErrorCode;
import io.seata.common.thread.NamedThreadFactory;
+import io.seata.commonapi.fence.CommonFenceHandler;
+import io.seata.commonapi.fence.exception.CommonFenceException;
import io.seata.core.rpc.Disposable;
-import io.seata.rm.tcc.TCCFenceHandler;
-import io.seata.rm.tcc.exception.TCCFenceException;
-import io.seata.rm.tcc.store.db.TCCFenceStoreDataBaseDAO;
+import io.seata.commonapi.fence.store.db.CommonFenceStoreDataBaseDAO;
import org.apache.commons.lang.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,48 +38,48 @@
import org.springframework.transaction.support.TransactionTemplate;
/**
- * TCC Fence Config
+ * Common Fence Config
*
* @author kaka2code
*/
-public class TCCFenceConfig implements InitializingBean, Disposable {
+public class CommonFenceConfig implements InitializingBean, Disposable {
- private static final Logger LOGGER = LoggerFactory.getLogger(TCCFenceConfig.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(CommonFenceConfig.class);
private final AtomicBoolean initialized = new AtomicBoolean(false);
/**
- * TCC fence clean period max value. maximum interval is 68 years
+ * Common fence clean period max value. maximum interval is 68 years
*/
private static final Duration MAX_PERIOD = Duration.ofSeconds(Integer.MAX_VALUE);
/**
- * TCC fence clean period. only duration type format are supported
+ * Common fence clean period. only duration type format are supported
*/
- private Duration cleanPeriod = Duration.ofDays(DefaultValues.DEFAULT_TCC_FENCE_CLEAN_PERIOD);
+ private Duration cleanPeriod = Duration.ofDays(DefaultValues.DEFAULT_COMMON_FENCE_CLEAN_PERIOD);
/**
- * TCC fence log table name
+ * Common fence log table name
*/
- private String logTableName = DefaultValues.DEFAULT_TCC_FENCE_LOG_TABLE_NAME;
+ private String logTableName = DefaultValues.DEFAULT_COMMON_FENCE_LOG_TABLE_NAME;
/**
- * TCC fence datasource
+ * Common fence datasource
*/
private final DataSource dataSource;
/**
- * TCC fence transactionManager
+ * Common fence transactionManager
*/
private final PlatformTransactionManager transactionManager;
/**
- * TCC fence clean scheduled thread pool
+ * Common fence clean scheduled thread pool
*/
private final ScheduledThreadPoolExecutor tccFenceClean = new ScheduledThreadPoolExecutor(1,
new NamedThreadFactory("tccFenceClean", 1));
- public TCCFenceConfig(final DataSource dataSource, final PlatformTransactionManager transactionManager) {
+ public CommonFenceConfig(final DataSource dataSource, final PlatformTransactionManager transactionManager) {
this.dataSource = dataSource;
this.transactionManager = transactionManager;
}
@@ -116,7 +116,7 @@ public void initCleanTask() {
Date timeBefore = null;
try {
timeBefore = DateUtils.addSeconds(new Date(), -(int)periodSeconds);
- int deletedRowCount = TCCFenceHandler.deleteFenceByDate(timeBefore);
+ int deletedRowCount = CommonFenceHandler.deleteFenceByDate(timeBefore);
if (deletedRowCount > 0) {
LOGGER.info("TCC fence clean task executed success, timeBefore: {}, deleted row count: {}",
timeBefore, deletedRowCount);
@@ -141,20 +141,19 @@ public void destroy() {
public void afterPropertiesSet() {
// set log table name
if (logTableName != null) {
- TCCFenceStoreDataBaseDAO.getInstance().setLogTableName(logTableName);
+ CommonFenceStoreDataBaseDAO.getInstance().setLogTableName(logTableName);
}
if (dataSource != null) {
// set dataSource
- TCCFenceHandler.setDataSource(dataSource);
+ CommonFenceHandler.setDataSource(dataSource);
} else {
- throw new TCCFenceException(FrameworkErrorCode.DateSourceNeedInjected);
+ throw new CommonFenceException(FrameworkErrorCode.DateSourceNeedInjected);
}
if (transactionManager != null) {
// set transaction template
- TCCFenceHandler.setTransactionTemplate(new TransactionTemplate(transactionManager));
+ CommonFenceHandler.setTransactionTemplate(new TransactionTemplate(transactionManager));
} else {
- throw new TCCFenceException(FrameworkErrorCode.TransactionManagerNeedInjected);
+ throw new CommonFenceException(FrameworkErrorCode.TransactionManagerNeedInjected);
}
}
}
-
diff --git a/tcc/src/main/java/io/seata/rm/tcc/constant/TCCFenceConstant.java b/common-api/src/main/java/io/seata/commonapi/fence/constant/CommonFenceConstant.java
similarity index 88%
rename from tcc/src/main/java/io/seata/rm/tcc/constant/TCCFenceConstant.java
rename to common-api/src/main/java/io/seata/commonapi/fence/constant/CommonFenceConstant.java
index 7c9a2b416cf..4371ba6b070 100644
--- a/tcc/src/main/java/io/seata/rm/tcc/constant/TCCFenceConstant.java
+++ b/common-api/src/main/java/io/seata/commonapi/fence/constant/CommonFenceConstant.java
@@ -13,16 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.rm.tcc.constant;
+package io.seata.commonapi.fence.constant;
/**
- * TCC Fence Constant
+ * Common Fence Constant
*
* @author kaka2code
*/
-public class TCCFenceConstant {
+public class CommonFenceConstant {
- private TCCFenceConstant() {
+ private CommonFenceConstant() {
throw new IllegalStateException("Utility class");
}
@@ -45,4 +45,4 @@ private TCCFenceConstant() {
* Suspended status.
*/
public static final int STATUS_SUSPENDED = 4;
-}
+}
\ No newline at end of file
diff --git a/tcc/src/main/java/io/seata/rm/tcc/exception/TCCFenceException.java b/common-api/src/main/java/io/seata/commonapi/fence/exception/CommonFenceException.java
similarity index 64%
rename from tcc/src/main/java/io/seata/rm/tcc/exception/TCCFenceException.java
rename to common-api/src/main/java/io/seata/commonapi/fence/exception/CommonFenceException.java
index 716da66ed1f..081c3b3962c 100644
--- a/tcc/src/main/java/io/seata/rm/tcc/exception/TCCFenceException.java
+++ b/common-api/src/main/java/io/seata/commonapi/fence/exception/CommonFenceException.java
@@ -13,40 +13,40 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.rm.tcc.exception;
+package io.seata.commonapi.fence.exception;
import io.seata.common.exception.FrameworkErrorCode;
import io.seata.common.exception.FrameworkException;
/**
- * TCC Fence Exception
+ * Common Fence Exception
*
* @author kaka2code
*/
-public class TCCFenceException extends FrameworkException {
+public class CommonFenceException extends FrameworkException {
- public TCCFenceException(FrameworkErrorCode err) {
+ public CommonFenceException(FrameworkErrorCode err) {
super(err);
}
- public TCCFenceException(String msg) {
+ public CommonFenceException(String msg) {
super(msg);
}
- public TCCFenceException(String msg, FrameworkErrorCode errCode) {
+ public CommonFenceException(String msg, FrameworkErrorCode errCode) {
super(msg, errCode);
}
- public TCCFenceException(Throwable cause, String msg, FrameworkErrorCode errCode) {
+ public CommonFenceException(Throwable cause, String msg, FrameworkErrorCode errCode) {
super(cause, msg, errCode);
}
- public TCCFenceException(Throwable th) {
+ public CommonFenceException(Throwable th) {
super(th);
}
- public TCCFenceException(Throwable th, String msg) {
+ public CommonFenceException(Throwable th, String msg) {
super(th, msg);
}
-}
+}
\ No newline at end of file
diff --git a/tcc/src/main/java/io/seata/rm/tcc/store/TCCFenceDO.java b/common-api/src/main/java/io/seata/commonapi/fence/store/CommonFenceDO.java
similarity index 94%
rename from tcc/src/main/java/io/seata/rm/tcc/store/TCCFenceDO.java
rename to common-api/src/main/java/io/seata/commonapi/fence/store/CommonFenceDO.java
index 6878a9a0c74..a8f35b9364e 100644
--- a/tcc/src/main/java/io/seata/rm/tcc/store/TCCFenceDO.java
+++ b/common-api/src/main/java/io/seata/commonapi/fence/store/CommonFenceDO.java
@@ -13,16 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.rm.tcc.store;
+package io.seata.commonapi.fence.store;
import java.util.Date;
/**
- * TCC Fence Domain
+ * Common Fence Domain
*
* @author kaka2code
*/
-public class TCCFenceDO {
+public class CommonFenceDO {
/**
* the global transaction id
@@ -40,7 +40,7 @@ public class TCCFenceDO {
private String actionName;
/**
- * the tcc fence status
+ * the common fence status
* tried: 1; committed: 2; rollbacked: 3; suspended: 4
*/
private Integer status;
@@ -103,4 +103,4 @@ public void setGmtModified(Date gmtModified) {
this.gmtModified = gmtModified;
}
-}
+}
\ No newline at end of file
diff --git a/tcc/src/main/java/io/seata/rm/tcc/store/TCCFenceStore.java b/common-api/src/main/java/io/seata/commonapi/fence/store/CommonFenceStore.java
similarity index 72%
rename from tcc/src/main/java/io/seata/rm/tcc/store/TCCFenceStore.java
rename to common-api/src/main/java/io/seata/commonapi/fence/store/CommonFenceStore.java
index 3f356526e5d..f2ac8480ad9 100644
--- a/tcc/src/main/java/io/seata/rm/tcc/store/TCCFenceStore.java
+++ b/common-api/src/main/java/io/seata/commonapi/fence/store/CommonFenceStore.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.rm.tcc.store;
+package io.seata.commonapi.fence.store;
import java.sql.Connection;
import java.util.Date;
@@ -21,20 +21,20 @@
import java.util.Set;
/**
- * The TCC Fence Store
+ * The common Fence Store
*
* @author kaka2code
*/
-public interface TCCFenceStore {
+public interface CommonFenceStore {
/**
- * Query tcc fence do.
+ * Query common fence do.
* @param conn the connection
* @param xid the global transaction id
* @param branchId the branch transaction id
- * @return the tcc fence do
+ * @return the common fence do
*/
- TCCFenceDO queryTCCFenceDO(Connection conn, String xid, Long branchId);
+ CommonFenceDO queryCommonFenceDO(Connection conn, String xid, Long branchId);
/**
* Query xid.
@@ -46,15 +46,15 @@ public interface TCCFenceStore {
Set queryEndStatusXidsByDate(Connection conn, Date datetime, int limit);
/**
- * Insert tcc fence do boolean.
+ * Insert common fence do boolean.
* @param conn the connection
- * @param tccFenceDO the tcc fence do
+ * @param commonFenceDO the common fence do
* @return the boolean
*/
- boolean insertTCCFenceDO(Connection conn, TCCFenceDO tccFenceDO);
+ boolean insertCommonFenceDO(Connection conn, CommonFenceDO commonFenceDO);
/**
- * Update tcc fence do boolean.
+ * Update common fence do boolean.
* @param conn the connection
* @param xid the global transaction id
* @param branchId the branch transaction id
@@ -62,16 +62,16 @@ public interface TCCFenceStore {
* @param oldStatus the old status
* @return the boolean
*/
- boolean updateTCCFenceDO(Connection conn, String xid, Long branchId, int newStatus, int oldStatus);
+ boolean updateCommonFenceDO(Connection conn, String xid, Long branchId, int newStatus, int oldStatus);
/**
- * Delete tcc fence do boolean.
+ * Delete common fence do boolean.
* @param conn the connection
* @param xid the global transaction id
* @param branchId the branch transaction id
* @return the boolean
*/
- boolean deleteTCCFenceDO(Connection conn, String xid, Long branchId);
+ boolean deleteCommonFenceDO(Connection conn, String xid, Long branchId);
/**
* Delete tcc fence do boolean.
@@ -82,13 +82,13 @@ public interface TCCFenceStore {
int deleteTCCFenceDO(Connection conn, List xids);
/**
- * Delete tcc fence by datetime.
+ * Delete common fence by datetime.
* @param conn the connection
* @param datetime datetime
* @param limit limit
* @return the deleted row count
*/
- int deleteTCCFenceDOByDate(Connection conn, Date datetime, int limit);
+ int deleteCommonFenceDOByDate(Connection conn, Date datetime, int limit);
/**
* Set LogTable Name
diff --git a/tcc/src/main/java/io/seata/rm/tcc/store/db/TCCFenceStoreDataBaseDAO.java b/common-api/src/main/java/io/seata/commonapi/fence/store/db/CommonFenceStoreDataBaseDAO.java
similarity index 66%
rename from tcc/src/main/java/io/seata/rm/tcc/store/db/TCCFenceStoreDataBaseDAO.java
rename to common-api/src/main/java/io/seata/commonapi/fence/store/db/CommonFenceStoreDataBaseDAO.java
index 98b96662687..49a4cd8c46e 100644
--- a/tcc/src/main/java/io/seata/rm/tcc/store/db/TCCFenceStoreDataBaseDAO.java
+++ b/common-api/src/main/java/io/seata/commonapi/fence/store/db/CommonFenceStoreDataBaseDAO.java
@@ -13,17 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.rm.tcc.store.db;
+package io.seata.commonapi.fence.store.db;
import io.seata.common.DefaultValues;
import io.seata.common.exception.DataAccessException;
import io.seata.common.exception.FrameworkErrorCode;
import io.seata.common.exception.StoreException;
import io.seata.common.util.IOUtil;
-import io.seata.rm.tcc.exception.TCCFenceException;
-import io.seata.rm.tcc.store.TCCFenceDO;
-import io.seata.rm.tcc.store.TCCFenceStore;
-import io.seata.rm.tcc.store.db.sql.TCCFenceStoreSqls;
+import io.seata.commonapi.fence.exception.CommonFenceException;
+import io.seata.commonapi.fence.store.CommonFenceDO;
+import io.seata.commonapi.fence.store.CommonFenceStore;
+import io.seata.commonapi.fence.store.db.sql.CommonFenceStoreSqls;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -37,26 +37,26 @@
import java.util.Set;
/**
- * The type TCC Fence store data base dao
+ * The type Common Fence store data base dao
*
* @author kaka2code
*/
-public class TCCFenceStoreDataBaseDAO implements TCCFenceStore {
+public class CommonFenceStoreDataBaseDAO implements CommonFenceStore {
/**
- * TCC fence log table name
+ * Common fence log table name
*/
- private String logTableName = DefaultValues.DEFAULT_TCC_FENCE_LOG_TABLE_NAME;
+ private String logTableName = DefaultValues.DEFAULT_COMMON_FENCE_LOG_TABLE_NAME;
- private static volatile TCCFenceStoreDataBaseDAO instance = null;
+ private static volatile CommonFenceStoreDataBaseDAO instance = null;
- private TCCFenceStoreDataBaseDAO() {}
+ private CommonFenceStoreDataBaseDAO() {}
- public static TCCFenceStore getInstance() {
+ public static CommonFenceStore getInstance() {
if (instance == null) {
- synchronized (TCCFenceStore.class) {
+ synchronized (CommonFenceStore.class) {
if (instance == null) {
- instance = new TCCFenceStoreDataBaseDAO();
+ instance = new CommonFenceStoreDataBaseDAO();
}
}
}
@@ -64,21 +64,21 @@ public static TCCFenceStore getInstance() {
}
@Override
- public TCCFenceDO queryTCCFenceDO(Connection conn, String xid, Long branchId) {
+ public CommonFenceDO queryCommonFenceDO(Connection conn, String xid, Long branchId) {
PreparedStatement ps = null;
ResultSet rs = null;
try {
- String sql = TCCFenceStoreSqls.getQuerySQLByBranchIdAndXid(logTableName);
+ String sql = CommonFenceStoreSqls.getQuerySQLByBranchIdAndXid(logTableName);
ps = conn.prepareStatement(sql);
ps.setString(1, xid);
ps.setLong(2, branchId);
rs = ps.executeQuery();
if (rs.next()) {
- TCCFenceDO tccFenceDO = new TCCFenceDO();
- tccFenceDO.setXid(rs.getString("xid"));
- tccFenceDO.setBranchId(rs.getLong("branch_id"));
- tccFenceDO.setStatus(rs.getInt("status"));
- return tccFenceDO;
+ CommonFenceDO commonFenceDO = new CommonFenceDO();
+ commonFenceDO.setXid(rs.getString("xid"));
+ commonFenceDO.setBranchId(rs.getLong("branch_id"));
+ commonFenceDO.setStatus(rs.getInt("status"));
+ return commonFenceDO;
} else {
return null;
}
@@ -94,7 +94,7 @@ public Set queryEndStatusXidsByDate(Connection conn, Date datetime, int
PreparedStatement ps = null;
ResultSet rs = null;
try {
- String sql = TCCFenceStoreSqls.getQueryEndStatusSQLByDate(logTableName);
+ String sql = CommonFenceStoreSqls.getQueryEndStatusSQLByDate(logTableName);
ps = conn.prepareStatement(sql);
ps.setTimestamp(1, new Timestamp(datetime.getTime()));
ps.setInt(2, limit);
@@ -112,22 +112,22 @@ public Set queryEndStatusXidsByDate(Connection conn, Date datetime, int
}
@Override
- public boolean insertTCCFenceDO(Connection conn, TCCFenceDO tccFenceDO) {
+ public boolean insertCommonFenceDO(Connection conn, CommonFenceDO commonFenceDO) {
PreparedStatement ps = null;
try {
Timestamp now = new Timestamp(System.currentTimeMillis());
- String sql = TCCFenceStoreSqls.getInsertLocalTCCLogSQL(logTableName);
+ String sql = CommonFenceStoreSqls.getInsertLocalTCCLogSQL(logTableName);
ps = conn.prepareStatement(sql);
- ps.setString(1, tccFenceDO.getXid());
- ps.setLong(2, tccFenceDO.getBranchId());
- ps.setString(3, tccFenceDO.getActionName());
- ps.setInt(4, tccFenceDO.getStatus());
+ ps.setString(1, commonFenceDO.getXid());
+ ps.setLong(2, commonFenceDO.getBranchId());
+ ps.setString(3, commonFenceDO.getActionName());
+ ps.setInt(4, commonFenceDO.getStatus());
ps.setTimestamp(5, now);
ps.setTimestamp(6, now);
return ps.executeUpdate() > 0;
} catch (SQLIntegrityConstraintViolationException e) {
- throw new TCCFenceException(String.format("Insert tcc fence record duplicate key exception. xid= %s, branchId= %s", tccFenceDO.getXid(), tccFenceDO.getBranchId()),
+ throw new CommonFenceException(String.format("Insert tcc fence record duplicate key exception. xid= %s, branchId= %s", commonFenceDO.getXid(), commonFenceDO.getBranchId()),
FrameworkErrorCode.DuplicateKeyException);
} catch (SQLException e) {
throw new StoreException(e);
@@ -137,10 +137,10 @@ public boolean insertTCCFenceDO(Connection conn, TCCFenceDO tccFenceDO) {
}
@Override
- public boolean updateTCCFenceDO(Connection conn, String xid, Long branchId, int newStatus, int oldStatus) {
+ public boolean updateCommonFenceDO(Connection conn, String xid, Long branchId, int newStatus, int oldStatus) {
PreparedStatement ps = null;
try {
- String sql = TCCFenceStoreSqls.getUpdateStatusSQLByBranchIdAndXid(logTableName);
+ String sql = CommonFenceStoreSqls.getUpdateStatusSQLByBranchIdAndXid(logTableName);
ps = conn.prepareStatement(sql);
ps.setInt(1, newStatus);
// gmt_modified
@@ -157,10 +157,10 @@ public boolean updateTCCFenceDO(Connection conn, String xid, Long branchId, int
}
@Override
- public boolean deleteTCCFenceDO(Connection conn, String xid, Long branchId) {
+ public boolean deleteCommonFenceDO(Connection conn, String xid, Long branchId) {
PreparedStatement ps = null;
try {
- String sql = TCCFenceStoreSqls.getDeleteSQLByBranchIdAndXid(logTableName);
+ String sql = CommonFenceStoreSqls.getDeleteSQLByBranchIdAndXid(logTableName);
ps = conn.prepareStatement(sql);
ps.setString(1, xid);
ps.setLong(2, branchId);
@@ -178,7 +178,7 @@ public int deleteTCCFenceDO(Connection conn, List xids) {
PreparedStatement ps = null;
try {
String paramsPlaceHolder = org.apache.commons.lang.StringUtils.repeat("?", ",", xids.size());
- String sql = TCCFenceStoreSqls.getDeleteSQLByXids(logTableName, paramsPlaceHolder);
+ String sql = CommonFenceStoreSqls.getDeleteSQLByXids(logTableName, paramsPlaceHolder);
ps = conn.prepareStatement(sql);
for (int i = 0; i < xids.size(); i++) {
ps.setString(i + 1, xids.get(i));
@@ -192,10 +192,10 @@ public int deleteTCCFenceDO(Connection conn, List xids) {
}
@Override
- public int deleteTCCFenceDOByDate(Connection conn, Date datetime, int limit) {
+ public int deleteCommonFenceDOByDate(Connection conn, Date datetime, int limit) {
PreparedStatement ps = null;
try {
- String sql = TCCFenceStoreSqls.getDeleteSQLByDateAndStatus(logTableName);
+ String sql = CommonFenceStoreSqls.getDeleteSQLByDateAndStatus(logTableName);
ps = conn.prepareStatement(sql);
ps.setTimestamp(1, new Timestamp(datetime.getTime()));
ps.setInt(2, limit);
@@ -211,4 +211,4 @@ public int deleteTCCFenceDOByDate(Connection conn, Date datetime, int limit) {
public void setLogTableName(String logTableName) {
this.logTableName = logTableName;
}
-}
+}
\ No newline at end of file
diff --git a/tcc/src/main/java/io/seata/rm/tcc/store/db/sql/TCCFenceStoreSqls.java b/common-api/src/main/java/io/seata/commonapi/fence/store/db/sql/CommonFenceStoreSqls.java
similarity index 88%
rename from tcc/src/main/java/io/seata/rm/tcc/store/db/sql/TCCFenceStoreSqls.java
rename to common-api/src/main/java/io/seata/commonapi/fence/store/db/sql/CommonFenceStoreSqls.java
index f1b43b2540e..eae59da4101 100644
--- a/tcc/src/main/java/io/seata/rm/tcc/store/db/sql/TCCFenceStoreSqls.java
+++ b/common-api/src/main/java/io/seata/commonapi/fence/store/db/sql/CommonFenceStoreSqls.java
@@ -13,18 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.rm.tcc.store.db.sql;
+package io.seata.commonapi.fence.store.db.sql;
-import io.seata.rm.tcc.constant.TCCFenceConstant;
+import io.seata.commonapi.fence.constant.CommonFenceConstant;
/**
* TCC Fence Store Sqls
*
* @author kaka2code
*/
-public class TCCFenceStoreSqls {
+public class CommonFenceStoreSqls {
- private TCCFenceStoreSqls() {
+ private CommonFenceStoreSqls() {
throw new IllegalStateException("Utility class");
}
@@ -59,7 +59,7 @@ private TCCFenceStoreSqls() {
protected static final String QUERY_END_STATUS_BY_DATE = "select xid, branch_id, status, gmt_create, gmt_modified "
+ "from " + LOCAL_TCC_LOG_PLACEHOLD
+ " where gmt_modified < ? "
- + " and status in (" + TCCFenceConstant.STATUS_COMMITTED + " , " + TCCFenceConstant.STATUS_ROLLBACKED + " , " + TCCFenceConstant.STATUS_SUSPENDED + ")"
+ + " and status in (" + CommonFenceConstant.STATUS_COMMITTED + " , " + CommonFenceConstant.STATUS_ROLLBACKED + " , " + CommonFenceConstant.STATUS_SUSPENDED + ")"
+ " limit ?";
/**
@@ -84,7 +84,7 @@ private TCCFenceStoreSqls() {
*/
protected static final String DELETE_BY_DATE_AND_STATUS = "delete from " + LOCAL_TCC_LOG_PLACEHOLD
+ " where gmt_modified < ? "
- + " and status in (" + TCCFenceConstant.STATUS_COMMITTED + " , " + TCCFenceConstant.STATUS_ROLLBACKED + " , " + TCCFenceConstant.STATUS_SUSPENDED + ")"
+ + " and status in (" + CommonFenceConstant.STATUS_COMMITTED + " , " + CommonFenceConstant.STATUS_ROLLBACKED + " , " + CommonFenceConstant.STATUS_SUSPENDED + ")"
+ " limit ?";
public static String getInsertLocalTCCLogSQL(String localTccTable) {
@@ -116,4 +116,4 @@ public static String getDeleteSQLByDateAndStatus(String localTccTable) {
return DELETE_BY_DATE_AND_STATUS.replace(LOCAL_TCC_LOG_PLACEHOLD, localTccTable);
}
-}
+}
\ No newline at end of file
diff --git a/tcc/src/main/java/io/seata/rm/tcc/interceptor/ActionContextFilter.java b/common-api/src/main/java/io/seata/commonapi/interceptor/ActionContextFilter.java
similarity index 89%
rename from tcc/src/main/java/io/seata/rm/tcc/interceptor/ActionContextFilter.java
rename to common-api/src/main/java/io/seata/commonapi/interceptor/ActionContextFilter.java
index 32a6f492161..0b17371e46a 100644
--- a/tcc/src/main/java/io/seata/rm/tcc/interceptor/ActionContextFilter.java
+++ b/common-api/src/main/java/io/seata/commonapi/interceptor/ActionContextFilter.java
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.rm.tcc.interceptor;
+package io.seata.commonapi.interceptor;
-import io.seata.rm.tcc.api.BusinessActionContextParameter;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContextParameter;
/**
* The interface Action context filter.
diff --git a/tcc/src/main/java/io/seata/rm/tcc/interceptor/ActionContextUtil.java b/common-api/src/main/java/io/seata/commonapi/interceptor/ActionContextUtil.java
similarity index 98%
rename from tcc/src/main/java/io/seata/rm/tcc/interceptor/ActionContextUtil.java
rename to common-api/src/main/java/io/seata/commonapi/interceptor/ActionContextUtil.java
index 8b50b52bce9..167d57b6f4c 100644
--- a/tcc/src/main/java/io/seata/rm/tcc/interceptor/ActionContextUtil.java
+++ b/common-api/src/main/java/io/seata/commonapi/interceptor/ActionContextUtil.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.rm.tcc.interceptor;
+package io.seata.commonapi.interceptor;
import java.lang.reflect.Field;
import java.util.Collections;
@@ -28,9 +28,9 @@
import io.seata.common.util.CollectionUtils;
import io.seata.common.util.ReflectionUtil;
import io.seata.common.util.StringUtils;
-import io.seata.rm.tcc.api.BusinessActionContext;
-import io.seata.rm.tcc.api.BusinessActionContextParameter;
-import io.seata.rm.tcc.api.ParamType;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContext;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContextParameter;
+import io.seata.commonapi.rm.tcc.api.ParamType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/tcc/src/main/java/io/seata/rm/tcc/interceptor/ActionInterceptorHandler.java b/common-api/src/main/java/io/seata/commonapi/interceptor/ActionInterceptorHandler.java
similarity index 55%
rename from tcc/src/main/java/io/seata/rm/tcc/interceptor/ActionInterceptorHandler.java
rename to common-api/src/main/java/io/seata/commonapi/interceptor/ActionInterceptorHandler.java
index 3fdec847b63..f387c4d9862 100644
--- a/tcc/src/main/java/io/seata/rm/tcc/interceptor/ActionInterceptorHandler.java
+++ b/common-api/src/main/java/io/seata/commonapi/interceptor/ActionInterceptorHandler.java
@@ -13,15 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.rm.tcc.interceptor;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.lang.reflect.UndeclaredThrowableException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.Nonnull;
+package io.seata.commonapi.interceptor;
import com.alibaba.fastjson.JSON;
import io.seata.common.Constants;
@@ -30,21 +22,34 @@
import io.seata.common.executor.Callback;
import io.seata.common.util.CollectionUtils;
import io.seata.common.util.NetUtil;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContext;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContextParameter;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContextUtil;
+import io.seata.commonapi.rm.tcc.api.ParamType;
+import io.seata.commonapi.fence.CommonFenceHandler;
+import io.seata.commonapi.util.DubboUtil;
+import io.seata.commonapi.util.SpringProxyUtils;
import io.seata.core.context.RootContext;
-import io.seata.core.model.BranchType;
+import io.seata.commonapi.remoting.RemotingDesc;
import io.seata.rm.DefaultResourceManager;
-import io.seata.rm.tcc.TCCFenceHandler;
-import io.seata.rm.tcc.api.BusinessActionContext;
-import io.seata.rm.tcc.api.BusinessActionContextParameter;
-import io.seata.rm.tcc.api.BusinessActionContextUtil;
-import io.seata.rm.tcc.api.ParamType;
-import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
+
+
+import org.aopalliance.intercept.MethodInvocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
/**
- * Handler the TCC Participant Aspect : Setting Context, Creating Branch Record
+ * Handler the Tx Participant Aspect : Setting Context, Creating Branch Record
*
* @author zhangsen
*/
@@ -53,31 +58,33 @@ public class ActionInterceptorHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(ActionInterceptorHandler.class);
/**
- * Handler the TCC Aspect
+ * Handler the Tx Aspect
*
* @param method the method
* @param arguments the arguments
* @param xid the xid
- * @param businessAction the business action
+ * @param businessActionParam the business action params
* @param targetCallback the target callback
* @return the business result
* @throws Throwable the throwable
*/
- public Object proceed(Method method, Object[] arguments, String xid, TwoPhaseBusinessAction businessAction,
- Callback
${project.groupId}
- seata-tcc
+ seata-rm
${project.version}
${project.groupId}
- seata-rm
+ common-api
${project.version}
@@ -64,6 +64,10 @@
org.springframework
spring-context
+
+ org.springframework
+ spring-jdbc
+
org.jetbrains.kotlin
kotlin-stdlib-jdk8
@@ -78,8 +82,10 @@
org.jetbrains.kotlinx
kotlinx-coroutines-core
-
-
+
+ com.alibaba
+ fastjson
+
@@ -102,4 +108,4 @@
-
+
\ No newline at end of file
diff --git a/spring/src/main/java/io/seata/spring/annotation/GlobalTransactionScanner.java b/spring/src/main/java/io/seata/spring/annotation/GlobalTransactionScanner.java
index 852d959e55e..15e0f049f5f 100644
--- a/spring/src/main/java/io/seata/spring/annotation/GlobalTransactionScanner.java
+++ b/spring/src/main/java/io/seata/spring/annotation/GlobalTransactionScanner.java
@@ -25,6 +25,8 @@
import javax.annotation.Nullable;
+import io.seata.commonapi.autoproxy.DefaultTransactionAutoProxy;
+import io.seata.commonapi.autoproxy.IsTransactionProxyResult;
import io.seata.common.util.CollectionUtils;
import io.seata.common.util.StringUtils;
import io.seata.config.ConfigurationCache;
@@ -35,12 +37,11 @@
import io.seata.core.rpc.ShutdownHook;
import io.seata.core.rpc.netty.RmNettyRemotingClient;
import io.seata.core.rpc.netty.TmNettyRemotingClient;
+import io.seata.commonapi.interceptor.TxBeanParserUtils;
import io.seata.rm.RMClient;
import io.seata.spring.annotation.scannercheckers.PackageScannerChecker;
-import io.seata.spring.tcc.TccActionInterceptor;
import io.seata.spring.util.OrderUtil;
-import io.seata.spring.util.SpringProxyUtils;
-import io.seata.spring.util.TCCBeanParserUtils;
+import io.seata.commonapi.util.SpringProxyUtils;
import io.seata.tm.TMClient;
import io.seata.tm.api.FailureHandler;
import org.aopalliance.aop.Advice;
@@ -209,8 +210,8 @@ private void initClient() {
}
if (DEFAULT_TX_GROUP_OLD.equals(txServiceGroup)) {
LOGGER.warn("the default value of seata.tx-service-group: {} has already changed to {} since Seata 1.5, " +
- "please change your default configuration as soon as possible " +
- "and we don't recommend you to use default tx-service-group's value provided by seata",
+ "please change your default configuration as soon as possible " +
+ "and we don't recommend you to use default tx-service-group's value provided by seata",
DEFAULT_TX_GROUP_OLD, DEFAULT_TX_GROUP);
}
if (StringUtils.isNullOrEmpty(applicationId) || StringUtils.isNullOrEmpty(txServiceGroup)) {
@@ -245,23 +246,24 @@ private void registerSpringShutdownHook() {
/**
* The following will be scanned, and added corresponding interceptor:
- *
+ *
* TM:
+ *
* @see io.seata.spring.annotation.GlobalTransactional // TM annotation
* Corresponding interceptor:
* @see io.seata.spring.annotation.GlobalTransactionalInterceptor#handleGlobalTransaction(MethodInvocation, AspectTransactional) // TM handler
- *
+ *
* GlobalLock:
* @see io.seata.spring.annotation.GlobalLock // GlobalLock annotation
* Corresponding interceptor:
* @see io.seata.spring.annotation.GlobalTransactionalInterceptor#handleGlobalLock(MethodInvocation, GlobalLock) // GlobalLock handler
- *
+ *
* TCC mode:
* @see io.seata.rm.tcc.api.LocalTCC // TCC annotation on interface
* @see io.seata.rm.tcc.api.TwoPhaseBusinessAction // TCC annotation on try method
- * @see io.seata.rm.tcc.remoting.RemotingParser // Remote TCC service parser
+ * @see io.seata.spring.remoting.RemotingParser // Remote TCC service parser
* Corresponding interceptor:
- * @see io.seata.spring.tcc.TccActionInterceptor // the interceptor of TCC mode
+ * @see io.seata.rm.tcc.interceptor.TccActionInterceptor // the interceptor of TCC mode
*/
@Override
protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) {
@@ -276,20 +278,21 @@ protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey)
return bean;
}
interceptor = null;
- //check TCC proxy
- if (TCCBeanParserUtils.isTccAutoProxy(bean, beanName, applicationContext)) {
+ //check Transaction proxy
+ if (TxBeanParserUtils.isTxAutoProxy(bean, beanName, applicationContext)) {
+ IsTransactionProxyResult isTransactionProxyResult = DefaultTransactionAutoProxy.get().getIsProxyTargetBeanResult(beanName);
// init tcc fence clean task if enable useTccFence
- TCCBeanParserUtils.initTccFenceCleanTask(TCCBeanParserUtils.getRemotingDesc(beanName), applicationContext);
- //TCC interceptor, proxy bean of sofa:reference/dubbo:reference, and LocalTCC
- interceptor = new TccActionInterceptor(TCCBeanParserUtils.getRemotingDesc(beanName));
+ TxBeanParserUtils.initCommonFenceCleanTask(TxBeanParserUtils.getRemotingDesc(beanName), applicationContext, isTransactionProxyResult.isUseCommonFence());
+ //transaction interceptor(TCC/SAGA), proxy bean of sofa:reference/dubbo:reference, LocalTCC and LocalService
+ interceptor = isTransactionProxyResult.getMethodInterceptor();
ConfigurationCache.addConfigListener(ConfigurationKeys.DISABLE_GLOBAL_TRANSACTION,
- (ConfigurationChangeListener)interceptor);
+ (ConfigurationChangeListener) interceptor);
} else {
Class> serviceInterface = SpringProxyUtils.findTargetClass(bean);
Class>[] interfacesIfJdk = SpringProxyUtils.findInterfaces(bean);
if (!existsAnnotation(new Class[]{serviceInterface})
- && !existsAnnotation(interfacesIfJdk)) {
+ && !existsAnnotation(interfacesIfJdk)) {
return bean;
}
@@ -297,7 +300,7 @@ protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey)
globalTransactionalInterceptor = new GlobalTransactionalInterceptor(failureHandlerHook);
ConfigurationCache.addConfigListener(
ConfigurationKeys.DISABLE_GLOBAL_TRANSACTION,
- (ConfigurationChangeListener)globalTransactionalInterceptor);
+ (ConfigurationChangeListener) globalTransactionalInterceptor);
}
interceptor = globalTransactionalInterceptor;
}
@@ -325,7 +328,7 @@ protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey)
private boolean doCheckers(Object bean, String beanName) {
if (PROXYED_SET.contains(beanName) || EXCLUDE_BEAN_NAME_SET.contains(beanName)
- || FactoryBean.class.isAssignableFrom(bean.getClass())) {
+ || FactoryBean.class.isAssignableFrom(bean.getClass())) {
return false;
}
@@ -406,7 +409,7 @@ private Integer computePositionIfHasTransactionInterceptor(AdvisedSupport advise
Advice seataAdvice = seataAdvisor.getAdvice();
if (SeataInterceptorPosition.AfterTransaction == seataInterceptorPosition && OrderUtil.higherThan(seataOrder, transactionInterceptorOrder)) {
int newSeataOrder = OrderUtil.lower(transactionInterceptorOrder, 1);
- ((SeataInterceptor)seataAdvice).setOrder(newSeataOrder);
+ ((SeataInterceptor) seataAdvice).setOrder(newSeataOrder);
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("The {}'s order '{}' is higher or equals than {}'s order '{}' , reset {}'s order to lower order '{}'.",
seataAdvice.getClass().getSimpleName(), seataOrder,
@@ -417,7 +420,7 @@ private Integer computePositionIfHasTransactionInterceptor(AdvisedSupport advise
return transactionInterceptorPosition + 1;
} else if (SeataInterceptorPosition.BeforeTransaction == seataInterceptorPosition && OrderUtil.lowerThan(seataOrder, transactionInterceptorOrder)) {
int newSeataOrder = OrderUtil.higher(transactionInterceptorOrder, 1);
- ((SeataInterceptor)seataAdvice).setOrder(newSeataOrder);
+ ((SeataInterceptor) seataAdvice).setOrder(newSeataOrder);
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("The {}'s order '{}' is lower or equals than {}'s order '{}' , reset {}'s order to higher order '{}'.",
seataAdvice.getClass().getSimpleName(), seataOrder,
@@ -448,7 +451,7 @@ private int findPositionInAdvisors(Advisor[] advisors, Advisor seataAdvisor) {
private SeataInterceptorPosition getSeataInterceptorPosition(Advisor seataAdvisor) {
Advice seataAdvice = seataAdvisor.getAdvice();
if (seataAdvice instanceof SeataInterceptor) {
- return ((SeataInterceptor)seataAdvice).getPosition();
+ return ((SeataInterceptor) seataAdvice).getPosition();
} else {
return SeataInterceptorPosition.Any;
}
@@ -505,7 +508,7 @@ public void afterPropertiesSet() {
LOGGER.info("Global transaction is disabled.");
}
ConfigurationCache.addConfigListener(ConfigurationKeys.DISABLE_GLOBAL_TRANSACTION,
- (ConfigurationChangeListener)this);
+ (ConfigurationChangeListener) this);
return;
}
if (initialized.compareAndSet(false, true)) {
@@ -558,4 +561,4 @@ public static void addScannerExcludeBeanNames(String... beanNames) {
EXCLUDE_BEAN_NAME_SET.addAll(Arrays.asList(beanNames));
}
}
-}
+}
\ No newline at end of file
diff --git a/spring/src/main/java/io/seata/spring/annotation/GlobalTransactional.java b/spring/src/main/java/io/seata/spring/annotation/GlobalTransactional.java
index 2fb478073e9..40ff30dad0c 100644
--- a/spring/src/main/java/io/seata/spring/annotation/GlobalTransactional.java
+++ b/spring/src/main/java/io/seata/spring/annotation/GlobalTransactional.java
@@ -40,7 +40,7 @@
* @see io.seata.spring.annotation.datasource.SeataAutoDataSourceProxyAdvice#invoke(MethodInvocation) io.seata.spring
* .annotation.datasource.SeataAutoDataSourceProxyAdvice#invoke(MethodInvocation)// RM: the interceptor of
* GlobalLockLogic and AT/XA mode
- * @see io.seata.spring.tcc.TccActionInterceptor#invoke(MethodInvocation) io.seata.spring.tcc
+ * @see io.seata.rm.tcc.interceptor.TccActionInterceptor#invoke(MethodInvocation) io.seata.spring.tcc
* .TccActionInterceptor#invoke(MethodInvocation)// RM: the interceptor of TCC mode
*/
@Retention(RetentionPolicy.RUNTIME)
diff --git a/tcc/pom.xml b/tcc/pom.xml
index 70d8a152bdf..67a7b6707f4 100644
--- a/tcc/pom.xml
+++ b/tcc/pom.xml
@@ -52,5 +52,15 @@
com.alibaba
fastjson
+
+ io.seata
+ seata-spring
+ ${project.version}
+
+
+ ${project.groupId}
+ common-api
+ ${project.version}
+
-
+
\ No newline at end of file
diff --git a/tcc/src/main/java/io/seata/rm/tcc/TCCResourceManager.java b/tcc/src/main/java/io/seata/rm/tcc/TCCResourceManager.java
index f431861e7ce..481dd1b702d 100644
--- a/tcc/src/main/java/io/seata/rm/tcc/TCCResourceManager.java
+++ b/tcc/src/main/java/io/seata/rm/tcc/TCCResourceManager.java
@@ -15,23 +15,23 @@
*/
package io.seata.rm.tcc;
-import java.lang.reflect.Method;
-import java.lang.reflect.UndeclaredThrowableException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import com.alibaba.fastjson.JSON;
import io.seata.common.Constants;
import io.seata.common.exception.ShouldNeverHappenException;
import io.seata.common.exception.SkipCallbackWrapperException;
-import io.seata.common.util.StringUtils;
import io.seata.core.exception.TransactionException;
import io.seata.core.model.BranchStatus;
import io.seata.core.model.BranchType;
import io.seata.core.model.Resource;
+import io.seata.commonapi.fence.CommonFenceHandler;
+import io.seata.commonapi.remoting.TwoPhaseResult;
import io.seata.rm.AbstractResourceManager;
-import io.seata.rm.tcc.api.BusinessActionContext;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContext;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContextUtil;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
/**
* TCC resource manager
@@ -95,15 +95,16 @@ public BranchStatus branchCommit(BranchType branchType, String xid, long branchI
}
try {
//BusinessActionContext
- BusinessActionContext businessActionContext = getBusinessActionContext(xid, branchId, resourceId,
- applicationData);
+ BusinessActionContext businessActionContext = BusinessActionContextUtil.getBusinessActionContext(xid, branchId, resourceId,
+ applicationData);
+
Object[] args = this.getTwoPhaseCommitArgs(tccResource, businessActionContext);
Object ret;
boolean result;
// add idempotent and anti hanging
- if (Boolean.TRUE.equals(businessActionContext.getActionContext(Constants.USE_TCC_FENCE))) {
+ if (Boolean.TRUE.equals(businessActionContext.getActionContext(Constants.USE_COMMON_FENCE))) {
try {
- result = TCCFenceHandler.commitFence(commitMethod, targetTCCBean, xid, branchId, args);
+ result = CommonFenceHandler.commitFence(commitMethod, targetTCCBean, xid, branchId, args);
} catch (SkipCallbackWrapperException | UndeclaredThrowableException e) {
throw e.getCause();
}
@@ -153,15 +154,15 @@ public BranchStatus branchRollback(BranchType branchType, String xid, long branc
}
try {
//BusinessActionContext
- BusinessActionContext businessActionContext = getBusinessActionContext(xid, branchId, resourceId,
- applicationData);
+ BusinessActionContext businessActionContext = BusinessActionContextUtil.getBusinessActionContext(xid, branchId, resourceId,
+ applicationData);
Object[] args = this.getTwoPhaseRollbackArgs(tccResource, businessActionContext);
Object ret;
boolean result;
// add idempotent and anti hanging
- if (Boolean.TRUE.equals(businessActionContext.getActionContext(Constants.USE_TCC_FENCE))) {
+ if (Boolean.TRUE.equals(businessActionContext.getActionContext(Constants.USE_COMMON_FENCE))) {
try {
- result = TCCFenceHandler.rollbackFence(rollbackMethod, targetTCCBean, xid, branchId,
+ result = CommonFenceHandler.rollbackFence(rollbackMethod, targetTCCBean, xid, branchId,
args, tccResource.getActionName());
} catch (SkipCallbackWrapperException | UndeclaredThrowableException e) {
throw e.getCause();
@@ -187,33 +188,6 @@ public BranchStatus branchRollback(BranchType branchType, String xid, long branc
}
}
- /**
- * transfer tcc applicationData to BusinessActionContext
- *
- * @param xid the xid
- * @param branchId the branch id
- * @param resourceId the resource id
- * @param applicationData the application data
- * @return business action context
- */
- protected BusinessActionContext getBusinessActionContext(String xid, long branchId, String resourceId,
- String applicationData) {
- Map actionContextMap = null;
- if (StringUtils.isNotBlank(applicationData)) {
- Map tccContext = JSON.parseObject(applicationData, Map.class);
- actionContextMap = (Map)tccContext.get(Constants.TCC_ACTION_CONTEXT);
- }
- if (actionContextMap == null) {
- actionContextMap = new HashMap<>(2);
- }
-
- //instance the action context
- BusinessActionContext businessActionContext = new BusinessActionContext(
- xid, String.valueOf(branchId), actionContextMap);
- businessActionContext.setActionName(resourceId);
- return businessActionContext;
- }
-
/**
* get phase two commit method's args
* @param tccResource tccResource
@@ -223,7 +197,7 @@ protected BusinessActionContext getBusinessActionContext(String xid, long branch
private Object[] getTwoPhaseCommitArgs(TCCResource tccResource, BusinessActionContext businessActionContext) {
String[] keys = tccResource.getPhaseTwoCommitKeys();
Class>[] argsCommitClasses = tccResource.getCommitArgsClasses();
- return this.getTwoPhaseMethodParams(keys, argsCommitClasses, businessActionContext);
+ return BusinessActionContextUtil.getTwoPhaseMethodParams(keys, argsCommitClasses, businessActionContext);
}
/**
@@ -235,23 +209,11 @@ private Object[] getTwoPhaseCommitArgs(TCCResource tccResource, BusinessActionCo
private Object[] getTwoPhaseRollbackArgs(TCCResource tccResource, BusinessActionContext businessActionContext) {
String[] keys = tccResource.getPhaseTwoRollbackKeys();
Class>[] argsRollbackClasses = tccResource.getRollbackArgsClasses();
- return this.getTwoPhaseMethodParams(keys, argsRollbackClasses, businessActionContext);
- }
-
- private Object[] getTwoPhaseMethodParams(String[] keys, Class>[] argsClasses, BusinessActionContext businessActionContext) {
- Object[] args = new Object[argsClasses.length];
- for (int i = 0; i < argsClasses.length; i++) {
- if (argsClasses[i].equals(BusinessActionContext.class)) {
- args[i] = businessActionContext;
- } else {
- args[i] = businessActionContext.getActionContext(keys[i], argsClasses[i]);
- }
- }
- return args;
+ return BusinessActionContextUtil.getTwoPhaseMethodParams(keys, argsRollbackClasses, businessActionContext);
}
@Override
public BranchType getBranchType() {
return BranchType.TCC;
}
-}
+}
\ No newline at end of file
diff --git a/tcc/src/main/java/io/seata/rm/tcc/api/LocalTCC.java b/tcc/src/main/java/io/seata/rm/tcc/api/LocalTCC.java
index 4b3be4ea139..2a8ee88c40a 100644
--- a/tcc/src/main/java/io/seata/rm/tcc/api/LocalTCC.java
+++ b/tcc/src/main/java/io/seata/rm/tcc/api/LocalTCC.java
@@ -15,6 +15,8 @@
*/
package io.seata.rm.tcc.api;
+import io.seata.rm.tcc.remoting.parser.LocalTCCRemotingParser;
+
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
@@ -26,7 +28,7 @@
*
* @author zhangsen
* @see io.seata.spring.annotation.GlobalTransactionScanner#wrapIfNecessary(Object, String, Object) // the scanner for TM, GlobalLock, and TCC mode
- * @see io.seata.rm.tcc.remoting.parser.LocalTCCRemotingParser // the RemotingParser impl for LocalTCC
+ * @see LocalTCCRemotingParser // the RemotingParser impl for LocalTCC
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
diff --git a/tcc/src/main/java/io/seata/rm/tcc/api/TwoPhaseBusinessAction.java b/tcc/src/main/java/io/seata/rm/tcc/api/TwoPhaseBusinessAction.java
index 0bc714b7b6e..0f30d5aaf63 100644
--- a/tcc/src/main/java/io/seata/rm/tcc/api/TwoPhaseBusinessAction.java
+++ b/tcc/src/main/java/io/seata/rm/tcc/api/TwoPhaseBusinessAction.java
@@ -15,6 +15,11 @@
*/
package io.seata.rm.tcc.api;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContext;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContextParameter;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContextUtil;
+import io.seata.rm.tcc.interceptor.TccActionInterceptor;
+
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
@@ -29,7 +34,7 @@
* @author zhangsen
* @see io.seata.rm.tcc.api.LocalTCC // TCC annotation, which added on the TCC interface. It can't be left out.
* @see io.seata.spring.annotation.GlobalTransactionScanner#wrapIfNecessary(Object, String, Object) // the scanner for TM, GlobalLock, and TCC mode
- * @see io.seata.spring.tcc.TccActionInterceptor // the interceptor of TCC mode
+ * @see TccActionInterceptor // the interceptor of TCC mode
* @see BusinessActionContext
* @see BusinessActionContextUtil
* @see BusinessActionContextParameter
diff --git a/tcc/src/main/java/io/seata/rm/tcc/autoproxy/TccTransactionAutoProxy.java b/tcc/src/main/java/io/seata/rm/tcc/autoproxy/TccTransactionAutoProxy.java
new file mode 100644
index 00000000000..8f452f1c927
--- /dev/null
+++ b/tcc/src/main/java/io/seata/rm/tcc/autoproxy/TccTransactionAutoProxy.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright 1999-2019 Seata.io Group.
+ *
+ * Licensed 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 io.seata.rm.tcc.autoproxy;
+
+import io.seata.commonapi.autoproxy.IsTransactionProxyResult;
+import io.seata.commonapi.autoproxy.TransactionAutoProxy;
+import io.seata.common.exception.FrameworkException;
+import io.seata.commonapi.remoting.Protocols;
+import io.seata.commonapi.remoting.RemotingDesc;
+import io.seata.commonapi.remoting.parser.DefaultRemotingParser;
+import io.seata.rm.DefaultResourceManager;
+import io.seata.rm.tcc.TCCResource;
+import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
+import io.seata.rm.tcc.interceptor.TccActionInterceptor;
+import io.seata.rm.tcc.interceptor.TccManualApiExecute;
+
+import java.lang.reflect.Method;
+
+/**
+ * the tcc implements of TransactionAutoProxy
+ *
+ * @author ruishansun
+ */
+public class TccTransactionAutoProxy implements TransactionAutoProxy {
+
+ /**
+ * is TCC proxy-bean/target-bean: LocalTCC , the proxy bean of sofa:reference/dubbo:reference
+ *
+ * @param remotingDesc the remoting desc
+ * @return boolean
+ */
+ @Override
+ public IsTransactionProxyResult isTransactionProxyTargetBean(RemotingDesc remotingDesc) {
+ if (remotingDesc == null) {
+ return new IsTransactionProxyResult();
+ }
+ //check if it is TCC bean
+ boolean isTccClazz = false;
+ boolean userFence = false;
+ Class> tccServiceClazz = remotingDesc.getServiceClass();
+ Method[] methods = tccServiceClazz.getMethods();
+ TwoPhaseBusinessAction twoPhaseBusinessAction;
+ for (Method method : methods) {
+ twoPhaseBusinessAction = method.getAnnotation(TwoPhaseBusinessAction.class);
+ if (twoPhaseBusinessAction != null) {
+ isTccClazz = true;
+ if (twoPhaseBusinessAction.useTCCFence()) {
+ userFence = true;
+ }
+ break;
+ }
+ }
+ if (!isTccClazz) {
+ return new IsTransactionProxyResult();
+ }
+
+ if (// LocalTCC in jvm TCC bean , AOP
+ Protocols.IN_JVM == remotingDesc.getProtocol()
+ // sofa:reference / dubbo:reference, AOP
+ || remotingDesc.isReference()) {
+ this.registryResource(remotingDesc);
+ IsTransactionProxyResult result = new IsTransactionProxyResult();
+ result.setProxyTargetBean(true);
+ result.setUseCommonFence(userFence);
+ result.setMethodInterceptor(new TccActionInterceptor(remotingDesc));
+ result.setManualApiExecute(new TccManualApiExecute());
+ return result;
+ }
+ return new IsTransactionProxyResult();
+
+ }
+
+ private void registryResource(RemotingDesc remotingDesc) {
+ if (remotingDesc.isService()) {
+ try {
+ Class> tccServiceClazz = remotingDesc.getServiceClass();
+ Method[] methods = tccServiceClazz.getMethods();
+ //service bean, registry resource
+ Object targetBean = remotingDesc.getTargetBean();
+ for (Method m : methods) {
+ TwoPhaseBusinessAction twoPhaseBusinessAction = m.getAnnotation(TwoPhaseBusinessAction.class);
+ if (twoPhaseBusinessAction != null) {
+ TCCResource tccResource = new TCCResource();
+ tccResource.setActionName(twoPhaseBusinessAction.name());
+ tccResource.setTargetBean(targetBean);
+ tccResource.setPrepareMethod(m);
+ tccResource.setCommitMethodName(twoPhaseBusinessAction.commitMethod());
+ tccResource.setCommitMethod(tccServiceClazz.getMethod(twoPhaseBusinessAction.commitMethod(),
+ twoPhaseBusinessAction.commitArgsClasses()));
+ tccResource.setRollbackMethodName(twoPhaseBusinessAction.rollbackMethod());
+ tccResource.setRollbackMethod(tccServiceClazz.getMethod(twoPhaseBusinessAction.rollbackMethod(),
+ twoPhaseBusinessAction.rollbackArgsClasses()));
+ // set argsClasses
+ tccResource.setCommitArgsClasses(twoPhaseBusinessAction.commitArgsClasses());
+ tccResource.setRollbackArgsClasses(twoPhaseBusinessAction.rollbackArgsClasses());
+ // set phase two method's keys
+ tccResource.setPhaseTwoCommitKeys(DefaultRemotingParser.get().getTwoPhaseArgs(tccResource.getCommitMethod(),
+ twoPhaseBusinessAction.commitArgsClasses()));
+ tccResource.setPhaseTwoRollbackKeys(DefaultRemotingParser.get().getTwoPhaseArgs(tccResource.getRollbackMethod(),
+ twoPhaseBusinessAction.rollbackArgsClasses()));
+ //registry tcc resource
+ DefaultResourceManager.get().registerResource(tccResource);
+ }
+ }
+ } catch (Throwable t) {
+ throw new FrameworkException(t, "parser remoting service error");
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/spring/src/main/java/io/seata/spring/tcc/TccActionInterceptor.java b/tcc/src/main/java/io/seata/rm/tcc/interceptor/TccActionInterceptor.java
similarity index 62%
rename from spring/src/main/java/io/seata/spring/tcc/TccActionInterceptor.java
rename to tcc/src/main/java/io/seata/rm/tcc/interceptor/TccActionInterceptor.java
index b09f282ec72..36b95a9560f 100644
--- a/spring/src/main/java/io/seata/spring/tcc/TccActionInterceptor.java
+++ b/tcc/src/main/java/io/seata/rm/tcc/interceptor/TccActionInterceptor.java
@@ -13,11 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.spring.tcc;
-
-import java.lang.reflect.Method;
-import javax.annotation.Nullable;
+package io.seata.rm.tcc.interceptor;
+import io.seata.common.Constants;
import io.seata.common.DefaultValues;
import io.seata.config.ConfigurationChangeEvent;
import io.seata.config.ConfigurationChangeListener;
@@ -25,11 +23,10 @@
import io.seata.core.constants.ConfigurationKeys;
import io.seata.core.context.RootContext;
import io.seata.core.model.BranchType;
+import io.seata.commonapi.interceptor.ActionInterceptorHandler;
+import io.seata.commonapi.interceptor.TwoPhaseBusinessActionParam;
+import io.seata.commonapi.remoting.RemotingDesc;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
-import io.seata.rm.tcc.interceptor.ActionInterceptorHandler;
-import io.seata.rm.tcc.remoting.RemotingDesc;
-import io.seata.rm.tcc.remoting.parser.DubboUtil;
-import io.seata.spring.util.SpringProxyUtils;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.slf4j.Logger;
@@ -37,6 +34,10 @@
import org.slf4j.MDC;
import org.springframework.core.Ordered;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
import static io.seata.common.DefaultValues.DEFAULT_DISABLE_GLOBAL_TRANSACTION;
import static io.seata.core.constants.ConfigurationKeys.TCC_ACTION_INTERCEPTOR_ORDER;
@@ -55,7 +56,7 @@ public class TccActionInterceptor implements MethodInterceptor, ConfigurationCha
private ActionInterceptorHandler actionInterceptorHandler = new ActionInterceptorHandler();
private volatile boolean disable = ConfigurationFactory.getInstance().getBoolean(
- ConfigurationKeys.DISABLE_GLOBAL_TRANSACTION, DEFAULT_DISABLE_GLOBAL_TRANSACTION);
+ ConfigurationKeys.DISABLE_GLOBAL_TRANSACTION, DEFAULT_DISABLE_GLOBAL_TRANSACTION);
/**
* remoting bean info
@@ -83,7 +84,7 @@ public Object invoke(final MethodInvocation invocation) throws Throwable {
//not in transaction, or this interceptor is disabled
return invocation.proceed();
}
- Method method = getActionInterfaceMethod(invocation);
+ Method method = actionInterceptorHandler.getActionInterfaceMethod(invocation, this.remotingDesc);
TwoPhaseBusinessAction businessAction = method.getAnnotation(TwoPhaseBusinessAction.class);
//try method
if (businessAction != null) {
@@ -96,8 +97,20 @@ public Object invoke(final MethodInvocation invocation) throws Throwable {
RootContext.bindBranchType(BranchType.TCC);
}
try {
+ TwoPhaseBusinessActionParam businessActionParam = new TwoPhaseBusinessActionParam();
+ businessActionParam.setActionName(businessAction.name());
+ businessActionParam.setDelayReport(businessAction.isDelayReport());
+ businessActionParam.setUseCommonFence(businessAction.useTCCFence());
+ businessActionParam.setBranchType(BranchType.TCC);
+ Map businessActionContextMap = new HashMap<>(4);
+ //the phase two method name
+ businessActionContextMap.put(Constants.COMMIT_METHOD, businessAction.commitMethod());
+ businessActionContextMap.put(Constants.ROLLBACK_METHOD, businessAction.rollbackMethod());
+ businessActionContextMap.put(Constants.ACTION_NAME, businessAction.name());
+ businessActionContextMap.put(Constants.USE_COMMON_FENCE, businessAction.useTCCFence());
+ businessActionParam.setBusinessActionContext(businessActionContextMap);
//Handler the TCC Aspect, and return the business result
- return actionInterceptorHandler.proceed(method, invocation.getArguments(), xid, businessAction,
+ return actionInterceptorHandler.proceed(method, invocation.getArguments(), xid, businessActionParam,
invocation::proceed);
} finally {
//if not TCC, unbind branchType
@@ -113,63 +126,11 @@ public Object invoke(final MethodInvocation invocation) throws Throwable {
return invocation.proceed();
}
- /**
- * get the method from interface
- *
- * @param invocation the invocation
- * @return the action interface method
- */
- protected Method getActionInterfaceMethod(MethodInvocation invocation) {
- Class> serviceType = null;
- try {
- if (remotingDesc == null) {
- serviceType = getProxyInterface(invocation.getThis());
- } else {
- serviceType = remotingDesc.getServiceClass();
- }
- if (serviceType == null && remotingDesc != null && remotingDesc.getServiceClassName() != null) {
- serviceType = Class.forName(remotingDesc.getServiceClassName(), true,
- Thread.currentThread().getContextClassLoader());
- }
- if (serviceType == null) {
- return invocation.getMethod();
- }
- return serviceType.getMethod(invocation.getMethod().getName(),
- invocation.getMethod().getParameterTypes());
- } catch (NoSuchMethodException e) {
- if (serviceType != null && !"toString".equals(invocation.getMethod().getName())) {
- LOGGER.warn("no such method '{}' from interface {}", invocation.getMethod().getName(), serviceType.getName());
- }
- return invocation.getMethod();
- } catch (Exception e) {
- LOGGER.warn("get Method from interface failed", e);
- return invocation.getMethod();
- }
- }
-
- /**
- * get the interface of proxy
- *
- * @param proxyBean the proxy bean
- * @return proxy interface
- * @throws Exception the exception
- */
- @Nullable
- protected Class> getProxyInterface(Object proxyBean) throws Exception {
- if (DubboUtil.isDubboProxyName(proxyBean.getClass().getName())) {
- //dubbo javaassist proxy
- return DubboUtil.getAssistInterface(proxyBean);
- } else {
- //jdk/cglib proxy
- return SpringProxyUtils.getTargetInterface(proxyBean);
- }
- }
-
@Override
public void onChangeEvent(ConfigurationChangeEvent event) {
if (ConfigurationKeys.DISABLE_GLOBAL_TRANSACTION.equals(event.getDataId())) {
LOGGER.info("{} config changed, old value:{}, new value:{}", ConfigurationKeys.DISABLE_GLOBAL_TRANSACTION,
- disable, event.getNewValue());
+ disable, event.getNewValue());
disable = Boolean.parseBoolean(event.getNewValue().trim());
}
}
@@ -178,4 +139,4 @@ public void onChangeEvent(ConfigurationChangeEvent event) {
public int getOrder() {
return ORDER_NUM;
}
-}
+}
\ No newline at end of file
diff --git a/tcc/src/main/java/io/seata/rm/tcc/interceptor/TccManualApiExecute.java b/tcc/src/main/java/io/seata/rm/tcc/interceptor/TccManualApiExecute.java
new file mode 100644
index 00000000000..1b447317474
--- /dev/null
+++ b/tcc/src/main/java/io/seata/rm/tcc/interceptor/TccManualApiExecute.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 1999-2019 Seata.io Group.
+ *
+ * Licensed 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 io.seata.rm.tcc.interceptor;
+
+import io.seata.commonapi.autoproxy.ManualApiExecute;
+import io.seata.common.Constants;
+import io.seata.core.context.RootContext;
+import io.seata.core.model.BranchType;
+import io.seata.commonapi.interceptor.ActionInterceptorHandler;
+import io.seata.commonapi.interceptor.TwoPhaseBusinessActionParam;
+import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+public class TccManualApiExecute implements ManualApiExecute {
+
+ private ActionInterceptorHandler actionInterceptorHandler;
+
+ @Override
+ public void manualApiBefore(Method method, Object[] arguments) throws Throwable {
+
+ TwoPhaseBusinessAction businessAction = method.getAnnotation(TwoPhaseBusinessAction.class);
+ if (businessAction != null) {
+ //save the xid
+ String xid = RootContext.getXID();
+ //save the previous branchType
+ BranchType previousBranchType = RootContext.getBranchType();
+ //if not TCC, bind TCC branchType
+ if (BranchType.TCC != previousBranchType) {
+ RootContext.bindBranchType(BranchType.TCC);
+ }
+
+ TwoPhaseBusinessActionParam businessActionParam = new TwoPhaseBusinessActionParam();
+ businessActionParam.setActionName(businessAction.name());
+ businessActionParam.setDelayReport(businessAction.isDelayReport());
+ businessActionParam.setUseCommonFence(businessAction.useTCCFence());
+ businessActionParam.setBranchType(BranchType.TCC);
+ Map businessActionContextMap = new HashMap<>(4);
+ //the phase two method name
+ businessActionContextMap.put(Constants.COMMIT_METHOD, businessAction.commitMethod());
+ businessActionContextMap.put(Constants.ROLLBACK_METHOD, businessAction.rollbackMethod());
+ businessActionContextMap.put(Constants.ACTION_NAME, businessAction.name());
+ businessActionContextMap.put(Constants.USE_COMMON_FENCE, businessAction.useTCCFence());
+ businessActionParam.setBusinessActionContext(businessActionContextMap);
+ //Handler the TCC Aspect, and return the business result
+ if (actionInterceptorHandler == null) {
+ actionInterceptorHandler = new ActionInterceptorHandler();
+ }
+ actionInterceptorHandler.proceedManual(method, arguments, xid, businessActionParam);
+ }
+ }
+}
diff --git a/tcc/src/main/java/io/seata/rm/tcc/remoting/parser/LocalTCCRemotingParser.java b/tcc/src/main/java/io/seata/rm/tcc/remoting/parser/LocalTCCRemotingParser.java
index 7a966df29b5..f950201e2fa 100644
--- a/tcc/src/main/java/io/seata/rm/tcc/remoting/parser/LocalTCCRemotingParser.java
+++ b/tcc/src/main/java/io/seata/rm/tcc/remoting/parser/LocalTCCRemotingParser.java
@@ -15,15 +15,16 @@
*/
package io.seata.rm.tcc.remoting.parser;
-import java.util.Set;
-
import io.seata.common.exception.FrameworkException;
import io.seata.common.util.ReflectionUtil;
+import io.seata.commonapi.remoting.Protocols;
+import io.seata.commonapi.remoting.RemotingDesc;
+import io.seata.commonapi.remoting.parser.AbstractedRemotingParser;
import io.seata.rm.tcc.api.LocalTCC;
-import io.seata.rm.tcc.remoting.Protocols;
-import io.seata.rm.tcc.remoting.RemotingDesc;
import org.springframework.aop.framework.AopProxyUtils;
+import java.util.Set;
+
/**
* local tcc bean parsing
*
@@ -47,7 +48,8 @@ public RemotingDesc getServiceDesc(Object bean, String beanName) throws Framewor
return null;
}
RemotingDesc remotingDesc = new RemotingDesc();
- remotingDesc.setReference(true);
+ remotingDesc.setReference(this.isReference(bean, beanName));
+ remotingDesc.setService(this.isService(bean, beanName));
remotingDesc.setProtocol(Protocols.IN_JVM);
Class> classType = bean.getClass();
// check if LocalTCC annotation is marked on the implementation class
@@ -90,4 +92,4 @@ private boolean isLocalTCC(Object bean) {
}
return classType.isAnnotationPresent(LocalTCC.class);
}
-}
+}
\ No newline at end of file
diff --git a/tcc/src/main/resources/META-INF/services/io.seata.rm.tcc.remoting.RemotingParser b/tcc/src/main/resources/META-INF/services/io.seata.rm.tcc.remoting.RemotingParser
deleted file mode 100644
index 30ef923192e..00000000000
--- a/tcc/src/main/resources/META-INF/services/io.seata.rm.tcc.remoting.RemotingParser
+++ /dev/null
@@ -1,4 +0,0 @@
-io.seata.rm.tcc.remoting.parser.DubboRemotingParser
-io.seata.rm.tcc.remoting.parser.LocalTCCRemotingParser
-io.seata.rm.tcc.remoting.parser.SofaRpcRemotingParser
-io.seata.rm.tcc.remoting.parser.HSFRemotingParser
\ No newline at end of file
diff --git a/tcc/src/test/java/io/seata/rm/tcc/TccAction.java b/tcc/src/test/java/io/seata/rm/tcc/TccAction.java
index 94f22365fa2..1f6dfe5c3c6 100644
--- a/tcc/src/test/java/io/seata/rm/tcc/TccAction.java
+++ b/tcc/src/test/java/io/seata/rm/tcc/TccAction.java
@@ -15,8 +15,8 @@
*/
package io.seata.rm.tcc;
-import io.seata.rm.tcc.api.BusinessActionContext;
-import io.seata.rm.tcc.api.BusinessActionContextParameter;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContext;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
diff --git a/tcc/src/test/java/io/seata/rm/tcc/TccActionImpl.java b/tcc/src/test/java/io/seata/rm/tcc/TccActionImpl.java
index 81646bda9fb..e6ab96218f5 100644
--- a/tcc/src/test/java/io/seata/rm/tcc/TccActionImpl.java
+++ b/tcc/src/test/java/io/seata/rm/tcc/TccActionImpl.java
@@ -15,8 +15,8 @@
*/
package io.seata.rm.tcc;
-import io.seata.rm.tcc.api.BusinessActionContext;
-import io.seata.rm.tcc.api.BusinessActionContextParameter;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContext;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContextParameter;
import java.util.List;
diff --git a/tcc/src/test/java/io/seata/rm/tcc/TccParam.java b/tcc/src/test/java/io/seata/rm/tcc/TccParam.java
index c5013a4958a..98168a4fc44 100644
--- a/tcc/src/test/java/io/seata/rm/tcc/TccParam.java
+++ b/tcc/src/test/java/io/seata/rm/tcc/TccParam.java
@@ -15,7 +15,7 @@
*/
package io.seata.rm.tcc;
-import io.seata.rm.tcc.api.BusinessActionContextParameter;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContextParameter;
/**
* The type Tcc param.
diff --git a/tcc/src/test/java/io/seata/rm/tcc/interceptor/ActionInterceptorHandlerTest.java b/tcc/src/test/java/io/seata/rm/tcc/interceptor/ActionInterceptorHandlerTest.java
index 1fb8f1b5fb8..5da62c20f67 100644
--- a/tcc/src/test/java/io/seata/rm/tcc/interceptor/ActionInterceptorHandlerTest.java
+++ b/tcc/src/test/java/io/seata/rm/tcc/interceptor/ActionInterceptorHandlerTest.java
@@ -15,9 +15,10 @@
*/
package io.seata.rm.tcc.interceptor;
+import io.seata.commonapi.interceptor.ActionInterceptorHandler;
import io.seata.rm.tcc.TccAction;
import io.seata.rm.tcc.TccParam;
-import io.seata.rm.tcc.api.BusinessActionContext;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContext;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -36,7 +37,7 @@ public class ActionInterceptorHandlerTest {
/**
* The Action interceptor handler.
*/
- protected ActionInterceptorHandler actionInterceptorHandler = new ActionInterceptorHandler();
+ protected ActionInterceptorHandler actionInterceptorHandler = new ActionInterceptorHandler();
/**
* Test business action context.
diff --git a/tcc/src/test/java/io/seata/rm/tcc/remoting/parser/DefaultRemotingParserTest.java b/tcc/src/test/java/io/seata/rm/tcc/remoting/parser/DefaultRemotingParserTest.java
index 33e493af265..04b62fd0e7a 100644
--- a/tcc/src/test/java/io/seata/rm/tcc/remoting/parser/DefaultRemotingParserTest.java
+++ b/tcc/src/test/java/io/seata/rm/tcc/remoting/parser/DefaultRemotingParserTest.java
@@ -15,8 +15,9 @@
*/
package io.seata.rm.tcc.remoting.parser;
+import io.seata.commonapi.remoting.parser.DefaultRemotingParser;
import io.seata.rm.tcc.TccParam;
-import io.seata.rm.tcc.api.BusinessActionContext;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContext;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -24,7 +25,7 @@
public class DefaultRemotingParserTest {
- DefaultRemotingParser defaultRemotingParser = new DefaultRemotingParser();
+ DefaultRemotingParser defaultRemotingParser = DefaultRemotingParser.get();
@Test
public void testGetTwoPhaseArgs() throws Exception {
@@ -41,4 +42,4 @@ public void testGetTwoPhaseArgs() throws Exception {
Assertions.assertEquals("tccParam", keys[1]);
}
-}
+}
\ No newline at end of file
diff --git a/tcc/src/test/java/io/seata/rm/tcc/remoting/parser/LocalTCCRemotingParserTest.java b/tcc/src/test/java/io/seata/rm/tcc/remoting/parser/LocalTCCRemotingParserTest.java
index 6618c3395c0..0d26f65c04c 100644
--- a/tcc/src/test/java/io/seata/rm/tcc/remoting/parser/LocalTCCRemotingParserTest.java
+++ b/tcc/src/test/java/io/seata/rm/tcc/remoting/parser/LocalTCCRemotingParserTest.java
@@ -15,9 +15,9 @@
*/
package io.seata.rm.tcc.remoting.parser;
+import io.seata.commonapi.remoting.RemotingDesc;
import io.seata.rm.tcc.TccAction;
import io.seata.rm.tcc.TccActionImpl;
-import io.seata.rm.tcc.remoting.RemotingDesc;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
diff --git a/spring/src/test/java/io/seata/spring/annotation/Business.java b/tcc/src/test/java/io/seata/rm/tcc/spring/Business.java
similarity index 95%
rename from spring/src/test/java/io/seata/spring/annotation/Business.java
rename to tcc/src/test/java/io/seata/rm/tcc/spring/Business.java
index aaa351d03a3..2ad498f4d9e 100644
--- a/spring/src/test/java/io/seata/spring/annotation/Business.java
+++ b/tcc/src/test/java/io/seata/rm/tcc/spring/Business.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.spring.annotation;
+package io.seata.rm.tcc.spring;
/**
* The interface Business.
diff --git a/spring/src/test/java/io/seata/spring/annotation/BusinessImpl.java b/tcc/src/test/java/io/seata/rm/tcc/spring/BusinessImpl.java
similarity index 92%
rename from spring/src/test/java/io/seata/spring/annotation/BusinessImpl.java
rename to tcc/src/test/java/io/seata/rm/tcc/spring/BusinessImpl.java
index 2ac53976727..15c8e5b27c1 100644
--- a/spring/src/test/java/io/seata/spring/annotation/BusinessImpl.java
+++ b/tcc/src/test/java/io/seata/rm/tcc/spring/BusinessImpl.java
@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.spring.annotation;
+package io.seata.rm.tcc.spring;
+import io.seata.spring.annotation.GlobalTransactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/spring/src/test/java/io/seata/spring/annotation/BusinessProxy.java b/tcc/src/test/java/io/seata/rm/tcc/spring/BusinessProxy.java
similarity index 97%
rename from spring/src/test/java/io/seata/spring/annotation/BusinessProxy.java
rename to tcc/src/test/java/io/seata/rm/tcc/spring/BusinessProxy.java
index 14e0043e06a..6eb4cc798e8 100644
--- a/spring/src/test/java/io/seata/spring/annotation/BusinessProxy.java
+++ b/tcc/src/test/java/io/seata/rm/tcc/spring/BusinessProxy.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.spring.annotation;
+package io.seata.rm.tcc.spring;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
diff --git a/tcc/src/test/java/io/seata/rm/tcc/spring/GlobalTransactionScannerSub.java b/tcc/src/test/java/io/seata/rm/tcc/spring/GlobalTransactionScannerSub.java
new file mode 100644
index 00000000000..c3667a6d823
--- /dev/null
+++ b/tcc/src/test/java/io/seata/rm/tcc/spring/GlobalTransactionScannerSub.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 1999-2019 Seata.io Group.
+ *
+ * Licensed 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 io.seata.rm.tcc.spring;
+
+import io.seata.spring.annotation.GlobalTransactionScanner;
+
+/**
+ * the subclass of GlobalTransactionScanner for test public method wrapIfNecessary
+ */
+public class GlobalTransactionScannerSub extends GlobalTransactionScanner {
+
+
+ public GlobalTransactionScannerSub(String txServiceGroup) {
+ super(txServiceGroup);
+ }
+
+ public Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) {
+ return super.wrapIfNecessary(bean, beanName, cacheKey);
+ }
+}
diff --git a/spring/src/test/java/io/seata/spring/annotation/GlobalTransactionScannerTest.java b/tcc/src/test/java/io/seata/rm/tcc/spring/GlobalTransactionScannerTest.java
similarity index 91%
rename from spring/src/test/java/io/seata/spring/annotation/GlobalTransactionScannerTest.java
rename to tcc/src/test/java/io/seata/rm/tcc/spring/GlobalTransactionScannerTest.java
index 1ab5b9927be..523247ab6c5 100644
--- a/spring/src/test/java/io/seata/spring/annotation/GlobalTransactionScannerTest.java
+++ b/tcc/src/test/java/io/seata/rm/tcc/spring/GlobalTransactionScannerTest.java
@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.spring.annotation;
+package io.seata.rm.tcc.spring;
-import io.seata.spring.tcc.LocalTccAction;
-import io.seata.spring.tcc.LocalTccActionImpl;
-import io.seata.spring.tcc.TccAction;
-import io.seata.spring.tcc.TccActionImpl;
+import io.seata.rm.tcc.spring.tcc.LocalTccAction;
+import io.seata.rm.tcc.spring.tcc.LocalTccActionImpl;
+import io.seata.rm.tcc.spring.tcc.TccAction;
+import io.seata.rm.tcc.spring.tcc.TccActionImpl;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
@@ -34,7 +34,7 @@ public class GlobalTransactionScannerTest {
/**
* The Global transaction scanner.
*/
- protected GlobalTransactionScanner globalTransactionScanner = new GlobalTransactionScanner("global-trans-scanner-test");
+ protected GlobalTransactionScannerSub globalTransactionScanner = new GlobalTransactionScannerSub("global-trans-scanner-test");
/**
* Test wrap normal bean.
diff --git a/spring/src/test/java/io/seata/spring/tcc/LocalTccAction.java b/tcc/src/test/java/io/seata/rm/tcc/spring/tcc/LocalTccAction.java
similarity index 95%
rename from spring/src/test/java/io/seata/spring/tcc/LocalTccAction.java
rename to tcc/src/test/java/io/seata/rm/tcc/spring/tcc/LocalTccAction.java
index 4fdeb378a18..a3a2fb33473 100644
--- a/spring/src/test/java/io/seata/spring/tcc/LocalTccAction.java
+++ b/tcc/src/test/java/io/seata/rm/tcc/spring/tcc/LocalTccAction.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.spring.tcc;
+package io.seata.rm.tcc.spring.tcc;
import io.seata.rm.tcc.api.LocalTCC;
diff --git a/spring/src/test/java/io/seata/spring/tcc/LocalTccActionImpl.java b/tcc/src/test/java/io/seata/rm/tcc/spring/tcc/LocalTccActionImpl.java
similarity index 95%
rename from spring/src/test/java/io/seata/spring/tcc/LocalTccActionImpl.java
rename to tcc/src/test/java/io/seata/rm/tcc/spring/tcc/LocalTccActionImpl.java
index e693c1e92cc..2b9c4091b70 100644
--- a/spring/src/test/java/io/seata/spring/tcc/LocalTccActionImpl.java
+++ b/tcc/src/test/java/io/seata/rm/tcc/spring/tcc/LocalTccActionImpl.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.spring.tcc;
+package io.seata.rm.tcc.spring.tcc;
/**
* The type Local tcc action.
diff --git a/spring/src/test/java/io/seata/spring/tcc/TccAction.java b/tcc/src/test/java/io/seata/rm/tcc/spring/tcc/TccAction.java
similarity index 93%
rename from spring/src/test/java/io/seata/spring/tcc/TccAction.java
rename to tcc/src/test/java/io/seata/rm/tcc/spring/tcc/TccAction.java
index db39fb708f5..2c01cf82dac 100644
--- a/spring/src/test/java/io/seata/spring/tcc/TccAction.java
+++ b/tcc/src/test/java/io/seata/rm/tcc/spring/tcc/TccAction.java
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.spring.tcc;
+package io.seata.rm.tcc.spring.tcc;
-import io.seata.rm.tcc.api.BusinessActionContext;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
/**
diff --git a/spring/src/test/java/io/seata/spring/tcc/TccActionImpl.java b/tcc/src/test/java/io/seata/rm/tcc/spring/tcc/TccActionImpl.java
similarity index 91%
rename from spring/src/test/java/io/seata/spring/tcc/TccActionImpl.java
rename to tcc/src/test/java/io/seata/rm/tcc/spring/tcc/TccActionImpl.java
index c28a844c4ae..2cd528ccaeb 100644
--- a/spring/src/test/java/io/seata/spring/tcc/TccActionImpl.java
+++ b/tcc/src/test/java/io/seata/rm/tcc/spring/tcc/TccActionImpl.java
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package io.seata.spring.tcc;
+package io.seata.rm.tcc.spring.tcc;
-import io.seata.rm.tcc.api.BusinessActionContext;
+import io.seata.commonapi.rm.tcc.api.BusinessActionContext;
/**
* The type Tcc action.