Mercurial > hg > monetdb-java
comparison src/main/java/org/monetdb/jdbc/MonetConnection.java @ 422:8368cbc670bf
Send reply size and time zone during initial handshake
author | Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com> |
---|---|
date | Tue, 02 Feb 2021 13:50:13 +0100 (2021-02-02) |
parents | b3c876a0d61f |
children | de2ef68b672f |
comparison
equal
deleted
inserted
replaced
421:163b784aa93b | 422:8368cbc670bf |
---|---|
33 import java.util.WeakHashMap; | 33 import java.util.WeakHashMap; |
34 import java.util.concurrent.Executor; | 34 import java.util.concurrent.Executor; |
35 | 35 |
36 import org.monetdb.mcl.io.BufferedMCLReader; | 36 import org.monetdb.mcl.io.BufferedMCLReader; |
37 import org.monetdb.mcl.io.BufferedMCLWriter; | 37 import org.monetdb.mcl.io.BufferedMCLWriter; |
38 import org.monetdb.mcl.net.HandshakeOptions; | |
38 import org.monetdb.mcl.net.MapiSocket; | 39 import org.monetdb.mcl.net.MapiSocket; |
39 import org.monetdb.mcl.parser.HeaderLineParser; | 40 import org.monetdb.mcl.parser.HeaderLineParser; |
40 import org.monetdb.mcl.parser.MCLParseException; | 41 import org.monetdb.mcl.parser.MCLParseException; |
41 import org.monetdb.mcl.parser.StartOfHeaderParser; | 42 import org.monetdb.mcl.parser.StartOfHeaderParser; |
42 | 43 |
255 server.setHash(hash); | 256 server.setHash(hash); |
256 if (database != null) | 257 if (database != null) |
257 server.setDatabase(database); | 258 server.setDatabase(database); |
258 server.setLanguage(language); | 259 server.setLanguage(language); |
259 | 260 |
261 HandshakeOptions handshakeOptions = new HandshakeOptions(); | |
262 final Calendar cal = Calendar.getInstance(); | |
263 int offsetMillis = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET); | |
264 int offsetSeconds = offsetMillis / 1000; | |
265 handshakeOptions.setTimeZone(offsetSeconds); | |
266 handshakeOptions.setReplySize(DEF_FETCHSIZE); | |
267 server.setHandshakeOptions(handshakeOptions); | |
268 | |
260 // we're debugging here... uhm, should be off in real life | 269 // we're debugging here... uhm, should be off in real life |
261 if (debug) { | 270 if (debug) { |
262 try { | 271 try { |
263 final String fname = props.getProperty("logfile", "monet_" + System.currentTimeMillis() + ".log"); | 272 final String fname = props.getProperty("logfile", "monet_" + System.currentTimeMillis() + ".log"); |
264 File f = new File(fname); | 273 File f = new File(fname); |
334 //commandTempl[2] = ""; // separator (is not used) | 343 //commandTempl[2] = ""; // separator (is not used) |
335 } else { | 344 } else { |
336 lang = LANG_UNKNOWN; | 345 lang = LANG_UNKNOWN; |
337 } | 346 } |
338 | 347 |
348 if (!handshakeOptions.mustSendReplySize()) { | |
349 // Initially, it had to be sent. If it no more needs to be sent now, | |
350 // it must have been sent during the auth challenge/response. | |
351 // Record the value it was set to. | |
352 this.curReplySize = handshakeOptions.getReplySize(); | |
353 } | |
354 | |
339 // the following initialisers are only valid when the language is SQL... | 355 // the following initialisers are only valid when the language is SQL... |
340 if (lang == LANG_SQL) { | 356 if (lang == LANG_SQL) { |
341 // enable auto commit | 357 // enable auto commit |
342 setAutoCommit(true); | 358 setAutoCommit(true); |
343 | 359 |
344 // set our time zone on the server | 360 // set our time zone on the server, if we haven't already |
345 final Calendar cal = Calendar.getInstance(); | 361 if (handshakeOptions.mustSendTimeZone()) { |
346 int offset = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET); | 362 int offsetMinutes = handshakeOptions.getTimeZone() / 60; |
347 offset /= (60 * 1000); // milliseconds to minutes | 363 String tz = offsetMinutes < 0 ? "-" : "+"; |
348 String tz = offset < 0 ? "-" : "+"; | 364 tz += (Math.abs(offsetMinutes) / 60 < 10 ? "0" : "") + (Math.abs(offsetMinutes) / 60) + ":"; |
349 tz += (Math.abs(offset) / 60 < 10 ? "0" : "") + (Math.abs(offset) / 60) + ":"; | 365 offsetMinutes -= (offsetMinutes / 60) * 60; |
350 offset -= (offset / 60) * 60; | 366 tz += (offsetMinutes < 10 ? "0" : "") + offsetMinutes; |
351 tz += (offset < 10 ? "0" : "") + offset; | 367 sendIndependentCommand("SET TIME ZONE INTERVAL '" + tz + "' HOUR TO MINUTE"); |
352 sendIndependentCommand("SET TIME ZONE INTERVAL '" + tz + "' HOUR TO MINUTE"); | 368 } |
353 } | 369 } |
354 | 370 |
355 // we're absolutely not closed, since we're brand new | 371 // we're absolutely not closed, since we're brand new |
356 closed = false; | 372 closed = false; |
357 } | 373 } |