requiredProjections.add(downloadMap.getContentDownloadColumn());
requiredProjections.addAll(mediaTypeValueMaker.projectionSpecs());
newRelation.project(requiredProjections);
newRelation.limit(1);
Relation filteredRelation = newRelation.immutableSnapshot();
SelectStatementBuilder builder = new SelectStatementBuilder(filteredRelation);
String sql = builder.getSQLStatement();
int contentColumn = builder.getColumnSpecs().indexOf(downloadMap.getContentDownloadColumn()) + 1;
db = filteredRelation.database();
Connection conn = db.connection();
try {
statement = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
log.debug(sql);
db.vendor().beforeQuery(conn);
resultSet = statement.executeQuery(sql);
db.vendor().afterQuery(conn);
if (!resultSet.next()) {
close();
return; // 0 results
}
int type = resultSet.getMetaData().getColumnType(contentColumn);
// TODO Handle Oracle BFILE type; there's some code for that already in ResultRowMap
if (type == Types.BINARY || type == Types.VARBINARY || type == Types.LONGVARBINARY || type == Types.BLOB) {
resultStream = resultSet.getBinaryStream(contentColumn);
if (resultSet.wasNull()) {
resultStream = null;
}
} else {
String s = resultSet.getString(contentColumn);
if (!resultSet.wasNull()) {
resultStream = new ByteArrayInputStream(s.getBytes());
}
}
mediaType = mediaTypeValueMaker.makeValue(
ResultRowMap.fromResultSet(resultSet, builder.getColumnSpecs(), db));
} catch (SQLException ex) {
throw new D2RQException(ex);
}
}