Mercurial > hg > monetdb-java
changeset 72:af83fa389393 embedded
Made it working with an old mapi connection!!! But I need to test more and make make it more efficient! (Retrieve data column wise instead of row wise)
author | Pedro Ferreira <pedro.ferreira@monetdbsolutions.com> |
---|---|
date | Mon, 12 Dec 2016 18:09:53 +0100 (2016-12-12) |
parents | 4e2a2a81cc6a |
children | 953422c41194 |
files | src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.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 |
diffstat | 5 files changed, 26 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java @@ -1499,18 +1499,16 @@ public abstract class MonetConnection ex try { synchronized (protocol) { - // make sure we're ready to send query; read data till we - // have the prompt it is possible (and most likely) that we - // already have the prompt and do not have to skip any - // lines. Ignore errors from previous result sets. + // make sure we're ready to send query; read data till we have the prompt it is possible (and most + // likely) that we already have the prompt and do not have to skip any lines. Ignore errors from + // previous result sets. protocol.waitUntilPrompt(); // {{{ set reply size /** - * Change the reply size of the server. If the given - * value is the same as the current value known to use, - * then ignore this call. If it is set to 0 we get a - * prompt after the server sent it's header. + * Change the reply size of the server. If the given value is the same as the current value known + * 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; size = maxrows != 0 ? Math.min(maxrows, size) : size; @@ -1524,14 +1522,11 @@ public abstract class MonetConnection ex } // }}} set reply size - // If the query is larger than the TCP buffer size, use a - // special send thread to avoid deadlock with the server due - // to blocking behaviour when the buffer is full. Because - // the server will be writing back results to us, it will - // eventually block as well when its TCP buffer gets full, - // as we are blocking an not consuming from it. The result - // is a state where both client and server want to write, - // but block. + // If the query is larger than the TCP buffer size, use a special send thread to avoid deadlock with + // the server due to blocking behaviour when the buffer is full. Because the server will be writing + // back results to us, it will eventually block as well when its TCP buffer gets full, as we are + // blocking an not consuming from it. The result is a state where both client and server want to + // write, but block. if (query.length() > getBlockSize()) { // get a reference to the send thread if (sendThread == null) { @@ -1547,7 +1542,7 @@ public abstract class MonetConnection ex } // go for new results - protocol.fetchNextResponseData(); //&1 0 27 1 27 + protocol.fetchNextResponseData(); ServerResponses nextResponse = protocol.getCurrentServerResponseHeader(); IResponse res = null; while (nextResponse != ServerResponses.PROMPT) { @@ -1564,8 +1559,7 @@ public abstract class MonetConnection ex res = protocol.getNextResultSetResponse(MonetConnection.this, ResponseList.this, this.seqnr); ResultSetResponse rsreponse = (ResultSetResponse) res; - // only add this resultset to - // the hashmap if it can possibly + // only add this resultset to the hashmap if it can possibly // have an additional datablock if (rsreponse.getRowcount() < rsreponse.getTuplecount()) { if (rsresponses == null) {
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java @@ -120,6 +120,7 @@ public class MonetResultSet extends Mone this.columns = header.getNames(); this.types = header.getTypes(); this.JdbcSQLTypes = header.getJdbcSQLTypes(); + this.values = header.getLine(this.curRow); } /**
--- a/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiTableHeaderParser.java +++ b/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiTableHeaderParser.java @@ -65,7 +65,7 @@ final class OldMapiTableHeaderParser { } break; default: - throw new ProtocolException("unknown header: " + builder.substring(pos, len - pos)); + throw new ProtocolException("unknown header: " + builder.substring(pos, len)); } return res; } @@ -75,12 +75,12 @@ final class OldMapiTableHeaderParser { for (int i = start + 1; i < stop; i++) { if (builder.charAt(i) == '\t' && builder.charAt(i - 1) == ',') { - stringValues[elem++] = builder.substring(start, i - 1 - start); + stringValues[elem++] = builder.substring(start, i - 1); start = i + 1; } } // add the left over part - stringValues[elem + 1] = builder.substring(start, stop - start); + stringValues[elem] = builder.substring(start, stop); } private static void GetIntValues(StringBuilder builder, int stop, int[] intValues) throws ProtocolException { @@ -102,6 +102,6 @@ final class OldMapiTableHeaderParser { } } // add the left over part - intValues[elem + 1] = tmp; + intValues[elem] = tmp; } }
--- a/src/main/java/nl/cwi/monetdb/mcl/responses/DataBlockResponse.java +++ b/src/main/java/nl/cwi/monetdb/mcl/responses/DataBlockResponse.java @@ -76,7 +76,7 @@ public class DataBlockResponse implement @Override public boolean wantsMore() { // remember: pos is the value already stored - return pos + 1 < data.length; + return (this.pos + 1) < this.data.length; } /** @@ -87,9 +87,9 @@ public class DataBlockResponse implement */ @Override public void complete() throws SQLException { - if ((pos + 1) != data.length) { - throw new SQLException("Inconsistent state detected! Current block capacity: " + data.length + - ", block usage: " + (pos + 1) + ". Did MonetDB send what it promised to?", "M0M10"); + if ((this.pos + 1) != this.data.length) { + throw new SQLException("Inconsistent state detected! Current block capacity: " + this.data.length + + ", block usage: " + (this.pos + 1) + ". Did MonetDB send what it promised to?", "M0M10"); } } @@ -100,6 +100,9 @@ public class DataBlockResponse implement public void close() { // feed all rows to the garbage collector for (int i = 0; i < data.length; i++) { + for (int j = 0; j < data[0].length; j++) { + data[i][j] = null; + } data[i] = null; } }
--- a/src/main/java/nl/cwi/monetdb/mcl/responses/ResultSetResponse.java +++ b/src/main/java/nl/cwi/monetdb/mcl/responses/ResultSetResponse.java @@ -274,8 +274,7 @@ public class ResultSetResponse implement public void addLine(ServerResponses response, Object line) throws ProtocolException { if (this.isSet >= IsSetFinalValue) { this.resultBlocks[0].addLine(response, line); - } - if (response != ServerResponses.HEADER) { + } else if (response != ServerResponses.HEADER) { throw new ProtocolException("header expected, got: " + response.toString()); } else { //we will always pass the tableNames pointer