Example usage for java.sql Array getBaseType

List of usage examples for java.sql Array getBaseType

Introduction

In this page you can find the example usage for java.sql Array getBaseType.

Prototype

int getBaseType() throws SQLException;

Source Link

Document

Retrieves the JDBC type of the elements in the array designated by this Array object.

Usage

From source file:annis.sqlgen.AnnotatedSpanExtractor.java

@Override
public AnnotatedSpan mapRow(ResultSet resultSet, int rowNum) throws SQLException {
    long id = resultSet.getLong("id");
    String coveredText = resultSet.getString("span");

    Array arrayAnnotation = resultSet.getArray("annotations");
    ResultSetMetaData rsMeta = resultSet.getMetaData();
    Array arrayMeta = null;//from  www  .j  av  a 2 s .c o m
    for (int i = 1; i <= rsMeta.getColumnCount(); i++) {
        if ("metadata".equals(rsMeta.getColumnName(i))) {
            arrayMeta = resultSet.getArray(i);
            break;
        }
    }

    List<Annotation> annotations = extractAnnotations(arrayAnnotation);
    List<Annotation> metaData = arrayMeta == null ? new LinkedList<Annotation>()
            : extractAnnotations(arrayMeta);

    // create key
    Array sqlKey = resultSet.getArray("key");
    Validate.isTrue(!resultSet.wasNull(), "Match group identifier must not be null");
    Validate.isTrue(sqlKey.getBaseType() == Types.BIGINT,
            "Key in database must be from the type \"bigint\" but was \"" + sqlKey.getBaseTypeName() + "\"");

    List<Long> key = Arrays.asList((Long[]) sqlKey.getArray());

    return new AnnotatedSpan(id, coveredText, annotations, metaData, key);
}

From source file:annis.sqlgen.MatrixSqlGenerator.java

@Override
public List<AnnotatedMatch> extractData(ResultSet resultSet) throws SQLException, DataAccessException {
    List<AnnotatedMatch> matches = new ArrayList<AnnotatedMatch>();

    Map<List<Long>, AnnotatedSpan[]> matchesByGroup = new HashMap<List<Long>, AnnotatedSpan[]>();

    while (resultSet.next()) {
        long id = resultSet.getLong("id");
        String coveredText = resultSet.getString("span");

        Array arrayAnnotation = resultSet.getArray("annotations");
        Array arrayMeta = resultSet.getArray("metadata");

        List<Annotation> annotations = extractAnnotations(arrayAnnotation);
        List<Annotation> metaData = extractAnnotations(arrayMeta);

        // create key
        Array sqlKey = resultSet.getArray("key");
        Validate.isTrue(!resultSet.wasNull(), "Match group identifier must not be null");
        Validate.isTrue(sqlKey.getBaseType() == Types.BIGINT,
                "Key in database must be from the type \"bigint\" but was \"" + sqlKey.getBaseTypeName()
                        + "\"");

        Long[] keyArray = (Long[]) sqlKey.getArray();
        int matchWidth = keyArray.length;
        List<Long> key = Arrays.asList(keyArray);

        if (!matchesByGroup.containsKey(key)) {
            matchesByGroup.put(key, new AnnotatedSpan[matchWidth]);
        }//  w w w . j av a  2 s . c  o  m

        // set annotation spans for *all* positions of the id
        // (node could have matched several times)
        for (int posInMatch = 0; posInMatch < key.size(); posInMatch++) {
            if (key.get(posInMatch) == id) {
                matchesByGroup.get(key)[posInMatch] = new AnnotatedSpan(id, coveredText, annotations, metaData);
            }
        }
    }

    for (AnnotatedSpan[] match : matchesByGroup.values()) {
        matches.add(new AnnotatedMatch(Arrays.asList(match)));
    }

    return matches;

}

From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectOracle.java

@Override
public Serializable[] getArrayResult(Array array) throws SQLException {
    Serializable[] ids;//w ww.  ja  v  a2  s  .  c o m
    if (array.getBaseType() == Types.NUMERIC) {
        long[] longs;
        try {
            longs = (long[]) arrayGetLongArrayMethod.invoke(array);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException(e);
        } catch (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;
}

From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectPostgreSQL.java

@Override
@SuppressWarnings("boxing")
public Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException {
    int jdbcType = rs.getMetaData().getColumnType(index);
    if (column.getJdbcType() == Types.ARRAY && jdbcType != Types.ARRAY) {
        jdbcType = column.getJdbcBaseType();
    } else {//from www .  j av a  2s. c om
        jdbcType = column.getJdbcType();
    }
    switch (jdbcType) {
    case Types.VARCHAR:
    case Types.CLOB:
        return getFromResultSetString(rs, index, column);
    case Types.BIT:
        return rs.getBoolean(index);
    case Types.SMALLINT:
    case Types.INTEGER:
    case Types.BIGINT:
        return rs.getLong(index);
    case Types.DOUBLE:
        return rs.getDouble(index);
    case Types.TIMESTAMP:
        return getCalendarFromTimestamp(rs.getTimestamp(index));
    case Types.ARRAY:
        Array array = rs.getArray(index);
        if (array == null) {
            return null;
        }
        if (array.getBaseType() == Types.TIMESTAMP) {
            return getCalendarFromTimestamp((Timestamp[]) array.getArray());
        } else {
            return (Serializable) array.getArray();
        }
    case Types.OTHER:
        ColumnType type = column.getType();
        if (type.isId()) {
            return getId(rs, index);
        }
        throw new SQLException("Unhandled type: " + column.getType());
    }
    throw new SQLException(
            "Unhandled JDBC type: " + column.getJdbcType() + " for type " + column.getType().toString());
}