Mercurial > hg > monetdb-java
comparison src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java @ 172:60063c67f9e7 embedded
Merged with default
author | Pedro Ferreira <pedro.ferreira@monetdbsolutions.com> |
---|---|
date | Tue, 19 Sep 2017 13:49:34 +0200 (2017-09-19) |
parents | 53ef497672bf 7c9e386fe49a |
children | 89c285fc0a49 |
comparison
equal
deleted
inserted
replaced
171:0f95fee3cf29 | 172:60063c67f9e7 |
---|---|
9 package nl.cwi.monetdb.jdbc; | 9 package nl.cwi.monetdb.jdbc; |
10 | 10 |
11 import nl.cwi.monetdb.mcl.responses.*; | 11 import nl.cwi.monetdb.mcl.responses.*; |
12 import nl.cwi.monetdb.mcl.responses.ResultSetResponse; | 12 import nl.cwi.monetdb.mcl.responses.ResultSetResponse; |
13 | 13 |
14 import java.io.IOException; | |
14 import java.sql.BatchUpdateException; | 15 import java.sql.BatchUpdateException; |
15 import java.sql.Connection; | 16 import java.sql.Connection; |
16 import java.sql.Statement; | 17 import java.sql.Statement; |
17 import java.sql.ResultSet; | 18 import java.sql.ResultSet; |
18 import java.sql.SQLException; | 19 import java.sql.SQLException; |
43 * Multi-result queries are supported using the getMoreResults() method. | 44 * Multi-result queries are supported using the getMoreResults() method. |
44 * | 45 * |
45 * @author Martin van Dinther | 46 * @author Martin van Dinther |
46 * @version 0.7 | 47 * @version 0.7 |
47 */ | 48 */ |
48 public class MonetStatement extends MonetWrapper implements Statement { | 49 public class MonetStatement extends MonetWrapper implements Statement, AutoCloseable { |
49 /** The parental Connection object */ | 50 /** The parental Connection object */ |
50 private MonetConnection connection; | 51 private MonetConnection connection; |
51 /** The last ResponseList object this Statement produced */ | 52 /** The last ResponseList object this Statement produced */ |
52 private MonetConnection.ResponseList lastResponseList; | 53 private MonetConnection.ResponseList lastResponseList; |
53 /** The last Response that this object uses */ | 54 /** The last Response that this object uses */ |
79 * This constructor is only accessible to classes from the jdbc package. | 80 * This constructor is only accessible to classes from the jdbc package. |
80 * | 81 * |
81 * @param connection the connection that created this Statement | 82 * @param connection the connection that created this Statement |
82 * @param resultSetType type of ResultSet to produce | 83 * @param resultSetType type of ResultSet to produce |
83 * @param resultSetConcurrency concurrency of ResultSet to produce | 84 * @param resultSetConcurrency concurrency of ResultSet to produce |
84 * @throws SQLException if an error occurs during login | |
85 * @throws IllegalArgumentException is one of the arguments is null or empty | 85 * @throws IllegalArgumentException is one of the arguments is null or empty |
86 */ | 86 */ |
87 MonetStatement(MonetConnection connection, int resultSetType, int resultSetConcurrency, int resultSetHoldability) | 87 MonetStatement(MonetConnection connection, int resultSetType, int resultSetConcurrency, int resultSetHoldability) |
88 throws SQLException, IllegalArgumentException { | 88 throws IllegalArgumentException { |
89 if (connection == null) throw | 89 if (connection == null) throw |
90 new IllegalArgumentException("No Connection given!"); | 90 new IllegalArgumentException("No Connection given!"); |
91 | 91 |
92 this.connection = connection; | 92 this.connection = connection; |
93 this.resultSetType = resultSetType; | 93 this.resultSetType = resultSetType; |
239 try { | 239 try { |
240 boolean type = internalExecute(batch); | 240 boolean type = internalExecute(batch); |
241 int count = -1; | 241 int count = -1; |
242 if (!type) count = getUpdateCount(); | 242 if (!type) count = getUpdateCount(); |
243 do { | 243 do { |
244 if (offset >= max) throw | 244 if (offset >= max) |
245 new SQLException("Overflow: don't use multi statements when batching (" + max + ")", "M1M16"); | 245 throw new SQLException("Overflow: don't use multi statements when batching (" + max + ")", "M1M16"); |
246 if (type) { | 246 if (type) { |
247 e.setNextException(new SQLException("Batch query produced a ResultSet! " + | 247 e.setNextException(new SQLException("Batch query produced a ResultSet! " + |
248 "Ignoring and setting update count to value " + EXECUTE_FAILED, "M1M17")); | 248 "Ignoring and setting update count to value " + EXECUTE_FAILED, "M1M17")); |
249 counts[offset] = EXECUTE_FAILED; | 249 counts[offset] = EXECUTE_FAILED; |
250 } else if (count >= 0) { | 250 } else if (count >= 0) { |
328 */ | 328 */ |
329 @Override | 329 @Override |
330 public boolean execute(String sql) throws SQLException { | 330 public boolean execute(String sql) throws SQLException { |
331 return internalExecute(sql); | 331 return internalExecute(sql); |
332 } | 332 } |
333 | 333 |
334 /** | 334 /** |
335 * Executes the given SQL statement, which may return multiple | 335 * Executes the given SQL statement, which may return multiple |
336 * results, and signals the driver that any auto-generated keys | 336 * results, and signals the driver that any auto-generated keys |
337 * should be made available for retrieval. The driver will ignore | 337 * should be made available for retrieval. The driver will ignore |
338 * this signal if the SQL statement is not an INSERT statement. | 338 * this signal if the SQL statement is not an INSERT statement. |
677 ((long[]) results[0])[0] = -1; | 677 ((long[]) results[0])[0] = -1; |
678 } | 678 } |
679 | 679 |
680 try { | 680 try { |
681 return new MonetVirtualResultSet(this, columns, types, jdbcTypes, results); | 681 return new MonetVirtualResultSet(this, columns, types, jdbcTypes, results); |
682 } catch (IllegalArgumentException e) { | 682 } catch (IllegalArgumentException | IOException e) { |
683 throw new SQLException("Internal driver error: " + e.getMessage(), "M0M03"); | 683 throw new SQLException("Internal driver error: " + e.getMessage(), "M0M03"); |
684 } | 684 } |
685 } | 685 } |
686 | 686 |
687 /** | 687 /** |
1186 final class MonetVirtualResultSet extends MonetResultSet { | 1186 final class MonetVirtualResultSet extends MonetResultSet { |
1187 private Object[] results; | 1187 private Object[] results; |
1188 private boolean closed; | 1188 private boolean closed; |
1189 | 1189 |
1190 MonetVirtualResultSet(Statement statement, String[] columns, String[] types, int[] jdbcTypes, Object[] results) | 1190 MonetVirtualResultSet(Statement statement, String[] columns, String[] types, int[] jdbcTypes, Object[] results) |
1191 throws IllegalArgumentException { | 1191 throws IllegalArgumentException, IOException, SQLException { |
1192 super(statement, columns, types, jdbcTypes, results.length); | 1192 super(statement, columns, types, jdbcTypes, results.length); |
1193 this.results = results; | 1193 this.results = results; |
1194 this.closed = false; | 1194 this.closed = false; |
1195 } | 1195 } |
1196 | 1196 |