mirror of https://github.com/tasks/tasks
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.6 KiB
Java
87 lines
2.6 KiB
Java
15 years ago
|
package com.todoroo.andlib.sql;
|
||
15 years ago
|
|
||
15 years ago
|
import static com.todoroo.andlib.sql.Constants.AND;
|
||
|
import static com.todoroo.andlib.sql.Constants.BETWEEN;
|
||
|
import static com.todoroo.andlib.sql.Constants.COMMA;
|
||
|
import static com.todoroo.andlib.sql.Constants.LEFT_PARENTHESIS;
|
||
|
import static com.todoroo.andlib.sql.Constants.RIGHT_PARENTHESIS;
|
||
|
import static com.todoroo.andlib.sql.Constants.SPACE;
|
||
15 years ago
|
|
||
|
public class Field extends DBObject<Field> {
|
||
|
|
||
|
protected Field(String expression) {
|
||
|
super(expression);
|
||
|
}
|
||
|
|
||
|
public static Field field(String expression) {
|
||
|
return new Field(expression);
|
||
|
}
|
||
|
|
||
|
public Criterion eq(Object value) {
|
||
|
return UnaryCriterion.eq(this, value);
|
||
|
}
|
||
|
|
||
|
public Criterion neq(Object value) {
|
||
|
return UnaryCriterion.neq(this, value);
|
||
|
}
|
||
|
|
||
|
public Criterion gt(Object value) {
|
||
|
return UnaryCriterion.gt(this, value);
|
||
|
}
|
||
|
|
||
|
public Criterion lt(final Object value) {
|
||
|
return UnaryCriterion.lt(this, value);
|
||
|
}
|
||
|
|
||
|
public Criterion isNull() {
|
||
|
return UnaryCriterion.isNull(this);
|
||
|
}
|
||
|
|
||
|
public Criterion isNotNull() {
|
||
|
return UnaryCriterion.isNotNull(this);
|
||
|
}
|
||
|
|
||
|
public Criterion between(final Object lower, final Object upper) {
|
||
|
final Field field = this;
|
||
|
return new Criterion(null) {
|
||
|
|
||
|
@Override
|
||
|
protected void populate(StringBuilder sb) {
|
||
|
sb.append(field).append(SPACE).append(BETWEEN).append(SPACE).append(lower).append(SPACE).append(AND)
|
||
|
.append(SPACE).append(upper);
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
public Criterion like(final String value) {
|
||
|
return UnaryCriterion.like(this, value);
|
||
|
}
|
||
|
|
||
|
public <T> Criterion in(final T... value) {
|
||
|
final Field field = this;
|
||
|
return new Criterion(Operator.in) {
|
||
|
|
||
|
@Override
|
||
|
protected void populate(StringBuilder sb) {
|
||
|
sb.append(field).append(SPACE).append(Operator.in).append(SPACE).append(LEFT_PARENTHESIS);
|
||
|
for (T t : value) {
|
||
|
sb.append(t.toString()).append(COMMA);
|
||
|
}
|
||
|
sb.deleteCharAt(sb.length() - 1).append(RIGHT_PARENTHESIS);
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
public Criterion in(final Query query) {
|
||
|
final Field field = this;
|
||
|
return new Criterion(Operator.in) {
|
||
|
|
||
|
@Override
|
||
|
protected void populate(StringBuilder sb) {
|
||
|
sb.append(field).append(SPACE).append(Operator.in).append(SPACE).append(LEFT_PARENTHESIS).append(query)
|
||
|
.append(RIGHT_PARENTHESIS);
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
}
|