use of io.github.ihongs.dh.IReflux in project HongsCORE by ihongs.
the class CommitRunner method run.
public static void run(Run run, Core core) throws HongsException, HongsExemption {
// 外部已指定则不再处理
if (core.isset(Cnst.REFLUX_MODE)) {
try {
// 执行
run.run();
} catch (Throwable ex) {
if (ex instanceof HongsException) {
throw (HongsException) ex;
} else if (ex instanceof HongsExemption) {
throw (HongsExemption) ex;
}
throw new HongsException(ex);
}
return;
}
try {
// 开启
core.set(Cnst.REFLUX_MODE, true);
Hub crux = new Hub(core);
Core.THREAD_CORE.set(crux);
for (Object o : crux.values()) {
if (o instanceof IReflux) {
((IReflux) o).begin();
}
}
try {
// 执行
run.run();
// 提交
for (Object o : crux.values().toArray()) {
if (o instanceof IReflux) {
((IReflux) o).commit();
}
}
} catch (Throwable ex) {
// 回滚
for (Object o : crux.values().toArray()) {
if (o instanceof IReflux) {
((IReflux) o).revert();
}
}
if (ex instanceof HongsException) {
throw (HongsException) ex;
} else if (ex instanceof HongsExemption) {
throw (HongsExemption) ex;
}
// 其他异常需包裹
throw new HongsException(1109, ex);
}
} finally {
// 重置
core.unset(Cnst.REFLUX_MODE);
Core.THREAD_CORE.set(core);
}
}
Aggregations