-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
本地多数据源事务传播机制
- Loading branch information
Showing
14 changed files
with
328 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/com/baomidou/dynamic/datasource/exception/TransactionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.baomidou.dynamic.datasource.exception; | ||
|
||
public class TransactionException extends RuntimeException { | ||
public TransactionException(String message) { | ||
super(message); | ||
} | ||
|
||
public TransactionException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/com/baomidou/dynamic/datasource/tx/DsPropagation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
package com.baomidou.dynamic.datasource.tx; | ||
|
||
|
||
public enum DsPropagation { | ||
//支持当前事务,如果当前没有事务,就新建一个事务。这是最常见的选择。 | ||
REQUIRED, | ||
//新建事务,如果当前存在事务,把当前事务挂起。 | ||
REQUIRES_NEW, | ||
//以非事务方式执行操作,如果当前存在事务,就把当前事务挂起。 | ||
NOT_SUPPORTED, | ||
//支持当前事务,如果当前没有事务,就以非事务方式执行。 | ||
SUPPORTS, | ||
//以非事务方式执行,如果当前存在事务,则抛出异常。 | ||
NEVER, | ||
//支持当前事务,如果当前没有事务,就抛出异常。 | ||
MANDATORY | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/com/baomidou/dynamic/datasource/tx/SuspendedResourcesHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.baomidou.dynamic.datasource.tx; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
public class SuspendedResourcesHolder { | ||
/** | ||
* The xid | ||
*/ | ||
private String xid; | ||
|
||
public SuspendedResourcesHolder(String xid) { | ||
if (xid == null) { | ||
throw new IllegalArgumentException("xid must be not null"); | ||
} | ||
this.xid = xid; | ||
} | ||
|
||
@Nonnull | ||
public String getXid() { | ||
return xid; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/baomidou/dynamic/datasource/tx/TransactionalExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.baomidou.dynamic.datasource.tx; | ||
|
||
|
||
|
||
public interface TransactionalExecutor { | ||
|
||
Object execute() throws Throwable; | ||
|
||
TransactionalInfo getTransactionInfo(); | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/baomidou/dynamic/datasource/tx/TransactionalInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.baomidou.dynamic.datasource.tx; | ||
|
||
public class TransactionalInfo { | ||
|
||
Class<? extends Throwable>[] rollbackFor; | ||
|
||
Class<? extends Throwable>[] noRollbackFor; | ||
|
||
DsPropagation propagation; | ||
|
||
public Class<? extends Throwable>[] getRollbackFor() { | ||
return rollbackFor; | ||
} | ||
|
||
public void setRollbackFor(Class<? extends Throwable>[] rollbackFor) { | ||
this.rollbackFor = rollbackFor; | ||
} | ||
|
||
public Class<? extends Throwable>[] getNoRollbackFor() { | ||
return noRollbackFor; | ||
} | ||
|
||
public void setNoRollbackFor(Class<? extends Throwable>[] noRollbackFor) { | ||
this.noRollbackFor = noRollbackFor; | ||
} | ||
|
||
public DsPropagation getPropagation() { | ||
return propagation; | ||
} | ||
|
||
public void setPropagation(DsPropagation propagation) { | ||
this.propagation = propagation; | ||
} | ||
} |
Oops, something went wrong.