public <T> Number[] updateBySQLWithArgs(String[] sqls, Object[][] args) throws DAOException {
    Number[] result = null;
    Connection con = null;
    try {
      con = ds.getConnection();
      result = JdbcUtil.updateWithArgs(con, sqls, args);
    } catch (Exception e) {
      throw new DAOException("updateBySQLWithArgs exception ", e);
    }

    return result;
  }
 public <T> Number deleteWhere(Class<T> clazz, String condition, Object[] args)
     throws DAOException {
   Number id = 0;
   if (clazz != null) {
     Connection con = null;
     try {
       con = ds.getConnection();
       String sql =
           SqlFactory.getDeleteSql(new Object[] {clazz.newInstance()})
               .deleteWhere(ORMConfigBeanUtil.parseQuery(condition, clazz));
       id = JdbcUtil.updateWithArgs(con, sql, args);
       // 缓存
     } catch (Exception e) {
       throw new DAOException("", e);
     }
   }
   return id;
 }
Exemple #3
0
  public int execute() {
    int id = -1;
    String sql =
        this.sql.toString().replace("${_where_}", this.condition.toString()).replace("'?'", "?");
    DataSource ds = DataSourceWrapCache.get(dsName);
    try {
      int rs = 0;
      if (args != null && args.size() > 0) {
        rs =
            (Integer)
                JdbcUtil.updateWithArgs(ds.getConnection(), sql, args.toArray(new Object[] {}));
      } else {
        rs = (Integer) JdbcUtil.update(ds.getConnection(), sql);
      }

      if (rs > 0 && sql.contains("INSERT INTO")) {
        if (Map.class.isAssignableFrom(clazz)) {
          if (map == null) {
            map = new HashMap<String, Object>();
            map.put("idColumn", "id");
            map.put("table", this.table);
          } else if (map.get("idColumn") == null) {
            map.put("idColumn", "id");
          }

          id = (Integer) DAOUtil.selectMaxId(map, ds.getConnection(), dbType);
        } else {
          id = (Integer) DAOUtil.selectMaxId(clazz, ds.getConnection(), dbType);
        }
      }

    } catch (SQLException e) {
      log.error("sql-->" + sql + "exception:" + StringUtil.getExceptionString(e));
      throw new DAOException(sql + " execute exception", e);
    }

    // this.clear();
    return id;
  }