Changeset: 4a93f75c72c9 for monetdb-java
URL: http://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=4a93f75c72c9
Modified Files:
src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
src/main/java/nl/cwi/monetdb/mcl/connection/ControlCommands.java
src/main/java/nl/cwi/monetdb/mcl/connection/SenderThread.java
src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java
src/main/java/nl/cwi/monetdb/mcl/protocol/AbstractProtocol.java
src/main/java/nl/cwi/monetdb/mcl/protocol/ServerResponses.java
src/main/java/nl/cwi/monetdb/mcl/protocol/StarterHeaders.java
src/main/java/nl/cwi/monetdb/mcl/protocol/TableResultHeaders.java
src/main/java/nl/cwi/monetdb/mcl/protocol/newmapi/NewMapiProtocol.java
src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiProtocol.java
src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiServerResponseParser.java
src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiStartOfHeaderParser.java
src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiTableHeaderParser.java
src/main/java/nl/cwi/monetdb/mcl/responses/DataBlockResponse.java
src/main/java/nl/cwi/monetdb/mcl/responses/ResultSetResponse.java
src/main/java/nl/cwi/monetdb/merovingian/Control.java
src/main/java/nl/cwi/monetdb/util/SQLRestore.java
Branch: embedded
Log Message:
Java enums are compiled into objects, so changing the server responses
parameters into integers gives an extra performance.
diffs (truncated from 645 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
@@ -6,6 +6,7 @@ import nl.cwi.monetdb.mcl.connection.map
import nl.cwi.monetdb.mcl.protocol.ProtocolException;
import nl.cwi.monetdb.mcl.protocol.AbstractProtocol;
import nl.cwi.monetdb.mcl.protocol.ServerResponses;
+import nl.cwi.monetdb.mcl.protocol.StarterHeaders;
import nl.cwi.monetdb.mcl.responses.*;
import nl.cwi.monetdb.mcl.responses.DataBlockResponse;
import nl.cwi.monetdb.mcl.responses.ResultSetResponse;
@@ -131,7 +132,7 @@ public abstract class MonetConnection ex
public abstract String getJDBCURL();
- public abstract void sendControlCommand(ControlCommands con, int data)
throws SQLException;
+ public abstract void sendControlCommand(int con, int data) throws
SQLException;
public abstract ResponseList createResponseList(int fetchSize, int
maxRows, int resultSetType,
int resultSetConcurrency)
throws SQLException;
@@ -1251,7 +1252,8 @@ public abstract class MonetConnection ex
try {
protocol.writeNextQuery(language.getQueryTemplateIndex(0),
command, language.getQueryTemplateIndex(1));
protocol.waitUntilPrompt();
- if (protocol.getCurrentServerResponseHeader() ==
ServerResponses.ERROR) {
+ int csrh = protocol.getCurrentServerResponseHeader();
+ if (csrh == ServerResponses.ERROR) {
String error = protocol.getRemainingStringLine(0);
throw new SQLException(error.substring(6), error.substring(0,
5));
}
@@ -1471,19 +1473,20 @@ public abstract class MonetConnection ex
// go for new results
protocol.fetchNextResponseData();
- ServerResponses nextResponse =
protocol.getCurrentServerResponseHeader();
+ int nextResponse = protocol.getCurrentServerResponseHeader();
IResponse res = null;
while (nextResponse != ServerResponses.PROMPT) {
// each response should start with a start of header (or
error)
switch (nextResponse) {
- case SOHEADER:
+ case ServerResponses.SOHEADER:
// make the response object, and fill it
+ int nextStartHeader =
protocol.getNextStarterHeader();
try {
- switch (protocol.getNextStarterHeader()) {
- case Q_PARSE:
- throw new ProtocolException("Q_PARSE
header not allowed here", 1);
- case Q_TABLE:
- case Q_PREPARE: {
+ switch (nextStartHeader) {
+ case StarterHeaders.Q_PARSE:
+ throw new ProtocolException("Q_PARSE
header not allowed here");
+ case StarterHeaders.Q_TABLE:
+ case StarterHeaders.Q_PREPARE: {
res =
protocol.getNextResultSetResponse(MonetConnection.this,
ResponseList.this, this.seqnr);
ResultSetResponse rsreponse =
(ResultSetResponse) res;
@@ -1497,13 +1500,13 @@ public abstract class MonetConnection ex
}
}
break;
- case Q_UPDATE:
+ case StarterHeaders.Q_UPDATE:
res = protocol.getNextUpdateResponse();
break;
- case Q_SCHEMA:
+ case StarterHeaders.Q_SCHEMA:
res = protocol.getNextSchemaResponse();
break;
- case Q_TRANS:
+ case StarterHeaders.Q_TRANS:
res =
protocol.getNextAutoCommitResponse();
boolean isAutoCommit =
((AutoCommitResponse) res).isAutocommit();
@@ -1513,7 +1516,7 @@ public abstract class MonetConnection ex
}
MonetConnection.this.autoCommit =
isAutoCommit;
break;
- case Q_BLOCK: {
+ case StarterHeaders.Q_BLOCK: {
DataBlockResponse next =
protocol.getNextDatablockResponse(rsresponses);
if (next == null) {
error = "M0M12!No
ResultSetResponse for a DataBlock found";
@@ -1571,13 +1574,13 @@ public abstract class MonetConnection ex
protocol.fetchNextResponseData();
nextResponse =
protocol.getCurrentServerResponseHeader();
break;
- case INFO:
+ case ServerResponses.INFO:
addWarning(protocol.getRemainingStringLine(0),
"01000");
// read the next line (can be prompt, new result,
error, etc.) before we start the loop over
protocol.fetchNextResponseData();
nextResponse =
protocol.getCurrentServerResponseHeader();
break;
- case ERROR:
+ case ServerResponses.ERROR:
// read everything till the prompt (should be
error) we don't know if we ignore some
// garbage here... but the log should reveal that
error = protocol.getRemainingStringLine(0);
diff --git a/src/main/java/nl/cwi/monetdb/mcl/connection/ControlCommands.java
b/src/main/java/nl/cwi/monetdb/mcl/connection/ControlCommands.java
--- a/src/main/java/nl/cwi/monetdb/mcl/connection/ControlCommands.java
+++ b/src/main/java/nl/cwi/monetdb/mcl/connection/ControlCommands.java
@@ -8,14 +8,14 @@
package nl.cwi.monetdb.mcl.connection;
-public enum ControlCommands {
+public final class ControlCommands {
/** Send autocommit statement */
- AUTO_COMMIT,
+ public static final int AUTO_COMMIT = 1;
/** Set reply size for the server */
- REPLY_SIZE,
+ public static final int REPLY_SIZE = 2;
/** Release a prepared statement data */
- RELEASE,
+ public static final int RELEASE = 3;
/** Close a query */
- CLOSE
+ public static final int CLOSE = 4;
}
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
@@ -29,20 +29,18 @@ import java.util.concurrent.locks.Reentr
*/
public class SenderThread extends Thread {
- private enum SendThreadStatus {
- /** The state WAIT represents this thread to be waiting for something
to do */
- WAIT,
- /** The state QUERY represents this thread to be executing a query */
- QUERY,
- /** The state SHUTDOWN is the final state that ends this thread */
- SHUTDOWN
- }
+ /** The state WAIT represents this thread to be waiting for something to
do */
+ private static final int WAIT = 1;
+ /** The state QUERY represents this thread to be executing a query */
+ private static final int QUERY = 2;
+ /** The state SHUTDOWN is the final state that ends this thread */
+ private static final int SHUTDOWN = 3;
private String[] templ;
private String query;
private AbstractProtocol protocol;
private String error;
- private SendThreadStatus state = SendThreadStatus.WAIT;
+ private int state = SenderThread.WAIT;
private final Lock sendLock = new ReentrantLock();
private final Condition queryAvailable = sendLock.newCondition();
private final Condition waiting = sendLock.newCondition();
@@ -64,14 +62,14 @@ public class SenderThread extends Thread
this.sendLock.lock();
try {
while (true) {
- while (this.state == SendThreadStatus.WAIT) {
+ while (this.state == SenderThread.WAIT) {
try {
this.queryAvailable.await();
} catch (InterruptedException e) {
// woken up, eh?
}
}
- if (this.state == SendThreadStatus.SHUTDOWN)
+ if (this.state == SenderThread.SHUTDOWN)
break;
// state is QUERY here
@@ -84,7 +82,7 @@ public class SenderThread extends Thread
// update our state, and notify, maybe someone is waiting
// for us in throwErrors
- this.state = SendThreadStatus.WAIT;
+ this.state = SenderThread.WAIT;
this.waiting.signal();
}
} finally {
@@ -103,13 +101,13 @@ public class SenderThread extends Thread
public void runQuery(String[] templ, String query) throws SQLException {
this.sendLock.lock();
try {
- if (this.state != SendThreadStatus.WAIT) {
+ if (this.state != SenderThread.WAIT) {
throw new SQLException("Sender Thread already in use or
shutting down!", "M0M03");
}
this.templ = templ;
this.query = query;
// let the thread know there is some work to do
- this.state = SendThreadStatus.QUERY;
+ this.state = SenderThread.QUERY;
this.queryAvailable.signal();
} finally {
this.sendLock.unlock();
@@ -125,14 +123,14 @@ public class SenderThread extends Thread
this.sendLock.lock();
try {
// make sure the thread is in WAIT state, not QUERY
- while (this.state == SendThreadStatus.QUERY) {
+ while (this.state == SenderThread.QUERY) {
try {
this.waiting.await();
} catch (InterruptedException e) {
// just try again
}
}
- if (this.state == SendThreadStatus.SHUTDOWN)
+ if (this.state == SenderThread.SHUTDOWN)
this.error = "SendThread is shutting down";
} finally {
this.sendLock.unlock();
@@ -145,7 +143,7 @@ public class SenderThread extends Thread
*/
public void shutdown() {
sendLock.lock();
- state = SendThreadStatus.SHUTDOWN;
+ state = SenderThread.SHUTDOWN;
sendLock.unlock();
this.interrupt(); // break any wait conditions
}
diff --git
a/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java
b/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java
--- a/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java
+++ b/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java
@@ -201,25 +201,26 @@ public class MapiConnection extends Mone
* @throws SQLException if an IO exception or a database error occurs
*/
@Override
- public void sendControlCommand(ControlCommands con, int data) throws
SQLException {
+ public void sendControlCommand(int con, int data) throws SQLException {
String command = null;
switch (con) {
- case AUTO_COMMIT:
+ case ControlCommands.AUTO_COMMIT:
command = "auto_commit " + ((data == 1) ? "1" : "0");
break;
- case REPLY_SIZE:
+ case ControlCommands.REPLY_SIZE:
command = "reply_size " + data;
break;
- case RELEASE:
+ case ControlCommands.RELEASE:
command = "release " + data;
break;
- case CLOSE:
+ case ControlCommands.CLOSE:
command = "close " + data;
}
try {
protocol.writeNextQuery(language.getCommandTemplateIndex(0),
command, language.getCommandTemplateIndex(1));
protocol.waitUntilPrompt();
- if (protocol.getCurrentServerResponseHeader() ==
ServerResponses.ERROR) {
+ int csrh = protocol.getCurrentServerResponseHeader();
+ if (csrh == ServerResponses.ERROR) {
String error = protocol.getRemainingStringLine(0);
throw new SQLException(error.substring(6), error.substring(0,
5));
}
@@ -267,19 +268,19 @@ public class MapiConnection extends Mone
List<String> redirects = new ArrayList<>();
List<String> warns = new ArrayList<>();
String err = "";
- ServerResponses next;
+ int next;
do {
this.protocol.fetchNextResponseData();
next = this.protocol.getCurrentServerResponseHeader();
switch (next) {
- case ERROR:
+ case ServerResponses.ERROR:
err += "\n" + this.protocol.getRemainingStringLine(7);
break;
- case INFO:
+ case ServerResponses.INFO:
warns.add(this.protocol.getRemainingStringLine(1));
break;
- case REDIRECT:
+ case ServerResponses.REDIRECT:
redirects.add(this.protocol.getRemainingStringLine(1));
}
} while (next != ServerResponses.PROMPT);
diff --git a/src/main/java/nl/cwi/monetdb/mcl/protocol/AbstractProtocol.java
b/src/main/java/nl/cwi/monetdb/mcl/protocol/AbstractProtocol.java
--- a/src/main/java/nl/cwi/monetdb/mcl/protocol/AbstractProtocol.java
+++ b/src/main/java/nl/cwi/monetdb/mcl/protocol/AbstractProtocol.java
@@ -24,9 +24,9 @@ public abstract class AbstractProtocol {
public abstract void fetchNextResponseData() throws IOException;
- public abstract ServerResponses getCurrentServerResponseHeader();
+ public abstract int getCurrentServerResponseHeader();
- public abstract StarterHeaders getNextStarterHeader();
+ public abstract int getNextStarterHeader();
public abstract ResultSetResponse getNextResultSetResponse(MonetConnection
con, MonetConnection.ResponseList list,
int seqnr)
throws ProtocolException;
@@ -42,8 +42,8 @@ public abstract class AbstractProtocol {
public abstract DataBlockResponse getNextDatablockResponse(Map<Integer,
ResultSetResponse> rsresponses)
throws ProtocolException;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list