Changeset: df18aa5c8a61 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/df18aa5c8a61
Modified Files:
src/main/java/org/monetdb/jdbc/MonetDriver.java
src/main/java/org/monetdb/mcl/net/Parameter.java
tests/JDBC_API_Tester.java
Branch: default
Log Message:
Add test for MonetDriver.getPropertyInfo(url, props).
The implementation is moved to Parameter.java which contains the list of
connection parameters.
It currently only returns the mandatory connection parameters.
diffs (254 lines):
diff --git a/src/main/java/org/monetdb/jdbc/MonetDriver.java
b/src/main/java/org/monetdb/jdbc/MonetDriver.java
--- a/src/main/java/org/monetdb/jdbc/MonetDriver.java
+++ b/src/main/java/org/monetdb/jdbc/MonetDriver.java
@@ -12,6 +12,7 @@
package org.monetdb.jdbc;
+import org.monetdb.mcl.net.Parameter;
import org.monetdb.mcl.net.Target;
import org.monetdb.mcl.net.ValidationError;
@@ -139,7 +140,7 @@ public final class MonetDriver implement
* discover what properties it should prompt a human for in order to get
* enough information to connect to a database. Note that depending on
the
* values the human has supplied so far, additional values may become
- * necessary, so it may be necessary to iterate though several calls to
the
+ * necessary, so it may be necessary to iterate through several calls
to the
* getPropertyInfo method.
*
* @param url the URL of the database to which to connect
@@ -154,66 +155,8 @@ public final class MonetDriver implement
if (!acceptsURL(url))
return null;
- final String[] boolean_choices = new String[] { "true", "false"
};
- final DriverPropertyInfo[] dpi = new DriverPropertyInfo[10];
// we currently support 10 connection properties
-
- DriverPropertyInfo prop = new DriverPropertyInfo("user", info
!= null ? info.getProperty("user") : null);
- prop.required = true;
- prop.description = "The user loginname to use when
authenticating on the database server";
- dpi[0] = prop;
-
- prop = new DriverPropertyInfo("password", info != null ?
info.getProperty("password") : null);
- prop.required = true;
- prop.description = "The password to use when authenticating on
the database server";
- dpi[1] = prop;
-
- prop = new DriverPropertyInfo("debug", "false");
- prop.required = false;
- prop.description = "Whether or not to create a log file for
debugging purposes";
- prop.choices = boolean_choices;
- dpi[2] = prop;
-
- prop = new DriverPropertyInfo("logfile", null);
- prop.required = false;
- prop.description = "The filename to write the debug log to.
Only takes effect if debug is set to true. If the file exists, an incrementing
number is added, till the filename is unique.";
- dpi[3] = prop;
-
- prop = new DriverPropertyInfo("language", "sql");
- prop.required = false;
- prop.description = "What language to use for MonetDB
conversations (experts only)";
- prop.choices = new String[] { "sql", "mal" };
- dpi[4] = prop;
-
- prop = new DriverPropertyInfo("hash", null);
- prop.required = false;
- prop.description = "Force the use of the given hash algorithm
(SHA512 or SHA384 or SHA256 or SHA1) during challenge response";
- prop.choices = new String[] { "SHA512", "SHA384", "SHA256",
"SHA1" };
- dpi[5] = prop;
-
- prop = new DriverPropertyInfo("treat_blob_as_binary", "true");
- prop.required = false;
- prop.description = "Should blob columns be mapped to
Types.VARBINARY instead of Types.BLOB in ResultSets and PreparedStatements"; //
recommend for increased performance due to less overhead
- prop.choices = boolean_choices;
- dpi[6] = prop;
-
- prop = new DriverPropertyInfo("treat_clob_as_varchar", "true");
- prop.required = false;
- prop.description = "Should clob columns be mapped to
Types.VARCHAR instead of Types.CLOB in ResultSets and PreparedStatements"; //
recommend for increased performance due to less overhead
- prop.choices = boolean_choices;
- dpi[7] = prop;
-
- prop = new DriverPropertyInfo("so_timeout", "0");
- prop.required = false;
- prop.description = "Defines the maximum time to wait in
milliseconds on a blocking read socket call"; // this corresponds to the
Connection.setNetworkTimeout() method introduced in JDBC 4.1
- dpi[8] = prop;
-
- prop = new DriverPropertyInfo("autocommit", "true");
- prop.required = false;
- prop.description = "Whether the connection should start in
auto-commit mode";
- prop.choices = boolean_choices;
- dpi[9] = prop;
-
- return dpi;
+ // delegate to mcl.net.Parameters enum class, which maintains
all connection properties
+ return Parameter.getPropertyInfo(info,
url.startsWith("jdbc:monetdbs:"));
}
/**
diff --git a/src/main/java/org/monetdb/mcl/net/Parameter.java
b/src/main/java/org/monetdb/mcl/net/Parameter.java
--- a/src/main/java/org/monetdb/mcl/net/Parameter.java
+++ b/src/main/java/org/monetdb/mcl/net/Parameter.java
@@ -12,12 +12,15 @@
package org.monetdb.mcl.net;
+import java.sql.DriverPropertyInfo;
import java.util.Calendar;
+import java.util.Properties;
/**
* Enumerates things that can be configured on a connection to MonetDB.
*/
public enum Parameter {
+ // String name, ParameterType type, Object defaultValue, String
description, boolean isCore
TLS("tls", ParameterType.Bool, false, "secure the connection using
TLS", true),
HOST("host", ParameterType.Str, "", "IP number, domain name or one of
the special values `localhost` and `localhost.`", true),
PORT("port", ParameterType.Int, -1, "Port to connect to, 1..65535 or -1
for 'not set'", true),
@@ -167,7 +170,7 @@ public enum Parameter {
}
/**
- * Determine if this Parameter is onlyu relevant when TlS is enabled.
+ * Determine if this Parameter is only relevant when TlS is enabled.
*
* Such parameters need not be shown to the user unless the URL starts
with <code>monetdbs://</code>.
*
@@ -184,4 +187,59 @@ public enum Parameter {
return false;
}
}
+
+ /**
+ * Gets information about the possible properties for this driver.
+ *
+ * The getPropertyInfo method is intended to allow a generic GUI tool to
+ * discover what properties it should prompt a human for in order to get
+ * enough information to connect to a database. Note that depending on
the
+ * values the human has supplied so far, additional values may become
+ * necessary, so it may be necessary to iterate through several calls
to the
+ * getPropertyInfo method.
+ *
+ * Note: This method is called from jdbc.MonetDriver.getPropertyInfo()
+ *
+ * @param info a proposed list of tag/value pairs that will be sent on
+ * connect open
+ * @return an array of DriverPropertyInfo objects describing possible
+ * properties. This array may be an empty array if no properties
+ * are required.
+ */
+ public static DriverPropertyInfo[] getPropertyInfo(final Properties
info, boolean requires_tls) {
+ final String tls = info != null ? info.getProperty("tls") :
null;
+ final boolean tls_enabled = requires_tls || (tls != null &&
tls.equals("true"));
+ final int dpi_size = (tls_enabled ? 4 : 2);
+ final DriverPropertyInfo[] dpi = new
DriverPropertyInfo[dpi_size];
+ DriverPropertyInfo prop = null;
+
+ // minimal required connection settings are "user" and
"password"
+ prop = new DriverPropertyInfo("user", info != null ?
info.getProperty("user") : null);
+ prop.required = true;
+ prop.description = "User loginname to use when authenticating
on the database server";
+ dpi[0] = prop;
+
+ prop = new DriverPropertyInfo("password", info != null ?
info.getProperty("password") : null);
+ prop.required = true;
+ prop.description = "Password to use when authenticating on the
database server";
+ dpi[1] = prop;
+
+ if (tls_enabled && dpi_size > 2) {
+ // when tls is enabled or required also "tls" and
"cert" become required
+ final String[] boolean_choices = new String[] { "true",
"false" };
+
+ prop = new DriverPropertyInfo("tls", tls);
+ prop.required = true;
+ prop.description = "secure the connection using TLS";
+ prop.choices = boolean_choices;
+ dpi[2] = prop;
+
+ prop = new DriverPropertyInfo("cert", info != null ?
info.getProperty("cert") : null);
+ prop.required = true;
+ prop.description = "path to TLS certificate to
authenticate server with";
+ dpi[3] = prop;
+ }
+
+ return dpi;
+ }
}
diff --git a/tests/JDBC_API_Tester.java b/tests/JDBC_API_Tester.java
--- a/tests/JDBC_API_Tester.java
+++ b/tests/JDBC_API_Tester.java
@@ -10,13 +10,11 @@
* Copyright 1997 - July 2008 CWI.
*/
-import java.sql.*;
-
import java.io.StringReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
-import java.sql.Date;
+import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -93,6 +91,7 @@ public final class JDBC_API_Tester {
jt.Test_Creplysize();
jt.Test_Csavepoints();
jt.Test_Ctransaction();
+ jt.Test_Driver(con_URL);
jt.Test_Dobjects();
jt.Test_DBCmetadata();
jt.Test_EmptySql();
@@ -731,6 +730,50 @@ public final class JDBC_API_Tester {
"13. commit...failed as expected: COMMIT: not allowed
in auto commit mode\n");
}
+ private void Test_Driver(String con_URL) {
+ sb.setLength(0); // clear the output log buffer
+
+ try {
+ final Driver driver = DriverManager.getDriver(con_URL);
+ DriverPropertyInfo[] props =
driver.getPropertyInfo(con_URL, null);
+ DriverPropertyInfo prop;
+ final String space = " ";
+ for (int i = 0; i < props.length; i++) {
+ prop = props[i];
+ sb.append(i).append(space);
+ sb.append(prop.name).append(space);
+ sb.append(prop.required).append(space);
+ sb.append(prop.value).append(space);
+ sb.append(prop.description).append("\n");
+ }
+ // also test against monetdbs, this should make tls and
cert required.
+ props = driver.getPropertyInfo("jdbc:monetdbs:", null);
+ sb.append("getPropertyInfo of
jdbc:monetdbs:").append("\n");
+ for (int i = 0; i < props.length; i++) {
+ prop = props[i];
+ sb.append(i).append(space);
+ sb.append(prop.name).append(space);
+ sb.append(prop.required).append(space);
+ sb.append(prop.value).append(space);
+ sb.append(prop.description).append("\n");
+ }
+ } catch (SQLException e) {
+ // this means we get what we expect
+ sb.append("failed to get Driver class:
").append(e.getMessage());
+ sb.append("\n");
+ }
+
+ compareExpectedOutput("Test_Driver",
+ "0 user true null User loginname to use when
authenticating on the database server\n" +
+ "1 password true null Password to use when
authenticating on the database server\n" +
+ "getPropertyInfo of jdbc:monetdbs:\n" +
+ "0 user true null User loginname to use when
authenticating on the database server\n" +
+ "1 password true null Password to use when
authenticating on the database server\n" +
+ "2 tls true null secure the connection using TLS\n"
+
+ "3 cert true null path to TLS certificate to
authenticate server with\n");
+ }
+
+
private void handleExecuteDDL(Statement stmt, String action, String
objtype, String objname, String sql) {
try {
int response = stmt.executeUpdate(sql);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]