com.kukababy.plus.dao.DeleteImpl Maven / Gradle / Ivy
The newest version!
package com.kukababy.plus.dao;
import java.io.Serializable;
import java.util.Map;
import javax.script.ScriptEngine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.kukababy.plus.pager.SqlFilter;
import com.kukababy.plus.pager.SqlInfo;
import com.kukababy.plus.pager.SqlWhere;
import com.kukababy.plus.pojo.P;
import com.kukababy.plus.pojo.SqlCfg;
import com.kukababy.plus.pojo.SqlPo;
import com.kukababy.plus.utils.HoldUtil;
import com.kukababy.plus.utils.SqlUtil;
/**
*
* 描述:
*
*
* @author [email protected]
* @date 2019年3月5日 下午10:51:35
*/
public class DeleteImpl extends BasePlus implements DeleteFace {
private static final Logger log = LoggerFactory.getLogger(DeleteImpl.class);
/**
* @param injectParam
*/
public DeleteImpl(SqlCfg sqlCfg, ScriptEngine engine) {
super(sqlCfg,engine);
// TODO Auto-generated constructor stub
}
/*
* (non-Javadoc)
*
* @see com.kukababy.plus.dao.InsertJdbc#get(java.lang.Class,
* java.io.Serializable)
*/
@Override
public int deleteId(Class> entityClass, Serializable id) {
SqlPo sqlPo = this.getSqlPo(entityClass, sqlCfg.getCamel());
String sql = "delete from " + sqlPo.getTableName() + " where " + sqlPo.getKey() + " = ?";
int count = sqlCfg.getJdbcTemplate().update(sql, id);
return count;
}
/*
* (non-Javadoc)
*
* @see com.kukababy.plus.dao.DeleteFace#deleteBy(java.lang.Class,
* com.kukababy.plus.pojo.Param[])
*/
@Override
public int deleteBy(Class> entityClass, P... whereColVals) {
SqlPo sqlPo = this.getSqlPo(entityClass, sqlCfg.getCamel());
// 可以支持列的名字,写成变量的名字,此处需要转换为列名
SqlUtil.varConvertCol(sqlPo.getCol2VarMap(), whereColVals);
SqlFilter sqlFilter = SqlUtil.param2SqlFilter(whereColVals);
SqlInfo sqlRes = SqlWhere.getWheres(sqlFilter);
String sqlWhere = sqlRes.getWhereSql();
String joinSql = "delete from " + sqlPo.getTableName() + sqlWhere;
return deleteBy(joinSql, sqlRes.getWhereVals().toArray());
}
@Override
public int deleteBy(Class> entityClass, SqlFilter sqlFilter) {
SqlPo sqlPo = this.getSqlPo(entityClass, sqlCfg.getCamel());
// 可以支持列的名字,写成变量的名字,此处需要转换为列名
SqlUtil.convertSqlFilterVar2Col(sqlFilter, sqlPo.getCol2VarMap());
SqlInfo sqlRes = SqlWhere.getWheres(sqlFilter);
String sqlWhere = sqlRes.getWhereSql();
String joinSql = "delete from " + sqlPo.getTableName() + sqlWhere;
return deleteBy(joinSql, sqlRes.getWhereVals().toArray());
}
private int deleteBy(String joinSql, Object sqlVals[]) {
int count = 0;
if (sqlVals.length == 0) {
count = sqlCfg.getJdbcTemplate().update(joinSql);
} else {
count = sqlCfg.getJdbcTemplate().update(joinSql, sqlVals);
}
return count;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy