diff options
Diffstat (limited to 'src/main/java/io/trygvis/esper/testing/sql')
3 files changed, 0 insertions, 142 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/sql/ResultSetF.java b/src/main/java/io/trygvis/esper/testing/sql/ResultSetF.java deleted file mode 100644 index e5a9e4e..0000000 --- a/src/main/java/io/trygvis/esper/testing/sql/ResultSetF.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.trygvis.esper.testing.sql; - -import java.sql.*; - -public class ResultSetF { - public static final SqlF<ResultSet, Integer> getInt = new SqlF<ResultSet, Integer>() { - public Integer apply(ResultSet rs) throws SQLException { - return rs.getInt(1); - } - }; - - public static final SqlF<ResultSet, Integer> getInteger = new SqlF<ResultSet, Integer>() { - public Integer apply(ResultSet rs) throws SQLException { - int i = rs.getInt(1); - return rs.wasNull() ? null : i; - } - }; -} diff --git a/src/main/java/io/trygvis/esper/testing/sql/SqlF.java b/src/main/java/io/trygvis/esper/testing/sql/SqlF.java deleted file mode 100644 index fb05e4c..0000000 --- a/src/main/java/io/trygvis/esper/testing/sql/SqlF.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.trygvis.esper.testing.sql; - -import java.sql.*; - -public abstract class SqlF<A, B> { - public abstract B apply(A a) throws SQLException; - - public <C> SqlF<A, C> andThen(final SqlF<B, C> f) { - return new SqlF<A, C>() { - public C apply(A a) throws SQLException { - return f.apply(SqlF.this.apply(a)); - } - }; - } -} diff --git a/src/main/java/io/trygvis/esper/testing/sql/SqlOption.java b/src/main/java/io/trygvis/esper/testing/sql/SqlOption.java deleted file mode 100644 index 288735a..0000000 --- a/src/main/java/io/trygvis/esper/testing/sql/SqlOption.java +++ /dev/null @@ -1,109 +0,0 @@ -package io.trygvis.esper.testing.sql; - -import java.sql.*; - -public abstract class SqlOption<A> { - public static <A> SqlOption<A> none() { - return new None<>(); - } - - public static <A> SqlOption<A> some(A a) { - return new Some<>(a); - } - - public static SqlOption<ResultSet> fromRs(ResultSet rs) throws SQLException { - if (!rs.next()) { - return none(); - } - - return some(rs); - } - - // ----------------------------------------------------------------------- - // - // ----------------------------------------------------------------------- - - public abstract <B> SqlOption<B> map(SqlF<A, B> f) throws SQLException; - - public <B> SqlOption<B> flatMap(SqlF<A, SqlOption<B>> f) throws SQLException { - SqlOption<SqlOption<B>> x = map(f); - - if (x.isNone()) { - return none(); - } - - return x.get(); - } - - public abstract A get() throws SQLException; - - public abstract boolean isSome(); - - public boolean isNone() { - return !isSome(); - } - - public abstract A getOrElse(A a); - - public static <A> SqlOption<A> fromNull(A a) { - if (a != null) { - return some(a); - } else { - return none(); - } - } - - // ----------------------------------------------------------------------- - // - // ----------------------------------------------------------------------- - - private static class None<A> extends SqlOption<A> { - public <B> SqlOption<B> map(SqlF<A, B> f) { - return none(); - } - - public A get() throws SQLException { - throw new SQLException("get() on None"); - } - - public boolean isSome() { - return false; - } - - public A getOrElse(A a) { - return a; - } - - public String toString() { - return "None"; - } - } - - private static class Some<A> extends SqlOption<A> { - private final A a; - - private Some(A a) { - this.a = a; - } - - public <B> SqlOption<B> map(SqlF<A, B> f) throws SQLException { - return some(f.apply(a)); - } - - public A get() { - return a; - } - - public boolean isSome() { - return true; - } - - public A getOrElse(A a) { - return this.a; - } - - public String toString() { - return "Some(" + a + ")"; - } - } -} |