Changeset: d39f656b6614 for monetdb-java
URL: http://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=d39f656b6614
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/MonetPreparedStatement.java
src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
src/main/java/nl/cwi/monetdb/jdbc/MonetStatement.java
src/main/java/nl/cwi/monetdb/mcl/connection/mapi/AbstractSocket.java
src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java
src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiProtocol.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/protocol/oldmapi/OldMapiTupleLineParserHelper.java
src/main/java/nl/cwi/monetdb/mcl/responses/DataBlockResponse.java
Branch: embedded
Log Message:
Made several bug fixes from the tests.
diffs (truncated from 643 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
@@ -84,6 +84,8 @@ public abstract class MonetConnection ex
private final boolean clobIsLongChar;
/** The underlying proticol provided by the connection (MAPI or embedded)
*/
protected AbstractProtocol protocol;
+ /** Tells if the connection is embedded or not */
+ private final boolean isEmbedded;
/**
* Constructor of a Connection for MonetDB. At this moment the current
implementation limits itself to storing the
@@ -99,6 +101,8 @@ public abstract class MonetConnection ex
this.language = language;
this.blobIsBinary = blobIsBinary;
this.clobIsLongChar = clobIsLongChar;
+ String embedded = props.getProperty("embedded");
+ this.isEmbedded = embedded != null && embedded.equals("true");
}
/**
@@ -183,18 +187,6 @@ public abstract class MonetConnection ex
public abstract void sendControlCommand(int commandID, int data) throws
SQLException;
/**
- * Creates a ResponseList.
- *
- * @param fetchSize the nubmer of rows per block in the response list
- * @param maxRows maximum number of rows to allow in the set
- * @param resultSetType the type of result sets to produce
- * @param resultSetConcurrency the concurrency of result sets to produce
- * @return A ResponseList instance
- */
- public abstract ResponseList createResponseList(int fetchSize, int
maxRows, int resultSetType,
- int resultSetConcurrency);
-
- /**
* 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.
*
@@ -1498,8 +1490,10 @@ public abstract class MonetConnection ex
* 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.
+ *
+ * 2017: For now, in the embedded connection, the value set
cachesize will be always the default one.
*/
- int size = cachesize == 0 ?
MonetConnection.this.getDefFetchsize() : cachesize;
+ int size = (cachesize != 0 && !isEmbedded) ? cachesize :
MonetConnection.this.getDefFetchsize();
size = maxrows != 0 ? Math.min(maxrows, size) : size;
// don't do work if it's not needed
if (language == MapiLanguage.LANG_SQL && size != curReplySize
&&
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
@@ -243,7 +243,7 @@ final public class MonetDriver implement
typeMap.put("double", Types.DOUBLE);
typeMap.put("geometry", Types.OTHER);
typeMap.put("geometrya", Types.OTHER);
- typeMap.put("hugeint", Types.NUMERIC); //but we will convert to
java.math.BigInteger
+ typeMap.put("hugeint", Types.NUMERIC);
typeMap.put("inet", Types.OTHER);
typeMap.put("int", Types.INTEGER);
typeMap.put("json", Types.OTHER);
diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
b/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
@@ -16,7 +16,6 @@ import java.io.InputStream;
import java.io.Reader;
import java.io.IOException;
import java.math.BigDecimal;
-import java.math.BigInteger;
import java.math.RoundingMode;
import java.net.URL;
import java.nio.CharBuffer;
@@ -1659,18 +1658,6 @@ public class MonetPreparedStatement exte
setDouble(parameterIndex, val6);
break;
case Types.NUMERIC:
- BigInteger val7;
- try {
- val7 = new
BigInteger((String)x);
- } catch (NumberFormatException e) {
- try {
- val7 = BigInteger.ZERO;
- } catch (NumberFormatException
ex) {
- throw new
SQLException("Internal error: unable to create template BigInteger: " +
ex.getMessage(), "M0M03");
- }
- }
- setObject(parameterIndex, val7);
- break;
case Types.DECIMAL:
BigDecimal val8;
try {
@@ -1736,7 +1723,7 @@ public class MonetPreparedStatement exte
default:
throw new SQLException("Conversion not
allowed", "M1M05");
}
- } else if (x instanceof BigDecimal || x instanceof BigInteger
|| x instanceof Byte || x instanceof Short || x instanceof Integer || x
instanceof Long || x instanceof Float || x instanceof Double) {
+ } else if (x instanceof BigDecimal || x instanceof Byte || x
instanceof Short || x instanceof Integer || x instanceof Long || x instanceof
Float || x instanceof Double) {
Number num = (Number)x;
switch (targetSqlType) {
case Types.TINYINT:
@@ -1758,12 +1745,6 @@ public class MonetPreparedStatement exte
setDouble(parameterIndex,
num.doubleValue());
break;
case Types.NUMERIC:
- if (x instanceof BigInteger) {
- setObject(parameterIndex, x);
- } else {
- setObject(parameterIndex, new
BigInteger(Integer.toString(num.intValue())));
- }
- break;
case Types.DECIMAL:
if (x instanceof BigDecimal) {
setBigDecimal(parameterIndex,
(BigDecimal)x);
@@ -1808,8 +1789,6 @@ public class MonetPreparedStatement exte
setDouble(parameterIndex, (val ? 1.0 :
0.0)); // do no cast to (double) as it generates a compiler warning
break;
case Types.NUMERIC:
- setObject(parameterIndex, val ?
BigInteger.ONE : BigInteger.ZERO);
- break;
case Types.DECIMAL:
setBigDecimal(parameterIndex, val ?
BigDecimal.ONE : BigDecimal.ZERO);
break;
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
@@ -17,7 +17,6 @@ import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
-import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Array;
@@ -93,7 +92,7 @@ public class MonetResultSet extends Mone
/** Just a dummy variable to keep store the fetchsize set. */
private int fetchSize;
/** The current row's values */
- DataBlockResponse currentBlock;
+ private DataBlockResponse currentBlock;
/**
* Main constructor backed by the given Header.
@@ -589,16 +588,12 @@ public class MonetResultSet extends Mone
}
BigDecimal val;
switch (JdbcSQLTypes[columnIndex - 1]) {
+ case Types.NUMERIC:
case Types.DECIMAL:
val = (BigDecimal)
currentBlock.getObjectValue(columnIndex - 1);
break;
- case Types.NUMERIC:
- BigInteger huge = (BigInteger)
currentBlock.getValueAsObject(columnIndex - 1);
- val =
BigDecimal.valueOf(huge.longValue());
- break;
case Types.BOOLEAN:
- byte bval =
currentBlock.getBooleanValue(columnIndex - 1) ? (byte) 1 : (byte) 0;
- val = new BigDecimal(bval);
+ val = new
BigDecimal(currentBlock.getBooleanValue(columnIndex - 1) ? (byte) 1 : (byte) 0);
break;
case Types.TINYINT:
val = new
BigDecimal(currentBlock.getByteValue(columnIndex - 1));
@@ -739,8 +734,6 @@ public class MonetResultSet extends Mone
return true;
throw
newSQLInvalidColumnIndexException(columnIndex);
case Types.NUMERIC:
- BigInteger huge = (BigInteger)
currentBlock.getValueAsObject(columnIndex - 1);
- return huge.compareTo(BigInteger.ZERO) != 0;
case Types.DECIMAL:
BigDecimal bigdec = (BigDecimal)
currentBlock.getValueAsObject(columnIndex - 1);
return
bigdec.compareTo(BigDecimal.ZERO) != 0;
@@ -805,8 +798,6 @@ public class MonetResultSet extends Mone
case Types.LONGVARBINARY:
return
Byte.parseByte(currentBlock.getValueAsString(columnIndex - 1));
case Types.NUMERIC:
- BigInteger huge = (BigInteger)
currentBlock.getValueAsObject(columnIndex - 1);
- return huge.byteValue();
case Types.DECIMAL:
BigDecimal bigdec = (BigDecimal)
currentBlock.getValueAsObject(columnIndex - 1);
return bigdec.byteValue();
@@ -961,8 +952,6 @@ public class MonetResultSet extends Mone
case Types.LONGVARBINARY:
return
Double.parseDouble(currentBlock.getValueAsString(columnIndex - 1));
case Types.NUMERIC:
- BigInteger huge = (BigInteger)
currentBlock.getValueAsObject(columnIndex - 1);
- return huge.doubleValue();
case Types.DECIMAL:
BigDecimal bigdec = (BigDecimal)
currentBlock.getValueAsObject(columnIndex - 1);
return bigdec.doubleValue();
@@ -1106,8 +1095,6 @@ public class MonetResultSet extends Mone
case Types.LONGVARBINARY:
return
Float.parseFloat(currentBlock.getValueAsString(columnIndex - 1));
case Types.NUMERIC:
- BigInteger huge = (BigInteger)
currentBlock.getValueAsObject(columnIndex - 1);
- return huge.floatValue();
case Types.DECIMAL:
BigDecimal bigdec = (BigDecimal)
currentBlock.getValueAsObject(columnIndex - 1);
return bigdec.floatValue();
@@ -1173,8 +1160,6 @@ public class MonetResultSet extends Mone
case Types.LONGVARBINARY:
return
Integer.parseInt(currentBlock.getValueAsString(columnIndex - 1));
case Types.NUMERIC:
- BigInteger huge = (BigInteger)
currentBlock.getValueAsObject(columnIndex - 1);
- return huge.intValue();
case Types.DECIMAL:
BigDecimal bigdec = (BigDecimal)
currentBlock.getValueAsObject(columnIndex - 1);
return bigdec.intValue();
@@ -1239,8 +1224,6 @@ public class MonetResultSet extends Mone
case Types.LONGVARBINARY:
return
Long.parseLong(currentBlock.getValueAsString(columnIndex - 1));
case Types.NUMERIC:
- BigInteger huge = (BigInteger)
currentBlock.getValueAsObject(columnIndex - 1);
- return huge.longValue();
case Types.DECIMAL:
BigDecimal bigdec = (BigDecimal)
currentBlock.getValueAsObject(columnIndex - 1);
return bigdec.longValue();
@@ -1909,8 +1892,6 @@ public class MonetResultSet extends Mone
}
if (type == null || type == String.class) {
return currentBlock.getValueAsString(columnIndex - 1);
- } else if (type == BigInteger.class) {
- return getObject(columnIndex);
} else if (type == BigDecimal.class) {
return getBigDecimal(columnIndex);
} else if (type == Boolean.class) {
@@ -2198,7 +2179,6 @@ public class MonetResultSet extends Mone
case Types.LONGVARCHAR:
return String.class;
case Types.NUMERIC:
- return BigInteger.class;
case Types.DECIMAL:
return BigDecimal.class;
case Types.BOOLEAN:
@@ -2356,8 +2336,6 @@ public class MonetResultSet extends Mone
case Types.LONGVARBINARY:
return
Short.parseShort(currentBlock.getValueAsString(columnIndex - 1));
case Types.NUMERIC:
- BigInteger huge = (BigInteger)
currentBlock.getValueAsObject(columnIndex - 1);
- return huge.shortValue();
case Types.DECIMAL:
BigDecimal bigdec = (BigDecimal)
currentBlock.getValueAsObject(columnIndex - 1);
return bigdec.shortValue();
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
@@ -196,9 +196,8 @@ public class MonetStatement extends Mone
for (int i = 0; i < batch.size(); i++) {
String tmp = batch.get(i);
if (sep.length() + tmp.length() >
connection.getBlockSize()) {
- // The thing is too big. Way too big.
Since it won't
- // be optimal anyway, just add it to
whatever we have
- // and continue.
+ // The thing is too big. Way too big.
Since it won't be optimal anyway, just add it to whatever we
+ // have and continue.
if (!first) {
tmpBatch.append(sep);
}
@@ -475,7 +474,7 @@ public class MonetStatement extends Mone
}
// create a container for the result
- lastResponseList = connection.createResponseList(fetchSize,
maxRows, resultSetType, resultSetConcurrency);
+ lastResponseList = connection.new ResponseList(fetchSize,
maxRows, resultSetType, resultSetConcurrency);
// fill the header list by processing the query
lastResponseList.processQuery(sql);
@@ -660,7 +659,7 @@ public class MonetStatement extends Mone
public ResultSet getGeneratedKeys() throws SQLException {
String[] columns = new String[1], types = new String[1];
int[] jdbcTypes = new int[1];
- String[][] results;
+ Object[] results;
columns[0] = "GENERATED_KEY";
/* the generated key should be an integer, because (wait for
it) other
@@ -668,16 +667,13 @@ public class MonetStatement extends Mone
types[0] = "BIGINT";
jdbcTypes[0] = MonetDriver.getJavaType(types[0]);
+ results = new Object[1];
+ results[0] = new long[1];
+
if (header instanceof UpdateResponse) {
- int lastid = ((UpdateResponse)header).getLastid();
- if (lastid ==-1) {
- results = new String[1][1];
- } else {
- results = new String[1][1];
- results[0][0] = Integer.toString(lastid);
- }
+ ((long[]) results[0])[0] =
((UpdateResponse)header).getLastid();
} else {
- results = new String[1][1];
+ ((long[]) results[0])[0] = -1;
}
try {
@@ -1187,15 +1183,14 @@ public class MonetStatement extends Mone
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list