本文整理了Java中com.jfinal.plugin.activerecord.Db.tx()
方法的一些代码示例,展示了Db.tx()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Db.tx()
方法的具体详情如下:
包路径:com.jfinal.plugin.activerecord.Db
类名称:Db
方法名:tx
[英]Execute transaction.
[中]
代码示例来源:origin: JpressProjects/jpress
@Override
public boolean deleteById(Object id) {
return Db.tx(() -> {
boolean delOk = ArticleServiceProvider.super.deleteById(id);
if (delOk == false) {
return false;
}
List<Record> records = Db.find("select * from article_category_mapping where article_id = ? ", id);
if (records == null || records.isEmpty()) {
return true;
}
Db.update("delete from article_category_mapping where article_id = ?", id);
records.stream().forEach(record -> {
categoryService.updateCount(record.get("category_id"));
});
return true;
});
}
代码示例来源:origin: JpressProjects/jpress
@Override
public void doUpdateCategorys(long articleId, Long[] categoryIds) {
Db.tx(() -> {
Db.update("delete from article_category_mapping where article_id = ?", articleId);
if (categoryIds != null && categoryIds.length > 0) {
List<Record> records = new ArrayList<>();
for (long categoryId : categoryIds) {
Record record = new Record();
record.set("article_id", articleId);
record.set("category_id", categoryId);
records.add(record);
}
Db.batchSave("article_category_mapping", records, records.size());
}
return true;
});
}
代码示例来源:origin: JpressProjects/jpress
@Override
@CacheEvict(name = "user_role", key = "*")
public boolean deleteById(Object id) {
return Db.tx(() -> {
Db.update("delete from user_role_mapping where role_id = ? ", id);
Db.update("delete from role_permission_mapping where role_id = ? ", id);
return RoleServiceProvider.super.deleteById(id);
});
}
代码示例来源:origin: JpressProjects/jpress
@Override
public boolean doChangeRoleByIds(Long roleId, Object... ids) {
for (Object id : ids) {
//删除role缓存
Jboot.me().getCache().remove("role", "user_roles:" + id);
}
return Db.tx(() -> {
//清空用户的其他所有角色
for (Object id : ids) {
Db.delete("delete from user_role_mapping where user_id = ? ", id);
}
//添加新的映射
List<Record> records = new ArrayList<>();
for (Object id : ids) {
Record record = new Record();
record.set("user_id", id);
record.set("role_id", roleId);
records.add(record);
}
Db.batchSave("user_role_mapping", records, records.size());
return true;
});
}
代码示例来源:origin: JpressProjects/jpress
@Override
@CachesEvict({
@CacheEvict(name = "user_role", key = "user_roles:#(userId)"),
@CacheEvict(name = "user_permission", key = "*")
})
public boolean doResetUserRoles(long userId, Long... RoleIds) {
if (RoleIds == null || RoleIds.length == 0) {
return Db.delete("delete from user_role_mapping where user_id = ? ", userId) > 0;
}
return Db.tx(() -> {
Db.delete("delete from user_role_mapping where user_id = ? ", userId);
List<Record> records = new ArrayList<>();
for (Long roleId : RoleIds) {
Record record = new Record();
record.set("user_id", userId);
record.set("role_id", roleId);
records.add(record);
}
Db.batchSave("user_role_mapping", records, records.size());
return true;
});
}
代码示例来源:origin: JpressProjects/jpress
@Override
@CacheEvict(name = "user_role", key = "*")
public boolean deleteByIds(Object... ids) {
return Db.tx(() -> {
Db.update("delete from user_role_mapping where role_id in " + SqlUtils.buildInSqlPara(ids));
Db.update("delete from role_permission_mapping where role_id in " + SqlUtils.buildInSqlPara(ids));
return Db.update("delete from role where id in " + SqlUtils.buildInSqlPara(ids)) > 0;
});
}
代码示例来源:origin: pkanyue/jboot-admin
@Override
public boolean auth(Long id, String resIds) {
List<RoleRes> roleResList = new ArrayList<RoleRes>();
return Db.tx(new IAtom() {
@Override
public boolean run() throws SQLException {
roleResService.deleteByRoleId(id);
if (StrKit.notBlank(resIds)) {
String[] ress = resIds.split(",");
for (String resId : ress) {
RoleRes roleRes = new RoleRes();
roleRes.setRoleId(id);
roleRes.setResId(Long.parseLong(resId));
roleResList.add(roleRes);
}
int[] rets = Db.batchSave(roleResList, roleResList.size());
for (int ret : rets) {
if (ret < 1) {
return false;
}
}
}
return true;
}
});
}
代码示例来源:origin: pkanyue/jboot-admin
user.setNote("保存系统用户");
return Db.tx(new IAtom() {
@Override
public boolean run() throws SQLException {
代码示例来源:origin: pkanyue/jboot-admin
user.setNote("修改系统用户");
return Db.tx(new IAtom() {
@Override
public boolean run() throws SQLException {
内容来源于网络,如有侵权,请联系作者删除!