Changeset: a3c686217ca1 for monetdb-java URL: http://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=a3c686217ca1 Modified Files: src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java src/main/java/nl/cwi/monetdb/mcl/connection/SenderThread.java src/main/java/nl/cwi/monetdb/mcl/connection/embedded/EmbeddedConnection.java src/main/java/nl/cwi/monetdb/mcl/connection/embedded/JDBCEmbeddedConnection.java src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java src/main/java/nl/cwi/monetdb/mcl/protocol/TableResultHeaders.java src/main/java/nl/cwi/monetdb/mcl/protocol/embedded/EmbeddedProtocol.java src/main/java/nl/cwi/monetdb/mcl/responses/ResultSetResponse.java Branch: embedded Log Message:
Made many fixes for the embedded connection diffs (truncated from 650 to 300 lines): diff --git a/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java b/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java --- a/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java +++ b/src/main/java/nl/cwi/monetdb/embedded/env/MonetDBEmbeddedConnection.java @@ -30,7 +30,7 @@ public class MonetDBEmbeddedConnection { protected MonetDBEmbeddedConnection(long connectionPointer) { this.connectionPointer = connectionPointer; } - long getConnectionPointer() { return connectionPointer; } + public long getConnectionPointer() { return connectionPointer; } /** * Gets the current schema set on the connection. 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 @@ -46,15 +46,9 @@ import java.util.concurrent.Executor; */ public abstract class MonetConnection extends MonetWrapper implements Connection { - /** the default number of rows that are (attempted to) read at once */ - private static int DEF_FETCHSIZE = 250; /** The sequence counter */ private static int SeqCounter = 0; - public static int GetDefFetchsize() { - return DEF_FETCHSIZE; - } - public static int GetSeqCounter() { return SeqCounter; } @@ -150,6 +144,8 @@ public abstract class MonetConnection ex public abstract int getBlockSize(); + public abstract int getDefFetchsize(); + public abstract int getSoTimeout(); public abstract void setSoTimeout(int s); @@ -164,6 +160,10 @@ public abstract class MonetConnection ex public abstract void sendControlCommand(ControlCommands con, int data) throws SQLException; + public abstract ResponseList createResponseList(int fetchSize, int maxRows, int resultSetType, int resultSetConcurrency) throws SQLException; + + public abstract void setServerMaxRows(int maxRows) throws SQLException; + /** * Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be * automatically released. All Statements created from this Connection will be closed when this method is called. @@ -1167,8 +1167,7 @@ public abstract class MonetConnection ex * Sets the given schema name to access. * * @param schema the name of a schema in which to work - * @throws SQLException if a database access error occurs or this - * method is called on a closed connection + * @throws SQLException if a database access error occurs or this method is called on a closed connection * @since 1.7 */ @Override @@ -1190,8 +1189,7 @@ public abstract class MonetConnection ex * Retrieves this Connection object's current schema name. * * @return the current schema name or null if there is none - * @throws SQLException if a database access error occurs or this - * method is called on a closed connection + * @throws SQLException if a database access error occurs or this method is called on a closed connection */ @Override public String getSchema() throws SQLException { @@ -1225,12 +1223,9 @@ public abstract class MonetConnection ex * Calling abort marks the connection closed and releases any * resources. Calling abort on a closed connection is a no-op. * - * @param executor The Executor implementation which will be used by - * abort - * @throws SQLException if a database access error occurs or the - * executor is null - * @throws SecurityException if a security manager exists and - * its checkPermission method denies calling abort + * @param executor The Executor implementation which will be used by abort + * @throws SQLException if a database access error occurs or the executor is null + * @throws SecurityException if a security manager exists and its checkPermission method denies calling abort */ @Override public void abort(Executor executor) throws SQLException { @@ -1253,13 +1248,10 @@ public abstract class MonetConnection ex * isClosed or Connection.isValid methods, will result in a * SQLException. * - * @param executor The Executor implementation which will be used by - * setNetworkTimeout - * @param millis The time in milliseconds to wait for the - * database operation to complete - * @throws SQLException if a database access error occurs, this - * method is called on a closed connection, the executor is - * null, or the value specified for seconds is less than 0. + * @param executor The Executor implementation which will be used by setNetworkTimeout + * @param millis The time in milliseconds to wait for the database operation to complete + * @throws SQLException if a database access error occurs, this method is called on a closed connection, the + * executor is null, or the value specified for seconds is less than 0. */ @Override public void setNetworkTimeout(Executor executor, int millis) throws SQLException { @@ -1274,14 +1266,11 @@ public abstract class MonetConnection ex } /** - * Retrieves the number of milliseconds the driver will wait for a - * database request to complete. If the limit is exceeded, a - * SQLException is thrown. + * Retrieves the number of milliseconds the driver will wait for a database request to complete. If the limit is + * exceeded, a SQLException is thrown. * - * @return the current timeout limit in milliseconds; zero means - * there is no limit - * @throws SQLException if a database access error occurs or - * this method is called on a closed Connection + * @return the current timeout limit in milliseconds; zero means there is no limit + * @throws SQLException if a database access error occurs or this method is called on a closed Connection */ @Override public int getNetworkTimeout() throws SQLException { @@ -1301,10 +1290,8 @@ public abstract class MonetConnection ex } /** - * Sends the given string to MonetDB as regular statement, making - * sure there is a prompt after the command is sent. All possible - * returned information is discarded. Encountered errors are - * reported. + * Sends the given string to MonetDB as regular statement, making sure there is a prompt after the command is sent. + * All possible returned information is discarded. Encountered errors are reported. * * @param command the exact string to send to MonetDB * @throws SQLException if an IO exception or a database error occurs @@ -1326,10 +1313,8 @@ public abstract class MonetConnection ex } /** - * Adds a warning to the pile of warnings this Connection object - * has. If there were no warnings (or clearWarnings was called) - * this warning will be the first, otherwise this warning will get - * appended to the current warning. + * Adds a warning to the pile of warnings this Connection object has. If there were no warnings (or clearWarnings + * was called) this warning will be the first, otherwise this warning will get appended to the current warning. * * @param reason the warning message */ @@ -1373,7 +1358,7 @@ public abstract class MonetConnection ex * @param rstype the type of result sets to produce * @param rsconcur the concurrency of result sets to produce */ - ResponseList(int cachesize, int maxrows, int rstype, int rsconcur) throws SQLException { + public ResponseList(int cachesize, int maxrows, int rstype, int rsconcur) throws SQLException { this.cachesize = cachesize; this.maxrows = maxrows; this.rstype = rstype; @@ -1504,13 +1489,12 @@ public abstract class MonetConnection ex * to use, then ignore this call. If it is set to 0 we get a prompt after the server sent it's * header. */ - int size = cachesize == 0 ? DEF_FETCHSIZE : cachesize; + int size = cachesize == 0 ? MonetConnection.this.getDefFetchsize() : cachesize; size = maxrows != 0 ? Math.min(maxrows, size) : size; // don't do work if it's not needed if (language == MapiLanguage.LANG_SQL && size != curReplySize && !Arrays.deepEquals(templ, language.getCommandTemplates())) { - sendControlCommand(ControlCommands.REPLY_SIZE, size); - + setServerMaxRows(size); // store the reply size after a successful change curReplySize = size; } @@ -1529,8 +1513,7 @@ public abstract class MonetConnection ex // tell it to do some work! senderThread.runQuery(templ, query); } else { - // this is a simple call, which is a lot cheaper and will - // always succeed for small queries. + // this is a simple call, which is a lot cheaper and will always succeed for small queries. protocol.writeNextQuery((templ[0] == null) ? "" : templ[0], query, (templ[1] == null) ? "" : templ[1]); } 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 @@ -46,9 +46,6 @@ import java.util.concurrent.locks.Reentr * @version 0.7 */ public class MonetStatement extends MonetWrapper implements Statement { - /** the default value of maxRows, 0 indicates unlimited */ - private static final int DEF_MAXROWS = 0; - /** The parental Connection object */ private MonetConnection connection; /** The last ResponseList object this Statement produced */ @@ -65,8 +62,8 @@ public class MonetStatement extends Mone private boolean closeOnCompletion = false; /** The size of the blocks of results to ask for at the server */ private int fetchSize = 0; - /** The maximum number of rows to return in a ResultSet */ - private int maxRows = DEF_MAXROWS; + /** The maximum number of rows to return in a ResultSet, 0 indicates unlimited */ + private int maxRows = 0; /** 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 */ @@ -477,7 +474,7 @@ public class MonetStatement extends Mone } // create a container for the result - lastResponseList = connection.new ResponseList(fetchSize, maxRows, resultSetType, resultSetConcurrency); + lastResponseList = connection.createResponseList(fetchSize, maxRows, resultSetType, resultSetConcurrency); // fill the header list by processing the query lastResponseList.processQuery(sql); @@ -642,8 +639,7 @@ public class MonetStatement extends Mone * setFetchSize, or the method setFetchSize was called as such to let * the driver ignore the hint, 0 is returned. * - * @return the default fetch size for result sets generated from this - * Statement object + * @return the default fetch size for result sets generated from this Statement object */ @Override public int getFetchSize() { @@ -655,8 +651,8 @@ public class MonetStatement extends Mone * executing this Statement object. If this Statement object did not * generate any keys, an empty ResultSet object is returned. * - * @return a ResultSet object containing the auto-generated key(s) - * generated by the execution of this Statement object + * @return a ResultSet object containing the auto-generated key(s) generated by the execution of this Statement + * object * @throws SQLException - if a database access error occurs */ @Override @@ -1091,7 +1087,7 @@ public class MonetStatement extends Mone /** * Requests that a Statement be pooled or not pooled. The value * specified is a hint to the statement pool implementation - * indicating whether the applicaiton wants the statement to be + * indicating whether the application wants the statement to be * pooled. It is up to the statement pool manager as to whether the * hint is used. * diff --git a/src/main/java/nl/cwi/monetdb/mcl/connection/SenderThread.java b/src/main/java/nl/cwi/monetdb/mcl/connection/SenderThread.java --- a/src/main/java/nl/cwi/monetdb/mcl/connection/SenderThread.java +++ b/src/main/java/nl/cwi/monetdb/mcl/connection/SenderThread.java @@ -96,7 +96,7 @@ public class SenderThread extends Thread this.sendLock.lock(); try { if (this.state != SendThreadStatus.WAIT) { - throw new SQLException("SendThread already in use or shutting down!", "M0M03"); + throw new SQLException("Sender Thread already in use or shutting down!", "M0M03"); } this.templ = templ; this.query = query; diff --git a/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/EmbeddedConnection.java b/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/EmbeddedConnection.java --- a/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/EmbeddedConnection.java +++ b/src/main/java/nl/cwi/monetdb/mcl/connection/embedded/EmbeddedConnection.java @@ -63,6 +63,11 @@ public final class EmbeddedConnection ex } @Override + public int getDefFetchsize() { + return Integer.MAX_VALUE; + } + + @Override public int getSoTimeout() { this.addWarning("Cannot get a timeout on a embedded connection!", "M1M05"); return -1; @@ -83,23 +88,32 @@ public final class EmbeddedConnection ex try { switch (con) { case AUTO_COMMIT: - ((EmbeddedProtocol)protocol).sendAutocommitCommand(data); - break; - case REPLY_SIZE: - ((EmbeddedProtocol)protocol).sendReplySizeCommand(data); + ((EmbeddedProtocol)protocol).getEmbeddedConnection().sendAutocommitCommand(data); break; case RELEASE: - ((EmbeddedProtocol)protocol).sendReleaseCommand(data); + ((EmbeddedProtocol)protocol).getEmbeddedConnection().sendReleaseCommand(data); break; case CLOSE: - ((EmbeddedProtocol)protocol).sendCloseCommand(data); + ((EmbeddedProtocol)protocol).getEmbeddedConnection().sendCloseCommand(data); + case REPLY_SIZE: + throw new SQLException("Cannot set reply size on a Embedded connection!", "M1M05"); } protocol.waitUntilPrompt(); if (protocol.getCurrentServerResponseHeader() == ServerResponses.ERROR) { throw new SQLException(protocol.getRemainingStringLine(0)); } - } catch (IOException | ProtocolException ex) { _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list