X-Git-Url: http://git.megacz.com/?p=org.ibex.io.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fio%2FFountain.java;h=849544fbf6cb3e11ae0d3a8896d7edacfcaf90cc;hp=dd216589b6d38db1abd98e13e5e223a1c0c9e443;hb=5cd3a7e2cd07d5a09a7649da341f49ea7a6dac95;hpb=f24a25bd4b457e97d578f2a1dc86f40b517a35da diff --git a/src/org/ibex/io/Fountain.java b/src/org/ibex/io/Fountain.java index dd21658..849544f 100644 --- a/src/org/ibex/io/Fountain.java +++ b/src/org/ibex/io/Fountain.java @@ -77,6 +77,55 @@ public interface Fountain { } } + // FIXME: untested + // note: only one ResultSet is allowed per Statement + public static class DatabaseColumn implements Fountain { + private ResultSet rs; + private int row; + private int column; + public DatabaseColumn(ResultSet rs, int column) throws SQLException { + this(rs, column, rs.getRow()); + } + public DatabaseColumn(ResultSet rs, int column, int row) throws SQLException { + this.rs = rs; + this.row = row; + this.column = column; + synchronized(rs) { + int type = rs.getType(); + if ((type | ResultSet.TYPE_SCROLL_INSENSITIVE) == 0) + throw new RuntimeException("Fountain.DatabaseColumn(ResultSet,int) requires a SCROLL_INSENSITIVE ResultSet"); + if ((type | ResultSet.TYPE_FORWARD_ONLY) != 0) + throw new RuntimeException("Fountain.DatabaseColumn(ResultSet,int) cannot use TYPE_FORWARD_ONLY ResultSets"); + } + // FIXME: do we want to check HOLD_CURSORS_OVER_COMMIT ? + } + private Blob getBlob() throws SQLException { + synchronized(rs) { + if (!rs.absolute(row)) + throw new RuntimeException("resultset was unable to move to desired row"); + return rs.getBlob(column); + } + } + public Stream getStream() { + try { + synchronized(rs) { + return new Stream(rs.getBinaryStream(column)); + } + } catch (SQLException e) { throw new RuntimeException(e); } + } + public long getLength() { + try { + synchronized(rs) { + return getBlob().length(); + } + } catch (SQLException e) { throw new RuntimeException(e); } + } + public int getNumLines() { + throw new RuntimeException("not implemented"); + } + } + + //public static class LazyCachingStreamFountain implements Fountain { //}