changeset 33:e67d58485172 embedded

More cleaning
author Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
date Tue, 01 Nov 2016 13:30:23 +0100 (2016-11-01)
parents 57978db4ee57
children 068ec5964f28
files src/main/java/nl/cwi/monetdb/client/JMonetDB.java src/main/java/nl/cwi/monetdb/client/JdbcClient.java src/main/java/nl/cwi/monetdb/mcl/parser/HeaderLineParser.java src/main/java/nl/cwi/monetdb/util/CmdLineOpts.java src/main/java/nl/cwi/monetdb/util/XMLExporter.java
diffstat 5 files changed, 24 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/client/JMonetDB.java
+++ b/src/main/java/nl/cwi/monetdb/client/JMonetDB.java
@@ -10,7 +10,6 @@ package nl.cwi.monetdb.client;
 
 import nl.cwi.monetdb.util.*;
 import nl.cwi.monetdb.merovingian.*;
-import java.io.*;
 import java.util.*;
 
 /**
@@ -22,7 +21,6 @@ import java.util.*;
  */
 
 public class JMonetDB {
-	private static PrintWriter out;
 
 	public final static void main(String[] args) throws Exception {
 		CmdLineOpts copts = new CmdLineOpts();
@@ -74,8 +72,6 @@ copts.produceHelpMessage()
 			System.exit(0);
 		}
 
-		out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
-
 		String pass = copts.getOption("passphrase").getArgument();
 
 		// we need the password from the user, fetch it with a pseudo
@@ -99,9 +95,9 @@ copts.produceHelpMessage()
 		}
 		int port = Integer.parseInt(sport);
 
