From: adam Date: Sat, 17 Mar 2007 08:50:30 +0000 (+0000) Subject: add experimental Fountain.DatabaseColumn X-Git-Url: http://git.megacz.com/?p=org.ibex.io.git;a=commitdiff_plain;h=5cd3a7e2cd07d5a09a7649da341f49ea7a6dac95 add experimental Fountain.DatabaseColumn darcs-hash:20070317085030-5007d-491876651021b006d25b7aa7578363f2dbab97a3.gz --- 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 { //}