Mercurial > hg > monetdb-java
comparison src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java @ 175:8700d9ef2ace
Added possibility via a connection property to let the JDBC driver
return columnType value Types.VARCHAR instead of Types.CLOB in case
the result column of a ResultSet or parameter in a PreparedStatement
is of data type 'clob'.
With this connection property set, you can reduce the overhead when
working with clob column data from generic JDBC programs.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 28 Sep 2017 16:17:51 +0200 (2017-09-28) |
parents | 89e954e7acbb |
children | dd12348c41cf |
comparison
equal
deleted
inserted
replaced
174:bac9345e7d99 | 175:8700d9ef2ace |
---|---|
139 /** an unknown language */ | 139 /** an unknown language */ |
140 final static int LANG_UNKNOWN = -1; | 140 final static int LANG_UNKNOWN = -1; |
141 /** The language which is used */ | 141 /** The language which is used */ |
142 final int lang; | 142 final int lang; |
143 | 143 |
144 /** Whether or not BLOB is mapped to BINARY within the driver */ | 144 /** Whether or not BLOB is mapped to Types.VARBINARY instead of Types.BLOB within this connection */ |
145 private final boolean blobIsBinary; | 145 private boolean treatBlobAsVarBinary = false; |
146 /** Whether or not CLOB is mapped to Types.VARCHAR instead of Types.CLOB within this connection */ | |
147 private boolean treatClobAsVarChar = false; | |
146 | 148 |
147 /** | 149 /** |
148 * Constructor of a Connection for MonetDB. At this moment the | 150 * Constructor of a Connection for MonetDB. At this moment the |
149 * current implementation limits itself to storing the given host, | 151 * current implementation limits itself to storing the given host, |
150 * database, username and password for later use by the | 152 * database, username and password for later use by the |
199 | 201 |
200 String hash = props.getProperty("hash"); | 202 String hash = props.getProperty("hash"); |
201 if (hash != null) | 203 if (hash != null) |
202 conn_props.setProperty("hash", hash); | 204 conn_props.setProperty("hash", hash); |
203 | 205 |
204 String blobIsBinary_prop = props.getProperty("treat_blob_as_binary"); | 206 String treatBlobAsVarBinary_prop = props.getProperty("treat_blob_as_binary"); |
205 if (blobIsBinary_prop != null) { | 207 if (treatBlobAsVarBinary_prop != null) { |
206 blobIsBinary = Boolean.parseBoolean(blobIsBinary_prop); | 208 treatBlobAsVarBinary = Boolean.parseBoolean(treatBlobAsVarBinary_prop); |
207 conn_props.setProperty("treat_blob_as_binary", Boolean.toString(blobIsBinary)); | 209 conn_props.setProperty("treat_blob_as_binary", Boolean.toString(treatBlobAsVarBinary)); |
208 } else { | 210 typeMap.put("blob", Byte[].class); |
209 blobIsBinary = false; | 211 } |
212 | |
213 String treatClobAsVarChar_prop = props.getProperty("treat_clob_as_varchar"); | |
214 if (treatClobAsVarChar_prop != null) { | |
215 treatClobAsVarChar = Boolean.parseBoolean(treatClobAsVarChar_prop); | |
216 conn_props.setProperty("treat_clob_as_varchar", Boolean.toString(treatClobAsVarChar)); | |
217 typeMap.put("clob", String.class); | |
210 } | 218 } |
211 | 219 |
212 int sockTimeout = 0; | 220 int sockTimeout = 0; |
213 String so_timeout_prop = props.getProperty("so_timeout"); | 221 String so_timeout_prop = props.getProperty("so_timeout"); |
214 if (so_timeout_prop != null) { | 222 if (so_timeout_prop != null) { |
1250 stmt.setQueryTimeout(original_timeout); | 1258 stmt.setQueryTimeout(original_timeout); |
1251 } | 1259 } |
1252 } | 1260 } |
1253 } catch (SQLException se) { | 1261 } catch (SQLException se) { |
1254 String msg = se.getMessage(); | 1262 String msg = se.getMessage(); |
1255 // System.out.println("Con.isValid(): " + msg); | 1263 // System.out.println(se.getSQLState() + " Con.isValid(): " + msg); |
1256 if (msg != null && msg.equals("Current transaction is aborted (please ROLLBACK)")) { | 1264 if (msg != null && msg.equalsIgnoreCase("Current transaction is aborted (please ROLLBACK)")) { |
1265 // Must use equalsIgnoreCase() here because up to Jul2017 release 'Current' was 'current' so with lowercase c. | |
1266 // It changed to 'Current' after Jul2017 release. We need to support all server versions. | |
1267 // SQLState = 25005 | |
1257 isValid = true; | 1268 isValid = true; |
1258 } | 1269 } |
1259 /* ignore stmt errors/exceptions, we are only testing if the connection is still alive and usable */ | 1270 /* ignore stmt errors/exceptions, we are only testing if the connection is still alive and usable */ |
1260 } finally { | 1271 } finally { |
1261 if (rs != null) { | 1272 if (rs != null) { |
1369 name.equals("database") || | 1380 name.equals("database") || |
1370 name.equals("language") || | 1381 name.equals("language") || |
1371 name.equals("so_timeout") || | 1382 name.equals("so_timeout") || |
1372 name.equals("debug") || | 1383 name.equals("debug") || |
1373 name.equals("hash") || | 1384 name.equals("hash") || |
1374 name.equals("treat_blob_as_binary")) { | 1385 name.equals("treat_blob_as_binary") || |
1386 name.equals("treat_clob_as_varchar")) | |
1387 { | |
1375 conn_props.setProperty(name, value); | 1388 conn_props.setProperty(name, value); |
1376 } else { | 1389 } else { |
1377 addWarning("setClientInfo: " + name + "is not a recognised property", "01M07"); | 1390 addWarning("setClientInfo: " + name + "is not a recognised property", "01M07"); |
1378 } | 1391 } |
1379 return; | 1392 return; |
1569 language = "?language=mal"; | 1582 language = "?language=mal"; |
1570 return "jdbc:monetdb://" + hostname + ":" + port + "/" + database + language; | 1583 return "jdbc:monetdb://" + hostname + ":" + port + "/" + database + language; |
1571 } | 1584 } |
1572 | 1585 |
1573 /** | 1586 /** |
1574 * Returns whether the BLOB type should be mapped to BINARY type. | 1587 * Returns whether the JDBC BLOB type should be mapped to VARBINARY type. |
1575 */ | 1588 * This allows generic JDBC programs to fetch Blob data via getBytes() |
1576 boolean getBlobAsBinary() { | 1589 * instead of getBlob() and Blob.getBinaryStream() to reduce overhead. |
1577 return blobIsBinary; | 1590 */ |
1578 } | 1591 boolean mapBlobAsVarBinary() { |
1579 | 1592 return treatBlobAsVarBinary; |
1593 } | |
1594 | |
1595 /** | |
1596 * Returns whether the JDBC CLOB type should be mapped to VARCHAR type. | |
1597 * This allows generic JDBC programs to fetch Clob data via getString() | |
1598 * instead of getClob() and Clob.getCharacterStream() to reduce overhead. | |
1599 */ | |
1600 boolean mapClobAsVarChar() { | |
1601 return treatClobAsVarChar; | |
1602 } | |
1580 | 1603 |
1581 /** | 1604 /** |
1582 * Sends the given string to MonetDB as special transaction command. | 1605 * Sends the given string to MonetDB as special transaction command. |
1583 * All possible returned information is discarded. | 1606 * All possible returned information is discarded. |
1584 * Encountered errors are reported. | 1607 * Encountered errors are reported. |