Mercurial > hg > monetdb-java
comparison src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in @ 333:55330e40cbf1
Eliminate the need for private static final variables which are filled by preproccesor.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Wed, 25 Sep 2019 14:26:34 +0200 (2019-09-25) |
parents | 003ae6d881db |
children | 11e1ccef1cf6 |
comparison
equal
deleted
inserted
replaced
332:e8962bdaa206 | 333:55330e40cbf1 |
---|---|
18 import java.sql.Types; | 18 import java.sql.Types; |
19 import java.util.Map.Entry; | 19 import java.util.Map.Entry; |
20 import java.util.Properties; | 20 import java.util.Properties; |
21 | 21 |
22 /** | 22 /** |
23 * A Driver suitable for the MonetDB database. | 23 * A JDBC Driver suitable for the MonetDB RDBMS. |
24 * | 24 * |
25 * This driver will be used by the DriverManager to determine if an URL | 25 * This driver will be used by the DriverManager to determine if an URL |
26 * is to be handled by this driver, and if it does, then this driver | 26 * is to be handled by this driver, and if it does, then this driver |
27 * will supply a Connection suitable for MonetDB. | 27 * will supply a Connection suitable for MonetDB. |
28 * | 28 * |
29 * This class has no explicit constructor, the default constructor | 29 * This class has no explicit constructor, the default constructor |
30 * generated by the Java compiler will be sufficient since nothing has | 30 * generated by the Java compiler will be sufficient since nothing has |
31 * to be set in order to use this driver. | 31 * to be set in order to use this driver. |
32 * | 32 * |
33 * This Driver supports MonetDB database URLs. MonetDB URLs are defined | 33 * This Driver supports MonetDB database URLs. MonetDB URLs are defined as: |
34 * as: | |
35 * <tt>jdbc:monetdb://<host>[:<port>]/<database></tt> | 34 * <tt>jdbc:monetdb://<host>[:<port>]/<database></tt> |
36 * where [:<port>] denotes that a port is optional. If not | 35 * where [:<port>] denotes that a port is optional. If not |
37 * given the default (@JDBC_DEF_PORT@) will be used. | 36 * given the default (@JDBC_DEF_PORT@) will be used. |
38 * | 37 * |
39 * @author Fabian Groffen | 38 * @author Fabian Groffen |
40 * @version @JDBC_MAJOR@.@JDBC_MINOR@ (@JDBC_VER_SUFFIX@) | 39 * @version @JDBC_MAJOR@.@JDBC_MINOR@ (@JDBC_VER_SUFFIX@) based on MCL v@MCL_MAJOR@.@MCL_MINOR@" |
41 */ | 40 */ |
42 final public class MonetDriver implements Driver { | 41 final public class MonetDriver implements Driver { |
43 // the url kind will be jdbc:monetdb://<host>[:<port>]/<database> | 42 // the url kind will be jdbc:monetdb://<host>[:<port>]/<database> |
44 // Chapter 9.2.1 from Sun JDBC 3.0 specification | 43 // Chapter 9.2.1 from Sun JDBC 3.0 specification |
45 /** The prefix of a MonetDB url */ | 44 /** The prefix of a MonetDB url */ |
46 static final String MONETURL = "jdbc:monetdb://"; | 45 static final String MONETURL = "jdbc:monetdb://"; |
47 /** Major version of this driver */ | |
48 private static final int DRIVERMAJOR = @JDBC_MAJOR@; | |
49 /** Minor version of this driver */ | |
50 private static final int DRIVERMINOR = @JDBC_MINOR@; | |
51 /** Version suffix string */ | |
52 private static final String DRIVERVERSIONSUFFIX = | |
53 "@JDBC_VER_SUFFIX@ based on MCL v@MCL_MAJOR@.@MCL_MINOR@"; | |
54 | |
55 /** MonetDB default port to connect to */ | |
56 private static final String PORT = "@JDBC_DEF_PORT@"; | |
57 | |
58 | 46 |
59 // initialize this class: register it at the DriverManager | 47 // initialize this class: register it at the DriverManager |
60 // Chapter 9.2 from Sun JDBC 3.0 specification | 48 // Chapter 9.2 from Sun JDBC 3.0 specification |
61 static { | 49 static { |
62 try { | 50 try { |
110 if (!acceptsURL(url)) | 98 if (!acceptsURL(url)) |
111 return null; | 99 return null; |
112 | 100 |
113 final Properties props = new Properties(); | 101 final Properties props = new Properties(); |
114 // set the optional properties and their defaults here | 102 // set the optional properties and their defaults here |
115 props.put("port", PORT); | 103 props.put("port", "@JDBC_DEF_PORT@"); |
116 props.put("debug", "false"); | 104 props.put("debug", "false"); |
117 props.put("language", "sql"); // mal, sql, <future> | 105 props.put("language", "sql"); // mal, sql, <future> |
118 props.put("so_timeout", "0"); | 106 props.put("so_timeout", "0"); |
119 | 107 |
120 if (info != null) | 108 if (info != null) |
167 * | 155 * |
168 * @return this driver's major version number | 156 * @return this driver's major version number |
169 */ | 157 */ |
170 @Override | 158 @Override |
171 public int getMajorVersion() { | 159 public int getMajorVersion() { |
172 return DRIVERMAJOR; | 160 return @JDBC_MAJOR@; |
173 } | 161 } |
174 | 162 |
175 /** | 163 /** |
176 * Gets the driver's minor version number. Initially this should be 0. | 164 * Gets the driver's minor version number. Initially this should be 0. |
177 * | 165 * |
178 * @return this driver's minor version number | 166 * @return this driver's minor version number |
179 */ | 167 */ |
180 @Override | 168 @Override |
181 public int getMinorVersion() { | 169 public int getMinorVersion() { |
182 return DRIVERMINOR; | 170 return @JDBC_MINOR@; |
183 } | 171 } |
184 | 172 |
185 /** | 173 /** |
186 * Gets information about the possible properties for this driver. | 174 * Gets information about the possible properties for this driver. |
187 * | 175 * |
203 public DriverPropertyInfo[] getPropertyInfo(final String url, final Properties info) { | 191 public DriverPropertyInfo[] getPropertyInfo(final String url, final Properties info) { |
204 if (!acceptsURL(url)) | 192 if (!acceptsURL(url)) |
205 return null; | 193 return null; |
206 | 194 |
207 final String[] boolean_choices = new String[] { "true", "false" }; | 195 final String[] boolean_choices = new String[] { "true", "false" }; |
208 final String[] language_choices = new String[] { "sql", "mal" }; | |
209 final String[] hash_choices = new String[] { "SHA512", "SHA384", "SHA256", "SHA1", "MD5" }; | |
210 final DriverPropertyInfo[] dpi = new DriverPropertyInfo[9]; // we currently support 9 connection properties | 196 final DriverPropertyInfo[] dpi = new DriverPropertyInfo[9]; // we currently support 9 connection properties |
211 | 197 |
212 DriverPropertyInfo prop = new DriverPropertyInfo("user", info != null ? info.getProperty("user") : null); | 198 DriverPropertyInfo prop = new DriverPropertyInfo("user", info != null ? info.getProperty("user") : null); |
213 prop.required = true; | 199 prop.required = true; |
214 prop.description = "The user loginname to use when authenticating on the database server"; | 200 prop.description = "The user loginname to use when authenticating on the database server"; |
231 dpi[3] = prop; | 217 dpi[3] = prop; |
232 | 218 |
233 prop = new DriverPropertyInfo("language", "sql"); | 219 prop = new DriverPropertyInfo("language", "sql"); |
234 prop.required = false; | 220 prop.required = false; |
235 prop.description = "What language to use for MonetDB conversations (experts only)"; | 221 prop.description = "What language to use for MonetDB conversations (experts only)"; |
236 prop.choices = language_choices; | 222 prop.choices = new String[] { "sql", "mal" }; |
237 dpi[4] = prop; | 223 dpi[4] = prop; |
238 | 224 |
239 prop = new DriverPropertyInfo("hash", null); | 225 prop = new DriverPropertyInfo("hash", null); |
240 prop.required = false; | 226 prop.required = false; |
241 prop.description = "Force the use of the given hash algorithm during challenge response (one of SHA1, MD5, plain)"; | 227 prop.description = "Force the use of the given hash algorithm during challenge response (one of SHA1, MD5, plain)"; |
242 prop.choices = hash_choices; | 228 prop.choices = new String[] { "SHA512", "SHA384", "SHA256", "SHA1", "MD5" }; |
243 dpi[5] = prop; | 229 dpi[5] = prop; |
244 | 230 |
245 prop = new DriverPropertyInfo("treat_blob_as_binary", "false"); | 231 prop = new DriverPropertyInfo("treat_blob_as_binary", "false"); |
246 prop.required = false; | 232 prop.required = false; |
247 prop.description = "Should blob columns be mapped to Types.VARBINARY instead of default Types.BLOB in ResultSets and PreparedStatements"; | 233 prop.description = "Should blob columns be mapped to Types.VARBINARY instead of default Types.BLOB in ResultSets and PreparedStatements"; |
312 throw MonetWrapper.newSQLFeatureNotSupportedException("getParentLogger"); | 298 throw MonetWrapper.newSQLFeatureNotSupportedException("getParentLogger"); |
313 } | 299 } |
314 | 300 |
315 //== end methods of interface driver | 301 //== end methods of interface driver |
316 | 302 |
303 | |
304 /** | |
305 * utility methods called by MonetDatabaseMetaData methods | |
306 */ | |
307 static final int getDriverMajorVersion() { | |
308 return @JDBC_MAJOR@; | |
309 } | |
310 | |
311 static final int getDriverMinorVersion() { | |
312 return @JDBC_MINOR@; | |
313 } | |
314 | |
315 /** | |
316 * Returns a touched up identifying version string of this driver. | |
317 * It is made public as it is called from nl/cwi/monetdb/client/JdbcClient.java | |
318 * @return the version string | |
319 */ | |
320 public static final String getDriverVersion() { | |
321 return "@JDBC_MAJOR@.@JDBC_MINOR@ (@JDBC_VER_SUFFIX@ based on MCL v@MCL_MAJOR@.@MCL_MINOR@)"; | |
322 } | |
317 | 323 |
318 /** A static Map containing the mapping between MonetDB types and Java SQL types */ | 324 /** A static Map containing the mapping between MonetDB types and Java SQL types */ |
319 /* use SELECT sqlname, * FROM sys.types order by 1, id; to view all MonetDB types */ | 325 /* use SELECT sqlname, * FROM sys.types order by 1, id; to view all MonetDB types */ |
320 /* see http://docs.oracle.com/javase/7/docs/api/java/sql/Types.html to view all supported java SQL types */ | 326 /* see http://docs.oracle.com/javase/7/docs/api/java/sql/Types.html to view all supported java SQL types */ |
321 private static final java.util.Map<String, Integer> typeMap = new java.util.HashMap<String, Integer>(); | 327 private static final java.util.Map<String, Integer> typeMap = new java.util.HashMap<String, Integer>(); |
398 // as the typeMap is static, cache this SQL part for all next calls | 404 // as the typeMap is static, cache this SQL part for all next calls |
399 TypeMapppingSQL = val.toString(); | 405 TypeMapppingSQL = val.toString(); |
400 } | 406 } |
401 return "CASE " + column + TypeMapppingSQL; | 407 return "CASE " + column + TypeMapppingSQL; |
402 } | 408 } |
403 | |
404 /** | |
405 * Returns a touched up identifying version string of this driver. | |
406 * It is made public as it is called from nl/cwi/monetdb/client/JdbcClient.java | |
407 * @return the version string | |
408 */ | |
409 public static final String getDriverVersion() { | |
410 return DRIVERMAJOR + "." + DRIVERMINOR + " (" + DRIVERVERSIONSUFFIX + ")"; | |
411 } | |
412 | |
413 static final int getDriverMajorVersion() { | |
414 return DRIVERMAJOR; | |
415 } | |
416 | |
417 static final int getDriverMinorVersion() { | |
418 return DRIVERMINOR; | |
419 } | |
420 } | 409 } |