Changeset: 83aee4f60649 for monetdb-java
URL: http://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=83aee4f60649
Modified Files:
src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
Branch: default
Log Message:
Added private method sendTransactionCommand(String); to reduce duplicate code
in 6 methods.
Throw a SQLFeatureNotSupportedException for not implemented methods:
prepareStatement(String sql, int[] columnIndexes) and
prepareStatement(String sql, String[] columnNames).
Rest of the changes are only layout and removal of trailing tabs.
diffs (truncated from 503 to 300 lines):
diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
b/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
@@ -396,20 +396,7 @@ public class MonetConnection extends Mon
public void commit() throws SQLException {
// note: can't use sendIndependentCommand here because we need
// to process the auto_commit state the server gives
-
- // create a container for the result
- ResponseList l = new ResponseList(
- 0,
- 0,
- ResultSet.FETCH_FORWARD,
- ResultSet.CONCUR_READ_ONLY
- );
- // send commit to the server
- try {
- l.processQuery("COMMIT");
- } finally {
- l.close();
- }
+ sendTransactionCommand("COMMIT");
}
/**
@@ -428,10 +415,7 @@ public class MonetConnection extends Mon
*/
@Override
public Statement createStatement() throws SQLException {
- return createStatement(
- ResultSet.TYPE_FORWARD_ONLY,
- ResultSet.CONCUR_READ_ONLY,
- ResultSet.HOLD_CURSORS_OVER_COMMIT);
+ return createStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
}
/**
@@ -450,15 +434,8 @@ public class MonetConnection extends Mon
* @throws SQLException if a database access error occurs
*/
@Override
- public Statement createStatement(
- int resultSetType,
- int resultSetConcurrency)
- throws SQLException
- {
- return createStatement(
- resultSetType,
- resultSetConcurrency,
- ResultSet.HOLD_CURSORS_OVER_COMMIT);
+ public Statement createStatement(int resultSetType, int
resultSetConcurrency) throws SQLException {
+ return createStatement(resultSetType, resultSetConcurrency,
ResultSet.HOLD_CURSORS_OVER_COMMIT);
}
/**
@@ -485,20 +462,9 @@ public class MonetConnection extends Mon
* concurrency, and holdability
*/
@Override
- public Statement createStatement(
- int resultSetType,
- int resultSetConcurrency,
- int resultSetHoldability)
- throws SQLException
- {
+ public Statement createStatement(int resultSetType, int
resultSetConcurrency, int resultSetHoldability) throws SQLException {
try {
- Statement ret =
- new MonetStatement(
- this,
- resultSetType,
- resultSetConcurrency,
- resultSetHoldability
- );
+ Statement ret = new MonetStatement(this, resultSetType,
resultSetConcurrency, resultSetHoldability);
// store it in the map for when we close...
statements.put(ret, null);
return ret;
@@ -510,11 +476,9 @@ public class MonetConnection extends Mon
}
/**
- * Retrieves the current auto-commit mode for this Connection
- * object.
+ * Retrieves the current auto-commit mode for this Connection object.
*
- * @return the current state of this Connection object's auto-commit
- * mode
+ * @return the current state of this Connection object's auto-commit
mode
* @see #setAutoCommit(boolean)
*/
@Override
@@ -534,7 +498,7 @@ public class MonetConnection extends Mon
// MonetDB does NOT support catalogs
return null;
}
-
+
/**
* Retrieves the current holdability of ResultSet objects created
* using this Connection object.
@@ -654,16 +618,29 @@ public class MonetConnection extends Mon
}
@Override
- public String nativeSQL(String sql) {return sql;}
+ public String nativeSQL(String sql) {
+ /* there is currently no way to get the native MonetDB
rewritten SQL string back, so just return the original string */
+ /* in future we may replace/remove the escape sequences {
<escape-type> ...} before sending it to the server */
+ return sql;
+ }
@Override
- public CallableStatement prepareCall(String sql) {return null;}
+ public CallableStatement prepareCall(String sql) {
+ /* not implemented yet */
+ return null;
+ }
@Override
- public CallableStatement prepareCall(String sql, int resultSetType, int
resultSetConcurrency) {return null;}
+ public CallableStatement prepareCall(String sql, int resultSetType, int
resultSetConcurrency) {
+ /* not implemented yet */
+ return null;
+ }
@Override
- public CallableStatement prepareCall(String sql, int resultSetType, int
resultSetConcurrency, int resultSetHoldability) {return null;}
+ public CallableStatement prepareCall(String sql, int resultSetType, int
resultSetConcurrency, int resultSetHoldability) {
+ /* not implemented yet */
+ return null;
+ }
/**
* Creates a PreparedStatement object for sending parameterized SQL
@@ -694,12 +671,7 @@ public class MonetConnection extends Mon
*/
@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, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
}
/**
@@ -723,18 +695,8 @@ public class MonetConnection extends Mon
* type and concurrency
*/
@Override
- public PreparedStatement prepareStatement(
- String sql,
- int resultSetType,
- int resultSetConcurrency)
- throws SQLException
- {
- return prepareStatement(
- sql,
- resultSetType,
- resultSetConcurrency,
- ResultSet.HOLD_CURSORS_OVER_COMMIT
- );
+ public PreparedStatement prepareStatement(String sql, int
resultSetType, int resultSetConcurrency) throws SQLException {
+ return prepareStatement(sql, resultSetType,
resultSetConcurrency, ResultSet.HOLD_CURSORS_OVER_COMMIT);
}
/**
@@ -764,11 +726,7 @@ public class MonetConnection extends Mon
* concurrency, and holdability
*/
@Override
- public PreparedStatement prepareStatement(
- String sql,
- int resultSetType,
- int resultSetConcurrency,
- int resultSetHoldability)
+ public PreparedStatement prepareStatement(String sql, int
resultSetType, int resultSetConcurrency, int resultSetHoldability)
throws SQLException
{
try {
@@ -823,29 +781,79 @@ public class MonetConnection extends Mon
* whether auto-generated keys should be returned
*/
@Override
- public PreparedStatement prepareStatement(
- String sql,
- int autoGeneratedKeys)
- throws SQLException
- {
+ public PreparedStatement prepareStatement(String sql, int
autoGeneratedKeys) throws SQLException {
if (autoGeneratedKeys != Statement.RETURN_GENERATED_KEYS &&
- autoGeneratedKeys !=
Statement.NO_GENERATED_KEYS)
+ autoGeneratedKeys != Statement.NO_GENERATED_KEYS)
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, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
}
+ /**
+ * Creates a default PreparedStatement object capable of returning the
auto-generated keys designated by the given array.
+ * This array contains the indexes of the columns in the target table
that contain the auto-generated keys that should be made available.
+ * The driver will ignore the array if the SQL statement is not an
INSERT statement, or an SQL statement able to
+ * return auto-generated keys (the list of such statements is
vendor-specific).
+ *
+ * An SQL statement with or without IN parameters can be pre-compiled
and stored in a PreparedStatement object.
+ * This object can then be used to efficiently execute this statement
multiple times.
+ *
+ * Note: This method is optimized for handling parametric SQL
statements that benefit from precompilation.
+ * If the driver supports precompilation, the method prepareStatement
will send the statement to the database for precompilation.
+ * Some drivers may not support precompilation. In this case, the
statement may not be sent to the database until the PreparedStatement
+ * object is executed. This has no direct effect on users; however, it
does affect which methods throw certain SQLExceptions.
+ *
+ * Result sets created using the returned PreparedStatement object will
by default be type TYPE_FORWARD_ONLY and have
+ * a concurrency level of CONCUR_READ_ONLY. The holdability of the
created result sets can be determined by calling getHoldability().
+ *
+ * Parameters:
+ * sql - an SQL statement that may contain one or more '?' IN
parameter placeholders
+ * columnIndexes - an array of column indexes indicating the
columns that should be returned from the inserted row or rows
+ * Returns:
+ * a new PreparedStatement object, containing the pre-compiled
statement, that is capable of
+ * returning the auto-generated keys designated by the given array
of column indexes
+ * Throws:
+ * SQLException - if a database access error occurs or this method
is called on a closed connection
+ * SQLFeatureNotSupportedException - if the JDBC driver does not
support this method
+ */
@Override
- public PreparedStatement prepareStatement(String sql, int[]
columnIndexes) {return null;}
+ public PreparedStatement prepareStatement(String sql, int[]
columnIndexes) throws SQLException {
+ throw new
SQLFeatureNotSupportedException("prepareStatement(String sql, int[]
columnIndexes) not supported", "0A000");
+ }
+ /**
+ * Creates a default PreparedStatement object capable of returning the
auto-generated keys designated by the given array.
+ * This array contains the names of the columns in the target table
that contain the auto-generated keys that should be returned.
+ * The driver will ignore the array if the SQL statement is not an
INSERT statement, or an SQL statement able to
+ * return auto-generated keys (the list of such statements is
vendor-specific).
+ *
+ * An SQL statement with or without IN parameters can be pre-compiled
and stored in a PreparedStatement object.
+ * This object can then be used to efficiently execute this statement
multiple times.
+ *
+ * Note: This method is optimized for handling parametric SQL
statements that benefit from precompilation.
+ * If the driver supports precompilation, the method prepareStatement
will send the statement to the database for precompilation.
+ * Some drivers may not support precompilation. In this case, the
statement may not be sent to the database until the PreparedStatement
+ * object is executed. This has no direct effect on users; however, it
does affect which methods throw certain SQLExceptions.
+ *
+ * Result sets created using the returned PreparedStatement object will
by default be type TYPE_FORWARD_ONLY and have
+ * a concurrency level of CONCUR_READ_ONLY. The holdability of the
created result sets can be determined by calling getHoldability().
+ *
+ * Parameters:
+ * sql - an SQL statement that may contain one or more '?' IN
parameter placeholders
+ * columnNames - an array of column names indicating the columns
that should be returned from the inserted row or rows
+ * Returns:
+ * a new PreparedStatement object, containing the pre-compiled
statement, that is capable of
+ * returning the auto-generated keys designated by the given array
of column names
+ * Throws:
+ * SQLException - if a database access error occurs or this method
is called on a closed connection
+ * SQLFeatureNotSupportedException - if the JDBC driver does not
support this method
+ */
@Override
- public PreparedStatement prepareStatement(String sql, String[]
columnNames) {return null;}
+ public PreparedStatement prepareStatement(String sql, String[]
columnNames) throws SQLException {
+ throw new
SQLFeatureNotSupportedException("prepareStatement(String sql, String[]
columnNames) not supported", "0A000");
+ }
/**
* Removes the given Savepoint object from the current transaction.
@@ -866,20 +874,7 @@ public class MonetConnection extends Mon
// note: can't use sendIndependentCommand here because we need
// to process the auto_commit state the server gives
-
- // create a container for the result
- ResponseList l = new ResponseList(
- 0,
- 0,
- ResultSet.FETCH_FORWARD,
- ResultSet.CONCUR_READ_ONLY
- );
- // send the appropriate query string to the database
- try {
- l.processQuery("RELEASE SAVEPOINT " + sp.getName());
- } finally {
- l.close();
- }
+ sendTransactionCommand("RELEASE SAVEPOINT " + sp.getName());
}
/**
@@ -895,20 +890,7 @@ public class MonetConnection extends Mon
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list