/*
Creates a logging version of a ResultSet

@param rs - the ResultSet to proxy
@return - the ResultSet with logging
483484
public static ResultSet newInstance(ResultSet rs, Log statementLog, int queryStack) {
        InvocationHandler handler = new ResultSetLogger(rs, statementLog, queryStack);
        ClassLoader cl = ResultSet.class.getClassLoader();
        return (ResultSet) Proxy.newProxyInstance(cl, new Class[]{ResultSet.class}, handler);
    }
534628
public static void sqlRS(Connection conn, String sql, Consumer<ResultSet> consumer) {
        try (Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql)) {
            consumer.accept(rs);
        } catch (SQLException e) {
            logger.error(e.getMessage(), e);
        }
    }
1206466
static JobDef map(ResultSet rs, int colShift)
    {
        JobDef tmp = new JobDef();

        try
        {
            tmp.id = rs.getInt(1 + colShift);
            tmp.application = rs.getString(2 + colShift);
            tmp.applicationName = rs.getString(3 + colShift);
            tmp.canBeRestarted = true;
            tmp.classLoader = rs.getInt(4 + colShift) > 0 ? rs.getInt(4 + colShift) : null;
            tmp.description = rs.getString(5 + colShift);
            tmp.enabled = rs.getBoolean(6 + colShift);
            tmp.external = rs.getBoolean(7 + colShift);
            tmp.highlander = rs.getBoolean(8 + colShift);
            tmp.jarPath = rs.getString(9 + colShift);
            tmp.javaClassName = rs.getString(10 + colShift);
            tmp.javaOpts = rs.getString(11 + colShift);
            tmp.keyword1 = rs.getString(12 + colShift);
            tmp.keyword2 = rs.getString(13 + colShift);
            tmp.keyword3 = rs.getString(14 + colShift);
            tmp.maxTimeRunning = rs.getInt(15 + colShift);
            tmp.module = rs.getString(16 + colShift);
            tmp.pathType = PathType.valueOf(rs.getString(17 + colShift));
            tmp.queue_id = rs.getInt(18 + colShift);
            tmp.priority = rs.getInt(19 + colShift) > 0 ? rs.getInt(19 + colShift) : null;
        }
        catch (SQLException e)
        {
            throw new DatabaseException(e);
        }
        return tmp;
    }
183589
private void fetchResultBatchWithRetry(RecordSetList<JsonElement> rs)
      throws AsyncApiException, DataRecordException, IOException {
    boolean success = false;
    int retryCount = 0;
    int recordCountBeforeFetch = this.bulkRecordCount;

    do {
      try {
        // reinitialize the reader to establish a new connection to handle transient network errors
        if (retryCount > 0) {
          reinitializeBufferedReader();
        }

        // on retries there may already be records in rs, so pass the number of records as the initial count
        fetchResultBatch(rs, this.bulkRecordCount - recordCountBeforeFetch);
        success = true;
      } catch (IOException e) {
        if (retryCount < this.fetchRetryLimit) {
          log.info("Exception while fetching data, retrying: " + e.getMessage(), e);
          retryCount++;
        } else {
          log.error("Exception while fetching data: " + e.getMessage(), e);
          throw e;
        }
      }
    } while (!success);
  }
956346
public T mapRow(ResultSet rs) throws SQLException {
    Map<String, Object> map = new HashMap<String, Object>();
    ResultSetMetaData metadata = rs.getMetaData();

    for (int i = 1; i <= metadata.getColumnCount(); ++i) {
      String label = metadata.getColumnLabel(i);

      final Object value;
      // calling getObject on a BLOB/CLOB produces weird results
      switch (metadata.getColumnType(i)) {
        case Types.BLOB:
          value = rs.getBytes(i);
          break;
        case Types.CLOB:
          value = rs.getString(i);
          break;
        default:
          value = rs.getObject(i);
      }

      // don't use table name extractor because we don't want aliased table name
      boolean overwrite = this.tableName != null && this.tableName.equals(metadata.getTableName(i));
      String tableName = TABLE_NAME_EXTRACTOR.getTableName(metadata, i);
      if (tableName != null && !tableName.isEmpty()) {
        String qualifiedName = tableName + "." + metadata.getColumnName(i);
        add(map, qualifiedName, value, overwrite);
      }

      add(map, label, value, overwrite);
    }

    return objectMapper.convertValue(map, type);
  }
708604
public static <E, T extends Collection<E>> T handleRsToBeanList(ResultSet rs, T collection, Class<E> elementBeanType) throws SQLException {
		final ResultSetMetaData meta = rs.getMetaData();
		final int columnCount = meta.getColumnCount();

		while (rs.next()) {
			collection.add(handleRow(columnCount, meta, rs, elementBeanType));
		}

		return collection;
	}
348681
private Object getValue(final ResultSet rs, final ResultSetMetaData rsmd, final int columnIndex)
			throws SQLException {
		JavaType javaType = this.dialect.getJavaType(rsmd.getColumnType(columnIndex),
				rsmd.getColumnTypeName(columnIndex));
		return this.mapperManager.getValue(javaType, rs, columnIndex);
	}
196121
private IEntityLock instanceFromResultSet(java.sql.ResultSet rs)
            throws SQLException, LockingException {
        Integer entityTypeID = rs.getInt(1);
        Class entityType = EntityTypesLocator.getEntityTypes().getEntityTypeFromID(entityTypeID);
        String key = rs.getString(2);
        int lockType = rs.getInt(3);
        Timestamp ts = rs.getTimestamp(4);
        String lockOwner = rs.getString(5);

        return newInstance(entityType, key, lockType, ts, lockOwner);
    }
1108965
public ProxyDataSourceBuilder logQueryBySlf4j(SLF4JLogLevel logLevel, String slf4jLoggerName) {
        this.createSlf4jQueryListener = true;
        this.slf4jLogLevel = logLevel;
        this.slf4jLoggerName = slf4jLoggerName;
        return this;
    }
1031271
static void closeQuietly(ResultSet rs) {
        try {
            if (rs != null && !rs.isClosed()) {
                rs.close();
                log.debug("closed {}", rs);
            }
        } catch (SQLException e) {
            log.debug(e.getMessage(), e);
        } catch (RuntimeException e) {
            log.debug(e.getMessage(), e);
        }
    }
982439
public static void close(ResultSet rs) {
		Statement st = null;
		Connection con = null;
		try {
			try {
				if (rs != null) {
					st = rs.getStatement();
					rs.close();
				}
			} finally {
				try {
					if (st != null) {
						con = st.getConnection();
						st.close();
					}
				} finally {
					if (con != null) {
						con.close();
					}
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
1015759
public final List<Element> mapRowToList(final ResultSet rs, final String columnNameArray) throws SQLException {
        if (rs == null) {
            return Collections.emptyList();
        }

        final Array sqlArray = rs.getArray(columnNameArray);

        if (sqlArray == null) {
            return Collections.emptyList();
        } else {
            final ResultSet resultSet = sqlArray.getResultSet();
            final List<String> l = new ArrayList<String>();
            while (resultSet.next()) {
                String test = resultSet.getString(2);
                l.add(test);
            }

            List<Element> elements = new ArrayList<Element>(l.size());
            for (String s : l) {
                try {
                    List<String> resultList = ParseUtils.postgresROW2StringList(s);
                    Element element = new Element();
                    element.setRowList(resultList);
                    elements.add(element);
                } catch (Exception e) {
                    LOG.error("Problem parsing received ROW value [{}]: {}", new Object[] {s, e.getMessage(), e});
                }
            }

            return elements;
        }

    }
710
public static void closeResultSet(final ResultSet rs) {
        if (rs == null) {
            return;
        }

        try {
            rs.close();
        } catch (Exception e) {
            if (LOG.isWarnEnabled()) LOG.warn("Error closing ResultSet: " + rs, e);
        }
    }
162940
public static List<Integer> getIntegerList(final ResultSet rs, final String columnName) throws SQLException
    {
        final Array ary = rs.getArray(columnName);
        if (ary != null) {
            Preconditions.checkArgument(ary.getBaseType() == Types.INTEGER || ary.getBaseType() == Types.SMALLINT);
            return Arrays.asList((Integer []) ary.getArray());
        }
        return null;
    }
498234
int getSize(ResultSet rs) {
    try {
      if (rs.getType() == ResultSet.TYPE_FORWARD_ONLY) {
        return -1;
      }

      rs.last();
      int total = rs.getRow();
      rs.beforeFirst();
      return total;
    } catch (SQLException | AbstractMethodError sqle) {
      return -1;
    }
  }
129702
public static String getLongString(ResultSet rs, int pos)
            throws SQLException {
        return instance.i_getLongString(rs, pos);
    }
550588
private List iterateAndReturnNative(final ResultSet rSet) {
        final Iterator<Row> rowIter = rSet.iterator();
        final List results = new ArrayList();
        final List item = new ArrayList<>();

        final boolean isSingle = (rSet.getColumnDefinitions().size() == 1);

        while (rowIter.hasNext()) {
            final Row row = rowIter.next();

            final ColumnDefinitions columnDefs = row.getColumnDefinitions();

            final Iterator<Definition> columnDefIter = columnDefs.iterator();

            item.clear();

            while (columnDefIter.hasNext()) {
                final Definition columnDef = columnDefIter.next();

                item.add(DSClientUtilities.assign(row, null, null, columnDef.getType().getName(), null,
                    columnDef.getName(), null, null));
            }

            if (isSingle) {
                if (!item.isEmpty())
                    results.add(item.get(0));
                else
                    results.add(null);
            } else
                results.add(item.toArray(new Object[item.size()]));
        }

        return results;
    }