Mercurial > hg > monetdb-java
view src/main/java/nl/cwi/monetdb/client/JMonetDB.java @ 85:073ee535234b embedded
Ok. Now everything compiles back with Ant again. Moved the Embedded stuff to the temporary MonetDBJavaLite repository before moving into the suggested MonetDBLite repository. The soon generated Embedded Connection jar will have a dependency on the regular JDBC driver jar. The JDBC driver jar is independent, however if attempted to create an Embedded Connection with will try to load the respective class from the class loader, failing if the Embedded Connection jar is not present. If anyone in the group has expertise on Java Class dynamic loading, please contact me because there might be issues on this. Removed the pom.xml file because the regular maven compilation fails.
author | Pedro Ferreira <pedro.ferreira@monetdbsolutions.com> |
---|---|
date | Fri, 30 Dec 2016 18:55:13 +0000 (2016-12-30) |
parents | 17365ed26611 |
children | 6f74e01c57da |
line wrap: on
line source
/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V. */ package nl.cwi.monetdb.client; import nl.cwi.monetdb.merovingian.Control; import nl.cwi.monetdb.merovingian.SabaothDB; import nl.cwi.monetdb.util.CmdLineOpts; import nl.cwi.monetdb.util.OptionsException; import java.util.ArrayList; import java.util.List; /** * This program mimics the monetdb tool. It is meant as demonstration * and test of the MeroControl library. * * @author Fabian Groffen * @version 1.0 */ public class JMonetDB { public static void main(String[] args) throws Exception { CmdLineOpts copts = new CmdLineOpts(); // arguments which take exactly one argument copts.addOption("h", "host", CmdLineOpts.CAR_ONE, "localhost", "The hostname of the host that runs the MonetDB server. " + "A port number can be supplied by use of a colon, i.e. " + "-h somehost:12345."); copts.addOption("p", "port", CmdLineOpts.CAR_ONE, "50000", "The port number to connect to."); copts.addOption("P", "passphrase", CmdLineOpts.CAR_ONE, null, "The passphrase to tell the MonetDB server"); copts.addOption("c", "command", CmdLineOpts.CAR_ONE_MANY, null, "The command to execute on the MonetDB server"); // arguments which have no argument(s) copts.addOption(null, "help", CmdLineOpts.CAR_ZERO, null, "This help screen."); // extended options copts.addOption(null, "Xhash", CmdLineOpts.CAR_ONE, null, "Use the given hash algorithm during challenge response. " + "Supported algorithm names: SHA256, SHA1, MD5."); // arguments which can have zero or one argument(s) copts.addOption(null, "Xdebug", CmdLineOpts.CAR_ONE, null, "Writes a transmission log to disk for debugging purposes. " + "A file name must be given."); try { copts.processArgs(args); } catch (OptionsException e) { System.err.println("Error: " + e.getMessage()); System.exit(1); } if (copts.getOption("help").isPresent()) { System.out.print( "Usage java -jar jmonetdb.jar\n" + " -h host[:port] -p port -P passphrase [-X<opt>] -c cmd ...\n" + "or using long option equivalents --host --port --passphrase.\n" + "Arguments may be written directly after the option like -p50000.\n" + "\n" + "If no host and port are given, localhost and 50000 are assumed.\n" + "\n" + "OPTIONS\n" + copts.produceHelpMessage()); System.exit(0); } String pass = copts.getOption("passphrase").getArgument(); // we need the password from the user, fetch it with a pseudo password protector if (pass == null) { char[] tmp = System.console().readPassword("passphrase: "); if (tmp == null) { System.err.println("Invalid passphrase!"); System.exit(1); } pass = String.valueOf(tmp); } // build the hostname String host = copts.getOption("host").getArgument(); String sport = copts.getOption("port").getArgument(); int pos; if ((pos = host.indexOf(":")) != -1) { sport = host.substring(pos + 1); host = host.substring(0, pos); } int port = Integer.parseInt(sport); String hash = null; if (copts.getOption("Xhash").isPresent()) hash = copts.getOption("Xhash").getArgument(); if (!copts.getOption("command").isPresent()) { System.err.println("need a command to execute (-c)"); System.exit(1); } Control ctl = null; try { ctl = new Control(host, port, pass); } catch (IllegalArgumentException e) { System.err.println(e.getMessage()); System.exit(1); } // FIXME: Control needs to respect Xhash String[] commands = copts.getOption("command").getArguments(); if (commands[0].equals("status")) { List<SabaothDB> sdbs; if (commands.length == 1) { sdbs = ctl.getAllStatuses(); } else { sdbs = new ArrayList<SabaothDB>(); for (int i = 1; i < commands.length; i++) sdbs.add(ctl.getStatus(commands[i])); } for (SabaothDB sdb : sdbs) { System.out.println(sdb.getName() + " " + sdb.getURI()); } } } }