Mercurial > hg > monetdb-java
changeset 248:14e6f812b43c embedded
Added oid support.
author | Pedro Ferreira <pedro.ferreira@monetdbsolutions.com> |
---|---|
date | Mon, 30 Jul 2018 14:18:27 +0200 (2018-07-30) |
parents | 3897bbab2d23 |
children | 96057ee68017 |
files | 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/protocol/AbstractProtocol.java src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiDataBlockResponse.java src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiProtocol.java src/main/java/nl/cwi/monetdb/mcl/responses/AbstractDataBlockResponse.java src/main/java/nl/cwi/monetdb/mcl/responses/ResultSetResponse.java |
diffstat | 7 files changed, 67 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in @@ -265,7 +265,7 @@ public final class MonetDriver implement typeMap.put("json", Types.OTHER); // typeMap.put("mbr", Types.???); typeMap.put("month_interval", Types.INTEGER); - // typeMap.put("oid", Types.BIGINT); + typeMap.put("oid", Types.OTHER); // typeMap.put("ptr", Types.???); typeMap.put("real", Types.REAL); typeMap.put("sec_interval", Types.BIGINT);
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java @@ -1222,6 +1222,21 @@ public class MonetResultSet extends Mone case Types.DECIMAL: BigDecimal bigdec = (BigDecimal) currentBlock.getValueAsObject(columnIndex - 1); return bigdec == null ? 0 : bigdec.intValue(); + case Types.OTHER: + if ("oid".equals(types[columnIndex - 1])) { + String val = currentBlock.getValueAsString(columnIndex - 1); + if(currentBlock.isLastReadWasNull()) { + return 0; + } + int len = val.length(); + if (len > 2 && val.endsWith("@0")) { + try { + return Integer.parseInt(val.substring(0, len - 2)); + } catch (NumberFormatException nfe) { + throw newSQLNumberFormatException(nfe); + } + } + } default: //OTHERS, BLOB, LONGVARBINARY, TIME... throw new SQLException("Conversion from " + types[columnIndex - 1] + " to integer type not supported", "M1M05"); @@ -1294,6 +1309,21 @@ public class MonetResultSet extends Mone case Types.DECIMAL: BigDecimal bigdec = (BigDecimal) currentBlock.getValueAsObject(columnIndex - 1); return bigdec == null ? 0 : bigdec.longValue(); + case Types.OTHER: + if ("oid".equals(types[columnIndex - 1])) { + String val = currentBlock.getValueAsString(columnIndex - 1); + if(currentBlock.isLastReadWasNull()) { + return 0; + } + int len = val.length(); + if (len > 2 && val.endsWith("@0")) { + try { + return Long.parseLong(val.substring(0, len - 2)); + } catch (NumberFormatException nfe) { + throw newSQLNumberFormatException(nfe); + } + } + } default: //OTHERS, BLOB, LONGVARBINARY, TIME... throw new SQLException("Conversion from " + types[columnIndex - 1] + " to long type not supported", "M1M05"); @@ -3737,4 +3767,16 @@ public class MonetResultSet extends Mone private static final SQLFeatureNotSupportedException newSQLFeatureNotSupportedException(String name) { return new SQLFeatureNotSupportedException("Method " + name + " not implemented", "0A000"); } + + /** + * Small helper method that formats the "Could not convert value to a number" message + * and creates a new SQLDataException object whose SQLState is set + * to "22003": Numeric value out of range. + * + * @param error the NumberFormatException + * @return a new created SQLDataException object with SQLState 22003 + */ + private static final SQLDataException newSQLNumberFormatException(NumberFormatException error) { + return new SQLDataException("Could not convert value to a number. " + error.getMessage(), "22003"); + } }
--- a/src/main/java/nl/cwi/monetdb/mcl/protocol/AbstractProtocol.java +++ b/src/main/java/nl/cwi/monetdb/mcl/protocol/AbstractProtocol.java @@ -212,11 +212,12 @@ public abstract class AbstractProtocol { * @param columncount - Number of tuples * @param protocol - This protocol * @param JdbcSQLTypes - the types array + * @param types - the description of the types array * @return An AbstractDataBlockResponse instance */ public abstract AbstractDataBlockResponse getAnEmptyDataBlockResponse(int rowcount, int columncount, AbstractProtocol protocol, - int[] JdbcSQLTypes); + int[] JdbcSQLTypes, String[] types); /** * Gets the next DataBlockResponse response from the server, belonging to a ResultSetResponse
--- a/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiDataBlockResponse.java +++ b/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiDataBlockResponse.java @@ -38,8 +38,9 @@ public class OldMapiDataBlockResponse ex /** The last parsed nanos values for timestamps */ private int lastNanos; - OldMapiDataBlockResponse(int rowcount, int columncount, AbstractProtocol protocol, int[] JdbcSQLTypes) { - super(rowcount, protocol, JdbcSQLTypes); + OldMapiDataBlockResponse(int rowcount, int columncount, AbstractProtocol protocol, int[] JdbcSQLTypes, + String[] types) { + super(rowcount, protocol, JdbcSQLTypes, types); this.pos = -1; this.data = new Object[columncount]; }
--- a/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiProtocol.java +++ b/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiProtocol.java @@ -191,10 +191,21 @@ public class OldMapiProtocol extends Abs return new AutoCommitResponse(ac); } + /** + * Get an empty OldMapiDataBlockResponse from the server. + * + * @param rowcount - Number of tuples + * @param columncount - Number of tuples + * @param protocol - This protocol + * @param JdbcSQLTypes - the types array + * @param types - the description of the types array + * @return An OldMapiDataBlockResponse instance + */ @Override public AbstractDataBlockResponse getAnEmptyDataBlockResponse(int rowcount, int columncount, - AbstractProtocol protocol, int[] JdbcSQLTypes) { - return new OldMapiDataBlockResponse(rowcount, columncount, protocol, JdbcSQLTypes); + AbstractProtocol protocol, int[] JdbcSQLTypes, + String[] types) { + return new OldMapiDataBlockResponse(rowcount, columncount, protocol, JdbcSQLTypes, types); } /**
--- a/src/main/java/nl/cwi/monetdb/mcl/responses/AbstractDataBlockResponse.java +++ b/src/main/java/nl/cwi/monetdb/mcl/responses/AbstractDataBlockResponse.java @@ -44,6 +44,8 @@ public abstract class AbstractDataBlockR public final int rowcount; /** The JdbcSQLTypes mapping */ public final int[] jdbcSQLTypes; + /** The types mapping */ + public final String[] types; /** whether the last read field (via some getXyz() method) was NULL */ public boolean lastReadWasNull = true; @@ -54,10 +56,11 @@ public abstract class AbstractDataBlockR * @param protocol the underlying protocol * @param JdbcSQLTypes an array of the JDBC mappings of the columns */ - public AbstractDataBlockResponse(int rowcount, AbstractProtocol protocol, int[] JdbcSQLTypes) { + public AbstractDataBlockResponse(int rowcount, AbstractProtocol protocol, int[] JdbcSQLTypes, String[] types) { this.rowcount = rowcount; this.protocol = protocol; this.jdbcSQLTypes = JdbcSQLTypes; + this.types = types; } /**
--- a/src/main/java/nl/cwi/monetdb/mcl/responses/ResultSetResponse.java +++ b/src/main/java/nl/cwi/monetdb/mcl/responses/ResultSetResponse.java @@ -123,7 +123,7 @@ public class ResultSetResponse implement this.resultBlocks = new AbstractDataBlockResponse[(tuplecount / cacheSize) + 1]; this.resultBlocks[0] = con.getProtocol().getAnEmptyDataBlockResponse(rowcount, columncount, - con.getProtocol(), this.JdbcSQLTypes); + con.getProtocol(), this.JdbcSQLTypes, this.type); } /** @@ -162,7 +162,7 @@ public class ResultSetResponse implement public AbstractDataBlockResponse addDataBlockResponse(int offset, int rowcount) { int block = (offset - blockOffset) / cacheSize; AbstractDataBlockResponse res = con.getProtocol().getAnEmptyDataBlockResponse(rowcount, - this.getColumncount(), this.con.getProtocol(), JdbcSQLTypes); + this.getColumncount(), this.con.getProtocol(), JdbcSQLTypes, type); resultBlocks[block] = res; return res; }