-		String hash = null;
+		/*String hash; TODO check this, the hash algorithm is not being used
 		if (copts.getOption("Xhash").isPresent())
-			hash = copts.getOption("Xhash").getArgument();
+			hash = copts.getOption("Xhash").getArgument();*/
 
 		if (!copts.getOption("command").isPresent()) {
 			System.err.println("need a command to execute (-c)");
@@ -128,13 +124,11 @@ copts.produceHelpMessage()
 			if (commands.length == 1) {
 				sdbs = ctl.getAllStatuses();
 			} else {
-				sdbs = new ArrayList<SabaothDB>();
+				sdbs = new ArrayList<>();
 				for (int i = 1; i < commands.length; i++)
 					sdbs.add(ctl.getStatus(commands[i]));
 			}
-			Iterator<SabaothDB> it = sdbs.iterator();
-			while (it.hasNext()) {
-				SabaothDB sdb = it.next();
+			for (SabaothDB sdb : sdbs) {
 				System.out.println(sdb.getName() + " " + sdb.getURI());
 			}
 		}
--- a/src/main/java/nl/cwi/monetdb/client/JdbcClient.java
+++ b/src/main/java/nl/cwi/monetdb/client/JdbcClient.java
@@ -133,7 +133,7 @@ public final class JdbcClient {
 			System.exit(1);
 		}
 		// we can actually compare pointers (objects) here
-		if (user != copts.getOption("user").getArgument()) pass = null;
+		if (user != null && !user.equals(copts.getOption("user").getArgument())) pass = null;
 
 		if (copts.getOption("help").isPresent()) {
 			System.out.print(
@@ -190,7 +190,7 @@ public final class JdbcClient {
 
 		// build the hostname
 		String host = copts.getOption("host").getArgument();
-		if (host.indexOf(":") == -1) {
+		if (!host.contains(":")) {
 			host = host + ":" + copts.getOption("port").getArgument();
 		}
 
@@ -268,7 +268,7 @@ public final class JdbcClient {
 			// 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>();
+			List<Table> tables = new LinkedList<>();
 			while (tbl.next()) {
 				tables.add(new Table(
 					tbl.getString("TABLE_SCHEM"),
@@ -276,7 +276,6 @@ public final class JdbcClient {
 					tbl.getString("TABLE_TYPE")));
 			}
 			tbl.close();
-			tbl = null;
 
 			if (xmlMode) {
 				exporter = new XMLExporter(out);
@@ -296,12 +295,10 @@ 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();
-				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()))
-						{
+				for (Table ttmp : tables) {
+					for (String dumper : dumpers) {
+						if (ttmp.getName().equalsIgnoreCase(dumper) ||
+								ttmp.getFqname().equalsIgnoreCase(dumper)) {
 							// dump the table
 							doDump(out, ttmp);
 						}
@@ -327,13 +324,12 @@ public final class JdbcClient {
 					fk.addDependancy(pk);
 				}
 				tbl.close();
-				tbl = null;
 
 				// search for cycles of type a -> (x ->)+ b probably not
 				// the most optimal way, but it works by just scanning
 				// every table for loops in a recursive manor
 				for (Table t : tables) {
-					Table.checkForLoop(t, new ArrayList<Table>());
+					Table.checkForLoop(t, new ArrayList<>());
 				}
 
 				// find the graph, at this point we know there are no
@@ -523,7 +519,7 @@ public final class JdbcClient {
 		// an SQL stack keeps track of ( " and '
 		SQLStack stack = new SQLStack();
 		// a query part is a line of an SQL query
-		QueryPart qp = null;
+		QueryPart qp;
 
 		String query = "", curLine;
 		boolean wasComplete = true, doProcess, lastac = false;
@@ -750,8 +746,7 @@ public final class JdbcClient {
 	{
 		// warnings generated during querying
 		SQLWarning warn;
-		long startTime = (showTiming ? System.currentTimeMillis() : 0);
-		long finishTime = 0;
+		long startTime = (showTiming ? System.currentTimeMillis() : 0), finishTime;
 
 		// execute the query, let the driver decide what type it is
 		int aff = -1;
@@ -1106,7 +1101,7 @@ class Table {
 	final String name;
 	final String type;
 	final String fqname;
-	List<Table> needs = new ArrayList<Table>();
+	List<Table> needs = new ArrayList<>();
 
 	Table(String schem, String name, String type) {
 		this.schem = schem;
@@ -1128,9 +1123,9 @@ class Table {
 
 	List<Table> requires(List<Table> existingTables) {
 		if (existingTables == null || existingTables.isEmpty())
-			return new ArrayList<Table>(needs);
+			return new ArrayList<>(needs);
 
-		List<Table> req = new ArrayList<Table>();
+		List<Table> req = new ArrayList<>();
 		for (Table n : needs) {
 			if (!existingTables.contains(n))
 				req.add(n);
--- a/src/main/java/nl/cwi/monetdb/mcl/parser/HeaderLineParser.java
+++ b/src/main/java/nl/cwi/monetdb/mcl/parser/HeaderLineParser.java
@@ -143,7 +143,7 @@ public class HeaderLineParser extends MC
 			}
 		}
 		// add the left over part
-		values[elem++] = new String(chrLine, start, stop - start);
+		values[elem + 1] = new String(chrLine, start, stop - start);
 	}
 
 	/**
@@ -164,7 +164,6 @@ public class HeaderLineParser extends MC
 			if (chrLine[i] == ',' && chrLine[i + 1] == '\t') {
 				intValues[elem++] = tmp;
 				tmp = 0;
-				start = i++;
 			} else {
 				tmp *= 10;
 				// note: don't use Character.isDigit() here, because
@@ -177,6 +176,6 @@ public class HeaderLineParser extends MC
 			}
 		}
 		// add the left over part
-		intValues[elem++] = tmp;
+		intValues[elem + 1] = tmp;
 	}
 }
--- a/src/main/java/nl/cwi/monetdb/util/CmdLineOpts.java
+++ b/src/main/java/nl/cwi/monetdb/util/CmdLineOpts.java
@@ -95,7 +95,7 @@ public class CmdLineOpts {
 		OptionContainer option = null;
 		int quant = -1;
 		int qcount = 0;
-		boolean moreData = false;
+		boolean moreData;
 		for (int i = 0; i < args.length; i++) {
 			if (option == null) {
 				if (args[i].charAt(0) != '-') throw
@@ -139,7 +139,7 @@ public class CmdLineOpts {
 					// single char argument
 					option = opts.get("" + args[i].charAt(1));
 					// is there more data left in the argument?
-					moreData = args[i].length() > 2 ? true : false;
+					moreData = args[i].length() > 2;
 				}
 
 				if (option != null) {
--- a/src/main/java/nl/cwi/monetdb/util/XMLExporter.java
+++ b/src/main/java/nl/cwi/monetdb/util/XMLExporter.java
@@ -32,7 +32,7 @@ public class XMLExporter extends Exporte
 			String name)
 		throws SQLException
 	{
-		if (type.indexOf("VIEW") != -1) {
+		if (type.contains("VIEW")) {
 			String[] types = new String[1];
 			types[0] = type;
 			ResultSet tbl = dbmd.getTables(catalog, schema, name, types);
@@ -332,9 +332,9 @@ public class XMLExporter extends Exporte
 					case java.sql.Types.TIMESTAMP:
 						Timestamp ts = rs.getTimestamp(i);
 						if ("timestamptz".equals(rsmd.getColumnTypeName(i))) {
-							data = xsd_tstz.format(ts).toString();
+							data = xsd_tstz.format(ts);
 						} else {
-							data = xsd_ts.format(ts).toString();
+							data = xsd_ts.format(ts);
 						}
 					break;
 					default: