Esempio n. 1
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);
     }
   }
 }
Esempio n. 2
0
 public static void execUpdateSQL(Connection db, String sql) {
   Statement statement = null;
   try {
     statement = db.createStatement();
     statement.executeUpdate(sql);
   } catch (Exception e) {
     logger.error("", e);
   } finally {
     closeResources(null, statement);
   }
 }
Esempio n. 3
0
 public static void execUpdateSQL(String sql, DataSource ds) {
   Connection con = null;
   try {
     con = ds.getConnection();
     execUpdateSQL(con, sql);
   } catch (Exception e) {
     logger.error("", e);
   } finally {
     closeResources(con, null);
   }
 }
Esempio n. 4
0
 // put the in(List) parameter at the last
 public static long getSingleIntResultSQL(String sql, Object[] param, DataSource ds) {
   Connection con = null;
   try {
     con = ds.getConnection();
     return getSingleIntResultSQL(sql, param, con);
   } catch (Exception e) {
     logger.error("", e);
     return -1;
   } finally {
     closeResources(con, null);
   }
 }
Esempio n. 5
0
 public static int execUpdateSQLWithParams(Connection db, String sql, Object[] params) {
   PreparedStatement statement = null;
   try {
     statement = db.prepareStatement(sql);
     bindParameters(statement, params);
     return statement.executeUpdate();
   } catch (Exception e) {
     logger.error("", e);
     return 0;
   } finally {
     closeResources(null, statement);
   }
 }
Esempio n. 6
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);
    }
  }
Esempio n. 7
0
 public static int deleteBySQL(String sql, String param, DataSource ds) {
   Connection con = null;
   PreparedStatement statement = null;
   int ret = -1;
   try {
     con = ds.getConnection();
     statement = con.prepareStatement(sql);
     statement.setString(1, param);
     ret = statement.executeUpdate();
     return ret;
   } catch (Exception e) {
     logger.error("", e);
     return ret;
   } finally {
     closeResources(con, statement);
   }
 }