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

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

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

Array.getBaseType介绍

[英]Returns the JDBC type of the entries in this array's underlying SQL array.
[中]返回此数组的基础SQL数组中项的JDBC类型。

代码示例

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

private Object buildArray(java.sql.Array array, StatementContext ctx) throws SQLException {
  if (!UNSUPPORTED_TYPES.contains(array.getBaseType())) {
    try {
      Object ary = array.getArray();
      if (componentType.equals(ary.getClass().getComponentType())) {
        return ary;
      }
    } catch (SQLFeatureNotSupportedException ignore) {}
  }
  UNSUPPORTED_TYPES.add(array.getBaseType());
  return buildFromResultSet(array, ctx);
}

代码示例来源:origin: apache/phoenix

public static PDataType fromLiteral(Object value) {
  if (value == null) { return null; }
  for (PDataType type : PDataType.values()) {
    if (type.isArrayType()) {
      if (value instanceof PhoenixArray) {
        PhoenixArray arr = (PhoenixArray)value;
        if ((type.getSqlType() == arr.baseType.sqlType + PDataType.ARRAY_TYPE_BASE)
            && type.getJavaClass().isInstance(value)) { return type; }
      } else {
        Array arr = (Array) value;
        try {
          // Does the array's component type make sense for what we were told it is
          if (arr.getBaseType() == type.getSqlType() - PDataType.ARRAY_TYPE_BASE) {
            return type;
          }
        } catch (SQLException e) { /* Passthrough to fail */ }
      }
    } else {
      if (type.getJavaClass().isInstance(value)) { return type; }
    }
  }
  throw new UnsupportedOperationException("Unsupported literal value [" + value + "] of type "
      + value.getClass().getName());
}

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

@Override
  public Integer call() throws SQLException {
    return array.getBaseType();
  }
});

代码示例来源:origin: com.nesscomputing.components/ness-jdbi

public static List<String> getStringList(final ResultSet rs, final int columnIndex) throws SQLException
{
  final Array ary = rs.getArray(columnIndex);
  if (ary != null) {
    Preconditions.checkArgument(ary.getBaseType() == Types.VARCHAR || ary.getBaseType() == Types.CHAR);
    return Arrays.asList((String []) ary.getArray());
  }
  return null;
}

代码示例来源:origin: com.nesscomputing.components/ness-jdbi

public static List<Integer> getIntegerList(final ResultSet rs, final int columnIndex) throws SQLException
{
  final Array ary = rs.getArray(columnIndex);
  if (ary != null) {
    Preconditions.checkArgument(ary.getBaseType() == Types.INTEGER || ary.getBaseType() == Types.SMALLINT);
    return Arrays.asList((Integer []) ary.getArray());
  }
  return null;
}

代码示例来源:origin: com.nesscomputing.components/ness-jdbi

/**
 * Returns an array of Integer or null if the input is null. Null is intentional (not empty list), to be
 * able to distinguish between null value and empty list in the db.
 */
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;
}

代码示例来源:origin: com.nesscomputing.components/ness-jdbi

/**
 * Returns an array of Strings or null if the input is null. Null is intentional (not empty list), to be
 * able to distinguish between null value and empty list in the db.
 */
public static List<String> getStringList(final ResultSet rs, final String columnName) throws SQLException
{
  final Array ary = rs.getArray(columnName);
  if (ary != null) {
    Preconditions.checkArgument(ary.getBaseType() == Types.VARCHAR || ary.getBaseType() == Types.CHAR);
    return Arrays.asList((String []) ary.getArray());
  }
  return null;
}

代码示例来源:origin: com.nesscomputing.components/ness-jdbi

/**
 * Returns an array of Long or null if the input is null. Null is intentional (not empty list), to be
 * able to distinguish between null value and empty list in the db.
 */
public static List<Long> getLongList(final ResultSet rs, final String columnName) throws SQLException
{
  final Array ary = rs.getArray(columnName);
  if (ary != null) {
    Preconditions.checkArgument(ary.getBaseType() == Types.BIGINT);
    return Arrays.asList((Long []) ary.getArray());
  }
  return null;
}

代码示例来源:origin: com.nesscomputing.components/ness-jdbi

public static List<Long> getLongList(final ResultSet rs, final int columnIndex) throws SQLException
  {
    final Array ary = rs.getArray(columnIndex);
    if (ary != null) {
      Preconditions.checkArgument(ary.getBaseType() == Types.BIGINT);
      return Arrays.asList((Long []) ary.getArray());
    }
    return null;
  }
}

代码示例来源: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: org.nuxeo.ecm.core/nuxeo-core-storage-sql

