Mercurial > hg > monetdb-java
comparison src/main/java/org/monetdb/jdbc/MonetConnection.java @ 656:c6fe5dfecafc
Refactor HandshakeOptions
author | Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com> |
---|---|
date | Fri, 09 Sep 2022 12:25:23 +0200 (2022-09-09) |
parents | 849f99124e32 |
children | 8476d6f4378f |
comparison
equal
deleted
inserted
replaced
655:2ded26c5a679 | 656:c6fe5dfecafc |
---|---|
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.io.LineType; | 38 import org.monetdb.mcl.io.LineType; |
39 import org.monetdb.mcl.net.HandshakeOptions; | 39 import org.monetdb.mcl.net.HandshakeOptions; |
40 import org.monetdb.mcl.net.HandshakeOptions.Setting; | |
40 import org.monetdb.mcl.net.MapiSocket; | 41 import org.monetdb.mcl.net.MapiSocket; |
41 import org.monetdb.mcl.parser.HeaderLineParser; | 42 import org.monetdb.mcl.parser.HeaderLineParser; |
42 import org.monetdb.mcl.parser.MCLParseException; | 43 import org.monetdb.mcl.parser.MCLParseException; |
43 import org.monetdb.mcl.parser.StartOfHeaderParser; | 44 import org.monetdb.mcl.parser.StartOfHeaderParser; |
44 | 45 |
285 | 286 |
286 final Calendar cal = Calendar.getInstance(); | 287 final Calendar cal = Calendar.getInstance(); |
287 int offsetMillis = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET); | 288 int offsetMillis = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET); |
288 int offsetSeconds = offsetMillis / 1000; | 289 int offsetSeconds = offsetMillis / 1000; |
289 final HandshakeOptions handshakeOptions = new HandshakeOptions(); | 290 final HandshakeOptions handshakeOptions = new HandshakeOptions(); |
290 handshakeOptions.setTimeZone(offsetSeconds); | 291 handshakeOptions.set(Setting.TimeZone, offsetSeconds); |
291 handshakeOptions.setReplySize(defaultFetchSize); | 292 handshakeOptions.set(Setting.ReplySize, defaultFetchSize); |
292 server.setHandshakeOptions(handshakeOptions); | 293 server.setHandshakeOptions(handshakeOptions); |
293 | 294 |
294 // we're debugging here... uhm, should be off in real life | 295 // we're debugging here... uhm, should be off in real life |
295 if (debug) { | 296 if (debug) { |
296 try { | 297 try { |
368 //commandTempl[2] = ""; // separator (is not used) | 369 //commandTempl[2] = ""; // separator (is not used) |
369 } else { | 370 } else { |
370 lang = LANG_UNKNOWN; | 371 lang = LANG_UNKNOWN; |
371 } | 372 } |
372 | 373 |
373 if (!handshakeOptions.mustSendReplySize()) { | 374 // The reply size is checked before every query and adjusted if |
374 // Initially, it had to be sent. If it no more needs to be sent now, | 375 // necessary. Update our current belief of what the server is set to. |
375 // it must have been sent during the auth challenge/response. | 376 if (handshakeOptions.wasSentInHandshake(HandshakeOptions.Setting.ReplySize)) { |
376 // Record the value it was set to. | 377 this.curReplySize = handshakeOptions.get(HandshakeOptions.Setting.ReplySize); |
377 this.curReplySize = handshakeOptions.getReplySize(); | 378 } |
379 | |
380 for (Setting setting : new Setting[] { Setting.SizeHeader }) { | |
381 if (handshakeOptions.mustSend(setting)) { | |
382 Integer value = handshakeOptions.get(setting); // guaranteed by mustSend to be non-null | |
383 String command = String.format("%s %d", setting.getXCommand(), value); | |
384 sendControlCommand(command); | |
385 } | |
378 } | 386 } |
379 | 387 |
380 // the following initialisers are only valid when the language is SQL... | 388 // the following initialisers are only valid when the language is SQL... |
381 if (lang == LANG_SQL) { | 389 if (lang == LANG_SQL) { |
382 // enable auto commit | 390 // enable auto commit |
383 setAutoCommit(true); | 391 setAutoCommit(true); |
384 | 392 |
385 // set our time zone on the server, if we haven't already | 393 // set our time zone on the server, if we haven't already |
386 if (handshakeOptions.mustSendTimeZone()) { | 394 if (handshakeOptions.mustSend(Setting.TimeZone)) { |
387 final StringBuilder tz = new StringBuilder(64); | 395 final StringBuilder tz = new StringBuilder(64); |
388 tz.append("SET TIME ZONE INTERVAL '"); | 396 tz.append("SET TIME ZONE INTERVAL '"); |
389 int offsetMinutes = handshakeOptions.getTimeZone() / 60; | 397 int offsetMinutes = handshakeOptions.get(Setting.TimeZone) / 60; |
390 if (offsetMinutes < 0) { | 398 if (offsetMinutes < 0) { |
391 tz.append('-'); | 399 tz.append('-'); |
392 offsetMinutes = -offsetMinutes; // make it positive | 400 offsetMinutes = -offsetMinutes; // make it positive |
393 } else { | 401 } else { |
394 tz.append('+'); | 402 tz.append('+'); |