Mercurial > hg > monetdb-java
changeset 126:6c74540a8e6b embedded
Following static methods naming conventions
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java @@ -51,7 +51,7 @@ public abstract class MonetConnection ex * * @return The current sequence counter */ - public static int GetSeqCounter() { + public static int getSeqCounter() { return SeqCounter; }
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetDriver.java.in @@ -69,7 +69,7 @@ public final class MonetDriver implement /** MonetDB default port to connect to */ private static final String PORT = "@JDBC_DEF_PORT@"; - private static Class EmbeddedConnectionClass = null; + private static Class embeddedConnectionClass = null; // initialize this class: register it at the DriverManager // Chapter 9.2 from Sun JDBC 3.0 specification @@ -413,13 +413,13 @@ public final class MonetDriver implement if (directory == null || directory.trim().isEmpty()) throw new IllegalArgumentException("directory should not be null or empty"); - if(EmbeddedConnectionClass == null) { - EmbeddedConnectionClass = Class.forName("nl.cwi.monetdb.embedded.jdbc.EmbeddedConnection"); - if(EmbeddedConnectionClass == null) { //if it's still null then there is a problem + if(embeddedConnectionClass == null) { + embeddedConnectionClass = Class.forName("nl.cwi.monetdb.embedded.jdbc.EmbeddedConnection"); + if(embeddedConnectionClass == null) { //if it is still null then there is a problem! throw new SQLException("EmbeddedConnection Class not found! Please add the MonetDBJavaEmbedded JAR to the Classpath!"); } } - res = (MonetConnection) EmbeddedConnectionClass + res = (MonetConnection) embeddedConnectionClass .getDeclaredConstructor(Properties.class, String.class, String.class, String.class) .newInstance(props, hash, language, directory); } catch (InvocationTargetException | InstantiationException | IllegalAccessException |
--- a/src/main/java/nl/cwi/monetdb/mcl/connection/helpers/BufferReallocator.java +++ b/src/main/java/nl/cwi/monetdb/mcl/connection/helpers/BufferReallocator.java @@ -30,7 +30,7 @@ public final class BufferReallocator { * @param buffer The buffer whose capacity will be expanded * @return The buffer's new capacity */ - private static int GetNewCapacity(CharBuffer buffer) { + private static int getNewCapacity(CharBuffer buffer) { int minCapacity = buffer.capacity() << 1; int newCapacity = (buffer.capacity() << 1) + 2; if (newCapacity - minCapacity < 0) { @@ -53,8 +53,8 @@ public final class BufferReallocator { * @param buffer The buffer whose capacity will be expanded * @return The new buffer allocated */ - public static CharBuffer ReallocateBuffer(CharBuffer buffer) { - int newCapacity = GetNewCapacity(buffer); + public static CharBuffer reallocateBuffer(CharBuffer buffer) { + int newCapacity = getNewCapacity(buffer); CharBuffer newBuffer = CharBuffer.wrap(new char[newCapacity]); buffer.flip(); newBuffer.put(buffer.array()); @@ -69,7 +69,7 @@ public final class BufferReallocator { * @param capacityThreshold The capacity threshold to test * @return The original buffer or the new one allocated */ - public static CharBuffer EnsureCapacity(CharBuffer buffer, int capacityThreshold) { + public static CharBuffer ensureCapacity(CharBuffer buffer, int capacityThreshold) { if(capacityThreshold > buffer.capacity()) { buffer = CharBuffer.wrap(new char[capacityThreshold]); }
--- a/src/main/java/nl/cwi/monetdb/mcl/connection/helpers/ChannelSecurity.java +++ b/src/main/java/nl/cwi/monetdb/mcl/connection/helpers/ChannelSecurity.java @@ -18,7 +18,7 @@ import java.security.NoSuchAlgorithmExce */ public final class ChannelSecurity { - private static char HexChar(int n) { return (n > 9) ? (char) ('a' + (n - 10)) : (char) ('0' + n); } + private static char hexChar(int n) { return (n > 9) ? (char) ('a' + (n - 10)) : (char) ('0' + n); } /** * Helper method to convert a byte string to a hexadecimal String representation. @@ -26,12 +26,12 @@ public final class ChannelSecurity { * @param digest The byte array to convert * @return The byte array as a hexadecimal string */ - private static String ToHex(byte[] digest) { + private static String toHex(byte[] digest) { char[] result = new char[digest.length * 2]; int pos = 0; for (byte aDigest : digest) { - result[pos++] = HexChar((aDigest & 0xf0) >> 4); - result[pos++] = HexChar(aDigest & 0x0f); + result[pos++] = hexChar((aDigest & 0xf0) >> 4); + result[pos++] = hexChar(aDigest & 0x0f); } return new String(result); } @@ -43,13 +43,13 @@ public final class ChannelSecurity { * @param toDigests The Strings to digest * @return The Strings digest as a hexadecimal string */ - public static String DigestStrings(String algorithm, byte[]... toDigests) { + public static String digestStrings(String algorithm, byte[]... toDigests) { try { MessageDigest md = MessageDigest.getInstance(algorithm); for (byte[] str : toDigests) { md.update(str); } - return ToHex(md.digest()); + return toHex(md.digest()); } catch (NoSuchAlgorithmException e) { throw new AssertionError("internal error: " + e.toString()); }
--- a/src/main/java/nl/cwi/monetdb/mcl/connection/helpers/GregorianCalendarParser.java +++ b/src/main/java/nl/cwi/monetdb/mcl/connection/helpers/GregorianCalendarParser.java @@ -44,8 +44,8 @@ public final class GregorianCalendarPars } } - /** The time zone information, to be resused to avoid memory allocations */ - private static final TimeZone DefaultTimeZone = TimeZone.getDefault(); + /** The time zone information, to be re-used to avoid memory allocations */ + private static final TimeZone defaultTimeZone = TimeZone.getDefault(); /** * Parses a date or time or timestamp MAPI String into a Java {@link Calendar} instance. @@ -57,14 +57,14 @@ public final class GregorianCalendarPars * @param jdbcType The JDBC type of the column * @return A {@link Calendar} instance of the parsed date */ - public static Calendar ParseDateString(MonetResultSet mrs, String toParse, ParsePosition pos, + public static Calendar parseDateString(MonetResultSet mrs, String toParse, ParsePosition pos, SimpleDateFormat parser, int jdbcType) { pos.setIndex(0); Calendar res = new GregorianCalendar(); if(jdbcType == Types.TIME || jdbcType == Types.TIMESTAMP || jdbcType == Types.DATE) { parser.setTimeZone(TimeZone.getTimeZone("GMT" + toParse.substring(toParse.length() - 6))); } else { - parser.setTimeZone(DefaultTimeZone); + parser.setTimeZone(defaultTimeZone); } Date aux = parser.parse(toParse, pos); @@ -123,7 +123,7 @@ public final class GregorianCalendarPars * @return A {@link Calendar} instance of the parsed date * @throws ProtocolException If the String could not be parsed */ - public static Calendar ParseDate(String toParse, ParsePosition pos, SimpleDateFormat parser) + public static Calendar parseDate(String toParse, ParsePosition pos, SimpleDateFormat parser) throws ProtocolException { pos.setIndex(0); Calendar res = new GregorianCalendar(); @@ -146,13 +146,13 @@ public final class GregorianCalendarPars * @return A {@link Calendar} instance of the parsed time * @throws ProtocolException If the String could not be parsed */ - public static Calendar ParseTime(String toParse, ParsePosition pos, SimpleDateFormat parser, boolean hasTimeZone) + public static Calendar parseTime(String toParse, ParsePosition pos, SimpleDateFormat parser, boolean hasTimeZone) throws ProtocolException { pos.setIndex(0); if(hasTimeZone) { // MonetDB/SQL99: Sign TwoDigitHours : Minutes parser.setTimeZone(TimeZone.getTimeZone("GMT" + toParse.substring(toParse.length() - 6))); } else { - parser.setTimeZone(DefaultTimeZone); + parser.setTimeZone(defaultTimeZone); } Calendar res = new GregorianCalendar(); @@ -175,13 +175,13 @@ public final class GregorianCalendarPars * @return A {@link TimestampHelper} instance of the parsed timestamp with nanos information * @throws ProtocolException If the String could not be parsed */ - public static TimestampHelper ParseTimestamp(String toParse, ParsePosition pos, SimpleDateFormat parser, + public static TimestampHelper parseTimestamp(String toParse, ParsePosition pos, SimpleDateFormat parser, boolean hasTimeZone) throws ProtocolException { pos.setIndex(0); if(hasTimeZone) { // MonetDB/SQL99: Sign TwoDigitHours : Minutes parser.setTimeZone(TimeZone.getTimeZone("GMT" + toParse.substring(toParse.length() - 6))); } else { - parser.setTimeZone(DefaultTimeZone); + parser.setTimeZone(defaultTimeZone); } GregorianCalendar res = new GregorianCalendar();
--- a/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/AbstractSocket.java +++ b/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/AbstractSocket.java @@ -184,7 +184,7 @@ public abstract class AbstractSocket imp found = true; } else { if(destinationPosition + 1 >= destinationLimit) { - lineBuffer = BufferReallocator.ReallocateBuffer(lineBuffer); + lineBuffer = BufferReallocator.reallocateBuffer(lineBuffer); destinationArray = lineBuffer.array(); destinationLimit = lineBuffer.limit(); }
--- a/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java +++ b/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiConnection.java @@ -57,7 +57,7 @@ public class MapiConnection extends Mone public MapiConnection(Properties props, String hash, String language, boolean blobIsBinary, boolean clobIsLongChar, String hostname, int port, String database) throws IOException { - super(props, hash, MapiLanguage.GetLanguageFromString(language), blobIsBinary, clobIsLongChar); + super(props, hash, MapiLanguage.getLanguageFromString(language), blobIsBinary, clobIsLongChar); this.hostname = hostname; this.port = port; this.database = database; @@ -356,7 +356,7 @@ public class MapiConnection extends Mone case "language": tmp = arg.substring(pos + 1); warns.add("redirect specifies use of different language: " + tmp); - this.language = MapiLanguage.GetLanguageFromString(tmp); + this.language = MapiLanguage.getLanguageFromString(tmp); break; case "user": tmp = arg.substring(pos + 1); @@ -481,7 +481,7 @@ public class MapiConnection extends Mone throw new MCLException("Unsupported password hash: " + chaltok[5]); } - password = ChannelSecurity.DigestStrings(algo, password.getBytes("UTF-8")); + password = ChannelSecurity.digestStrings(algo, password.getBytes("UTF-8")); // proto 7 (finally) used the challenge and works with a password hash. The supported implementations // come from the server challenge. We chose the best hash we can find, in the order SHA1, MD5, plain. @@ -517,7 +517,7 @@ public class MapiConnection extends Mone throw new MCLException("No supported password hashes in " + hashes); } - pwhash += ChannelSecurity.DigestStrings(algo, password.getBytes("UTF-8"), + pwhash += ChannelSecurity.digestStrings(algo, password.getBytes("UTF-8"), challenge.getBytes("UTF-8")); // generate response
--- a/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiLanguage.java +++ b/src/main/java/nl/cwi/monetdb/mcl/connection/mapi/MapiLanguage.java @@ -61,7 +61,7 @@ public enum MapiLanguage implements IMon return representation; } - public static MapiLanguage GetLanguageFromString(String language) { + public static MapiLanguage getLanguageFromString(String language) { switch (language) { case "sql": return LANG_SQL;
--- a/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiProtocol.java +++ b/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiProtocol.java @@ -96,7 +96,7 @@ public class OldMapiProtocol extends Abs if(this.lineBuffer.limit() == 0) { throw new IOException("Connection to server lost!"); } - this.currentServerResponseHeader = OldMapiServerResponseParser.ParseOldMapiServerResponse(this); + this.currentServerResponseHeader = OldMapiServerResponseParser.parseOldMapiServerResponse(this); this.lineBuffer.position(0); if (this.currentServerResponseHeader == ServerResponses.ERROR) { this.lineBuffer.position(1); @@ -118,7 +118,7 @@ public class OldMapiProtocol extends Abs if(this.lineBuffer.limit() == 0) { throw new IOException("Connection to server lost!"); } - this.currentServerResponseHeader = OldMapiServerResponseParser.ParseOldMapiServerResponse(this); + this.currentServerResponseHeader = OldMapiServerResponseParser.parseOldMapiServerResponse(this); if (this.currentServerResponseHeader == ServerResponses.ERROR && !this.lineBuffer.toString() .matches("^[0-9A-Z]{5}!.+")) { int limit = this.lineBuffer.limit(); @@ -139,7 +139,7 @@ public class OldMapiProtocol extends Abs */ @Override public int getNextStarterHeader() { - return OldMapiStartOfHeaderParser.GetNextStartHeaderOnOldMapi(this); + return OldMapiStartOfHeaderParser.getNextStartHeaderOnOldMapi(this); } /** @@ -155,10 +155,10 @@ public class OldMapiProtocol extends Abs @Override public ResultSetResponse getNextResultSetResponse(MonetConnection con, MonetConnection.ResponseList list, int seqnr, int maxrows) throws ProtocolException { - int id = OldMapiStartOfHeaderParser.GetNextResponseDataAsInt(this); //The order cannot be switched!! - int tuplecount = OldMapiStartOfHeaderParser.GetNextResponseDataAsInt(this); - int columncount = OldMapiStartOfHeaderParser.GetNextResponseDataAsInt(this); - int rowcount = OldMapiStartOfHeaderParser.GetNextResponseDataAsInt(this); + int id = OldMapiStartOfHeaderParser.getNextResponseDataAsInt(this); //The order cannot be switched!! + int tuplecount = OldMapiStartOfHeaderParser.getNextResponseDataAsInt(this); + int columncount = OldMapiStartOfHeaderParser.getNextResponseDataAsInt(this); + int rowcount = OldMapiStartOfHeaderParser.getNextResponseDataAsInt(this); if (maxrows != 0 && tuplecount > maxrows) { tuplecount = maxrows; } @@ -173,8 +173,8 @@ public class OldMapiProtocol extends Abs */ @Override public UpdateResponse getNextUpdateResponse() throws ProtocolException { - int count = OldMapiStartOfHeaderParser.GetNextResponseDataAsInt(this); //The order cannot be switched!! - int lastId = OldMapiStartOfHeaderParser.GetNextResponseDataAsInt(this); + int count = OldMapiStartOfHeaderParser.getNextResponseDataAsInt(this); //The order cannot be switched!! + int lastId = OldMapiStartOfHeaderParser.getNextResponseDataAsInt(this); return new UpdateResponse(lastId, count); } @@ -207,10 +207,10 @@ public class OldMapiProtocol extends Abs @Override public AbstractDataBlockResponse getNextDatablockResponse(Map<Integer, ResultSetResponse> rsresponses) throws ProtocolException { - int id = OldMapiStartOfHeaderParser.GetNextResponseDataAsInt(this); //The order cannot be switched!! - OldMapiStartOfHeaderParser.GetNextResponseDataAsInt(this); //column count - int rowcount = OldMapiStartOfHeaderParser.GetNextResponseDataAsInt(this); - int offset = OldMapiStartOfHeaderParser.GetNextResponseDataAsInt(this); + int id = OldMapiStartOfHeaderParser.getNextResponseDataAsInt(this); //The order cannot be switched!! + OldMapiStartOfHeaderParser.getNextResponseDataAsInt(this); //column count + int rowcount = OldMapiStartOfHeaderParser.getNextResponseDataAsInt(this); + int offset = OldMapiStartOfHeaderParser.getNextResponseDataAsInt(this); ResultSetResponse rs = rsresponses.get(id); if (rs == null) { @@ -232,7 +232,7 @@ public class OldMapiProtocol extends Abs @Override public int getNextTableHeader(String[] columnNames, int[] columnLengths, String[] types, String[] tableNames) throws ProtocolException { - return OldMapiTableHeaderParser.GetNextTableHeader(this.lineBuffer, columnNames, columnLengths, types, + return OldMapiTableHeaderParser.getNextTableHeader(this.lineBuffer, columnNames, columnLengths, types, tableNames); } @@ -247,7 +247,7 @@ public class OldMapiProtocol extends Abs * @throws ProtocolException If an error in the underlying connection happened. */ int parseTupleLines(int firstLineNumber, int[] typesMap, Object[] values) throws ProtocolException { - OldMapiTupleLineParser.OldMapiParseTupleLine(this, firstLineNumber, typesMap, values); + OldMapiTupleLineParser.oldMapiParseTupleLine(this, firstLineNumber, typesMap, values); return firstLineNumber; }
--- a/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiServerResponseParser.java +++ b/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiServerResponseParser.java @@ -25,7 +25,7 @@ final class OldMapiServerResponseParser * @param protocol An Old MAPI protocol instance from which the next server response will be retrieved * @return The integer representation of the next server response */ - static int ParseOldMapiServerResponse(OldMapiProtocol protocol) { + static int parseOldMapiServerResponse(OldMapiProtocol protocol) { int res; switch (protocol.lineBuffer.get()) { case '!':
--- a/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiStartOfHeaderParser.java +++ b/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiStartOfHeaderParser.java @@ -21,7 +21,7 @@ final class OldMapiStartOfHeaderParser { private OldMapiStartOfHeaderParser() {} - static int GetNextStartHeaderOnOldMapi(OldMapiProtocol protocol) { + static int getNextStartHeaderOnOldMapi(OldMapiProtocol protocol) { int res; switch (protocol.lineBuffer.get()) { case '0': @@ -64,7 +64,7 @@ final class OldMapiStartOfHeaderParser { * @return The next token in the Protocol as an integer * @throws ProtocolException if no numeric value could be read */ - static int GetNextResponseDataAsInt(OldMapiProtocol protocol) throws ProtocolException { + static int getNextResponseDataAsInt(OldMapiProtocol protocol) throws ProtocolException { int currentPointer = protocol.lineBuffer.position(); int limit = protocol.lineBuffer.limit(); char[] array = protocol.lineBuffer.array(); @@ -108,7 +108,7 @@ final class OldMapiStartOfHeaderParser { * @return The next token in the Protocol as a String * @throws ProtocolException if no character could be read */ - static String GetNextResponseDataAsString(OldMapiProtocol protocol) throws ProtocolException { + static String getNextResponseDataAsString(OldMapiProtocol protocol) throws ProtocolException { int currentPointer = protocol.lineBuffer.position(); int limit = protocol.lineBuffer.limit(); char[] array = protocol.lineBuffer.array();
--- a/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiTableHeaderParser.java +++ b/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiTableHeaderParser.java @@ -34,8 +34,8 @@ final class OldMapiTableHeaderParser { * @return The integer representation of the Table Result Header retrieved * @throws ProtocolException If an error while parsing occurred */ - static int GetNextTableHeader(CharBuffer lineBuffer, String[] columnNames, int[] columnLengths, - String[] types, String[] tableNames) throws ProtocolException { + static int getNextTableHeader(CharBuffer lineBuffer, String[] columnNames, int[] columnLengths, String[] types, + String[] tableNames) throws ProtocolException { int res = TableResultHeaders.UNKNOWN; int currentLength = lineBuffer.limit(); char[] array = lineBuffer.array(); @@ -75,22 +75,22 @@ final class OldMapiTableHeaderParser { switch (array[pos]) { case 'n': //name if (currentLength - pos == 4) { - GetStringValues(array, pos - 3, columnNames); + getStringValues(array, pos - 3, columnNames); res = TableResultHeaders.NAME; } break; case 'l': //length if (currentLength - pos == 6) { - GetIntValues(array, pos - 3, columnLengths); + getIntValues(array, pos - 3, columnLengths); res = TableResultHeaders.LENGTH; } break; case 't': if (currentLength - pos == 4) { //type - GetStringValues(array, pos - 3, types); + getStringValues(array, pos - 3, types); res = TableResultHeaders.TYPE; } else if (currentLength - pos == 10) { //table_name - GetStringValues(array, pos - 3, tableNames); + getStringValues(array, pos - 3, tableNames); res = TableResultHeaders.TABLE; } break; @@ -112,7 +112,7 @@ final class OldMapiTableHeaderParser { * @param stop The position to stop parsing * @param stringValues The String array to fill */ - private static void GetStringValues(char[] array, int stop, String[] stringValues) { + private static void getStringValues(char[] array, int stop, String[] stringValues) { int elem = 0, start = 2; for (int i = start + 1; i < stop; i++) { @@ -139,7 +139,7 @@ final class OldMapiTableHeaderParser { * @param intValues The integer array to fill * @throws ProtocolException If an error while parsing occurred */ - private static void GetIntValues(char[] array, int stop, int[] intValues) throws ProtocolException { + private static void getIntValues(char[] array, int stop, int[] intValues) throws ProtocolException { int elem = 0, tmp = 0, start = 2; for (int i = start; i < stop; i++) {
--- a/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiTupleLineParser.java +++ b/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiTupleLineParser.java @@ -47,7 +47,7 @@ final class OldMapiTupleLineParser { * @return The number of columns parsed * @throws ProtocolException If an error occurs during parsing */ - static int OldMapiParseTupleLine(OldMapiProtocol protocol, int lineNumber, int[] typesMap, Object[] values) + static int oldMapiParseTupleLine(OldMapiProtocol protocol, int lineNumber, int[] typesMap, Object[] values) throws ProtocolException { CharBuffer lineBuffer = protocol.lineBuffer; CharBuffer tupleLineBuffer = protocol.tupleLineBuffer; @@ -61,7 +61,8 @@ final class OldMapiTupleLineParser { throw new ProtocolException(typesMap.length + " columns expected, but only single value found"); } // return the whole string but the leading = - OldMapiStringToJavaDataConversion(protocol, array, 1, len - 1, lineNumber, values[0], typesMap[0]); + oldMapiStringToJavaDataConversion(protocol, array, 1, len - 1, lineNumber, values[0], + typesMap[0]); return 1; } @@ -100,7 +101,7 @@ final class OldMapiTupleLineParser { if (array[cursor] == '"' && array[i - 2] == '"') { // reuse the tupleLineBuffer by cleaning it and ensure the capacity tupleLineBuffer.clear(); - tupleLineBuffer = BufferReallocator.EnsureCapacity(tupleLineBuffer, (i - 2) - (cursor + 1)); + tupleLineBuffer = BufferReallocator.ensureCapacity(tupleLineBuffer, (i - 2) - (cursor + 1)); for (int pos = cursor + 1; pos < i - 2; pos++) { if (array[cursor] == '\\' && pos + 1 < i - 2) { @@ -163,11 +164,14 @@ final class OldMapiTupleLineParser { } // put the unescaped string in the right place tupleLineBuffer.flip(); - OldMapiStringToJavaDataConversion(protocol, tupleLineBuffer.array(), 0, tupleLineBuffer.limit(), lineNumber, values[column], typesMap[column]); - } else if ((i - 1) - cursor == 4 && OldMapiTupleLineParserHelper.CharIndexOf(array, 0, array.length, NULL_STRING, 0,4, cursor) == cursor) { - SetNullValue(lineNumber, values[column], typesMap[column]); + oldMapiStringToJavaDataConversion(protocol, tupleLineBuffer.array(), 0, + tupleLineBuffer.limit(), lineNumber, values[column], typesMap[column]); + } else if ((i - 1) - cursor == 4 && OldMapiTupleLineParserHelper.charIndexOf(array, + 0,array.length, NULL_STRING, 0,4, cursor) == cursor) { + setNullValue(lineNumber, values[column], typesMap[column]); } else { - OldMapiStringToJavaDataConversion(protocol, array, cursor, i - 1 - cursor, lineNumber, values[column], typesMap[column]); + oldMapiStringToJavaDataConversion(protocol, array, cursor, i - 1 - cursor, lineNumber, + values[column], typesMap[column]); } column++; cursor = i + 1; @@ -180,7 +184,8 @@ final class OldMapiTupleLineParser { protocol.tupleLineBuffer = tupleLineBuffer; // check if this result is of the size we expected it to be if (column != typesMap.length) - throw new ProtocolException("illegal result length: " + column + "\nlast read: " + (column > 0 ? values[column - 1] : "<none>")); + throw new ProtocolException("illegal result length: " + column + "\nlast read: " + + (column > 0 ? values[column - 1] : "<none>")); return column; } @@ -192,7 +197,7 @@ final class OldMapiTupleLineParser { * @param count The number of characters to read from the starter position * @return A Java byte[] instance with the parsed BLOB */ - private static byte[] BinaryBlobConverter(char[] toParse, int startPosition, int count) { + private static byte[] binaryBlobConverter(char[] toParse, int startPosition, int count) { int len = (startPosition + count) / 2; byte[] res = new byte[len]; for (int i = 0; i < len; i++) { @@ -212,24 +217,24 @@ final class OldMapiTupleLineParser { * @param jDBCMapping The JDBC mapping of the value * @throws ProtocolException If the JDBC Mapping is unknown */ - private static void OldMapiStringToJavaDataConversion(OldMapiProtocol protocol, char[] toParse, int startPosition, + private static void oldMapiStringToJavaDataConversion(OldMapiProtocol protocol, char[] toParse, int startPosition, int count, int lineNumber, Object columnArray, int jDBCMapping) throws ProtocolException { switch (jDBCMapping) { case Types.BOOLEAN: - ((byte[]) columnArray)[lineNumber] = OldMapiTupleLineParserHelper.CharArrayToBoolean(toParse, startPosition); + ((byte[]) columnArray)[lineNumber] = OldMapiTupleLineParserHelper.charArrayToBoolean(toParse, startPosition); break; case Types.TINYINT: - ((byte[]) columnArray)[lineNumber] = OldMapiTupleLineParserHelper.CharArrayToByte(toParse, startPosition, count); + ((byte[]) columnArray)[lineNumber] = OldMapiTupleLineParserHelper.charArrayToByte(toParse, startPosition, count); break; case Types.SMALLINT: - ((short[]) columnArray)[lineNumber] = OldMapiTupleLineParserHelper.CharArrayToShort(toParse, startPosition, count); + ((short[]) columnArray)[lineNumber] = OldMapiTupleLineParserHelper.charArrayToShort(toParse, startPosition, count); break; case Types.INTEGER: - ((int[]) columnArray)[lineNumber] = OldMapiTupleLineParserHelper.CharArrayToInt(toParse, startPosition, count); + ((int[]) columnArray)[lineNumber] = OldMapiTupleLineParserHelper.charArrayToInt(toParse, startPosition, count); break; case Types.BIGINT: - ((long[]) columnArray)[lineNumber] = OldMapiTupleLineParserHelper.CharArrayToLong(toParse, startPosition, count); + ((long[]) columnArray)[lineNumber] = OldMapiTupleLineParserHelper.charArrayToLong(toParse, startPosition, count); break; case Types.REAL: ((float[]) columnArray)[lineNumber] = Float.parseFloat(new String(toParse, startPosition, count)); @@ -248,28 +253,33 @@ final class OldMapiTupleLineParser { ((String[]) columnArray)[lineNumber] = new String(toParse, startPosition, count); break; case Types.DATE: - ((Calendar[]) columnArray)[lineNumber] = GregorianCalendarParser.ParseDate(new String(toParse, startPosition, count), protocol.getMonetParserPosition(), protocol.getMonetDate()); + ((Calendar[]) columnArray)[lineNumber] = GregorianCalendarParser.parseDate(new String(toParse, startPosition, count), + protocol.getMonetParserPosition(), protocol.getMonetDate()); break; case Types.TIME: - ((Calendar[]) columnArray)[lineNumber] = GregorianCalendarParser.ParseTime(new String(toParse, startPosition, count), protocol.getMonetParserPosition(), protocol.timeParser, false); + ((Calendar[]) columnArray)[lineNumber] = GregorianCalendarParser.parseTime(new String(toParse, startPosition, count), + protocol.getMonetParserPosition(), protocol.timeParser, false); break; case 2013: //Types.TIME_WITH_TIMEZONE: - ((Calendar[]) columnArray)[lineNumber] = GregorianCalendarParser.ParseTime(new String(toParse, startPosition, count), protocol.getMonetParserPosition(), protocol.timeParser, true); + ((Calendar[]) columnArray)[lineNumber] = GregorianCalendarParser.parseTime(new String(toParse, startPosition, count), + protocol.getMonetParserPosition(), protocol.timeParser, true); break; case Types.TIMESTAMP: - ((TimestampHelper[]) columnArray)[lineNumber] = GregorianCalendarParser.ParseTimestamp(new String(toParse, startPosition, count), protocol.getMonetParserPosition(), protocol.timestampParser, false); + ((TimestampHelper[]) columnArray)[lineNumber] = GregorianCalendarParser.parseTimestamp(new String(toParse, startPosition, count), + protocol.getMonetParserPosition(), protocol.timestampParser, false); break; case 2014: //Types.TIMESTAMP_WITH_TIMEZONE: - ((TimestampHelper[]) columnArray)[lineNumber] = GregorianCalendarParser.ParseTimestamp(new String(toParse, startPosition, count), protocol.getMonetParserPosition(), protocol.timestampParser, true); + ((TimestampHelper[]) columnArray)[lineNumber] = GregorianCalendarParser.parseTimestamp(new String(toParse, startPosition, count), + protocol.getMonetParserPosition(), protocol.timestampParser, true); break; case Types.CLOB: ((MonetClob[]) columnArray)[lineNumber] = new MonetClob(toParse, startPosition, count); break; case Types.BLOB: - ((MonetBlob[]) columnArray)[lineNumber] = new MonetBlob(BinaryBlobConverter(toParse, startPosition, count)); + ((MonetBlob[]) columnArray)[lineNumber] = new MonetBlob(binaryBlobConverter(toParse, startPosition, count)); break; case Types.LONGVARBINARY: - ((byte[][]) columnArray)[lineNumber] = BinaryBlobConverter(toParse, startPosition, count); + ((byte[][]) columnArray)[lineNumber] = binaryBlobConverter(toParse, startPosition, count); break; default: throw new ProtocolException("Unknown JDBC mapping!"); @@ -284,7 +294,7 @@ final class OldMapiTupleLineParser { * @param columnArray The column array where the value will be appended * @param jDBCMapping The JDBC mapping of the value */ - private static void SetNullValue(int lineNumber, Object columnArray, int jDBCMapping) { + private static void setNullValue(int lineNumber, Object columnArray, int jDBCMapping) { switch (jDBCMapping) { case Types.BOOLEAN: case Types.TINYINT:
new file mode 100644 --- /dev/null +++ b/src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiTupleLineParserHelper.java @@ -0,0 +1,232 @@ +/* + * 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 - 2017 MonetDB B.V. + */ + +package nl.cwi.monetdb.mcl.protocol.oldmapi; + +import nl.cwi.monetdb.mcl.protocol.ProtocolException; + +/** + * This is a helper Class for the OldMapiTupleLineParser. The main objective of this class is to parse primitive types + * without any memory allocation for performance reasons. The code may seem to be boilerplate, but it has to be done + * this way to due to poor typing of the Java programming language. + * + * @author Pedro Ferreira + */ +final class OldMapiTupleLineParserHelper { + + private OldMapiTupleLineParserHelper() {} + + /** + * Checks if a char[] (target) is inside on another (source), retrieving the first index on the source, where the + * target is, if found. In other words this a Java implementation of the strstr function from the C standard. + * As we search always from the beginning of the source, the start parameter is not used. + * + * @param source The source char[] to search + * @param sourceCount The number of characters in the source array to search + * @param target The target char[] to be found + * @param targetCount The result set column SQL types + * @return The integer representation of the Table Result Header retrieved + */ + static int charIndexOf(char[] source, int sourceOffset, int sourceCount, char[] target, int targetOffset, + int targetCount, int fromIndex) { + if (fromIndex >= sourceCount) { + return (targetCount == 0 ? sourceCount : -1); + } + if (fromIndex < 0) { + fromIndex = 0; + } + if (targetCount == 0) { + return fromIndex; + } + + char first = target[targetOffset]; + int max = sourceOffset + (sourceCount - targetCount); + + for (int i = sourceOffset + fromIndex; i <= max; i++) { + /* Look for first character. */ + if (source[i] != first) { + while (++i <= max && source[i] != first); + } + if (i <= max) { + int j = i + 1; + int end = j + targetCount - 1; + for (int k = targetOffset + 1; j < end && source[j] == target[k]; j++, k++); + + if (j == end) { + /* Found whole string. */ + return i - sourceOffset; + } + } + } + return -1; + } + + /** + * The character array representation of a TRUE value. + */ + private static final char[] TRUE_CONSTANT = new char[]{'t','r','u','e'}; + + /** + * Converts a segment of a CharBuffer's backing array into a Java boolean. + * + * @param start The first position in the array to parse + * @param data The CharBuffer's backing array to parse + * @return 1 it's a true value, 0 if false + */ + static byte charArrayToBoolean(char[] data, int start) { + return charIndexOf(data, 0, data.length, TRUE_CONSTANT, 0, 4, start) + == start ? (byte)1 : (byte)0; + } + + /** + * Converts a segment of a CharBuffer's backing array into a Java byte. + * + * @param data The CharBuffer's backing array to parse + * @param start The first position in the array to parse + * @param count The number of characters to read from the starter position + * @return The parsed byte value + */ + static byte charArrayToByte(char[] data, int start, int count) throws ProtocolException { + byte tmp = 0; + int limit = start + count; + boolean positive = true; + char chr = data[start++]; + + if (chr >= '0' && chr <= '9') { + tmp = (byte)(chr - '0'); + } else if(chr == '-') { + positive = false; + } else { + throw new ProtocolException("Expected a digit at the position " + (start - 1)); + } + while (start < limit) { + chr = data[start++]; + if(chr == ' ') { + break; + } + tmp *= 10; + if (chr >= '0' && chr <= '9') { + tmp += chr - '0'; + } else { + throw new ProtocolException("Expected a digit at the position " + (start - 1)); + } + } + return positive ? tmp : (byte) -tmp; + } + + /** + * Converts a segment of a CharBuffer's backing array into a Java short. + * + * @param data The CharBuffer's backing array to parse + * @param start The first position in the array to parse + * @param count The number of characters to read from the starter position + * @return The parsed short value + */ + static short charArrayToShort(char[] data, int start, int count) throws ProtocolException { + short tmp = 0; + int limit = start + count; + boolean positive = true; + char chr = data[start++]; + + if (chr >= '0' && chr <= '9') { + tmp = (short)(chr - '0'); + } else if(chr == '-') { + positive = false; + } else { + throw new ProtocolException("Expected a digit at the position " + (start - 1)); + } + while (start < limit) { + chr = data[start++]; + if(chr == ' ') { + break; + } + tmp *= 10; + if (chr >= '0' && chr <= '9') { + tmp += chr - '0'; + } else { + throw new ProtocolException("Expected a digit at the position " + (start - 1)); + } + } + return positive ? tmp : (short) -tmp; + } + + /** + * Converts a segment of a CharBuffer's backing array into a Java int. + * + * @param data The CharBuffer's backing array to parse + * @param start The first position in the array to parse + * @param count The number of characters to read from the starter position + * @return The parsed int value + */ + static int charArrayToInt(char[] data, int start, int count) throws ProtocolException { + int tmp = 0, limit = start + count; + boolean positive = true; + char chr = data[start++]; + + if (chr >= '0' && chr <= '9') { + tmp = chr - '0'; + } else if(chr == '-') { + positive = false; + } else { + throw new ProtocolException("Expected a digit at the position " + (start - 1)); + } + while (start < limit) { + chr = data[start++]; + if(chr == ' ') { + break; + } else if(chr == '.') { //for intervals + continue; + } + tmp *= 10; + if (chr >= '0' && chr <= '9') { + tmp += (int)chr - (int)'0'; + } else { + throw new ProtocolException("Expected a digit at the position " + (start - 1)); + } + } + return positive ? tmp : -tmp; + } + + /** + * Converts a segment of a CharBuffer's backing array into a Java long. + * + * @param data The CharBuffer's backing array to parse + * @param start The first position in the array to parse + * @param count The number of characters to read from the starter position + * @return The parsed long value + */ + static long charArrayToLong(char[] data, int start, int count) throws ProtocolException { + long tmp = 0; + int limit = start + count; + boolean positive = true; + char chr = data[start++]; + + if (chr >= '0' && chr <= '9') { + tmp = chr - '0'; + } else if(chr == '-') { + positive = false; + } else { + throw new ProtocolException("Expected a digit at the position " + (start - 1)); + } + while (start < limit) { + chr = data[start++]; + if(chr == ' ') { + break; + } else if(chr == '.') { //for intervals + continue; + } + tmp *= 10; + if (chr >= '0' && chr <= '9') { + tmp += chr - '0'; + } else { + throw new ProtocolException("Expected a digit at the position " + (start - 1)); + } + } + return positive ? tmp : -tmp; + } +}
--- a/src/main/java/nl/cwi/monetdb/mcl/responses/AbstractDataBlockResponse.java +++ b/src/main/java/nl/cwi/monetdb/mcl/responses/AbstractDataBlockResponse.java @@ -197,7 +197,7 @@ public abstract class AbstractDataBlockR default: throw new SQLException("Internal error!", "M1M05"); } - return GregorianCalendarParser.ParseDateString(mrs, value, protocol.getMonetParserPosition(), aux, jdbcType); + return GregorianCalendarParser.parseDateString(mrs, value, protocol.getMonetParserPosition(), aux, jdbcType); } catch (ProtocolException e) { throw new SQLException(e); }
--- a/src/main/java/nl/cwi/monetdb/mcl/responses/ResultSetResponse.java +++ b/src/main/java/nl/cwi/monetdb/mcl/responses/ResultSetResponse.java @@ -337,7 +337,7 @@ public class ResultSetResponse implement for (int i = 0; i < block; i++) resultBlocks[i] = null; - if (MonetConnection.GetSeqCounter() - 1 == seqnr && !cacheSizeSetExplicitly && + if (MonetConnection.getSeqCounter() - 1 == seqnr && !cacheSizeSetExplicitly && tuplecount - row > cacheSize && cacheSize < con.getDefFetchsize() * 10) { // there has no query been issued after this one, so we can consider this an uninterrupted // continuation request. Let's once increase the cacheSize as it was not explicitly set,