java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java
branchv_0
changeset 68 574cd7fbb5b2
parent 62 7a88ac6ba40c
child 69 0befec5034c2
--- 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<String, Integer> types;
-
-	public CLIParser() {
-		Map<String, Integer> 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<Integer> numberedTypes = new ArrayList<>();
-		Map<String, Integer> namedTypes = new HashMap<>();
+		List<SQLType> numberedTypes = new ArrayList<>();
+		Map<String, SQLType> 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);
 		}
 	}
 }