Changeset: fdf4c888d5b7 for monetdb-java URL: https://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=fdf4c888d5b7 Modified Files: src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java src/main/java/nl/cwi/monetdb/mcl/io/BufferedMCLReader.java src/main/java/nl/cwi/monetdb/mcl/io/BufferedMCLWriter.java src/main/java/nl/cwi/monetdb/mcl/net/MapiSocket.java src/main/java/nl/cwi/monetdb/mcl/parser/HeaderLineParser.java src/main/java/nl/cwi/monetdb/mcl/parser/StartOfHeaderParser.java src/main/java/nl/cwi/monetdb/mcl/parser/TupleLineParser.java Branch: default Log Message:
Small code and layout improvements diffs (truncated from 533 to 300 lines): diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in b/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in --- a/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in @@ -144,7 +144,7 @@ final public class MonetDriver implement int uri_port = uri.getPort(); if (uri_port > 0) - info.put("port", "" + uri_port); + info.put("port", Integer.toString(uri_port)); // check the database String uri_path = uri.getPath(); @@ -404,7 +404,7 @@ final public class MonetDriver implement * @return the version string */ public static String getDriverVersion() { - return "" + DRIVERMAJOR + "." + DRIVERMINOR + " (" + DRIVERVERSIONSUFFIX + ")"; + return DRIVERMAJOR + "." + DRIVERMINOR + " (" + DRIVERVERSIONSUFFIX + ")"; } public static int getDriverMajorVersion() { diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java --- a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java @@ -192,8 +192,8 @@ public class MonetResultSet /** * Internal utility method to fill the JdbcSQLTypes array with derivable values. - * By doing it once (in the constructor) we can avoid doing this in many getXyz() methods again and again - * thereby improving getXyz() method performance. + * By doing it once (in the constructor) we can avoid doing this in many getXyz() + * methods again and again thereby improving getXyz() method performance. */ private void populateJdbcSQLtypesArray() { MonetConnection connection = null; @@ -203,15 +203,15 @@ public class MonetResultSet for (int i = 0; i < types.length; i++) { int javaSQLtype = MonetDriver.getJavaType(types[i]); - JdbcSQLTypes[i] = javaSQLtype; if (javaSQLtype == Types.CLOB) { if (connection != null && connection.mapClobAsVarChar()) - JdbcSQLTypes[i] = Types.VARCHAR; + javaSQLtype = Types.VARCHAR; } else if (javaSQLtype == Types.BLOB) { if (connection != null && connection.mapBlobAsVarBinary()) - JdbcSQLTypes[i] = Types.VARBINARY; + javaSQLtype = Types.VARBINARY; } + JdbcSQLTypes[i] = javaSQLtype; } } diff --git a/src/main/java/nl/cwi/monetdb/mcl/io/BufferedMCLReader.java b/src/main/java/nl/cwi/monetdb/mcl/io/BufferedMCLReader.java --- a/src/main/java/nl/cwi/monetdb/mcl/io/BufferedMCLReader.java +++ b/src/main/java/nl/cwi/monetdb/mcl/io/BufferedMCLReader.java @@ -20,7 +20,7 @@ import java.io.UnsupportedEncodingExcept * to provide a means for efficient reading of characters, arrays and * lines. This class is based on the BufferedReader class, and provides * extra functionality useful for MCL. - * + * * The BufferedMCLReader is typically used as layer inbetween an * InputStream and a specific interpreter of the data. * <pre> @@ -42,29 +42,28 @@ import java.io.UnsupportedEncodingExcept * @see nl.cwi.monetdb.mcl.io.BufferedMCLWriter */ public class BufferedMCLReader extends BufferedReader { + /** "there is currently no line", or the the type is unknown is represented by UNKNOWN */ + public final static int UNKNOWN = 0; + /** a line starting with ! indicates ERROR */ + public final static int ERROR = '!'; + /** a line starting with % indicates HEADER */ + public final static int HEADER = '%'; + /** a line starting with [ indicates RESULT */ + public final static int RESULT = '['; + /** a line which matches the pattern of prompt1 is a PROMPT */ + public final static int PROMPT = '.'; + /** a line which matches the pattern of prompt2 is a MORE */ + public final static int MORE = ','; + /** a line starting with & indicates the start of a header block */ + public final static int SOHEADER = '&'; + /** a line starting with ^ indicates REDIRECT */ + public final static int REDIRECT = '^'; + /** a line starting with # indicates INFO */ + public final static int INFO = '#'; + /** The type of the last line read */ private int lineType; - /** "there is currently no line", or the the type is unknown is - represented by UNKNOWN */ - public final static int UNKNOWN = 0; - /** a line starting with ! indicates ERROR */ - public final static int ERROR = '!'; - /** a line starting with % indicates HEADER */ - public final static int HEADER = '%'; - /** a line starting with [ indicates RESULT */ - public final static int RESULT = '['; - /** a line which matches the pattern of prompt1 is a PROMPT */ - public final static int PROMPT = '.'; - /** a line which matches the pattern of prompt2 is a MORE */ - public final static int MORE = ','; - /** a line starting with & indicates the start of a header block */ - public final static int SOHEADER = '&'; - /** a line starting with ^ indicates REDIRECT */ - public final static int REDIRECT = '^'; - /** a line starting with # indicates INFO */ - public final static int INFO = '#'; - /** * Create a buffering character-input stream that uses a * default-sized input buffer. @@ -94,7 +93,7 @@ public class BufferedMCLReader extends B * carriage return followed immediately by a linefeed. Before this * method returns, it sets the linetype to any of the in MCL * recognised line types. - * + * * Warning: until the server properly prefixes all of its error * messages with SQLSTATE codes, this method prefixes all errors it * sees without sqlstate with the generic data exception code @@ -120,38 +119,38 @@ public class BufferedMCLReader extends B * * @param line the string to examine */ - void setLineType(String line) { + public void setLineType(String line) { lineType = UNKNOWN; if (line == null || line.length() == 0) return; switch (line.charAt(0)) { case '!': lineType = ERROR; - break; + break; case '&': lineType = SOHEADER; - break; + break; case '%': lineType = HEADER; - break; + break; case '[': lineType = RESULT; - break; + break; case '=': lineType = RESULT; - break; + break; case '^': lineType = REDIRECT; - break; + break; case '#': lineType = INFO; - break; + break; case '.': lineType = PROMPT; - break; + break; case ',': lineType = MORE; - break; + break; } } @@ -171,25 +170,26 @@ public class BufferedMCLReader extends B * for a new command. All read data is discarded. If the last line * read by readLine() was a prompt, this method will immediately * return. - * + * * If there are errors present in the lines that are read, then they * are put in one string and returned <b>after</b> the prompt has * been found. If no errors are present, null will be returned. * * @return a string containing error messages, or null if there aren't any * @throws IOException if an IO exception occurs while talking to the server - * - * TODO(Wouter): should probably not have to be synchronized. + StringBuilder... + * + * TODO(Wouter): should probably not have to be synchronized. */ final public synchronized String waitForPrompt() throws IOException { - String ret = "", tmp; + String tmp; + StringBuilder ret = new StringBuilder(128); while (lineType != PROMPT) { - if ((tmp = readLine()) == null) + tmp = readLine(); + if (tmp == null) throw new IOException("Connection to server lost!"); if (lineType == ERROR) - ret += "\n" + tmp.substring(1); + ret.append('\n').append(tmp.substring(1)); } - return ret == "" ? null : ret.trim(); + return ret.length() == 0 ? null : ret.toString().trim(); } - } diff --git a/src/main/java/nl/cwi/monetdb/mcl/io/BufferedMCLWriter.java b/src/main/java/nl/cwi/monetdb/mcl/io/BufferedMCLWriter.java --- a/src/main/java/nl/cwi/monetdb/mcl/io/BufferedMCLWriter.java +++ b/src/main/java/nl/cwi/monetdb/mcl/io/BufferedMCLWriter.java @@ -34,7 +34,7 @@ import java.io.Writer; * * @author Fabian Groffen <Fabian.Groffen> * @see nl.cwi.monetdb.mcl.net.MapiSocket - * @see nl.cwi.monetdb.mcl.io.BufferedMCLWriter + * @see nl.cwi.monetdb.mcl.io.BufferedMCLReader */ public class BufferedMCLWriter extends BufferedWriter { private BufferedMCLReader reader; @@ -63,6 +63,18 @@ public class BufferedMCLWriter extends B } /** + * Write a line separator. The line separator string is in this + * class always the single newline character '\n'. + * + * @throws IOException If an I/O error occurs + */ + @Override + public void newLine() throws IOException { + write('\n'); + } + + + /** * Registers the given reader in this writer. A registered reader * receives a linetype reset when a line is written from this * writer. @@ -74,17 +86,6 @@ public class BufferedMCLWriter extends B } /** - * Write a line separator. The line separator string is in this - * class always the single newline character '\n'. - * - * @throws IOException If an I/O error occurs - */ - @Override - public void newLine() throws IOException { - write('\n'); - } - - /** * Write a single line, terminated with a line separator, and flush * the stream. This is a shorthand method for a call to write() * and flush(). @@ -96,6 +97,7 @@ public class BufferedMCLWriter extends B write(line); flush(); // reset reader state, last line isn't valid any more now - if (reader != null) reader.setLineType(null); + if (reader != null) + reader.setLineType(null); } } diff --git a/src/main/java/nl/cwi/monetdb/mcl/net/MapiSocket.java b/src/main/java/nl/cwi/monetdb/mcl/net/MapiSocket.java --- a/src/main/java/nl/cwi/monetdb/mcl/net/MapiSocket.java +++ b/src/main/java/nl/cwi/monetdb/mcl/net/MapiSocket.java @@ -252,15 +252,16 @@ public final class MapiSocket { * @throws MCLException if an MCL related error occurs */ public List<String> connect(String host, int port, String user, String pass) - throws IOException, MCLParseException, MCLException { + throws IOException, MCLParseException, MCLException + { // Wrap around the internal connect that needs to know if it // should really make a TCP connection or not. return connect(host, port, user, pass, true); } - private List<String> connect(String host, int port, String user, String pass, - boolean makeConnection) - throws IOException, MCLParseException, MCLException { + private List<String> connect(String host, int port, String user, String pass, boolean makeConnection) + throws IOException, MCLParseException, MCLException + { if (ttl-- <= 0) throw new MCLException("Maximum number of redirects reached, aborting connection attempt. Sorry."); @@ -385,7 +386,7 @@ public final class MapiSocket { close(); } tmp = u.getPath(); - if (tmp != null && tmp.length() != 0) { + if (tmp != null && tmp.length() > 0) { tmp = tmp.substring(1).trim(); if (!tmp.isEmpty() && !tmp.equals(database)) { warns.add("redirect points to different " + "database: " + tmp); @@ -438,8 +439,8 @@ public final class MapiSocket { _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list