Skip to content

Commit

Permalink
Merge 'monetdbs' into 'default'
Browse files Browse the repository at this point in the history
  • Loading branch information
joerivanruth committed Jan 5, 2024
2 parents 7bd1f5d + 33b3900 commit 57ccf67
Show file tree
Hide file tree
Showing 19 changed files with 4,456 additions and 680 deletions.
46 changes: 32 additions & 14 deletions src/main/java/org/monetdb/client/JdbcClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;

/**
* This program acts like an extended client program for MonetDB. Its
Expand Down Expand Up @@ -127,6 +128,7 @@ public final class JdbcClient {
* @throws Exception if uncaught exception is thrown
*/
public final static void main(String[] args) throws Exception {
final Properties props = new Properties();
final CmdLineOpts copts = new CmdLineOpts();

// arguments which take exactly one argument
Expand Down Expand Up @@ -194,6 +196,10 @@ public final static void main(String[] args) throws Exception {
"statements read. Batching can greatly speedup the " +
"process of restoring a database dump.");

copts.addIgnored("save_history");
copts.addIgnored("format");
copts.addIgnored("width");

// we store user and password in separate variables in order to
// be able to properly act on them like forgetting the password
// from the user's file if the user supplies a username on the
Expand Down Expand Up @@ -287,19 +293,24 @@ public final static void main(String[] args) throws Exception {

user = copts.getOption("user").getArgument();

// build the hostname
// extract hostname and port
String host = copts.getOption("host").getArgument();
if (host.indexOf(':') == -1) {
host = host + ":" + copts.getOption("port").getArgument();
String port = copts.getOption("port").getArgument();
int hostColon = host.indexOf(':');
if (hostColon > 0) {
port = host.substring(hostColon + 1);
host = host.substring(0, hostColon);
}
props.setProperty("host", host);
props.setProperty("port", port);

// build the extra arguments of the JDBC connect string
// increase the fetchsize from the default 250 to 10000
String attr = "?fetchsize=10000&";
props.setProperty("fetchsize", "10000");

CmdLineOpts.OptionContainer oc = copts.getOption("language");
final String lang = oc.getArgument();
if (oc.isPresent())
attr += "language=" + lang + "&";
props.setProperty("language", lang);

/* Xquery is no longer functional or supported
// set some behaviour based on the language XQuery
Expand All @@ -311,13 +322,13 @@ public final static void main(String[] args) throws Exception {
*/
oc = copts.getOption("Xdebug");
if (oc.isPresent()) {
attr += "debug=true&";
props.setProperty("debug", "true");
if (oc.getArgumentCount() == 1)
attr += "logfile=" + oc.getArgument() + "&";
props.setProperty("logfile", "logfile=" + oc.getArgument());
}
oc = copts.getOption("Xhash");
if (oc.isPresent())
attr += "hash=" + oc.getArgument() + "&";
props.setProperty("hash", oc.getArgument());

// request a connection suitable for MonetDB from the driver
// manager note that the database specifier is only used when
Expand All @@ -329,11 +340,18 @@ public final static void main(String[] args) throws Exception {
// make sure the driver class is loaded (and thus register itself with the DriverManager)
Class.forName("org.monetdb.jdbc.MonetDriver");

con = DriverManager.getConnection(
"jdbc:monetdb://" + host + "/" + database + attr,
user,
pass
);
// If the database name is a full url, use that.
// Otherwise, construct something.
String url;
if (database.startsWith("jdbc:")) {
url = database;
} else {
url = "jdbc:monetdb:"; // special case
props.setProperty("database", database);
}
props.setProperty("user", user);
props.setProperty("password", pass);
con = DriverManager.getConnection(url, props);
SQLWarning warn = con.getWarnings();
while (warn != null) {
System.err.println("Connection warning: " + warn.getMessage());
Expand Down
Loading

0 comments on commit 57ccf67

Please sign in to comment.