Beispiel #1
0
  public static List<? extends Object> getObjectsByParam(
      String sql,
      Object[] param,
      Connection con,
      int offset,
      int limit,
      String myOrderBy,
      JDBCMapper mapper) {
    if (offset < 0) {
      offset = 0;
      logger.warn("negative offset not allowed on server side. reset to 0.");
    }

    if (limit > MAX_BATCH_SIZE) {
      limit = MAX_BATCH_SIZE;
      logger.warn(
          "limit larger than max_batch_size not allowed on server side. reset to "
              + MAX_BATCH_SIZE);
    }

    ArrayList<Object> objects = new ArrayList<Object>();
    String limitClause = getLimitRange(offset, limit);
    String orderBy = "";
    if (myOrderBy == null) {
      orderBy = " order by name ";
    } else {
      orderBy = myOrderBy;
    }

    PreparedStatement statement = null;
    try {
      statement = con.prepareStatement(sql + orderBy + limitClause);
      SqlUtil.bindParameters(statement, param);
      ResultSet rs = statement.executeQuery();
      while (rs.next()) {
        Object c = mapper.getObject(rs);
        logger.info("got object: " + c);
        objects.add(c);
      }
      if (rs != null && !rs.isClosed()) {
        rs.close();
      }
      return objects;
    } catch (Exception e) {
      logger.error("", e);
      return objects;
    } finally {
      SqlUtil.closeResources(null, statement);
    }
  }
Beispiel #2
0
 public static List<? extends Object> getObjectsByParam(
     String sql,
     Object[] param,
     Connection db,
     int offset,
     int limit,
     String myOrderBy,
     JDBCMapper mapper,
     DataSource dataSource) {
   ArrayList<Object> objects = new ArrayList<Object>();
   Connection con = null;
   try {
     if (db == null) {
       con = dataSource.getConnection();
     } else {
       con = db;
     }
     return getObjectsByParam(sql, param, con, offset, limit, myOrderBy, mapper);
   } catch (Exception e) {
     logger.error("", e);
     return objects;
   } finally {
     if (db == null) {
       SqlUtil.closeResources(con, null);
     }
   }
 }