--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java Sun Dec 15 19:20:50 2013 +0100
@@ -0,0 +1,63 @@
+package info.globalcode.sql.dk;
+
+import static info.globalcode.sql.dk.Functions.isNotEmpty;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ *
+ * @author Ing. František Kučera (frantovo.cz)
+ */
+public class CLIOptions {
+
+ private String sql;
+ private String databaseName;
+ private boolean batch;
+
+
+ public enum COMMAND_TYPE {
+
+ /** SELECT */
+ QUERY,
+ /** INSERT, UPDATE, DELETE */
+ UPDATE
+ };
+ private COMMAND_TYPE commandType;
+ private final Collection<NamedParameter> namedParameters = new ArrayList<>();
+ private final List<Parameter> numberedParameters = new ArrayList<>();
+
+ public void validate() throws InvalidOptionsException {
+ InvalidOptionsException e = new InvalidOptionsException();
+
+ if ( //
+ (hasDb() ? 1 : 0) + //
+ (hasSql() ? 1 : 0) + //
+ (hasBatch() ? 1 : 0)
+ != 2) //
+ {
+ e.addProblem(new InvalidOptionsException.OptionProblem("Invalid combination of DB, SQL and BATCH – please specify just 2 of this 3 options"));
+ }
+
+ if (!namedParameters.isEmpty() && !numberedParameters.isEmpty()) {
+ e.addProblem(new InvalidOptionsException.OptionProblem("Named and numbered parameters can not be used together in one command."));
+ }
+
+
+ if (e.hasProblems()) {
+ throw e;
+ }
+ }
+
+ public boolean hasSql() {
+ return isNotEmpty(sql, true);
+ }
+
+ public boolean hasDb() {
+ return isNotEmpty(databaseName, true);
+ }
+
+ public boolean hasBatch() {
+ return batch;
+ }
+}