Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Summer code 2022] tcc-sample-refactor #561

Open
wants to merge 1 commit into
base: sample-refactor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public interface TccActionOne {
/**
* Prepare boolean.
*
* @param actionContext the action context
*
* @param a the a
* @return the boolean
*/
@TwoPhaseBusinessAction(name = "DubboTccActionOne", commitMethod = "commit", rollbackMethod = "rollback")
public boolean prepare(BusinessActionContext actionContext, @BusinessActionContextParameter(paramName = "a") int a);
public boolean prepare(@BusinessActionContextParameter(paramName = "a") int a);

/**
* Commit boolean.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ public interface TccActionTwo {
/**
* Prepare boolean.
*
* @param actionContext the action context
*
* @param b the b
* @param list the list
* @return the boolean
*/
@TwoPhaseBusinessAction(name = "DubboTccActionTwo", commitMethod = "commit", rollbackMethod = "rollback")
public boolean prepare(BusinessActionContext actionContext,
@BusinessActionContextParameter(paramName = "b") String b,
public boolean prepare(@BusinessActionContextParameter(paramName = "b") String b,
@BusinessActionContextParameter(paramName = "c", index = 1) List list);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.seata.samples.tcc.dubbo.action.impl;

import io.seata.core.context.RootContext;
import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.samples.tcc.dubbo.action.ResultHolder;
import io.seata.samples.tcc.dubbo.action.TccActionOne;
Expand All @@ -27,8 +28,8 @@
public class TccActionOneImpl implements TccActionOne {

@Override
public boolean prepare(BusinessActionContext actionContext, int a) {
String xid = actionContext.getXid();
public boolean prepare(int a) {
String xid = RootContext.getXID();
System.out.println("TccActionOne prepare, xid:" + xid + ", a:" + a);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.List;

import io.seata.core.context.RootContext;
import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.samples.tcc.dubbo.action.ResultHolder;
import io.seata.samples.tcc.dubbo.action.TccActionTwo;
Expand All @@ -29,8 +30,8 @@
public class TccActionTwoImpl implements TccActionTwo {

@Override
public boolean prepare(BusinessActionContext actionContext, String b, List list) {
String xid = actionContext.getXid();
public boolean prepare(String b, List list) {
String xid = RootContext.getXID();
System.out.println("TccActionTwo prepare, xid:" + xid + ", b:" + b + ", c:" + list.get(1));
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public class TccTransactionService {
@GlobalTransactional
public String doTransactionCommit() {
//第一个TCC 事务参与者
boolean result = tccActionOne.prepare(null, 1);
boolean result = tccActionOne.prepare(1);
if (!result) {
throw new RuntimeException("TccActionOne failed.");
}
List list = new ArrayList();
list.add("c1");
list.add("c2");
result = tccActionTwo.prepare(null, "two", list);
result = tccActionTwo.prepare("two", list);
if (!result) {
throw new RuntimeException("TccActionTwo failed.");
}
Expand All @@ -66,14 +66,14 @@ public String doTransactionCommit() {
@GlobalTransactional
public String doTransactionRollback(Map map) {
//第一个TCC 事务参与者
boolean result = tccActionOne.prepare(null, 1);
boolean result = tccActionOne.prepare( 1);
if (!result) {
throw new RuntimeException("TccActionOne failed.");
}
List list = new ArrayList();
list.add("c1");
list.add("c2");
result = tccActionTwo.prepare(null, "two", list);
result = tccActionTwo.prepare("two", list);
if (!result) {
throw new RuntimeException("TccActionTwo failed.");
}
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public interface ActionOne {
/**
* Prepare boolean.
*
* @param actionContext the action context
*
* @param a the a
* @return the boolean
*/
@TwoPhaseBusinessAction(name = "TccActionOne", commitMethod = "commit", rollbackMethod = "rollback")
public boolean prepare(BusinessActionContext actionContext, @BusinessActionContextParameter(paramName = "a") int a);
public boolean prepare(@BusinessActionContextParameter(paramName = "a") int a);

/**
* Commit boolean.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ public interface ActionTwo {
/**
* Prepare boolean.
*
* @param actionContext the action context
*
* @param b the b
* @param list the list
* @return the boolean
*/
@TwoPhaseBusinessAction(name = "TccActionTwo", commitMethod = "commit", rollbackMethod = "rollback")
public boolean prepare(BusinessActionContext actionContext,
@BusinessActionContextParameter(paramName = "b") String b,
public boolean prepare(@BusinessActionContextParameter(paramName = "b") String b,
@BusinessActionContextParameter(paramName = "c", index = 1) List list);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.seata.edas.tcc.action.impl;

import io.seata.core.context.RootContext;
import io.seata.edas.tcc.action.ActionOne;
import io.seata.rm.tcc.api.BusinessActionContext;

Expand All @@ -26,8 +27,8 @@
public class ActionOneImpl implements ActionOne {

@Override
public boolean prepare(BusinessActionContext actionContext, int a) {
String xid = actionContext.getXid();
public boolean prepare(int a) {
String xid = RootContext.getXID();
System.out.println("TccActionOne prepare, xid:" + xid + ", a:" + a);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.List;

import io.seata.core.context.RootContext;
import io.seata.edas.tcc.action.ActionTwo;
import io.seata.rm.tcc.api.BusinessActionContext;

Expand All @@ -28,8 +29,8 @@
public class ActionTwoImpl implements ActionTwo {

@Override
public boolean prepare(BusinessActionContext actionContext, String b, List list) {
String xid = actionContext.getXid();
public boolean prepare(String b, List list) {
String xid = RootContext.getXID();
System.out.println("TccActionTwo prepare, xid:" + xid + ", b:" + b + ", c:" + list.get(1));
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ActivityServiceImpl {
@GlobalTransactional
public String doActivity(boolean commit) {
//第一个TCC 事务参与者
boolean result = actionOne.prepare(null, 1);
boolean result = actionOne.prepare(1);
if (!commit || !result) {
throw new RuntimeException("TccActionOne failed.");
}
Expand All @@ -45,7 +45,7 @@ public String doActivity(boolean commit) {
List list = new ArrayList();
list.add("c1");
list.add("c2");
result = actionTwo.prepare(null, "two", list);
result = actionTwo.prepare("two", list);
if (!result) {
throw new RuntimeException("TccActionTwo failed.");
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public interface TccActionOne {
/**
* Prepare boolean.
*
* @param actionContext the action context
*
* @param a the a
* @return the boolean
*/
@TwoPhaseBusinessAction(name = "TccActionOne", commitMethod = "commit", rollbackMethod = "rollback")
public boolean prepare(BusinessActionContext actionContext, int a);
public boolean prepare(int a);

/**
* Commit boolean.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public interface TccActionTwo {
/**
* Prepare boolean.
*
* @param actionContext the action context
*
* @param b the b
* @return the boolean
*/
@TwoPhaseBusinessAction(name = "TccActionTwo", commitMethod = "commit", rollbackMethod = "rollback")
public boolean prepare(BusinessActionContext actionContext, String b);
public boolean prepare(String b);

/**
* Commit boolean.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.seata.samples.tcc.action.impl;

import io.seata.core.context.RootContext;
import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.samples.tcc.action.ResultHolder;
import io.seata.samples.tcc.action.TccActionOne;
Expand All @@ -27,8 +28,8 @@
public class TccActionOneImpl implements TccActionOne {

@Override
public boolean prepare(BusinessActionContext actionContext, int a) {
String xid = actionContext.getXid();
public boolean prepare(int a) {
String xid = RootContext.getXID();
System.out.println("TccActionOne prepare, xid:" + xid);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.seata.samples.tcc.action.impl;

import io.seata.core.context.RootContext;
import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.samples.tcc.action.ResultHolder;
import io.seata.samples.tcc.action.TccActionTwo;
Expand All @@ -27,8 +28,8 @@
public class TccActionTwoImpl implements TccActionTwo {

@Override
public boolean prepare(BusinessActionContext actionContext, String b) {
String xid = actionContext.getXid();
public boolean prepare(String b) {
String xid = RootContext.getXID();
System.out.println("TccActionTwo prepare, xid:" + xid);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public class TccTransactionService {
@GlobalTransactional
public String doTransactionCommit() {
//第一个TCC 事务参与者
boolean result = tccActionOne.prepare(null, 1);
boolean result = tccActionOne.prepare( 1);
if (!result) {
throw new RuntimeException("TccActionOne failed.");
}
result = tccActionTwo.prepare(null, "two");
result = tccActionTwo.prepare( "two");
if (!result) {
throw new RuntimeException("TccActionTwo failed.");
}
Expand All @@ -61,11 +61,11 @@ public String doTransactionCommit() {
@GlobalTransactional
public String doTransactionRollback(Map map) {
//第一个TCC 事务参与者
boolean result = tccActionOne.prepare(null, 1);
boolean result = tccActionOne.prepare( 1);
if (!result) {
throw new RuntimeException("TccActionOne failed.");
}
result = tccActionTwo.prepare(null, "two");
result = tccActionTwo.prepare( "two");
if (!result) {
throw new RuntimeException("TccActionTwo failed.");
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public interface TccActionOne {
/**
* Prepare boolean.
*
* @param actionContext the action context
*
* @param a the a
* @return the boolean
*/
@TwoPhaseBusinessAction(name = "SofaRpcTccActionOne", commitMethod = "commit", rollbackMethod = "rollback")
public boolean prepare(BusinessActionContext actionContext, int a);
public boolean prepare(int a);

/**
* Commit boolean.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public interface TccActionTwo {
/**
* Prepare boolean.
*
* @param actionContext the action context
*
* @param b the b
* @return the boolean
*/
@TwoPhaseBusinessAction(name = "SofaRpcTccActionTwo", commitMethod = "commit", rollbackMethod = "rollback")
public boolean prepare(BusinessActionContext actionContext, String b);
public boolean prepare(String b);

/**
* Commit boolean.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.seata.samples.tcc.sofarpc.action.impl;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.core.context.RootContext;
import io.seata.samples.tcc.sofarpc.action.ResultHolder;
import io.seata.samples.tcc.sofarpc.action.TccActionOne;

Expand All @@ -12,8 +13,8 @@
public class TccActionOneImpl implements TccActionOne {

@Override
public boolean prepare(BusinessActionContext actionContext, int a) {
String txId = actionContext.getXid();
public boolean prepare(int a) {
String txId = RootContext.getXID();
System.out.println("TccActionOne prepare, txId:" + txId);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.seata.samples.tcc.sofarpc.action.impl;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.core.context.RootContext;
import io.seata.samples.tcc.sofarpc.action.ResultHolder;
import io.seata.samples.tcc.sofarpc.action.TccActionTwo;

Expand All @@ -12,8 +13,8 @@
public class TccActionTwoImpl implements TccActionTwo {

@Override
public boolean prepare(BusinessActionContext actionContext, String b) {
String txId = actionContext.getXid();
public boolean prepare(String b) {
String txId = RootContext.getXID();
System.out.println("TccActionTwo prepare, xid:" + txId);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public class TccTransactionService {
@GlobalTransactional
public String doTransactionCommit() {
//第一个TCC 事务参与者
boolean result = tccActionOne.prepare(null, 1);
boolean result = tccActionOne.prepare( 1);
if (!result) {
throw new RuntimeException("TccActionOne failed.");
}
result = tccActionTwo.prepare(null, "two");
result = tccActionTwo.prepare("two");
if (!result) {
throw new RuntimeException("TccActionTwo failed.");
}
Expand All @@ -46,11 +46,11 @@ public String doTransactionCommit() {
@GlobalTransactional
public String doTransactionRollback(Map map) {
//第一个TCC 事务参与者
boolean result = tccActionOne.prepare(null, 1);
boolean result = tccActionOne.prepare(1);
if (!result) {
throw new RuntimeException("TccActionOne failed.");
}
result = tccActionTwo.prepare(null, "two");
result = tccActionTwo.prepare("two");
if (!result) {
throw new RuntimeException("TccActionTwo failed.");
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public interface TccActionOne {
/**
* Prepare boolean.
*
* @param actionContext the action context
*
* @param a the a
* @return the boolean
*/
@TwoPhaseBusinessAction(name = "DubboTccActionOne", commitMethod = "commit", rollbackMethod = "rollback")
public boolean prepare(BusinessActionContext actionContext, @BusinessActionContextParameter(paramName = "a") int a);
public boolean prepare(@BusinessActionContextParameter(paramName = "a") int a);

/**
* Commit boolean.
Expand Down
Loading