James 5 年 前
コミット
9e9b15541e
1 ファイル変更24 行追加4 行削除
  1. 24 4
      src/main/java/com/jfinal/plugin/activerecord/Db.java

+ 24 - 4
src/main/java/com/jfinal/plugin/activerecord/Db.java

@@ -533,10 +533,6 @@ public class Db {
 		return MAIN.tx(config, transactionLevel, atom);
 	}
 	
-	public static boolean tx(int transactionLevel, IAtom atom) {
-		return MAIN.tx(transactionLevel, atom);
-	}
-	
 	/**
 	 * Execute transaction with default transaction level.
 	 * @see #tx(int, IAtom)
@@ -545,6 +541,30 @@ public class Db {
 		return MAIN.tx(atom);
 	}
 	
+	public static boolean tx(int transactionLevel, IAtom atom) {
+		return MAIN.tx(transactionLevel, atom);
+	}
+	
+	/**
+	 * 主要用于嵌套事务场景
+	 * 
+	 * 实例:https://jfinal.com/feedback/4008
+	 * 
+	 * 默认情况下嵌套事务会被合并成为一个事务,那么内层与外层任何地方回滚事务
+	 * 所有嵌套层都将回滚事务,也就是说嵌套事务无法独立提交与回滚
+	 * 
+	 * 使用 txInNewThread(...) 方法可以实现层之间的事务控制的独立性
+	 * 由于事务处理是将 Connection 绑定到线程上的,所以 txInNewThread(...)
+	 * 通过建立新线程来实现嵌套事务的独立控制
+	 */
+	public static void txInNewThread(IAtom atom) {
+		MAIN.txInNewThread(atom);
+	}
+	
+	public static void txInNewThread(int transactionLevel, IAtom atom) {
+		MAIN.txInNewThread(transactionLevel, atom);
+	}
+	
 	/**
 	 * Find Record by cache.
 	 * @see #find(String, Object...)