@Override
public Serializable[] getArrayResult(Array array) throws SQLException {
  Serializable[] ids;
  if (array.getBaseType() == Types.NUMERIC) {
    long[] longs;
    try {
      longs = (long[]) arrayGetLongArrayMethod.invoke(array);
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
      throw new RuntimeException(e);
    }
    ids = new Serializable[longs.length];
    for (int i = 0; i < ids.length; i++) {
      ids[i] = Long.valueOf(longs[i]);
    }
  } else {
    ids = (Serializable[]) array.getArray();
  }
  return ids;
}

代码示例来源:origin: prestodb/tempto

private QueryResultValueComparator comparatorForArrayElements(Array actualArray)
{
  QueryResultValueComparator elementComparator;
  try {
    elementComparator = comparatorForType(JDBCType.valueOf(actualArray.getBaseType()), configuration);
  }
  catch (SQLException e) {
    throw Throwables.propagate(e);
  }
  return elementComparator;
}

代码示例来源:origin: korpling/ANNIS

@Override
 public Annotation mapRow(ResultSet rs, int rowNum) throws SQLException
 {

  Integer pre = rs.getInt("pre");
  String corpusName = rs.getString("corpus_name");
  String type = rs.getString("type");
  String namespace = rs.getString("namespace");
  String name = rs.getString("name");
  String value = rs.getString("value");
  Array annotationPathArray = rs.getArray("path_name");
  List<String> annotationPath = new LinkedList<>();
  if(annotationPathArray.getBaseType() == Types.VARCHAR)
  {
   annotationPath = Arrays.asList((String[]) annotationPathArray.getArray());
  }
  return new Annotation(namespace, name, value, type, corpusName, pre,
   annotationPath);
 }
}

代码示例来源:origin: com.teradata.tempto/tempto-core

private QueryResultValueComparator comparatorForArrayElements(Array actualArray)
{
  QueryResultValueComparator elementComparator;
  try {
    elementComparator = comparatorForType(JDBCType.valueOf(actualArray.getBaseType()), configuration);
  }
  catch (SQLException e) {
    throw Throwables.propagate(e);
  }
  return elementComparator;
}

代码示例来源: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: org.jdbi/jdbi3

private Object buildArray(java.sql.Array array, StatementContext ctx) throws SQLException {
  if (!UNSUPPORTED_TYPES.contains(array.getBaseType())) {
    try {
      Object ary = array.getArray();
      if (componentType.equals(ary.getClass().getComponentType())) {
        return ary;
      }
    } catch (SQLFeatureNotSupportedException swallowed) {
      // fall through
    }
  }
  UNSUPPORTED_TYPES.add(array.getBaseType());
  return buildFromResultSet(array, ctx);
}

代码示例来源:origin: korpling/ANNIS

@Override
 public Annotation mapRow(ResultSet rs, int rowNum) throws SQLException
 {
  Annotation annotation = new Annotation();
  annotation.setName(rs.getString("name"));
  annotation.setPre(rs.getInt("pre"));
  Array annotationPathArray = rs.getArray("path_name");
  List<String> annotationPath = new LinkedList<>();
  if(annotationPathArray.getBaseType() == Types.VARCHAR)
  {
   annotationPath = Arrays.asList((String[]) annotationPathArray.getArray());
  }
  annotation.setAnnotationPath(annotationPath);
  return annotation;
 }
}

代码示例来源:origin: yandex/clickhouse-jdbc

@Override
public void setArray(int parameterIndex, Array x) throws SQLException {
  setBind(parameterIndex, ClickHouseArrayUtil.arrayToString(x.getArray(), x.getBaseType() != Types.BINARY));
}

代码示例来源:origin: ru.yandex.clickhouse/clickhouse-jdbc

@Override
public void setArray(int parameterIndex, Array x) throws SQLException {
  setBind(parameterIndex, ClickHouseArrayUtil.arrayToString(x.getArray(), x.getBaseType() != Types.BINARY));
}

代码示例来源:origin: com.aliyun.phoenix/ali-phoenix-core

public static PDataType fromLiteral(Object value) {
  if (value == null) { return null; }
  for (PDataType type : PDataType.values()) {
    if (type.isArrayType()) {
      if (value instanceof PhoenixArray) {
        PhoenixArray arr = (PhoenixArray)value;
        if ((type.getSqlType() == arr.baseType.sqlType + PDataType.ARRAY_TYPE_BASE)
            && type.getJavaClass().isInstance(value)) { return type; }
      } else {
        Array arr = (Array) value;
        try {
          // Does the array's component type make sense for what we were told it is
          if (arr.getBaseType() == type.getSqlType() - PDataType.ARRAY_TYPE_BASE) {
            return type;
          }
        } catch (SQLException e) { /* Passthrough to fail */ }
      }
    } else {
      if (type.getJavaClass().isInstance(value)) { return type; }
    }
  }
  throw new UnsupportedOperationException("Unsupported literal value [" + value + "] of type "
      + value.getClass().getName());
}

相关文章

微信公众号

最新文章

更多