use of cn.hutool.db.Db in project Jpom by dromara.
the class BaseDbCommonService method insert.
/**
* 插入数据
*
* @param t 数据
*/
public void insert(Collection<T> t) {
if (CollUtil.isEmpty(t)) {
return;
}
if (!DbConfig.getInstance().isInit()) {
// ignore
log.error("The database is not initialized, this execution will be ignored:{},{}", this.tClass, this.getClass());
return;
}
Db db = Db.use();
db.setWrapper((Character) null);
try {
List<Entity> entities = t.stream().map(this::dataBeanToEntity).collect(Collectors.toList());
db.insert(entities);
} catch (Exception e) {
throw warpException(e);
}
}
use of cn.hutool.db.Db in project Jpom by dromara.
the class BaseDbCommonService method findByCondition.
/**
* 查询列表
*
* @param wheres 条件
* @return List
*/
public List<T> findByCondition(Condition... wheres) {
if (!DbConfig.getInstance().isInit()) {
// ignore
log.error("The database is not initialized, this execution will be ignored:{},{}", this.tClass, this.getClass());
return null;
}
Db db = Db.use();
db.setWrapper((Character) null);
try {
List<Entity> entities = db.findBy(getTableName(), wheres);
return this.entityToBeanList(entities);
} catch (Exception e) {
throw warpException(e);
}
}
use of cn.hutool.db.Db in project Jpom by dromara.
the class BaseDbCommonService method update.
/**
* 修改数据
*
* @param entity 要修改的数据
* @param where 条件
* @return 影响行数
*/
public int update(Entity entity, Entity where) {
if (!DbConfig.getInstance().isInit()) {
// ignore
log.error("The database is not initialized, this execution will be ignored:{},{}", this.tClass, this.getClass());
return 0;
}
Db db = Db.use();
db.setWrapper((Character) null);
if (where.isEmpty()) {
throw new JpomRuntimeException("没有更新条件");
}
entity.setTableName(tableName);
where.setTableName(tableName);
try {
return db.update(entity, where);
} catch (Exception e) {
throw warpException(e);
}
}
use of cn.hutool.db.Db in project Jpom by dromara.
the class BaseDbCommonService method del.
/**
* 根据条件删除
*
* @param where 条件
* @return 影响行数
*/
public int del(Entity where) {
if (!DbConfig.getInstance().isInit()) {
// ignore
log.error("The database is not initialized, this execution will be ignored:{},{}", this.tClass, this.getClass());
return 0;
}
where.setTableName(tableName);
if (where.isEmpty()) {
throw new JpomRuntimeException("没有删除条件");
}
Db db = Db.use();
db.setWrapper((Character) null);
try {
return db.del(where);
} catch (Exception e) {
throw warpException(e);
}
}
use of cn.hutool.db.Db in project Jpom by dromara.
the class BaseDbCommonService method insert.
/**
* 插入数据
*
* @param entity 要修改的数据
* @return 影响行数
*/
public int insert(Entity entity) {
if (!DbConfig.getInstance().isInit()) {
// ignore
log.error("The database is not initialized, this execution will be ignored:{},{}", this.tClass, this.getClass());
return 0;
}
Db db = Db.use();
db.setWrapper((Character) null);
entity.setTableName(tableName);
try {
return db.insert(entity);
} catch (Exception e) {
throw warpException(e);
}
}
Aggregations