Skip to content

Commit

Permalink
#209 merge in latest updates from 4.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-conway committed Jul 5, 2018
2 parents fed9d06 + e44ed7f commit 8f14ea0
Show file tree
Hide file tree
Showing 16 changed files with 295 additions and 94 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Project: Jargon-core API

### Date: 07/05/2018
### Release Version: 4.3.0.0-RELEASE
### git tag: 4.3.0.0-RELEASE

## News

4.2.3 Compatability and maintenance
for milestone: https://github.com/DICE-UNC/jargon/milestone/23
>>>>>>> origin/4-2-stable
https://github.com/DICE-UNC/jargon/milestone/24

Expand Down
1 change: 0 additions & 1 deletion jargon-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<parent>
<groupId>org.irods</groupId>
<artifactId>jargon</artifactId>

<version>4.3.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ class GenQueryBuilderCondition {
private final QueryConditionOperators operator;
private final String value;

/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -56,7 +51,7 @@ public String toString() {
* condition
* @param value
* {@code String} with the right hand side of the query condition
* @return
* @return {@link GenQueryBuilderCondition}
*/
static GenQueryBuilderCondition instance(final String selectFieldColumnName,
final SelectFieldSource selectFieldSource, final String selectFieldNumericTranslation,
Expand All @@ -66,29 +61,7 @@ static GenQueryBuilderCondition instance(final String selectFieldColumnName,
operator, value);
}

/**
* Create a query condition for an 'BETWEEN' condition. Note that the individual
* values for the BETWEEN are to be provided in an array without quotes, which
* will be added during processing
*
* @param selectFieldColumnName
* {@code String} with the column name
* @param selectFieldSource
* {@link SelectFieldSource} that reflects the type of field
* @param selectFieldNumericTranslation
* {@code String} with the numeric iRODS gen query protocol value
* that maps to this field
* @param valuesWithoutQuotes
* {@code List<String>} of in arguments, as non quoted strings
* @return
*/
static GenQueryBuilderCondition instanceForBetween(final String selectFieldColumnName,
final SelectFieldSource selectFieldSource, final String selectFieldNumericTranslation,
final List<String> valuesWithoutQuotes) {

if (valuesWithoutQuotes == null || valuesWithoutQuotes.isEmpty()) {
throw new IllegalArgumentException("null or empty valueWithoutQuotes");
}
private static String stackListValues(final List<String> valuesWithoutQuotes) {

StringBuilder sb = new StringBuilder();
for (String value : valuesWithoutQuotes) {
Expand All @@ -98,15 +71,14 @@ static GenQueryBuilderCondition instanceForBetween(final String selectFieldColum
sb.append("' ");

}

return new GenQueryBuilderCondition(selectFieldColumnName, selectFieldSource, selectFieldNumericTranslation,
QueryConditionOperators.BETWEEN, sb.toString());
return sb.toString();
}


/**
* Create a query condition for an 'IN' condition. Note that the individual
* values for the IN are to be provided in an array without quotes, which will
* be added during processing
* Create a query condition for multi-value (BETWEEN, IN, etc) condition. Note
* that the individual values are to be provided in an array without quotes,
* which will be added during processing
*
* @param selectFieldColumnName
* {@code String} with the column name
Expand All @@ -117,45 +89,28 @@ static GenQueryBuilderCondition instanceForBetween(final String selectFieldColum
* that maps to this field
* @param valuesWithoutQuotes
* {@code List<String>} of in arguments, as non quoted strings
* @return
* @return {@link GenQueryBuilderCondition}
*/
static GenQueryBuilderCondition instanceForIn(final String selectFieldColumnName,
final SelectFieldSource selectFieldSource, final String selectFieldNumericTranslation,
final List<String> valuesWithoutQuotes) {
static GenQueryBuilderCondition instanceForMultiValue(final String selectFieldColumnName,
final QueryConditionOperators operator, final SelectFieldSource selectFieldSource,
final String selectFieldNumericTranslation, final List<String> valuesWithoutQuotes) {

if (valuesWithoutQuotes == null || valuesWithoutQuotes.isEmpty()) {
throw new IllegalArgumentException("null or empty valueWithoutQuotes");
}

StringBuilder sb = new StringBuilder();
sb.append('(');
boolean first = true;
for (String value : valuesWithoutQuotes) {

if (!first) {
sb.append(",");
/* between and not between need 2 vals */

if (operator == QueryConditionOperators.BETWEEN || operator == QueryConditionOperators.NOT_BETWEEN) {
if (valuesWithoutQuotes.size() != 2) {
throw new IllegalArgumentException("between type queries need two values");
}
sb.append("'");
sb.append(value);
sb.append("'");
first = false;
}

sb.append(")");

return new GenQueryBuilderCondition(selectFieldColumnName, selectFieldSource, selectFieldNumericTranslation,
QueryConditionOperators.IN, sb.toString());
operator, stackListValues(valuesWithoutQuotes));
}

/**
*
* @param selectFieldColumnName
* @param selectFieldSource
* @param selectFieldNumericTranslation
* @param operator
* @param value
*/
private GenQueryBuilderCondition(final String selectFieldColumnName, final SelectFieldSource selectFieldSource,
final String selectFieldNumericTranslation, final QueryConditionOperators operator, final String value) {
this.selectFieldColumnName = selectFieldColumnName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,21 +260,29 @@ public IRODSGenQueryBuilder addConditionAsMultiValueCondition(final RodsGenQuery
}

/*
* Format the query based on the operator TODO: add handling for tables, in, etc
* Format the query based on the operator
*/

if (operator == QueryConditionOperators.IN) {
GenQueryBuilderCondition genQueryBuilderCondition = GenQueryBuilderCondition

.instanceForIn(rodsGenQueryEnumValue.getName(), SelectFieldSource.DEFINED_QUERY_FIELD,
String.valueOf(rodsGenQueryEnumValue.getNumericValue()), nonQuotedValues);
if (operator == QueryConditionOperators.IN || operator == QueryConditionOperators.NOT_IN
|| operator == QueryConditionOperators.NOT_BETWEEN || operator == QueryConditionOperators.BETWEEN) {
GenQueryBuilderCondition genQueryBuilderCondition = GenQueryBuilderCondition.instanceForMultiValue(
rodsGenQueryEnumValue.getName(), operator, SelectFieldSource.DEFINED_QUERY_FIELD,
String.valueOf(rodsGenQueryEnumValue.getNumericValue()), nonQuotedValues);
conditions.add(genQueryBuilderCondition);
} else if (operator == QueryConditionOperators.NOT_IN) {
GenQueryBuilderCondition genQueryBuilderCondition = GenQueryBuilderCondition.instanceForMultiValue(
rodsGenQueryEnumValue.getName(), operator, SelectFieldSource.DEFINED_QUERY_FIELD,
String.valueOf(rodsGenQueryEnumValue.getNumericValue()), nonQuotedValues);
conditions.add(genQueryBuilderCondition);
} else if (operator == QueryConditionOperators.NOT_BETWEEN) {
GenQueryBuilderCondition genQueryBuilderCondition = GenQueryBuilderCondition.instanceForMultiValue(
rodsGenQueryEnumValue.getName(), operator, SelectFieldSource.DEFINED_QUERY_FIELD,
String.valueOf(rodsGenQueryEnumValue.getNumericValue()), nonQuotedValues);
conditions.add(genQueryBuilderCondition);

} else if (operator == QueryConditionOperators.BETWEEN) {
GenQueryBuilderCondition genQueryBuilderCondition = GenQueryBuilderCondition

.instanceForBetween(rodsGenQueryEnumValue.getName(), SelectFieldSource.DEFINED_QUERY_FIELD,
String.valueOf(rodsGenQueryEnumValue.getNumericValue()), nonQuotedValues);
GenQueryBuilderCondition genQueryBuilderCondition = GenQueryBuilderCondition.instanceForMultiValue(
rodsGenQueryEnumValue.getName(), operator, SelectFieldSource.DEFINED_QUERY_FIELD,
String.valueOf(rodsGenQueryEnumValue.getNumericValue()), nonQuotedValues);
conditions.add(genQueryBuilderCondition);
} else {
throw new UnsupportedOperationException("query operator not yet supported:" + operator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ public enum QueryConditionOperators {
NOT_EQUAL("<>"), LESS_THAN_OR_EQUAL_TO("<="), GREATER_THAN_OR_EQUAL_TO(">="), NOT_LIKE("not like"), SOUNDS_LIKE(
"sounds like"), SOUNDS_NOT_LIKE("sounds not like"), TABLE("table"), NUMERIC_LESS_THAN(
"n<"), NUMERIC_LESS_THAN_OR_EQUAL_TO("n<="), NUMERIC_GREATER_THAN_OR_EQUAL_TO(
"n>="), NUMERIC_GREATER_THAN("n>"), NUMERIC_EQUAL("n="), EQUAL(
"="), LESS_THAN("<"), GREATER_THAN(">"), IN("in"), BETWEEN("between"), LIKE("like");
"n>="), NUMERIC_GREATER_THAN("n>"), NUMERIC_EQUAL("n="), EQUAL("="), LESS_THAN(
"<"), GREATER_THAN(">"), IN("in"), NOT_IN(
"not in"), BETWEEN("between"), NOT_BETWEEN("not between"), LIKE("like");

private String operatorAsString;

Expand Down Expand Up @@ -88,9 +89,16 @@ public static QueryConditionOperators getOperatorFromStringValue(final String st
if (stringValue.equalsIgnoreCase(IN.operatorAsString)) {
return IN;
}

if (stringValue.equalsIgnoreCase(NOT_IN.operatorAsString)) {
return NOT_IN;
}
if (stringValue.equalsIgnoreCase(BETWEEN.operatorAsString)) {
return BETWEEN;
}
if (stringValue.equalsIgnoreCase(NOT_BETWEEN.operatorAsString)) {
return NOT_BETWEEN;
}
if (stringValue.equals(LIKE.operatorAsString)) {
return LIKE;
}
Expand Down Expand Up @@ -159,12 +167,20 @@ public static QueryConditionOperators getOperatorFromEnumStringValue(final Strin
if (stringValue.equalsIgnoreCase(GREATER_THAN.toString())) {
return GREATER_THAN;
}

if (stringValue.equalsIgnoreCase(NOT_IN.toString())) {
return NOT_IN;
}
if (stringValue.equalsIgnoreCase(IN.toString())) {
return IN;
}
if (stringValue.equalsIgnoreCase(BETWEEN.toString())) {
return BETWEEN;
}

if (stringValue.equalsIgnoreCase(NOT_BETWEEN.toString())) {
return NOT_BETWEEN;
}
if (stringValue.equals(LIKE.toString())) {
return LIKE;
}
Expand Down
Loading

0 comments on commit 8f14ea0

Please sign in to comment.