Leveraging Lambda for JDBC 4.2
Lance Andersen - Oracle
lance.andersen at oracle.com
Thu Dec 6 09:40:58 PST 2012
Folks
In order to make it a little easier for migration to the new JDBC releases I am planning to leverage default methods in Lambda.
For example;
interface Foo {
boolean hasFoo();
default long executeLargeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
throw new SQLFeatureNotSupportedException("setFoo not implemented");
}
default long getLargeUpdateCount() throws SQLException {
throw new UnsupportedOperationException("getLargeUpdateCount not implemented");
}
}
public class FooBar implements Foo {
public static void main(String[] args) throws Exception {
FooBar fb = new FooBar();
System.out.println("Has a Foo: " + fb.hasFoo());
try {
fb.getLargeUpdateCount();
} catch(Exception e) {
System.out.println("got: " + e);
}
try {
fb.executeLargeUpdate("hi", 1);
} catch(Exception e) {
System.out.println("got: " + e);
}
}
public boolean hasFoo() {
return true;
}
}
At runtime;
/ace2_apps/jdk8-ea/bin/java FooBar
Has a Foo: true
got: java.lang.UnsupportedOperationException: getLargeUpdateCount not implemented
got: java.sql.SQLFeatureNotSupportedException: setFoo not implemented
Optional methods will default to throwing a SQLFeatureNotSupportedException
Required methods will default to throwing a UnsupportedOperationException allowing for this to be flagged by the JDBC test suite as a compliance issue
Leveraging Lambda will allow existing code to compile on the new JDK without having to immediately add stubs or implementation.
Best
Lance
Lance Andersen| Principal Member of Technical Staff | +1.781.442.2037
Oracle Java Engineering
1 Network Drive
Burlington, MA 01803
Lance.Andersen at oracle.com
More information about the jdbc-spec-discuss
mailing list