1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java Thu Dec 26 01:53:15 2013 +0100
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java Thu Dec 26 11:58:14 2013 +0100
1.3 @@ -17,9 +17,7 @@
1.4 */
1.5 package info.globalcode.sql.dk;
1.6
1.7 -import java.sql.Types;
1.8 import java.util.ArrayList;
1.9 -import java.util.Collections;
1.10 import java.util.HashMap;
1.11 import java.util.List;
1.12 import java.util.Map;
1.13 @@ -31,24 +29,12 @@
1.14 public class CLIParser {
1.15
1.16 public static final String TYPE_NAME_SEPARATOR = ":";
1.17 - private final Map<String, Integer> types;
1.18 -
1.19 - public CLIParser() {
1.20 - Map<String, Integer> m = new HashMap<>();
1.21 - m.put("integer", Types.INTEGER);
1.22 - m.put("varchar", Types.VARCHAR);
1.23 - m.put("boolean", Types.BOOLEAN);
1.24 - /**
1.25 - * TODO: more types
1.26 - */
1.27 - types = Collections.unmodifiableMap(m);
1.28 - }
1.29
1.30 public CLIOptions parseOptions(String[] args) throws CLIParserException {
1.31 CLIOptions options = new CLIOptions();
1.32
1.33 - List<Integer> numberedTypes = new ArrayList<>();
1.34 - Map<String, Integer> namedTypes = new HashMap<>();
1.35 + List<SQLType> numberedTypes = new ArrayList<>();
1.36 + Map<String, SQLType> namedTypes = new HashMap<>();
1.37
1.38 for (int i = 0; i < args.length; i++) {
1.39 String arg = args[i];
1.40 @@ -90,7 +76,7 @@
1.41 parameter = new Parameter(arg, null);
1.42 } else {
1.43 int paramIndex = options.getNumberedParameters().size();
1.44 - int paramType;
1.45 + SQLType paramType;
1.46 try {
1.47 paramType = numberedTypes.get(paramIndex);
1.48 } catch (IndexOutOfBoundsException e) {
1.49 @@ -173,12 +159,11 @@
1.50 }
1.51 }
1.52
1.53 - private int getType(String typeString) throws CLIParserException {
1.54 - Integer type = types.get(typeString.trim());
1.55 - if (type == null) {
1.56 - throw new CLIParserException("Unsupported type: " + typeString);
1.57 - } else {
1.58 - return type;
1.59 + private SQLType getType(String typeString) throws CLIParserException {
1.60 + try {
1.61 + return SQLType.valueOf(typeString.trim());
1.62 + } catch (IllegalArgumentException e) {
1.63 + throw new CLIParserException("Unsupported type: " + typeString, e);
1.64 }
1.65 }
1.66 }