Example usage for java.sql Array getBaseTypeName

List of usage examples for java.sql Array getBaseTypeName

Introduction

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

Prototype

String getBaseTypeName() throws SQLException;

Source Link

Document

Retrieves the SQL type name 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;//ww w.  ja v a  2  s .c  om
    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  a v 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;

}