Skip to content

Commit 347102f

Browse files
authored
Merge pull request #10 from codingapi/dev
Dev
2 parents b2b89c6 + 7e0b5a6 commit 347102f

32 files changed

Lines changed: 222 additions & 358 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.codingapi</groupId>
77
<artifactId>tx-lcn</artifactId>
8-
<version>4.0.0</version>
8+
<version>4.0.2-SNAPSHOT</version>
99
<packaging>pom</packaging>
1010

1111
<name>tx-lcn</name>

transaction-dubbo/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<groupId>com.codingapi</groupId>
99
<artifactId>transaction-dubbo</artifactId>
10-
<version>4.0.1</version>
10+
<version>4.0.2-SNAPSHOT</version>
1111

1212
<name>transaction-dubbo</name>
1313
<url>https://github.com/codingapi/tx-lcn</url>
@@ -68,7 +68,7 @@
6868
<dependency>
6969
<groupId>com.codingapi</groupId>
7070
<artifactId>tx-client</artifactId>
71-
<version>4.0.1</version>
71+
<version>4.0.2-SNAPSHOT</version>
7272
</dependency>
7373

7474
<dependency>

transaction-motan/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.codingapi</groupId>
88
<artifactId>transaction-motan</artifactId>
9-
<version>4.0.1</version>
9+
<version>4.0.2-SNAPSHOT</version>
1010

1111
<name>transaction-motan</name>
1212
<url>https://github.com/codingapi/tx-lcn</url>
@@ -66,7 +66,7 @@
6666
<dependency>
6767
<groupId>com.codingapi</groupId>
6868
<artifactId>tx-client</artifactId>
69-
<version>4.0.1</version>
69+
<version>4.0.2-SNAPSHOT</version>
7070
</dependency>
7171

7272
<!-- motan config start-->

transaction-springcloud/pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55

6-
76
<groupId>com.codingapi</groupId>
87
<artifactId>transaction-springcloud</artifactId>
9-
<version>4.0.1</version>
8+
<version>4.0.2-SNAPSHOT</version>
109

1110
<name>transaction-springcloud</name>
1211
<url>https://github.com/codingapi/tx-lcn</url>
@@ -70,7 +69,7 @@
7069
<dependency>
7170
<groupId>com.codingapi</groupId>
7271
<artifactId>tx-client</artifactId>
73-
<version>4.0.1</version>
72+
<version>4.0.2-SNAPSHOT</version>
7473
</dependency>
7574

7675
<dependency>

tx-client/pom.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.codingapi</groupId>
77
<artifactId>tx-client</artifactId>
8-
<version>4.0.1</version>
8+
<version>4.0.2-SNAPSHOT</version>
99

1010
<name>tx-client</name>
1111
<url>https://github.com/codingapi/tx-lcn</url>
@@ -131,11 +131,6 @@
131131
<version>${org.springframework-version}</version>
132132
</dependency>
133133

134-
<dependency>
135-
<groupId>org.springframework</groupId>
136-
<artifactId>spring-tx</artifactId>
137-
<version>${org.springframework-version}</version>
138-
</dependency>
139134

140135
<dependency>
141136
<groupId>com.caucho</groupId>

tx-client/src/main/java/com/codingapi/tx/aop/bean/TxTransactionInfo.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.codingapi.tx.annotation.TxTransaction;
44
import com.codingapi.tx.model.TransactionInvocation;
5-
import org.springframework.transaction.annotation.Transactional;
65

76

87
/**
@@ -14,24 +13,29 @@ public class TxTransactionInfo {
1413

1514
private TxTransaction transaction;
1615

17-
private Transactional transactional;
1816

1917
private TxTransactionLocal txTransactionLocal;
2018

19+
/**
20+
* 事务组Id
21+
*/
2122
private String txGroupId;
2223

24+
/**
25+
* 最大超时时间(发起方模块的)
26+
*/
2327
private int maxTimeOut;
2428

29+
2530
private TransactionInvocation invocation;
2631

2732

