Пример #1
0
 @Override
 public Page<Map<String, Object>> searchPageMap(
     SqlHelper sqlHelper, Page<Map<String, Object>> page) throws Exception {
   if (sqlHelper == null || StringUtils.isBlank(sqlHelper.getSql())) {
     List<Map<String, Object>> list = new ArrayList<>();
     page.setTotalCount(0);
     page.setResult(list);
     return page;
   }
   return searchPageMap(sqlHelper.getSql(), sqlHelper.getParameters(), page);
 }
Пример #2
0
 @Override
 public <T> Page<T> searchPage(SqlHelper sqlHelper, Class<T> clazz, Page<T> page)
     throws Exception {
   if (sqlHelper == null || StringUtils.isBlank(sqlHelper.getSql())) {
     List<T> list = new ArrayList<>();
     page.setTotalCount(0);
     page.setResult(list);
     return page;
   }
   return searchPage(sqlHelper.getSql(), clazz, sqlHelper.getParameters(), page);
 }
Пример #3
0
  @Override
  public int del(Object id, Class clazz) throws Exception {
    EntityInfo entityInfo = ClassUtils.getEntityInfoByClazz(clazz);
    if (entityInfo == null) {
      throw new DaoException("无效的实体类class");
    }

    SqlHelper sqlHelper = SqlHelper.getDeleteHelper(clazz);
    sqlHelper.append(" WHERE ").append(entityInfo.getPkClumnName()).append("=?");
    sqlHelper.setParameters(id);
    return del(sqlHelper, clazz);
  }
Пример #4
0
  @Override
  public Map<String, Object> findMapById(Object id, Class clazz) throws Exception {

    EntityInfo entityInfo = ClassUtils.getEntityInfoByClazz(clazz);

    if (entityInfo == null) {
      throw new DaoException("无效的实体类class");
    }

    SqlHelper sqlHelper = SqlHelper.getSelectHelper(clazz);
    sqlHelper.append(" AND ").append(entityInfo.getPkClumnName()).append("=?");
    sqlHelper.setParameters(id);
    return searchMapForOne(sqlHelper);
  }
Пример #5
0
 @Override
 public void batchDel(List<Object> ids, Class clazz) throws Exception {
   EntityInfo entityInfo = ClassUtils.getEntityInfoByClazz(clazz);
   if (entityInfo == null) {
     throw new DaoException("无效的实体类class");
   }
   Object[] objects = new Object[ids.size()];
   Arrays.fill(objects, "?");
   SqlHelper sqlHelper = SqlHelper.getDeleteHelper(clazz);
   sqlHelper
       .append(" WHERE ")
       .append(entityInfo.getPkClumnName())
       .append(" IN (")
       .append(StringUtils.join(objects, ","))
       .append(")");
   update(sqlHelper.getSql(), ids);
 }
Пример #6
0
  public SqlHelper getUpdateSql(Map<String, Object> object, EntityInfo entityInfo) {

    Object id = object.get(entityInfo.getPkName());

    if (id == null) {
      throw new DaoException("缺少主键id参数");
    }

    object.remove(entityInfo.getPkName());

    SqlHelper sqlHelper = new SqlHelper("UPDATE ");
    sqlHelper.append(entityInfo.getTableName()).append(" SET ");
    //        List<String> columns = new ArrayList<String>();
    List<Object> values = new ArrayList<Object>();
    Map<String, String> ptcMap = ClassUtils.propToColumnMap.get(entityInfo.getClazzName());
    StringBuilder columnSql = new StringBuilder();
    for (Map.Entry<String, Object> entry : object.entrySet()) {
      if (entry.getValue() != null) {
        values.add(entry.getValue());
        if (!"".equals(columnSql.toString())) {
          columnSql.append(",");
        }
        columnSql.append(ptcMap.get(entry.getKey()));
        columnSql.append("=");
        columnSql.append("?");
      }
    }
    if (values.size() < 1) {
      throw new DaoException("没有要更新的参数");
    }

    sqlHelper.append(columnSql.toString());
    sqlHelper.append(" WHERE ");
    sqlHelper.append(entityInfo.getPkClumnName());
    sqlHelper.append("=?");
    return sqlHelper;
  }
Пример #7
0
 @Override
 public int searchForCount(SqlHelper sqlHelper) throws Exception {
   return getCount(sqlHelper.getSql(), sqlHelper.getParameters());
 }
Пример #8
0
 @Override
 public List<Map<String, Object>> searchAllMap(Class clazz) throws Exception {
   SqlHelper sqlHelper = SqlHelper.getSelectHelper(clazz);
   return searchForListMap(sqlHelper.getSql(), sqlHelper.getParameters());
 }
Пример #9
0
 @Override
 public <T> List<T> searchAll(Class<T> clazz) throws Exception {
   SqlHelper sqlHelper = SqlHelper.getSelectHelper(clazz);
   return searchForList(sqlHelper.getSql(), clazz, sqlHelper.getParameters());
 }
Пример #10
0
 @Override
 public List<Map<String, Object>> searchForListMap(SqlHelper sqlHelper) throws Exception {
   return searchForListMap(sqlHelper.getSql(), sqlHelper.getParameters());
 }
Пример #11
0
 @Override
 public <T> List<T> searchForList(SqlHelper sqlHelper, Class<T> clazz) throws Exception {
   return searchForList(sqlHelper.getSql(), clazz, sqlHelper.getParameters());
 }
Пример #12
0
 @Override
 public Map<String, Object> searchMapForOne(SqlHelper sqlHelper) throws Exception {
   return searchMapForOne(sqlHelper.getSql(), sqlHelper.getParameters());
 }
Пример #13
0
 @Override
 public int update(SqlHelper sqlHelper) throws Exception {
   return update(sqlHelper.getSql(), sqlHelper.getParameters());
 }