Changeset: 02f560eb3cf2 for monetdb-java
URL: http://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=02f560eb3cf2
Added Files:
src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiDataBlockResponse.java
src/main/java/nl/cwi/monetdb/mcl/responses/AbstractDataBlockResponse.java
Removed Files:
src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiTupleLineParserHelper.java
src/main/java/nl/cwi/monetdb/mcl/responses/DataBlockResponse.java
Modified Files:
src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in
src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java
src/main/java/nl/cwi/monetdb/mcl/connection/mapi/OldMapiSocket.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/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/protocol/oldmapi/OldMapiTupleLineParser.java
src/main/java/nl/cwi/monetdb/mcl/responses/ResultSetResponse.java
Branch: embedded
Log Message:
Major change in the Datablock response. Removed the arrays creation in the
Embedded connection, so it will run much faster now. It can be possible to do
it as well in the MAPI connection, but in the way the Old Mapi Protocol is
designed, it will be very complicated (ByteBuffers are designed to work with
binary data instead of textual data :S). I think it's better to wait for the
new protocol, which will be much faster and easier to parse.
diffs (truncated from 2950 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
@@ -1559,14 +1559,10 @@ public abstract class MonetConnection ex
res =
protocol.getNextResultSetResponse(MonetConnection.this,
ResponseList.this, this.seqnr,
this.maxrows);
ResultSetResponse rsreponse =
(ResultSetResponse) res;
- // only add this resultset to the
hashmap if it can possibly
- // have an additional datablock
- if (rsreponse.getRowcount() <
rsreponse.getTuplecount()) {
- if (rsresponses == null) {
- rsresponses = new HashMap<>();
- }
- rsresponses.put(rsreponse.getId(),
rsreponse);
+ if (rsresponses == null) {
+ rsresponses = new HashMap<>();
}
+ rsresponses.put(rsreponse.getId(),
rsreponse);
}
break;
case StarterHeaders.Q_UPDATE:
@@ -1586,7 +1582,7 @@ public abstract class MonetConnection ex
MonetConnection.this.autoCommit =
isAutoCommit;
break;
case StarterHeaders.Q_BLOCK: {
- DataBlockResponse next =
protocol.getNextDatablockResponse(rsresponses);
+ AbstractDataBlockResponse next =
protocol.getNextDatablockResponse(rsresponses);
if (next == null) {
error = "M0M12!No
ResultSetResponse for a DataBlock found";
break;
@@ -1636,7 +1632,7 @@ public abstract class MonetConnection ex
// it is of no use to store DataBlockResponses,
you never want to retrieve them directly
// anyway
- if (!(res instanceof DataBlockResponse)) {
+ if (!(res instanceof AbstractDataBlockResponse)) {
responses.add(res);
}
// read the next line (can be prompt, new result,
error, etc.) before we start the loop over
diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in
b/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in
@@ -48,7 +48,7 @@ import java.util.logging.Logger;
* @author Fabian Groffen, Pedro Ferreira
* @version @JDBC_MAJOR@.@JDBC_MINOR@ (@JDBC_VER_SUFFIX@)
*/
-final public class MonetDriver implements Driver {
+public final class MonetDriver implements Driver {
// the url kind will be jdbc:monetdb://<host>[:<port>]/<database> (in a
MAPI connection)
// the url kind will be jdbc:monetdb:embedded:<directory> (in an
Embedded connection)
// Chapter 9.2.1 from Sun JDBC 3.0 specification
diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
@@ -8,37 +8,23 @@
package nl.cwi.monetdb.jdbc;
-import nl.cwi.monetdb.mcl.responses.DataBlockResponse;
+import nl.cwi.monetdb.mcl.protocol.ProtocolException;
+import nl.cwi.monetdb.mcl.responses.AbstractDataBlockResponse;
import nl.cwi.monetdb.mcl.responses.ResultSetResponse;
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
-import java.sql.Array;
-import java.sql.Blob;
-import java.sql.Clob;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.Date;
-import java.sql.NClob;
-import java.sql.Ref;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.RowId;
-import java.sql.SQLData;
-import java.sql.SQLException;
-import java.sql.SQLFeatureNotSupportedException;
-import java.sql.SQLInput;
-import java.sql.SQLWarning;
-import java.sql.SQLXML;
-import java.sql.Statement;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.sql.Types;
-import java.util.*;
+import java.sql.*;
+import java.util.Calendar;
+import java.util.Map;
+import java.util.UUID;
/**
* A ResultSet suitable for the MonetDB database.
@@ -84,12 +70,10 @@ public class MonetResultSet extends Mone
private int concurrency = CONCUR_READ_ONLY;
/** The warnings for this ResultSet object */
private SQLWarning warnings;
- /** whether the last read field (via some getXyz() method) was NULL */
- private boolean lastReadWasNull = true;
/** Just a dummy variable to keep store the fetchsize set. */
private int fetchSize;
/** The current row's values */
- private DataBlockResponse currentBlock;
+ private AbstractDataBlockResponse currentBlock;
/**
* Main constructor backed by the given Header.
@@ -152,11 +136,6 @@ public class MonetResultSet extends Mone
this.JdbcSQLTypes = JdbcSQLTypes;
}
- private boolean setLastNullValue(int columnIndex) {
- this.lastReadWasNull =
currentBlock.checkValueIsNull(columnIndex);
- return this.lastReadWasNull;
- }
-
//== methods of interface ResultSet
// Chapter 14.2.2 Sun JDBC 3.0 Specification
@@ -303,23 +282,29 @@ public class MonetResultSet extends Mone
@Override
public InputStream getAsciiStream(int columnIndex) throws SQLException {
try {
- if(setLastNullValue(columnIndex - 1)) {
- return null;
- }
+ InputStream res = null;
switch (JdbcSQLTypes[columnIndex - 1]) {
+ case Types.CLOB:
+ Clob cl = getClob(columnIndex);
+ if(cl != null) {
+ res = cl.getAsciiStream();
+ }
+ break;
case Types.BLOB:
- return getClob(columnIndex).getAsciiStream();
- case Types.CLOB:
- return getClob(columnIndex).getAsciiStream();
case Types.LONGVARBINARY:
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
- return new ByteArrayInputStream(getBytes(columnIndex));
+ byte[] bytes = getBytes(columnIndex);
+ if(bytes != null) {
+ res = new ByteArrayInputStream(getBytes(columnIndex));
+ }
+ break;
default:
throw new SQLException("Conversion from " +
types[columnIndex - 1] +
" to ascii stream not supported", "M1M05");
}
+ return res;
} catch (ClassCastException ex) {
throw new SQLException(ex.getMessage());
} catch (IndexOutOfBoundsException e) {
@@ -362,18 +347,25 @@ public class MonetResultSet extends Mone
@Override
public InputStream getBinaryStream(int columnIndex) throws SQLException
{
try {
- if(setLastNullValue(columnIndex - 1)) {
- return null;
- }
+ InputStream res = null;
switch (JdbcSQLTypes[columnIndex - 1]) {
case Types.BLOB:
- return getBlob(columnIndex).getBinaryStream();
+ Blob cl = getBlob(columnIndex);
+ if(cl != null) {
+ res = cl.getBinaryStream();
+ }
+ break;
case Types.LONGVARBINARY:
- return new ByteArrayInputStream(getBytes(columnIndex));
+ byte[] bytes = getBytes(columnIndex);
+ if(bytes != null) {
+ res = new ByteArrayInputStream(getBytes(columnIndex));
+ }
+ break;
default:
throw new SQLException("Conversion from " +
types[columnIndex - 1] +
" to binary stream not supported", "M1M05");
}
+ return res;
} catch (ClassCastException ex) {
throw new SQLException(ex.getMessage());
} catch (IndexOutOfBoundsException e) {
@@ -414,13 +406,13 @@ public class MonetResultSet extends Mone
@Override
public Reader getCharacterStream(int columnIndex) throws SQLException {
try {
- if(setLastNullValue(columnIndex - 1)) {
- return null;
- }
- return new
StringReader(currentBlock.getValueAsString(columnIndex - 1));
+ String ss = currentBlock.getValueAsString(columnIndex -
1);
+ return (ss == null) ? null : new StringReader(ss);
} catch (ClassCastException ex) {
throw new SQLException(ex.getMessage());
- } catch (IndexOutOfBoundsException e) {
+ } catch (ProtocolException e) {
+ throw new SQLException(e);
+ } catch (IndexOutOfBoundsException e) {
throw newSQLInvalidColumnIndexException(columnIndex);
}
}
@@ -481,13 +473,12 @@ public class MonetResultSet extends Mone
@Override
public Blob getBlob(int columnIndex) throws SQLException {
try {
- if(setLastNullValue(columnIndex - 1)) {
- return null;
- }
return (MonetBlob)
currentBlock.getObjectValue(columnIndex - 1);
} catch (ClassCastException ex) {
throw new SQLException(ex.getMessage());
- } catch (IndexOutOfBoundsException e) {
+ } catch (ProtocolException e) {
+ throw new SQLException(e);
+ } catch (IndexOutOfBoundsException e) {
throw newSQLInvalidColumnIndexException(columnIndex);
}
}
@@ -516,13 +507,12 @@ public class MonetResultSet extends Mone
@Override
public Clob getClob(int columnIndex) throws SQLException {
try {
- if(setLastNullValue(columnIndex - 1)) {
- return null;
- }
return (MonetClob)
currentBlock.getObjectValue(columnIndex - 1);
} catch (ClassCastException ex) {
throw new SQLException(ex.getMessage());
- } catch (IndexOutOfBoundsException e) {
+ } catch (ProtocolException e) {
+ throw new SQLException(e);
+ } catch (IndexOutOfBoundsException e) {
throw newSQLInvalidColumnIndexException(columnIndex);
}
}
@@ -580,52 +570,48 @@ public class MonetResultSet extends Mone
@Override
public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
try {
- if(setLastNullValue(columnIndex - 1)) {
- return null;
- }
- BigDecimal val;
switch (JdbcSQLTypes[columnIndex - 1]) {
case Types.NUMERIC:
case Types.DECIMAL:
- val = (BigDecimal)
currentBlock.getObjectValue(columnIndex - 1);
- break;
+ return (BigDecimal)
currentBlock.getObjectValue(columnIndex - 1);
case Types.BOOLEAN:
- val = new
BigDecimal(currentBlock.getBooleanValue(columnIndex - 1) ? (byte) 1 : (byte) 0);
- break;
+ boolean bol =
currentBlock.getBooleanValue(columnIndex - 1);
+ return currentBlock.isLastReadWasNull()
? null : new BigDecimal(bol ? 1 : 0);
case Types.TINYINT:
- val = new
BigDecimal(currentBlock.getByteValue(columnIndex - 1));
- break;
+ byte bb =
currentBlock.getByteValue(columnIndex - 1);
+ return currentBlock.isLastReadWasNull()
? null : new BigDecimal(bb);
case Types.SMALLINT:
- val = new
BigDecimal(currentBlock.getShortValue(columnIndex - 1));
- break;
+ short sh =
currentBlock.getShortValue(columnIndex - 1);
+ return currentBlock.isLastReadWasNull()
? null : new BigDecimal(sh);
case Types.INTEGER:
- val = new
BigDecimal(currentBlock.getIntValue(columnIndex - 1));
- break;
+ int in =
currentBlock.getIntValue(columnIndex - 1);
+ return currentBlock.isLastReadWasNull()
? null : new BigDecimal(in);
case Types.BIGINT:
- val = new
BigDecimal(currentBlock.getLongValue(columnIndex - 1));
- break;
+ long lon =
currentBlock.getLongValue(columnIndex - 1);
+ return currentBlock.isLastReadWasNull()
? null : new BigDecimal(lon);
case Types.REAL:
- val = new
BigDecimal(currentBlock.getFloatValue(columnIndex - 1));
- break;
+ float floa =
currentBlock.getFloatValue(columnIndex - 1);
+ return currentBlock.isLastReadWasNull()
? null : new BigDecimal(floa);
case Types.DOUBLE:
- val = new
BigDecimal(currentBlock.getDoubleValue(columnIndex - 1));
- break;
+ double dou =
currentBlock.getDoubleValue(columnIndex - 1);
+ return currentBlock.isLastReadWasNull()
? null : new BigDecimal(dou);
case Types.CHAR:
case Types.VARCHAR:
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list