Kaynağa Gözat

废弃AbsDbWorker,增加IDbSimpleWorker,方便lambda表达式写法

4.0
郑根木 2 yıl önce
ebeveyn
işleme
41535d1b81
4 değiştirilmiş dosya ile 27 ekleme ve 10 silme
  1. +1
    -1
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleService.java
  2. +5
    -7
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowTransHandler.java
  3. +8
    -0
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/IDbSimpleWorker.java
  4. +13
    -2
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/JdbcEngine.java

+ 1
- 1
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleService.java Dosyayı Görüntüle

@@ -54,6 +54,6 @@ public class FlowSingleService extends LCSingleService {
}

public R retake(@SwBody SwMap params, UserSession us) {
return flowHandler(params, us, FlowTransHandler::submit);
return flowHandler(params, us, FlowTransHandler::retake);
}
}

+ 5
- 7
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowTransHandler.java Dosyayı Görüntüle

@@ -4,6 +4,8 @@ import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.db.DbEngine;
import cc.smtweb.framework.core.db.impl.DefaultEntity;
import cc.smtweb.framework.core.db.jdbc.AbsDbWorker;
import cc.smtweb.framework.core.db.jdbc.IDbSimpleWorker;
import cc.smtweb.framework.core.db.jdbc.IDbWorker;
import cc.smtweb.framework.core.mvc.service.SwListData;
import cc.smtweb.system.bpm.web.design.form.define.PageDataset;
@@ -53,19 +55,15 @@ public class FlowTransHandler<T extends DefaultEntity> extends AbstractDynPageHa

public R submit() {
load();
DbEngine.getInstance().doTrans(new IDbWorker() {
@Override
public void work() {
flowInstance.submit(params.readString("comment"));
}
});
DbEngine.getInstance().doTrans(() -> flowInstance.submit(params.readString("comment")));

return R.success(buildRetData());
}

public R retake() {
load();
flowInstance.retake();
DbEngine.getInstance().doTrans(() -> flowInstance.retake());

return R.success(buildRetData());
}
}

+ 8
- 0
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/IDbSimpleWorker.java Dosyayı Görüntüle

@@ -0,0 +1,8 @@
package cc.smtweb.framework.core.db.jdbc;

/**
* Created by Akmm at 2022-09-05 09:42
*/
public interface IDbSimpleWorker {
void work();
}

+ 13
- 2
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/JdbcEngine.java Dosyayı Görüntüle

@@ -281,7 +281,7 @@ public class JdbcEngine {
*
* @param extractor 回调方法
* @return 事务是否成功,如果异常会也会事务回滚后再抛出异常
*/
*//*
public boolean doTrans(Supplier<Boolean> extractor) {
try (JdbcTrans jdbcTrans = openTrans()) {
boolean result = extractor.get();
@@ -292,7 +292,7 @@ public class JdbcEngine {
}

return false;
}
}*/

public void beginTrans() {
Thread t = Thread.currentThread();
@@ -346,6 +346,17 @@ public class JdbcEngine {
dbWorker.doAfterDbCommit();
}

public void doTrans(IDbSimpleWorker dbWorker) throws SwException {
beginTrans();
try {
dbWorker.work();
commit();
} catch (Exception e) {
rollback(e);
throw new SwException(e);
}
}

//独立事务
public void doTransSingle(IDbWorker worker) throws Exception {
JdbcTrans jdbcTrans = openTrans();


Yükleniyor…
İptal
Kaydet