28-
public TxTransactionInfo(TxTransaction transaction,Transactional transactional, TxTransactionLocal txTransactionLocal,TransactionInvocation invocation, String txGroupId, int maxTimeOut) {
33+
public TxTransactionInfo(TxTransaction transaction, TxTransactionLocal txTransactionLocal, TransactionInvocation invocation, String txGroupId, int maxTimeOut) {
2934
this.transaction = transaction;
3035
this.txTransactionLocal = txTransactionLocal;
3136
this.txGroupId = txGroupId;
3237
this.maxTimeOut = maxTimeOut;
3338
this.invocation = invocation;
34-
this.transactional = transactional;
3539
}
3640

3741
public int getMaxTimeOut() {
@@ -56,7 +60,4 @@ public TransactionInvocation getInvocation() {
5660
return invocation;
5761
}
5862

59-
public Transactional getTransactional() {
60-
return transactional;
61-
}
6263
}

tx-client/src/main/java/com/codingapi/tx/aop/bean/TxTransactionLocal.java

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.codingapi.tx.aop.bean;
22

3-
import org.springframework.transaction.annotation.Transactional;
4-
53
/**
64
* 分布式事务远程调用控制对象
75
* Created by lorne on 2017/6/5.
@@ -14,18 +12,26 @@ public class TxTransactionLocal {
1412

1513
private int maxTimeOut;
1614

15+
/**
16+
* 是否同一个模块被多次请求
17+
*/
1718
private boolean hasIsGroup = false;
1819

20+
/**
21+
* 是否是发起方模块
22+
*/
1923
private boolean hasStart = false;
2024

25+
/**
26+
* 是否单模块下多次业务调用
27+
*/
28+
private boolean hasMoreService = false;
29+
2130
private String kid;
2231

2332
private String type;
2433

25-
private boolean readOnly;
26-
27-
private Transactional transactional;
28-
34+
private boolean autoCommit = true;
2935

3036
public boolean isHasIsGroup() {
3137
return hasIsGroup;
@@ -59,6 +65,13 @@ public void setGroupId(String groupId) {
5965
this.groupId = groupId;
6066
}
6167

68+
public boolean isHasMoreService() {
69+
return hasMoreService;
70+
}
71+
72+
public void setHasMoreService(boolean hasMoreService) {
73+
this.hasMoreService = hasMoreService;
74+
}
6275

6376
public TxTransactionLocal() {
6477

@@ -90,25 +103,11 @@ public String getType() {
90103
return type;
91104
}
92105

93-
94-
95-
public boolean isReadOnly() {
96-
return readOnly;
97-
}
98-
99-
public Transactional getTransactional() {
100-
return transactional;
106+
public boolean isAutoCommit() {
107+
return autoCommit;
101108
}
102109

103-
public void setTransactional(Transactional transactional) {
104-
this.transactional = transactional;
105-
106-
//set readOnly
107-
if(transactional==null){
108-
//没有配置事务注解的时候当做只读来处理
109-
readOnly = true;
110-
}else{
111-
readOnly = transactional.readOnly();
112-
}
110+
public void setAutoCommit(boolean autoCommit) {
111+
this.autoCommit = autoCommit;
113112
}
114113
}

tx-client/src/main/java/com/codingapi/tx/aop/service/impl/AspectBeforeServiceImpl.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
import com.codingapi.tx.model.TransactionInvocation;
1010
import org.aspectj.lang.ProceedingJoinPoint;
1111
import org.aspectj.lang.reflect.MethodSignature;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
1214
import org.springframework.beans.factory.annotation.Autowired;
1315
import org.springframework.stereotype.Service;
14-
import org.springframework.transaction.annotation.Transactional;
1516

1617
import java.lang.reflect.Method;
1718

@@ -25,6 +26,9 @@ public class AspectBeforeServiceImpl implements AspectBeforeService {
2526
private TransactionServerFactoryService transactionServerFactoryService;
2627

2728

29+
private Logger logger = LoggerFactory.getLogger(AspectBeforeServiceImpl.class);
30+
31+
2832
public Object around(String groupId,int maxTimeOut, ProceedingJoinPoint point) throws Throwable {
2933

3034
MethodSignature signature = (MethodSignature) point.getSignature();
@@ -35,16 +39,19 @@ public Object around(String groupId,int maxTimeOut, ProceedingJoinPoint point) t
3539

3640
TxTransaction transaction = thisMethod.getAnnotation(TxTransaction.class);
3741

38-
Transactional transactional = thisMethod.getAnnotation(Transactional.class);
39-
if (transactional == null) {
40-
transactional = clazz.getAnnotation(Transactional.class);
42+
TxTransactionLocal txTransactionLocal = TxTransactionLocal.current();
43+
44+
45+
if(txTransactionLocal!=null){
46+
//在同一次事务下,调用多个业务模块。
47+
txTransactionLocal.setHasMoreService(true);
4148
}
4249

43-
TxTransactionLocal txTransactionLocal = TxTransactionLocal.current();
50+
logger.info("around--> groupId-> " +groupId+",txTransactionLocal->"+txTransactionLocal);
4451

4552
TransactionInvocation invocation = new TransactionInvocation(clazz, thisMethod.getName(), thisMethod.toString(), args, method.getParameterTypes());
4653

47-
TxTransactionInfo info = new TxTransactionInfo(transaction,transactional,txTransactionLocal,invocation,groupId,maxTimeOut);
54+
TxTransactionInfo info = new TxTransactionInfo(transaction,txTransactionLocal,invocation,groupId,maxTimeOut);
4855

4956
TransactionServer server = transactionServerFactoryService.createTransactionServer(info);
5057

tx-client/src/main/java/com/codingapi/tx/aop/service/impl/TxRunningNoTransactionServerImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public Object execute(final ProceedingJoinPoint point, final TxTransactionInfo i
3232
txTransactionLocal.setGroupId(txGroupId);
3333
txTransactionLocal.setHasStart(false);
3434
txTransactionLocal.setKid(kid);
35-
txTransactionLocal.setTransactional(info.getTransactional());
3635
txTransactionLocal.setMaxTimeOut(info.getMaxTimeOut());
3736
TxTransactionLocal.setCurrent(txTransactionLocal);
3837

tx-client/src/main/java/com/codingapi/tx/aop/service/impl/TxRunningTransactionServerImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public Object execute(final ProceedingJoinPoint point, final TxTransactionInfo i
5151
txTransactionLocal.setGroupId(txGroupId);
5252
txTransactionLocal.setHasStart(false);
5353
txTransactionLocal.setKid(kid);
54-
txTransactionLocal.setTransactional(info.getTransactional());
5554
txTransactionLocal.setMaxTimeOut(info.getMaxTimeOut());
5655
TxTransactionLocal.setCurrent(txTransactionLocal);
5756

@@ -61,7 +60,7 @@ public Object execute(final ProceedingJoinPoint point, final TxTransactionInfo i
6160
Object res = point.proceed();
6261

6362
//写操作 处理
64-
if(!txTransactionLocal.isReadOnly()) {
63+
if(!txTransactionLocal.isAutoCommit()) {
6564

6665
String methodStr = info.getInvocation().getMethodStr();
6766

0 commit comments

Comments
 (0)