Mercurial > hg > monetdb-java
comparison src/main/java/org/monetdb/mcl/net/HandshakeOptions.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 | |
children | b95d007e1dfa |
comparison
equal
deleted
inserted
replaced
421:163b784aa93b | 422:8368cbc670bf |
---|---|
1 package org.monetdb.mcl.net; | |
2 | |
3 /** Keep track of MAPI handshake options. | |
4 * | |
5 * Recent server versions allow you to send configuration information during | |
6 * the authentication handshake so no additional round trips are necessary | |
7 * when that has completed. | |
8 * | |
9 * This class keeps track of the options to send, and whether they have already | |
10 * been sent. | |
11 */ | |
12 public class HandshakeOptions { | |
13 | |
14 // public Boolean autoCommit; | |
15 int replySize; | |
16 // public Integer replySize; | |
17 // public Integer ColumnarProtocol; | |
18 int timeZone; | |
19 | |
20 boolean mustSendReplySize; | |
21 boolean mustSendTimeZone; | |
22 | |
23 public int getReplySize() { | |
24 return replySize; | |
25 } | |
26 | |
27 public void setReplySize(int replySize) { | |
28 this.replySize = replySize; | |
29 this.mustSendReplySize = true; | |
30 } | |
31 | |
32 public boolean mustSendReplySize() { | |
33 return mustSendReplySize; | |
34 } | |
35 | |
36 public void mustSendReplySize(boolean mustSendReplySize) { | |
37 this.mustSendReplySize = mustSendReplySize; | |
38 } | |
39 | |
40 public int getTimeZone() { | |
41 return timeZone; | |
42 } | |
43 | |
44 public void setTimeZone(int timeZone) { | |
45 this.timeZone = timeZone; | |
46 this.mustSendTimeZone = true; | |
47 } | |
48 | |
49 public boolean mustSendTimeZone() { | |
50 return mustSendTimeZone; | |
51 } | |
52 | |
53 public void mustSendTimeZone(boolean mustSendTimeZone) { | |
54 this.mustSendTimeZone = mustSendTimeZone; | |
55 } | |
56 | |
57 public String formatResponse(int serverLevel) { | |
58 StringBuilder opts = new StringBuilder(100); | |
59 if (mustSendReplySize()) { | |
60 formatOption(opts, Level.ReplySize, serverLevel, replySize); | |
61 mustSendReplySize(false); | |
62 } | |
63 if (mustSendTimeZone()) { | |
64 formatOption(opts, Level.TimeZone, serverLevel, timeZone); | |
65 mustSendTimeZone(false); | |
66 } | |
67 | |
68 return opts.toString(); | |
69 } | |
70 | |
71 private void formatOption(StringBuilder opts, Level level, int serverLevel, int value) { | |
72 if (!level.isSupported(serverLevel)) | |
73 return; | |
74 if (opts.length() > 0) { | |
75 opts.append(","); | |
76 } | |
77 opts.append(level.field); | |
78 opts.append("="); | |
79 opts.append(value); | |
80 } | |
81 | |
82 public enum Level { | |
83 ReplySize("reply_size", 2), | |
84 TimeZone("time_zone", 5); | |
85 | |
86 private final int level; | |
87 private final String field; | |
88 | |
89 Level(String field, int level) { | |
90 this.field = field; | |
91 this.level = level; | |
92 } | |
93 | |
94 public boolean isSupported(int serverLevel) { | |
95 return this.level < serverLevel; | |
96 } | |
97 } | |
98 } |