Changeset: c26213e86442 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/c26213e86442
Modified Files:
src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java
Branch: default
Log Message:
Use newSQLFeatureNotSupportedException() for setArray()
Beautifying code layout and indentation.
diffs (287 lines):
diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
b/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
@@ -60,7 +60,8 @@ import java.util.Map;
* [ "int", 9, 0 ]
* </pre>
*
- * @author Fabian Groffen, Martin van Dinther
+ * @author Fabian Groffen
+ * @author Martin van Dinther
* @version 0.4
*/
public class MonetPreparedStatement
@@ -79,7 +80,7 @@ public class MonetPreparedStatement
private final int rscolcnt;
private final String[] values;
-
+
private final MonetConnection connection;
/* only parse the date patterns once, use multiple times */
@@ -280,7 +281,7 @@ public class MonetPreparedStatement
* statement does not return a ResultSet object
*/
@Override
- public ResultSet executeQuery() throws SQLException{
+ public ResultSet executeQuery() throws SQLException {
if (execute() != true)
throw new SQLException("Query did not produce a result
set", "M1M19");
@@ -463,7 +464,7 @@ public class MonetPreparedStatement
public boolean isCurrency(int column) {
return false;
}
-
+
/**
* Indicates whether values in the designated column
are signed
* numbers.
@@ -771,7 +772,7 @@ public class MonetPreparedStatement
if (column[i] == null)
cnt++;
}
-
+
return cnt;
}
@@ -943,14 +944,14 @@ public class MonetPreparedStatement
* Sets the designated parameter to the given Array object. The
* driver converts this to an SQL ARRAY value when it sends it to
* the database.
- *
+ *
* @param i the first parameter is 1, the second is 2, ...
* @param x an Array object that maps an SQL ARRAY value
* @throws SQLException if a database access error occurs
*/
@Override
public void setArray(int i, Array x) throws SQLException {
- throw new SQLException("Operation setArray(int i, Array x)
currently not supported!", "0A000");
+ throw newSQLFeatureNotSupportedException("setArray");
}
/**
@@ -1036,31 +1037,29 @@ public class MonetPreparedStatement
* @throws SQLException if a database access error occurs
*/
@Override
- public void setBigDecimal(int idx, BigDecimal x)
- throws SQLException
- {
- // get array position
- int i = getParamIdx(idx);
+ public void setBigDecimal(int idx, BigDecimal x) throws SQLException {
+ // get array position
+ int i = getParamIdx(idx);
- // round to the scale of the DB:
- x = x.setScale(scale[i], RoundingMode.HALF_UP);
+ // round to the scale of the DB:
+ x = x.setScale(scale[i], RoundingMode.HALF_UP);
+
+ // if precision is now greater than that of the db, throw an
error:
+ if (x.precision() > digits[i]) {
+ throw new SQLDataException("DECIMAL value exceeds
allowed digits/scale: " + x.toPlainString() + " (" + digits[i] + "/" + scale[i]
+ ")", "22003");
+ }
- // if precision is now greater than that of the db, throw an error:
- if (x.precision() > digits[i]) {
- throw new SQLDataException("DECIMAL value exceeds allowed
digits/scale: " + x.toPlainString() + " (" + digits[i] + "/" + scale[i] + ")",
"22003");
- }
-
- // MonetDB doesn't like leading 0's, since it counts them as part of
- // the precision, so let's strip them off. (But be careful not to do
- // this to the exact number "0".) Also strip off trailing
- // numbers that are inherent to the double representation.
- String xStr = x.toPlainString();
- int dot = xStr.indexOf('.');
- if (dot >= 0)
- xStr = xStr.substring(0, Math.min(xStr.length(), dot + 1 +
scale[i]));
- while (xStr.startsWith("0") && xStr.length() > 1)
- xStr = xStr.substring(1);
- setValue(idx, xStr);
+ // MonetDB doesn't like leading 0's, since it counts them as
part of
+ // the precision, so let's strip them off. (But be careful not
to do
+ // this to the exact number "0".) Also strip off trailing
+ // numbers that are inherent to the double representation.
+ String xStr = x.toPlainString();
+ int dot = xStr.indexOf('.');
+ if (dot >= 0)
+ xStr = xStr.substring(0, Math.min(xStr.length(), dot +
1 + scale[i]));
+ while (xStr.startsWith("0") && xStr.length() > 1)
+ xStr = xStr.substring(1);
+ setValue(idx, xStr);
}
/**
@@ -2128,7 +2127,7 @@ public class MonetPreparedStatement
public void writeLong(long x) throws
SQLException {
setLong(paramnr, x);
}
-
+
@Override
public void writeFloat(float x) throws
SQLException {
setFloat(paramnr, x);
diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java
b/src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java
@@ -22,17 +22,17 @@ import java.util.concurrent.locks.Reentr
/**
* A Statement suitable for the MonetDB database.
- *
+ *
* The object used for executing a static SQL statement and returning
* the results it produces.<br />
- *
+ *
* By default, only one {@link ResultSet} object per Statement object can be
* open at the same time. Therefore, if the reading of one ResultSet
* object is interleaved with the reading of another, each must have
* been generated by different {@link Statement} objects. All execution methods
* in the Statement interface implicitly close a Statement's current
* ResultSet object if an open one exists.
- *
+ *
* The current state of this Statement is that it only implements the
* executeQuery() which returns a ResultSet where from results can be
* read and executeUpdate() which doesn't return the affected rows.
@@ -41,6 +41,7 @@ import java.util.concurrent.locks.Reentr
* Multi-result queries are supported using the getMoreResults() method.
*
* @author Fabian Groffen
+ * @author Martin van Dinther
* @version 0.7
*/
public class MonetStatement extends MonetWrapper implements Statement {
@@ -147,7 +148,7 @@ public class MonetStatement extends Mone
}
Lock batchLock = new ReentrantLock();
-
+
/**
* Submits a batch of commands to the database for execution and if
* all commands execute successfully, returns an array of update
@@ -284,7 +285,7 @@ public class MonetStatement extends Mone
}
/**
- * Cancels this Statement object if both the DBMS and driver support
+ * Cancels this Statement object if both the DBMS and driver support
* aborting an SQL statement. This method can be used by one thread to
* cancel a statement that is being executed by another thread.
*
@@ -322,7 +323,8 @@ public class MonetStatement extends Mone
@Override
public void close() {
// close previous ResultSet, if not closed already
- if (lastResponseList != null) lastResponseList.close();
+ if (lastResponseList != null)
+ lastResponseList.close();
closed = true;
}
@@ -349,7 +351,7 @@ public class MonetStatement extends Mone
public boolean execute(String sql) throws SQLException {
return internalExecute(sql);
}
-
+
/**
* Executes the given SQL statement, which may return multiple
* results, and signals the driver that any auto-generated keys
@@ -385,11 +387,10 @@ public class MonetStatement extends Mone
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 ;) */
+
+ /* MonetDB has no way to disable this, so just do the normal
thing ;) */
return internalExecute(sql);
}
@@ -576,11 +577,10 @@ public class MonetStatement extends Mone
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 ;) */
+
+ /* MonetDB has no way to disable this, so just do the normal
thing ;) */
if (execute(sql) != false)
throw new SQLException("Query produced a result set",
"M1M17");
@@ -706,7 +706,7 @@ public class MonetStatement extends Mone
types = new String[1];
columns[0] = "GENERATED_KEY";
- /* the generated key should be an integer, because (wait for
it) other
+ /* the generated key should be an integer, because (wait for
it) other
* frameworks such as spring expect this. */
types[0] = "BIGINT";
@@ -745,9 +745,7 @@ public class MonetStatement extends Mone
* @throws SQLException if a database access error occurs
*/
@Override
- public int getMaxFieldSize()
- throws SQLException
- {
+ public int getMaxFieldSize() {
return 0;
}
@@ -814,11 +812,7 @@ public class MonetStatement extends Mone
// we default to keep current result, which requires no action
header = lastResponseList.getNextResponse();
- if (header instanceof MonetConnection.ResultSetResponse) {
- return true;
- } else {
- return false;
- }
+ return (header instanceof MonetConnection.ResultSetResponse);
}
/**
@@ -864,7 +858,7 @@ public class MonetStatement extends Mone
* @throws SQLException if a database access error occurs
*/
@Override
- public ResultSet getResultSet() throws SQLException{
+ public ResultSet getResultSet() throws SQLException {
return (header instanceof MonetConnection.ResultSetResponse)
? new MonetResultSet(this,
(MonetConnection.ResultSetResponse)header)
@@ -1024,7 +1018,7 @@ public class MonetStatement extends Mone
public void setFetchDirection(int direction) throws SQLException {
if (direction == ResultSet.FETCH_FORWARD ||
direction == ResultSet.FETCH_REVERSE ||
- direction == ResultSet.FETCH_UNKNOWN)
+ direction == ResultSet.FETCH_UNKNOWN)
{
fetchDirection = direction;
} else {
@@ -1169,7 +1163,7 @@ public class MonetStatement extends Mone
}
//== 1.7 methods (JDBC 4.1)
-
+
/**
* Specifies that this Statement will be closed when all its
* dependent result sets are closed. If execution of the Statement
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list