Mercurial > hg > monetdb-java
changeset 292:b127164342c4
Introduce default general behavior settings DEF_... for MonetResultSets and use them
when creating Statements, PreparedStatements and CallableStatements in MonetConnection.
Corrected documentation for MonetStatement constructor.
Corrected typo "@returns " into "@return ".
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Wed, 31 Jul 2019 19:04:20 +0200 (2019-07-31) |
parents | 611c0954b0e6 |
children | 60bfe2d0ba2a |
files | src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java |
diffstat | 4 files changed, 36 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java @@ -433,14 +433,14 @@ public class MonetConnection * * Result sets created using the returned Statement object will by * default be type TYPE_FORWARD_ONLY and have a concurrency level of - * CONCUR_READ_ONLY. + * CONCUR_READ_ONLY and a holdability of HOLD_CURSORS_OVER_COMMIT. * * @return a new default Statement object * @throws SQLException if a database access error occurs */ @Override public Statement createStatement() throws SQLException { - return createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); + return createStatement(MonetResultSet.DEF_RESULTSETTYPE, MonetResultSet.DEF_CONCURRENCY, MonetResultSet.DEF_HOLDABILITY); } /** @@ -460,7 +460,7 @@ public class MonetConnection */ @Override public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { - return createStatement(resultSetType, resultSetConcurrency, ResultSet.HOLD_CURSORS_OVER_COMMIT); + return createStatement(resultSetType, resultSetConcurrency, MonetResultSet.DEF_HOLDABILITY); } /** @@ -676,7 +676,7 @@ public class MonetConnection */ @Override public CallableStatement prepareCall(String sql) throws SQLException { - return prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); + return prepareCall(sql, MonetResultSet.DEF_RESULTSETTYPE, MonetResultSet.DEF_CONCURRENCY, MonetResultSet.DEF_HOLDABILITY); } /** @@ -697,7 +697,7 @@ public class MonetConnection */ @Override public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { - return prepareCall(sql, resultSetType, resultSetConcurrency, ResultSet.HOLD_CURSORS_OVER_COMMIT); + return prepareCall(sql, resultSetType, resultSetConcurrency, MonetResultSet.DEF_HOLDABILITY); } /** @@ -765,7 +765,7 @@ public class MonetConnection */ @Override public PreparedStatement prepareStatement(String sql) throws SQLException { - return prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); + return prepareStatement(sql, MonetResultSet.DEF_RESULTSETTYPE, MonetResultSet.DEF_CONCURRENCY, MonetResultSet.DEF_HOLDABILITY); } /** @@ -790,7 +790,7 @@ public class MonetConnection */ @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { - return prepareStatement(sql, resultSetType, resultSetConcurrency, ResultSet.HOLD_CURSORS_OVER_COMMIT); + return prepareStatement(sql, resultSetType, resultSetConcurrency, MonetResultSet.DEF_HOLDABILITY); } /** @@ -880,7 +880,7 @@ public class MonetConnection throw new SQLException("Invalid argument, expected RETURN_GENERATED_KEYS or NO_GENERATED_KEYS", "M1M05"); /* MonetDB has no way to disable this, so just do the normal thing ;) */ - return prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + return prepareStatement(sql, MonetResultSet.DEF_RESULTSETTYPE, MonetResultSet.DEF_CONCURRENCY, MonetResultSet.DEF_HOLDABILITY); } /**
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java @@ -389,7 +389,7 @@ public class MonetPreparedStatement /** * Returns the number of columns in this ResultSet object. * - * @returns the number of columns + * @return the number of columns */ @Override public int getColumnCount() { @@ -424,7 +424,7 @@ public class MonetPreparedStatement * Indicates whether a column's case matters. * * @param column the first column is 1, the second is 2, ... - * @returns false + * @return false */ @Override public boolean isCaseSensitive(int column) throws SQLException { @@ -454,7 +454,7 @@ public class MonetPreparedStatement * Returning true for all here, even for CLOB, BLOB. * * @param column the first column is 1, the second is 2, ... - * @returns true + * @return true */ @Override public boolean isSearchable(int column) { @@ -469,7 +469,7 @@ public class MonetPreparedStatement * we can always return false here. * * @param column the first column is 1, the second is 2, ... - * @returns false + * @return false */ @Override public boolean isCurrency(int column) {
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java @@ -70,6 +70,11 @@ public class MonetResultSet extends MonetWrapper implements ResultSet, AutoCloseable { + static final int DEF_RESULTSETTYPE = ResultSet.TYPE_FORWARD_ONLY; + static final int DEF_FETCHDIRECTION = ResultSet.FETCH_FORWARD; + static final int DEF_CONCURRENCY = ResultSet.CONCUR_READ_ONLY; + static final int DEF_HOLDABILITY = ResultSet.HOLD_CURSORS_OVER_COMMIT; + /** The parental Statement object */ private final Statement statement; /** A Header to retrieve lines from. Note: it will be null in case of a MonetVirtualResultSet ! */ @@ -91,9 +96,9 @@ public class MonetResultSet protected final int tupleCount; /** The type of this ResultSet (forward or scrollable) */ - private int type = TYPE_FORWARD_ONLY; + private int type = DEF_RESULTSETTYPE; /** The concurrency of this ResultSet (currently only read-only) */ - private int concurrency = CONCUR_READ_ONLY; + private int concurrency = DEF_CONCURRENCY; /** The warnings for this ResultSet object */ private SQLWarning warnings; /** whether the last read field (via some getXyz() method) was NULL */ @@ -1328,7 +1333,7 @@ public class MonetResultSet /** * Returns the number of columns in this ResultSet object. * - * @returns the number of columns + * @return the number of columns */ @Override public int getColumnCount() { @@ -1359,7 +1364,7 @@ public class MonetResultSet * Indicates whether a column's case matters. * * @param column the first column is 1, the second is 2, ... - * @returns true for all character string columns else false + * @return true for all character string columns else false */ @Override public boolean isCaseSensitive(int column) throws SQLException { @@ -1392,7 +1397,7 @@ public class MonetResultSet * real column existing in a table or not... * * @param column the first column is 1, the second is 2, ... - * @returns true + * @return true */ @Override public boolean isSearchable(int column) throws SQLException { @@ -1408,7 +1413,7 @@ public class MonetResultSet * we can always return false here. * * @param column the first column is 1, the second is 2, ... - * @returns false + * @return false */ @Override public boolean isCurrency(int column) throws SQLException {
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java @@ -42,7 +42,7 @@ import java.util.concurrent.locks.Reentr * * @author Fabian Groffen * @author Martin van Dinther - * @version 0.7 + * @version 0.8 */ public class MonetStatement extends MonetWrapper @@ -60,9 +60,9 @@ public class MonetStatement /** The warnings this Statement object generated */ private SQLWarning warnings; /** Whether this Statement object is closed or not */ - protected boolean closed; + protected boolean closed = false; /** Whether the application wants this Statement object to be pooled */ - protected boolean poolable; + protected boolean poolable = false; /** Whether this Statement should be closed if the last ResultSet closes */ private boolean closeOnCompletion = false; /** The timeout (in sec) for the query to return, 0 means no timeout */ @@ -71,12 +71,12 @@ public class MonetStatement private int fetchSize = 0; /** The maximum number of rows to return in a ResultSet */ private int maxRows = DEF_MAXROWS; + /** The type of ResultSet to produce; i.e. forward only, random access */ + private int resultSetType = MonetResultSet.DEF_RESULTSETTYPE; /** The suggested direction of fetching data (implemented but not used) */ - private int fetchDirection = ResultSet.FETCH_FORWARD; - /** The type of ResultSet to produce; i.e. forward only, random access */ - private int resultSetType = ResultSet.TYPE_FORWARD_ONLY; + private int fetchDirection = MonetResultSet.DEF_FETCHDIRECTION; /** The concurrency of the ResultSet to produce */ - private int resultSetConcurrency = ResultSet.CONCUR_READ_ONLY; + private int resultSetConcurrency = MonetResultSet.DEF_CONCURRENCY; /** A List to hold all queries of a batch */ private ArrayList<String> batch = null; @@ -84,15 +84,15 @@ public class MonetStatement /** - * MonetStatement constructor which checks the arguments for validity, tries - * to set up a socket to MonetDB and attempts to login. + * MonetStatement constructor which checks the arguments for validity. * This constructor is only accessible to classes from the jdbc package. * * @param connection the connection that created this Statement * @param resultSetType type of ResultSet to produce * @param resultSetConcurrency concurrency of ResultSet to produce + * @param resultSetHoldability holdability of ResultSet after commit * @throws SQLException if an error occurs during login - * @throws IllegalArgumentException is one of the arguments is null or empty + * @throws IllegalArgumentException is one of the arguments null or empty */ MonetStatement( MonetConnection connection, @@ -105,9 +105,10 @@ public class MonetStatement throw new IllegalArgumentException("No Connection given!"); this.connection = connection; + this.queryTimeout = connection.lastSetQueryTimeout; + this.resultSetType = resultSetType; this.resultSetConcurrency = resultSetConcurrency; - this.queryTimeout = connection.lastSetQueryTimeout; // check our limits, and generate warnings as appropriate if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) { @@ -123,11 +124,8 @@ public class MonetStatement // check type for supported holdability if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) { - addWarning("Close cursors at commit not supported, continuing with holdability to hold open cursors over commit.", "01M15"); + addWarning("Close cursors at commit not supported, continuing with holdability to hold cursors open over commit.", "01M15"); } - - closed = false; - poolable = false; } //== methods of interface Statement