Mercurial > hg > monetdb-java
comparison src/main/java/org/monetdb/jdbc/MonetConnection.java @ 834:5aa19bbed0d6 monetdbs
Comments and formatting
author | Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com> |
---|---|
date | Wed, 13 Dec 2023 15:39:47 +0100 (17 months ago) |
parents | 425592a53fcd |
children | 5df67d5d7a7b |
comparison
equal
deleted
inserted
replaced
813:a71afa48f269 | 834:5aa19bbed0d6 |
---|---|
73 */ | 73 */ |
74 public class MonetConnection | 74 public class MonetConnection |
75 extends MonetWrapper | 75 extends MonetWrapper |
76 implements Connection, AutoCloseable | 76 implements Connection, AutoCloseable |
77 { | 77 { |
78 /** All connection parameters */ | 78 /* All connection parameters */ |
79 Target target; | 79 Target target; |
80 /** A connection to mserver5 using a TCP socket */ | 80 /** A connection to mserver5 using a TCP socket */ |
81 private final MapiSocket server; | 81 private final MapiSocket server; |
82 /** The Reader from the server */ | 82 /** The Reader from the server */ |
83 private final BufferedMCLReader in; | 83 private final BufferedMCLReader in; |
137 | 137 |
138 /** A cache to reduce the number of DatabaseMetaData objects created by getMetaData() to maximum 1 per connection */ | 138 /** A cache to reduce the number of DatabaseMetaData objects created by getMetaData() to maximum 1 per connection */ |
139 private DatabaseMetaData dbmd; | 139 private DatabaseMetaData dbmd; |
140 | 140 |
141 /** | 141 /** |
142 * Constructor of a Connection for MonetDB. At this moment the | 142 * Constructor of a Connection for MonetDB. |
143 * current implementation limits itself to storing the given host, | 143 * This constructor is only accessible to |
144 * database, username and password for later use by the | |
145 * createStatement() call. This constructor is only accessible to | |
146 * classes from the jdbc package. | 144 * classes from the jdbc package. |
147 * | 145 * |
148 * @param target a Target object holding the connection parameters | 146 * @param target a {@link Target} object containing all connection parameters |
149 * @throws SQLException if a database error occurs | 147 * @throws SQLException if a database error occurs |
150 * @throws IllegalArgumentException is one of the arguments is null or empty | 148 * @throws IllegalArgumentException is one of the arguments is null or empty |
151 */ | 149 */ |
152 MonetConnection(Target target) | 150 MonetConnection(Target target) |
153 throws SQLException, IllegalArgumentException | 151 throws SQLException, IllegalArgumentException |
182 | 180 |
183 SqlOptionsCallback callback = null; | 181 SqlOptionsCallback callback = null; |
184 switch (target.getLanguage()) { | 182 switch (target.getLanguage()) { |
185 case "sql": | 183 case "sql": |
186 lang = LANG_SQL; | 184 lang = LANG_SQL; |
187 queryTempl[0] = "s"; // pre | 185 queryTempl[0] = "s"; // pre |
188 queryTempl[1] = "\n;"; // post | 186 queryTempl[1] = "\n;"; // post |
189 queryTempl[2] = "\n;\n"; // separator | 187 queryTempl[2] = "\n;\n"; // separator |
190 commandTempl[0] = "X"; // pre | 188 commandTempl[0] = "X"; // pre |
191 commandTempl[1] = ""; // post | 189 commandTempl[1] = ""; // post |
192 callback = new SqlOptionsCallback(); | 190 callback = new SqlOptionsCallback(); |
193 break; | 191 break; |
194 case "mal": | 192 case "mal": |
195 lang = LANG_MAL; | 193 lang = LANG_MAL; |
196 queryTempl[0] = ""; // pre | 194 queryTempl[0] = ""; // pre |
197 queryTempl[1] = ";\n"; // post | 195 queryTempl[1] = ";\n"; // post |
198 queryTempl[2] = ";\n"; // separator | 196 queryTempl[2] = ";\n"; // separator |
199 commandTempl[0] = ""; // pre | 197 commandTempl[0] = ""; // pre |
200 commandTempl[1] = ""; // post | 198 commandTempl[1] = ""; // post |
201 break; | 199 break; |
202 default: | 200 default: |
203 lang = LANG_UNKNOWN; | 201 lang = LANG_UNKNOWN; |
204 break; | 202 break; |
205 } | 203 } |
1245 } | 1243 } |
1246 } | 1244 } |
1247 } | 1245 } |
1248 return isValid; | 1246 return isValid; |
1249 } | 1247 } |
1248 | |
1249 /** | |
1250 * Construct a Properties object holding all connection parameters such | |
1251 * as host, port, TLS configuration, autocommit, etc. | |
1252 * Passing this to {@link DriverManager.getConnection()} together | |
1253 * with the URL "jdbc:monetdb:" will create a new connection identical to | |
1254 * the current one. | |
1255 * @return | |
1256 */ | |
1250 | 1257 |
1251 public Properties getConnectionProperties() { | 1258 public Properties getConnectionProperties() { |
1252 return target.getProperties(); | 1259 return target.getProperties(); |
1253 } | 1260 } |
1254 | 1261 |
3745 crPending = false; | 3752 crPending = false; |
3746 super.close(); | 3753 super.close(); |
3747 } | 3754 } |
3748 } | 3755 } |
3749 | 3756 |
3750 public static enum SqlOption { | 3757 /* encode knowledge of currently available handshake options as an enum. */ |
3758 enum SqlOption { | |
3751 Autocommit(1, "auto_commit"), | 3759 Autocommit(1, "auto_commit"), |
3752 ReplySize(2, "reply_size"), | 3760 ReplySize(2, "reply_size"), |
3753 SizeHeader(3, "size_header"), | 3761 SizeHeader(3, "size_header"), |
3754 // NOTE: 4 has been omitted on purpose | 3762 // NOTE: 4 has been omitted on purpose |
3755 TimeZone(5, "time_zone"), | 3763 TimeZone(5, "time_zone"), |
3764 } | 3772 } |
3765 | 3773 |
3766 | 3774 |
3767 private class SqlOptionsCallback extends MapiSocket.OptionsCallback { | 3775 private class SqlOptionsCallback extends MapiSocket.OptionsCallback { |
3768 private int level; | 3776 private int level; |
3777 | |
3769 @Override | 3778 @Override |
3770 public void addOptions(String lang, int level) { | 3779 public void addOptions(String lang, int level) { |
3771 if (!lang.equals("sql")) | 3780 if (!lang.equals("sql")) |
3772 return; | 3781 return; |
3773 this.level = level; | 3782 this.level = level; |
3782 if (contribute(SqlOption.TimeZone, target.getTimezone())) | 3791 if (contribute(SqlOption.TimeZone, target.getTimezone())) |
3783 timeZoneSet = true; | 3792 timeZoneSet = true; |
3784 } | 3793 } |
3785 | 3794 |
3786 private boolean contribute(SqlOption opt, int value) { | 3795 private boolean contribute(SqlOption opt, int value) { |
3787 if (this.level <= opt.level) | 3796 if (opt.level >= this.level) |
3788 return false; | 3797 return false; |
3789 contribute(opt.field, value); | 3798 contribute(opt.field, value); |
3790 return true; | 3799 return true; |
3791 } | 3800 } |
3792 } | 3801 } |