1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java Sun Dec 15 23:54:51 2013 +0100
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java Sun Dec 15 23:58:58 2013 +0100
1.3 @@ -27,7 +27,7 @@
1.4 types = Collections.unmodifiableMap(m);
1.5 }
1.6
1.7 - public CLIOptions parseOptions(String[] args) {
1.8 + public CLIOptions parseOptions(String[] args) throws CLIParserException {
1.9 CLIOptions options = new CLIOptions();
1.10
1.11 List<Integer> numberedTypes = new ArrayList<>();
1.12 @@ -86,9 +86,9 @@
1.13 try {
1.14 paramType = numberedTypes.get(paramIndex);
1.15 } catch (IndexOutOfBoundsException e) {
1.16 - throw new IllegalArgumentException("Missing type for parameter #" + paramIndex, e);
1.17 + throw new CLIParserException("Missing type for parameter #" + paramIndex, e);
1.18 } catch (NullPointerException e) {
1.19 - throw new IllegalArgumentException("Invalid type definition for parameter #" + paramIndex, e);
1.20 + throw new CLIParserException("Invalid type definition for parameter #" + paramIndex, e);
1.21 }
1.22 parameter = new Parameter(arg, paramType);
1.23 }
1.24 @@ -97,17 +97,17 @@
1.25 }
1.26 break;
1.27 default:
1.28 - throw new IllegalArgumentException("Unknown option: " + arg);
1.29 + throw new CLIParserException("Unknown option: " + arg);
1.30 }
1.31 }
1.32 return options;
1.33 }
1.34
1.35 - private String fetchNext(String[] args, int index) {
1.36 + private String fetchNext(String[] args, int index) throws CLIParserException {
1.37 if (index < args.length) {
1.38 return args[index];
1.39 } else {
1.40 - throw new IllegalArgumentException("Expecting value for option: " + args[index - 1]);
1.41 + throw new CLIParserException("Expecting value for option: " + args[index - 1]);
1.42 }
1.43 }
1.44
1.45 @@ -126,10 +126,10 @@
1.46 }
1.47 }
1.48
1.49 - private int getType(String typeString) {
1.50 + private int getType(String typeString) throws CLIParserException {
1.51 Integer type = types.get(typeString);
1.52 if (type == null) {
1.53 - throw new IllegalArgumentException("Unsupported type: " + typeString);
1.54 + throw new CLIParserException("Unsupported type: " + typeString);
1.55 } else {
1.56 return type;
1.57 }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIParserException.java Sun Dec 15 23:58:58 2013 +0100
2.3 @@ -0,0 +1,23 @@
2.4 +package info.globalcode.sql.dk;
2.5 +
2.6 +/**
2.7 + *
2.8 + * @author Ing. František Kučera (frantovo.cz)
2.9 + */
2.10 +public class CLIParserException extends Exception {
2.11 +
2.12 + public CLIParserException() {
2.13 + }
2.14 +
2.15 + public CLIParserException(String message) {
2.16 + super(message);
2.17 + }
2.18 +
2.19 + public CLIParserException(Throwable cause) {
2.20 + super(cause);
2.21 + }
2.22 +
2.23 + public CLIParserException(String message, Throwable cause) {
2.24 + super(message, cause);
2.25 + }
2.26 +}
3.1 --- a/java/sql-dk/test/info/globalcode/sql/dk/CLIParserTest.java Sun Dec 15 23:54:51 2013 +0100
3.2 +++ b/java/sql-dk/test/info/globalcode/sql/dk/CLIParserTest.java Sun Dec 15 23:58:58 2013 +0100
3.3 @@ -24,7 +24,7 @@
3.4 }
3.5
3.6 @Test
3.7 - public void testParseOptions_QueryNow_Numbered() throws InvalidOptionsException {
3.8 + public void testParseOptions_QueryNow_Numbered() throws InvalidOptionsException, CLIParserException {
3.9 String[] args = new String[]{Tokens.DB, DATABASE_NAME_1, Tokens.SQL, SQL_1, Tokens.DATA, DATA_1, DATA_2, DATA_3};
3.10 CLIOptions options = parser.parseOptions(args);
3.11 options.validate();
3.12 @@ -42,8 +42,8 @@
3.13 }
3.14
3.15 @Test
3.16 - public void testParseOptions_QueryNow_Named() throws InvalidOptionsException {
3.17 - String[] args = new String[]{Tokens.DB, DATABASE_NAME_1, Tokens.SQL, SQL_1, Tokens.TYPES};
3.18 + public void testParseOptions_QueryNow_Named() throws InvalidOptionsException, CLIParserException {
3.19 + String[] args = new String[]{Tokens.DB, DATABASE_NAME_1, Tokens.SQL, SQL_1};
3.20 CLIOptions options = parser.parseOptions(args);
3.21 options.validate();
3.22
3.23 @@ -53,7 +53,7 @@
3.24 }
3.25
3.26 @Test
3.27 - public void testParseOptions_PrepareBatch() throws InvalidOptionsException {
3.28 + public void testParseOptions_PrepareBatch() throws InvalidOptionsException, CLIParserException {
3.29 String[] args = new String[]{Tokens.BATCH, Tokens.SQL, SQL_1};
3.30 CLIOptions options = parser.parseOptions(args);
3.31 options.validate();
3.32 @@ -63,7 +63,7 @@
3.33 }
3.34
3.35 @Test
3.36 - public void testParseOptions_ExecuteBatch() throws InvalidOptionsException {
3.37 + public void testParseOptions_ExecuteBatch() throws InvalidOptionsException, CLIParserException {
3.38 String[] args = new String[]{Tokens.BATCH, Tokens.DB, DATABASE_NAME_1};
3.39 CLIOptions options = parser.parseOptions(args);
3.40 options.validate();