Changeset: 1948dbcd9991 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=1948dbcd9991
Modified Files:
src/main/java/nl/cwi/monetdb/client/JMonetDB.java
src/main/java/nl/cwi/monetdb/client/JdbcClient.java
Branch: default
Log Message:
Add "final" keyword to classes, method arguments and local variables where
possible.
diffs (truncated from 624 to 300 lines):
diff --git a/src/main/java/nl/cwi/monetdb/client/JMonetDB.java
b/src/main/java/nl/cwi/monetdb/client/JMonetDB.java
--- a/src/main/java/nl/cwi/monetdb/client/JMonetDB.java
+++ b/src/main/java/nl/cwi/monetdb/client/JMonetDB.java
@@ -10,14 +10,12 @@ 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.io.BufferedWriter;
-import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
/**
@@ -28,11 +26,11 @@ import java.util.List;
* @version 1.0
*/
-public class JMonetDB {
+public final class JMonetDB {
private static PrintWriter out;
public final static void main(String[] args) throws Exception {
- CmdLineOpts copts = new CmdLineOpts();
+ final CmdLineOpts copts = new CmdLineOpts();
// arguments which take exactly one argument
copts.addOption("h", "host", CmdLineOpts.CAR_ONE, "localhost",
@@ -68,27 +66,26 @@ public class JMonetDB {
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()
-);
+ "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);
}
- out = new PrintWriter(new BufferedWriter(new
OutputStreamWriter(System.out)));
+ out = new PrintWriter(new java.io.BufferedWriter(new
java.io.OutputStreamWriter(System.out)));
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:
");
+ final char[] tmp =
System.console().readPassword("passphrase: ");
if (tmp == null) {
System.err.println("Invalid passphrase!");
System.exit(1);
@@ -125,11 +122,11 @@ copts.produceHelpMessage()
// FIXME: Control needs to respect Xhash
if (copts.getOption("Xdebug").isPresent()) {
- String fname = copts.getOption("Xdebug").getArgument();
+ final String fname =
copts.getOption("Xdebug").getArgument();
ctl.setDebug(fname);
}
- String[] commands = copts.getOption("command").getArguments();
+ final String[] commands =
copts.getOption("command").getArguments();
if (commands[0].equals("status")) {
List<SabaothDB> sdbs;
if (commands.length == 1) {
@@ -139,7 +136,7 @@ copts.produceHelpMessage()
for (int i = 1; i < commands.length; i++)
sdbs.add(ctl.getStatus(commands[i]));
}
- Iterator<SabaothDB> it = sdbs.iterator();
+ final java.util.Iterator<SabaothDB> it =
sdbs.iterator();
while (it.hasNext()) {
SabaothDB sdb = it.next();
System.out.println(sdb.getName() + " " +
sdb.getURI());
diff --git a/src/main/java/nl/cwi/monetdb/client/JdbcClient.java
b/src/main/java/nl/cwi/monetdb/client/JdbcClient.java
--- a/src/main/java/nl/cwi/monetdb/client/JdbcClient.java
+++ b/src/main/java/nl/cwi/monetdb/client/JdbcClient.java
@@ -19,17 +19,11 @@ import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
-import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
@@ -37,7 +31,6 @@ import java.sql.SQLWarning;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
-import java.util.zip.GZIPInputStream;
/**
* This program acts like an extended client program for MonetDB. Its
@@ -60,7 +53,7 @@ public final class JdbcClient {
private static Exporter exporter;
public final static void main(String[] args) throws Exception {
- CmdLineOpts copts = new CmdLineOpts();
+ final CmdLineOpts copts = new CmdLineOpts();
// arguments which take exactly one argument
copts.addOption("h", "host", CmdLineOpts.CAR_ONE, "localhost",
@@ -184,7 +177,9 @@ public final class JdbcClient {
copts.produceHelpMessage()
);
System.exit(0);
- } else if (copts.getOption("version").isPresent()) {
+ }
+
+ if (copts.getOption("version").isPresent()) {
// We cannot use the DatabaseMetaData here, because we
// cannot get a Connection. So instead, we just get the
// values we want out of the Driver directly.
@@ -192,18 +187,15 @@ public final class JdbcClient {
System.exit(0);
}
- in = new BufferedReader(new InputStreamReader(System.in));
- out = new PrintWriter(new BufferedWriter(new
OutputStreamWriter(System.out)));
-
// whether the semi-colon at the end of a String terminates the
// query or not (default = yes => SQL)
- boolean scolonterm = true;
- boolean xmlMode =
"xml".equals(copts.getOption("Xoutput").getArgument());
+ final boolean scolonterm = true;
+ final boolean xmlMode =
"xml".equals(copts.getOption("Xoutput").getArgument());
// we need the password from the user, fetch it with a pseudo
// password protector
if (pass == null) {
- char[] tmp = System.console().readPassword("password:
");
+ final char[] tmp =
System.console().readPassword("password: ");
if (tmp == null) {
System.err.println("Invalid password!");
System.exit(1);
@@ -225,7 +217,7 @@ public final class JdbcClient {
// build the extra arguments of the JDBC connect string
String attr = "?";
CmdLineOpts.OptionContainer oc = copts.getOption("language");
- String lang = oc.getArgument();
+ final String lang = oc.getArgument();
if (oc.isPresent())
attr += "language=" + lang + "&";
@@ -252,9 +244,9 @@ public final class JdbcClient {
// connecting to a proxy-like service, since MonetDB itself
// can't access multiple databases.
con = null;
- String database = copts.getOption("database").getArgument();
+ final String database =
copts.getOption("database").getArgument();
try {
- con = DriverManager.getConnection(
+ con = java.sql.DriverManager.getConnection(
"jdbc:monetdb://" + host + "/" +
database + attr,
user,
pass
@@ -278,16 +270,17 @@ public final class JdbcClient {
dbmd = null;
}
- stmt = con.createStatement();
+ in = new BufferedReader(new InputStreamReader(System.in));
+ out = new PrintWriter(new BufferedWriter(new
java.io.OutputStreamWriter(System.out)));
+
+ stmt = con.createStatement(); // is used by doDump
// see if we will have to perform a database dump (only in SQL
mode)
if ("sql".equals(lang) && copts.getOption("dump").isPresent()) {
- ResultSet tbl;
-
// use the given file for writing
oc = copts.getOption("file");
if (oc.isPresent())
- out = new PrintWriter(new BufferedWriter(new
FileWriter(oc.getArgument())));
+ out = new PrintWriter(new BufferedWriter(new
java.io.FileWriter(oc.getArgument())));
// we only want user tables and views to be dumped,
unless a specific
// table is requested
@@ -295,9 +288,9 @@ public final class JdbcClient {
if (copts.getOption("dump").getArgumentCount() > 0)
types = null;
// request the tables available in the current schema
in the database
- tbl = dbmd.getTables(null, con.getSchema(), null,
types);
-
- List<Table> tables = new LinkedList<Table>();
+ ResultSet tbl = dbmd.getTables(null, con.getSchema(),
null, types);
+ final LinkedList<Table> tables = new
LinkedList<Table>();
+ // fetch all tables and store them in a LinkedList
while (tbl.next()) {
tables.add(new Table(
tbl.getString(2), // 2 =
"TABLE_SCHEM"
@@ -324,12 +317,13 @@ public final class JdbcClient {
// dump specific table(s) or not?
if (copts.getOption("dump").getArgumentCount() > 0) {
// yes we do
- String[] dumpers =
copts.getOption("dump").getArguments();
+ final String[] dumpers =
copts.getOption("dump").getArguments();
for (int i = 0; i < tables.size(); i++) {
Table ttmp = tables.get(i);
for (int j = 0; j < dumpers.length;
j++) {
- if
(ttmp.getName().equalsIgnoreCase(dumpers[j].toString()) ||
-
ttmp.getFqname().equalsIgnoreCase(dumpers[j].toString()))
+ String dumptblnm =
dumpers[j].toString();
+ if
(ttmp.getName().equalsIgnoreCase(dumptblnm) ||
+
ttmp.getFqname().equalsIgnoreCase(dumptblnm))
{
// dump the table
doDump(out, ttmp);
@@ -408,11 +402,10 @@ public final class JdbcClient {
try {
// use the given file for reading
- boolean hasFile = copts.getOption("file").isPresent();
- boolean doEcho = hasFile &&
copts.getOption("echo").isPresent();
+ final boolean hasFile =
copts.getOption("file").isPresent();
+ final boolean doEcho = hasFile &&
copts.getOption("echo").isPresent();
if (hasFile) {
- String tmp =
copts.getOption("file").getArgument();
- int batchSize = 0;
+ final String tmp =
copts.getOption("file").getArgument();
try {
in = getReader(tmp);
} catch (Exception e) {
@@ -421,6 +414,7 @@ public final class JdbcClient {
}
// check for batch mode
+ int batchSize = 0;
oc = copts.getOption("Xbatching");
if (oc.isPresent()) {
if (oc.getArgumentCount() == 1) {
@@ -441,10 +435,10 @@ public final class JdbcClient {
// print welcome message
out.println("Welcome to the MonetDB
interactive JDBC terminal!");
if (dbmd != null) {
+ out.println("JDBC Driver: " +
dbmd.getDriverName() +
+ " v" +
dbmd.getDriverVersion());
out.println("Database Server: "
+ dbmd.getDatabaseProductName() +
" v" +
dbmd.getDatabaseProductVersion());
- out.println("JDBC Driver: " +
dbmd.getDriverName() +
- " v" +
dbmd.getDriverVersion());
}
out.println("Current Schema: " +
con.getSchema());
out.println("Type \\q to quit (you can
also use: quit or exit), \\? or \\h for a list of available commands");
@@ -482,45 +476,46 @@ public final class JdbcClient {
* @return a BufferedReader for the uri
* @throws Exception if uri cannot be identified as a valid URL or file
*/
- static BufferedReader getReader(String uri) throws Exception {
+ static BufferedReader getReader(final String uri) throws Exception {
BufferedReader ret = null;
URL u = null;
// Try and parse as URL first
try {
u = new URL(uri);
- } catch (MalformedURLException e) {
+ } catch (java.net.MalformedURLException e) {
// no URL, try as file
try {
- ret = new BufferedReader(new FileReader(uri));
- } catch (FileNotFoundException fnfe) {
+ ret = new BufferedReader(new
java.io.FileReader(uri));
+ } catch (java.io.FileNotFoundException fnfe) {
// the message is descriptive enough, adds "(No
such file
// or directory)" itself.
throw new Exception(fnfe.getMessage());
}
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list