java.sql.Array.getResultSet()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中java.sql.Array.getResultSet()方法的一些代码示例,展示了Array.getResultSet()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Array.getResultSet()方法的具体详情如下:
包路径:java.sql.Array
类名称:Array
方法名:getResultSet

Array.getResultSet介绍

[英]Returns a ResultSet object which holds the entries of the SQL ARRAY associated with this array.
[中]返回一个ResultSet对象,该对象包含与此数组关联的SQL数组的条目。

代码示例

代码示例来源:origin: jdbi/jdbi

private Object buildFromResultSet(java.sql.Array array, StatementContext ctx) throws SQLException {
    List<Object> list = new ArrayList<>();
    try (ResultSet rs = array.getResultSet()) {
      while (rs.next()) {
        list.add(elementMapper.map(rs, 2, ctx));
      }
    }

    Object ary = Array.newInstance(componentType, list.size());
    if (componentType.isPrimitive()) {
      for (int i = 0; i < list.size(); i++) {
        Array.set(ary, i, list.get(i));
      }
      return ary;
    }

    return list.toArray((Object[]) ary);
  }
}

代码示例来源:origin: jdbi/jdbi

private R buildFromResultSet(Array array, StatementContext ctx) throws SQLException {
    A result = collector.supplier().get();
    BiConsumer<A, T> accumulator = collector.accumulator();

    try (ResultSet rs = array.getResultSet()) {
      while (rs.next()) {
        accumulator.accept(result, elementMapper.map(rs, 2, ctx));
      }
    }

    return collector.finisher().apply(result);
  }
}

代码示例来源:origin: rakam-io/rakam

if (resultSet.wasNull()) return NullNode.getInstance();
ResultSet rs = array.getResultSet();
int arrIdx = 1;
if (rs.next()) {

代码示例来源:origin: co.paralleluniverse/comsat-jdbc

@Override
  public ResultSet call() throws SQLException {
    return array.getResultSet(map);
  }
});

代码示例来源:origin: co.paralleluniverse/comsat-jdbc

@Override
  public ResultSet call() throws SQLException {
    return array.getResultSet();
  }
});

代码示例来源:origin: co.paralleluniverse/comsat-jdbc

@Override
  public ResultSet call() throws SQLException {
    return array.getResultSet(index, count);
  }
});

代码示例来源:origin: co.paralleluniverse/comsat-jdbc

@Override
  public ResultSet call() throws SQLException {
    return array.getResultSet(index, count, map);
  }
});

代码示例来源:origin: org.apache.calcite.avatica/avatica-core

/** Returns whether two arrays have the same contents.
 *
 * <p>Arrays must have the same size, and elements in the same order.
 * Elements are compared using {@link Object#equals(Object)}, and null
 * values are equal to each other. */
public static boolean equalContents(Array left, Array right) throws SQLException {
 ResultSet leftResultSet = left.getResultSet();
 ResultSet rightResultSet = right.getResultSet();
 while (leftResultSet.next() && rightResultSet.next()) {
  if (!Objects.equals(leftResultSet.getObject(1), rightResultSet.getObject(1))) {
   return false;
  }
 }
 return !leftResultSet.next() && !rightResultSet.next();
}

代码示例来源:origin: apache/calcite-avatica

/** Returns whether two arrays have the same contents.
 *
 * <p>Arrays must have the same size, and elements in the same order.
 * Elements are compared using {@link Object#equals(Object)}, and null
 * values are equal to each other. */
public static boolean equalContents(Array left, Array right) throws SQLException {
 ResultSet leftResultSet = left.getResultSet();
 ResultSet rightResultSet = right.getResultSet();
 while (leftResultSet.next() && rightResultSet.next()) {
  if (!Objects.equals(leftResultSet.getObject(1), rightResultSet.getObject(1))) {
   return false;
  }
 }
 return !leftResultSet.next() && !rightResultSet.next();
}

代码示例来源:origin: org.jdbi/jdbi3

private C buildFromResultSet(java.sql.Array array, StatementContext ctx) throws SQLException {
    C result = collectionSupplier.get();

    try (ResultSet rs = array.getResultSet()) {
      while (rs.next()) {
        result.add(elementMapper.map(rs, 2, ctx));
      }
    }

    return result;
  }
}

代码示例来源:origin: de.unijena.bioinf.ms/chemdb_sql_oss

private Fingerprint parseFingerprint(ResultSet result, int index) throws SQLException {
  try (final ResultSet fp = result.getArray(index).getResultSet()) {
    return parseFingerprint(fp);
  }
}

代码示例来源:origin: jajja/jorm

public static <T> List<T> toList(Class<T> clazz, Array array) throws SQLException {
  List<T> values = null;
  if (array != null) {
    values = new LinkedList<T>();
    ResultSet rs = array.getResultSet();
    while (rs.next()) {
      values.add(Row.convert(rs.getObject(2), clazz));
    }
  }
  return values;
}

代码示例来源:origin: org.ballerinalang/ballerina-sql

/**
 * This will retrieve the string value for the given array data.
 *
 * @param dataArray data
 * @return string value
 * @throws SQLException sql exception when reading result set
 */
