java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java
branchv_0
changeset 2 72da10f632b5
parent 1 f32dac78d13a
child 3 efdf2b886feb
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java	Sun Dec 15 19:20:50 2013 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java	Sun Dec 15 20:16:27 2013 +0100
     1.3 @@ -14,7 +14,13 @@
     1.4  	private String sql;
     1.5  	private String databaseName;
     1.6  	private boolean batch;
     1.7 -	
     1.8 +
     1.9 +	public enum MODE {
    1.10 +
    1.11 +		QUERY_NOW,
    1.12 +		PREPARE_BATCH,
    1.13 +		EXECUTE_BATCH
    1.14 +	}
    1.15  
    1.16  	public enum COMMAND_TYPE {
    1.17  
    1.18 @@ -30,12 +36,7 @@
    1.19  	public void validate() throws InvalidOptionsException {
    1.20  		InvalidOptionsException e = new InvalidOptionsException();
    1.21  
    1.22 -		if ( //
    1.23 -				(hasDb() ? 1 : 0) + //
    1.24 -				(hasSql() ? 1 : 0) + //
    1.25 -				(hasBatch() ? 1 : 0)
    1.26 -				!= 2) //
    1.27 -		{
    1.28 +		if (getMode() == null) {
    1.29  			e.addProblem(new InvalidOptionsException.OptionProblem("Invalid combination of DB, SQL and BATCH – please specify just 2 of this 3 options"));
    1.30  		}
    1.31  
    1.32 @@ -49,15 +50,73 @@
    1.33  		}
    1.34  	}
    1.35  
    1.36 -	public boolean hasSql() {
    1.37 -		return isNotEmpty(sql, true);
    1.38 +	private boolean hasSql() {
    1.39 +		return isNotEmpty(getSql(), true);
    1.40  	}
    1.41  
    1.42 -	public boolean hasDb() {
    1.43 -		return isNotEmpty(databaseName, true);
    1.44 +	private boolean hasDb() {
    1.45 +		return isNotEmpty(getDatabaseName(), true);
    1.46  	}
    1.47  
    1.48 -	public boolean hasBatch() {
    1.49 -		return batch;
    1.50 +	/**
    1.51 +	 * Depends on options: DB, BATCH, SQL
    1.52 +	 *
    1.53 +	 * @return mode | or null if options are not yet initialized or combination of options is
    1.54 +	 * invalid
    1.55 +	 */
    1.56 +	public MODE getMode() {
    1.57 +		if (hasDb() && !batch && hasSql()) {
    1.58 +			return MODE.QUERY_NOW;
    1.59 +		} else if (!hasDb() && batch && hasSql()) {
    1.60 +			return MODE.PREPARE_BATCH;
    1.61 +		} else if (hasDb() && batch && !hasSql()) {
    1.62 +			return MODE.EXECUTE_BATCH;
    1.63 +		} else {
    1.64 +			return null;
    1.65 +		}
    1.66 +	}
    1.67 +
    1.68 +	public String getSql() {
    1.69 +		return sql;
    1.70 +	}
    1.71 +
    1.72 +	public void setSql(String sql) {
    1.73 +		this.sql = sql;
    1.74 +	}
    1.75 +
    1.76 +	public String getDatabaseName() {
    1.77 +		return databaseName;
    1.78 +	}
    1.79 +
    1.80 +	public void setDatabaseName(String databaseName) {
    1.81 +		this.databaseName = databaseName;
    1.82 +	}
    1.83 +
    1.84 +	public void setBatch(boolean batch) {
    1.85 +		this.batch = batch;
    1.86 +	}
    1.87 +
    1.88 +	public COMMAND_TYPE getCommandType() {
    1.89 +		return commandType;
    1.90 +	}
    1.91 +
    1.92 +	public void setCommandType(COMMAND_TYPE commandType) {
    1.93 +		this.commandType = commandType;
    1.94 +	}
    1.95 +
    1.96 +	public Collection<NamedParameter> getNamedParameters() {
    1.97 +		return namedParameters;
    1.98 +	}
    1.99 +
   1.100 +	public List<Parameter> getNumberedParameters() {
   1.101 +		return numberedParameters;
   1.102 +	}
   1.103 +
   1.104 +	public void addNumberedParameter(Parameter p) {
   1.105 +		numberedParameters.add(p);
   1.106 +	}
   1.107 +
   1.108 +	public void addNamedParameter(NamedParameter p) {
   1.109 +		namedParameters.add(p);
   1.110  	}
   1.111  }