Make Schema and StatementExecutor interfaces AutoCloseable We target Java 7, so this should make things nicer. We do not make ResultSets AutoCloseable because they are implicitly closed when iteration is finished, and close should otherwise be called manually; they aren't really used from ARM blocks. Override the existing close methods so we can remove the exception, as the existing close implementations don't throw. Change-Id: Ibc628eb1d7694e52078bacef4866a2ec55b369d2
diff --git a/src/main/java/com/google/gwtorm/jdbc/JdbcExecutor.java b/src/main/java/com/google/gwtorm/jdbc/JdbcExecutor.java index 52f870a..b310535 100644 --- a/src/main/java/com/google/gwtorm/jdbc/JdbcExecutor.java +++ b/src/main/java/com/google/gwtorm/jdbc/JdbcExecutor.java
@@ -45,6 +45,7 @@ } } + @Override public void close() { try { stmt.close();
diff --git a/src/main/java/com/google/gwtorm/server/Schema.java b/src/main/java/com/google/gwtorm/server/Schema.java index b90ad03..2357a89 100644 --- a/src/main/java/com/google/gwtorm/server/Schema.java +++ b/src/main/java/com/google/gwtorm/server/Schema.java
@@ -55,7 +55,7 @@ * } * </pre> */ -public interface Schema { +public interface Schema extends AutoCloseable { /** Commit a pending transaction. */ public void commit() throws OrmException; @@ -72,7 +72,7 @@ * @param e executor to perform (or log) the statements. * @throws OrmException one or more objects could not be added to the schema. */ - void updateSchema(StatementExecutor e) throws OrmException; + public void updateSchema(StatementExecutor e) throws OrmException; /** * Drop any unused columns, tables, or sequences. @@ -82,15 +82,12 @@ * @param e executor to perform (or log) the statements. * @throws OrmException one or more drops could not be completed. */ - void pruneSchema(StatementExecutor e) throws OrmException; + public void pruneSchema(StatementExecutor e) throws OrmException; - /** - * @return access interface for each declared relation. - */ - Access<?, ?>[] allRelations(); + /** @return access interface for each declared relation. */ + public Access<?, ?>[] allRelations(); - /** - * Close the schema and release all resources. - */ - void close(); + /** Close the schema and release all resources. */ + @Override + public void close(); }
diff --git a/src/main/java/com/google/gwtorm/server/StatementExecutor.java b/src/main/java/com/google/gwtorm/server/StatementExecutor.java index 048c439..a202d55 100644 --- a/src/main/java/com/google/gwtorm/server/StatementExecutor.java +++ b/src/main/java/com/google/gwtorm/server/StatementExecutor.java
@@ -14,8 +14,10 @@ package com.google.gwtorm.server; - /** Executes statements against the schema. */ -public interface StatementExecutor { +public interface StatementExecutor extends AutoCloseable { void execute(String sql) throws OrmException; + + @Override + void close(); }