public static String getString(Array dataArray) throws SQLException {
  if (dataArray == null) {
    return null;
  }
  StringJoiner sj = new StringJoiner(",", "[", "]");
  ResultSet rs = dataArray.getResultSet();
  while (rs.next()) {
    Object arrayEl = rs.getObject(2);
    String val = String.valueOf(arrayEl);
    sj.add(val);
  }
  return sj.toString();
}

代码示例来源:origin: arnaudroger/SimpleFlatMapper

@Override
  public List<T> convert(Array in, Context context) throws Exception {
    if (in == null) return null;
    List<T> list = new ArrayList<T>();

    ResultSet rs = in.getResultSet();
    try {
      while(rs.next()) {
        list.add(getter.get(rs));
      }
    } finally {
      rs.close();
    }
    return list;
  }
}

代码示例来源:origin: org.simpleflatmapper/sfm-jdbc

@Override
  public List<T> convert(Array in, Context context) throws Exception {
    if (in == null) return null;
    List<T> list = new ArrayList<T>();

    ResultSet rs = in.getResultSet();
    try {
      while(rs.next()) {
        list.add(getter.get(rs));
      }
    } finally {
      rs.close();
    }
    return list;
  }
}

代码示例来源:origin: stackoverflow.com

conn = ds.getConnection();
   String storedProc = "{call enquiry_activity_report(?)}";
   CallableStatement cs = conn.prepareCall(storedProc);
   // register output parameter
   cs.registerOutParameter(1, OracleTypes.ARRAY, "ACTIVITY_REPORT_ITEMS_TYPE");
   cs.execute();
   Array array = cs.getArray(1);
   ResultSet rs = array.getResultSet();
   while (rs.next()) {
     // why getObject(2) instead of getObject(1)?
     Object elements[] = ((STRUCT) rs.getObject(2)).getAttributes();
     System.out.println(elements[0]);
     System.out.println(elements[1]);
     System.out.println(elements[2]);
   }
   cs.close();

代码示例来源:origin: org.jdbi/jdbi3

private Object buildFromResultSet(java.sql.Array array, StatementContext ctx) throws SQLException {
    List<Object> list = new ArrayList<>();
    try (ResultSet rs = array.getResultSet()) {
      while (rs.next()) {
        list.add(elementMapper.map(rs, 2, ctx));
      }
    }

    Object ary = Array.newInstance(componentType, list.size());
    if (componentType.isPrimitive()) {
      for (int i = 0; i < list.size(); i++) {
        Array.set(ary, i, list.get(i));
      }
      return ary;
    }

    return list.toArray((Object[]) ary);
  }
}

代码示例来源:origin: org.apache.calcite.avatica/avatica-server

/**
 * Converts an Array into a List using {@link Array#getResultSet()}. This implementation is
 * recursive and can parse multi-dimensional arrays.
 */
static List<?> extractUsingResultSet(Array array, Calendar calendar) throws SQLException {
 ResultSet arrayValues = array.getResultSet();
 TreeMap<Integer, Object> map = new TreeMap<>();
 while (arrayValues.next()) {
  // column 1 is the index in the array, column 2 is the value.
  // Recurse on `getValue` to unwrap nested types correctly.
  // `j` is zero-indexed and incremented for us, thus we have `1` being used twice.
  map.put(arrayValues.getInt(1), getValue(arrayValues, array.getBaseType(), 1, calendar));
 }
 // If the result set is not in the same order as the actual Array, TreeMap fixes that.
 // Need to make a concrete list to ensure Jackson serialization.
 return new ArrayList<>(map.values());
}

代码示例来源:origin: apache/calcite-avatica

/**
 * Converts an Array into a List using {@link Array#getResultSet()}. This implementation is
 * recursive and can parse multi-dimensional arrays.
 */
static List<?> extractUsingResultSet(Array array, Calendar calendar) throws SQLException {
 ResultSet arrayValues = array.getResultSet();
 TreeMap<Integer, Object> map = new TreeMap<>();
 while (arrayValues.next()) {
  // column 1 is the index in the array, column 2 is the value.
  // Recurse on `getValue` to unwrap nested types correctly.
  // `j` is zero-indexed and incremented for us, thus we have `1` being used twice.
  map.put(arrayValues.getInt(1), getValue(arrayValues, array.getBaseType(), 1, calendar));
 }
 // If the result set is not in the same order as the actual Array, TreeMap fixes that.
 // Need to make a concrete list to ensure Jackson serialization.
 return new ArrayList<>(map.values());
}

代码示例来源:origin: kaif-open/kaif

default <T> Stream<T> convertArray(Array array,
  CheckedSqlBiFunction<ResultSet, Integer, T> extract) {
 try {
  Stream.Builder<T> builder = Stream.builder();
  try (ResultSet arrayRs = array.getResultSet()) {
   while (arrayRs.next()) {
    // index 1 is array index number, so extract should use 2
    builder.add(extract.apply(arrayRs, 2));
   }
  }
  return builder.build();
 } catch (SQLException e) {
  // see NamedParameterJdbcTemplate for source code
  throw ((JdbcTemplate) jdbc()).getExceptionTranslator()
    .translate("could not convert array: " + array, null, e);
 }
}

相关文章

微信公众号

最新文章

更多