Exemple #1
0
  public DAOImpl(String dsName) {
    this.dsName = dsName;

    this.dsName = dsName;
    this.ds = DataSourceWrapCache.get(dsName);

    dbType = DBInfoConfigBeanCache.get(dsName).getDataBaseType();
  }
Exemple #2
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;
  }
Exemple #3
0
  private void init(Class<?> clazz, String dsName) {
    if (dsName == null) dsName = DAOConfigConstant.MYDBINFO;

    this.clazz = clazz;
    this.dsName = dsName;
    this.ds = DataSourceWrapCache.get(dsName);

    dbType = DBInfoConfigBeanCache.get(dsName).getDataBaseType();
    if (Map.class.isAssignableFrom(clazz)) {
      if (this.map != null) {
        selectAllColumn = ORMConfigBeanUtil.getSelectAllColumn(map);
        table = (String) map.get("table");
      }
    } else {
      this.table = ORMConfigBeanUtil.getTable(clazz);
      selectAllColumn = ORMConfigBeanUtil.getSelectAllColumn(clazz);
    }

    if (selectAllColumn == null || selectAllColumn.trim().length() == 0) selectAllColumn = "*";

    this.buffer.put("orderField", ORMConfigBeanUtil.getIdField(clazz));
    this.buffer.put("orderType", OrderType.DESC_ORDER);
  }