diff -r 10c9b9e54622 -r 574cd7fbb5b2 java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java Thu Dec 26 01:53:15 2013 +0100 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java Thu Dec 26 11:58:14 2013 +0100 @@ -17,9 +17,7 @@ */ package info.globalcode.sql.dk; -import java.sql.Types; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -31,24 +29,12 @@ public class CLIParser { public static final String TYPE_NAME_SEPARATOR = ":"; - private final Map types; - - public CLIParser() { - Map m = new HashMap<>(); - m.put("integer", Types.INTEGER); - m.put("varchar", Types.VARCHAR); - m.put("boolean", Types.BOOLEAN); - /** - * TODO: more types - */ - types = Collections.unmodifiableMap(m); - } public CLIOptions parseOptions(String[] args) throws CLIParserException { CLIOptions options = new CLIOptions(); - List numberedTypes = new ArrayList<>(); - Map namedTypes = new HashMap<>(); + List numberedTypes = new ArrayList<>(); + Map namedTypes = new HashMap<>(); for (int i = 0; i < args.length; i++) { String arg = args[i]; @@ -90,7 +76,7 @@ parameter = new Parameter(arg, null); } else { int paramIndex = options.getNumberedParameters().size(); - int paramType; + SQLType paramType; try { paramType = numberedTypes.get(paramIndex); } catch (IndexOutOfBoundsException e) { @@ -173,12 +159,11 @@ } } - private int getType(String typeString) throws CLIParserException { - Integer type = types.get(typeString.trim()); - if (type == null) { - throw new CLIParserException("Unsupported type: " + typeString); - } else { - return type; + private SQLType getType(String typeString) throws CLIParserException { + try { + return SQLType.valueOf(typeString.trim()); + } catch (IllegalArgumentException e) { + throw new CLIParserException("Unsupported type: " + typeString, e); } } }