Ejemplo n.º 1
0
 public <T> Collection<T> mapMany(ResultSet resultSet, RowMapper<T> mapper) throws Throwable {
   Collection<T> ret = new ArrayList<>();
   while (resultSet.next()) {
     ret.add(mapper.apply(resultSet).getOrElseThrow(Function.identity()));
   }
   return ret;
 }
Ejemplo n.º 2
0
 /**
  * Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the
  * query, mapping each row to a Java object via a RowMapper.
  *
  * @param sql
  * @param args
  * @param sqlTypes
  * @param rowMapper
  * @return
  * @throws SQLException
  */
 public List query(final String sql, Object[] args, int[] sqlTypes, RowMapper rowMapper) {
   if (showSql) {
     logger.info(getFinalSql(sql, args, sqlTypes));
   }
   Connection conn = null;
   PreparedStatement pstmt = null;
   ResultSet rs = null;
   try {
     conn = getConnection();
     pstmt = conn.prepareStatement(sql);
     if (args != null) {
       if (sqlTypes == null) {
         JdbcUtils.setPreparedStatementValue(pstmt, args);
       } else {
         JdbcUtils.setPreparedStatementValue(pstmt, args, sqlTypes);
       }
     }
     applyQueryTimeOut(pstmt);
     rs = pstmt.executeQuery();
     if (rs == null) {
       return null;
     } else {
       List resultList = new ArrayList();
       while (rs.next()) {
         resultList.add(rowMapper.mapRow(rs, rs.getRow()));
       }
       return resultList;
     }
   } catch (SQLException e) {
     throw new RuntimeException(e);
   } finally {
     JdbcUtils.closeQuietly(conn, pstmt, rs);
   }
 }
Ejemplo n.º 3
0
 public <T> T map(ResultSet resultSet, RowMapper<T> mapper) throws Throwable {
   resultSet.next();
   return mapper.apply(resultSet).getOrElseThrow(Function.identity());
 }
 /**
  * {@inheritDoc}
  *
  * @param row1 A {@link Row}.
  * @param row2 A {@link Row}.
  * @return A negative integer, zero, or a positive integer as the first argument is less than,
  *     equal to, or greater than the second according to a Lucene {@link Sort}.
  */
 @Override
 public int compare(Row row1, Row row2) {
   Columns columns1 = rowMapper.columns(row1);
   Columns columns2 = rowMapper.columns(row2);
   return comparatorChain.compare(columns1, columns2);
 }