use of org.h2.value.CompareMode in project h2database by h2database.
the class Table method compareTypeSafe.
/**
* Compare two values with the current comparison mode. The values may be of
* different type.
*
* @param a the first value
* @param b the second value
* @return 0 if both values are equal, -1 if the first value is smaller, and
* 1 otherwise
*/
public int compareTypeSafe(Value a, Value b) {
if (a == b) {
return 0;
}
int dataType = Value.getHigherOrder(a.getType(), b.getType());
a = a.convertTo(dataType);
b = b.convertTo(dataType);
return a.compareTypeSafe(b, compareMode);
}
use of org.h2.value.CompareMode in project h2database by h2database.
the class IndexCondition method getCurrentValueList.
/**
* Get the current value list of the expression. The value list is of the
* same type as the column, distinct, and sorted.
*
* @param session the session
* @return the value list
*/
public Value[] getCurrentValueList(Session session) {
HashSet<Value> valueSet = new HashSet<>();
for (Expression e : expressionList) {
Value v = e.getValue(session);
v = column.convert(v);
valueSet.add(v);
}
Value[] array = valueSet.toArray(new Value[valueSet.size()]);
final CompareMode mode = session.getDatabase().getCompareMode();
Arrays.sort(array, new Comparator<Value>() {
@Override
public int compare(Value o1, Value o2) {
return o1.compareTo(o2, mode);
}
});
return array;
}
use of org.h2.value.CompareMode in project h2database by h2database.
the class TestPattern method testCompareModeReuse.
private void testCompareModeReuse() {
CompareMode mode1, mode2;
mode1 = CompareMode.getInstance(null, 0);
mode2 = CompareMode.getInstance(null, 0);
assertTrue(mode1 == mode2);
mode1 = CompareMode.getInstance("DE", Collator.SECONDARY);
assertFalse(mode1 == mode2);
mode2 = CompareMode.getInstance("DE", Collator.SECONDARY);
assertTrue(mode1 == mode2);
}
use of org.h2.value.CompareMode in project h2database by h2database.
the class TestPattern method testPattern.
private void testPattern() {
CompareMode mode = CompareMode.getInstance(null, 0);
CompareLike comp = new CompareLike(mode, "\\", null, null, null, false);
test(comp, "B", "%_");
test(comp, "A", "A%");
test(comp, "A", "A%%");
test(comp, "A_A", "%\\_%");
for (int i = 0; i < 10000; i++) {
String pattern = getRandomPattern();
String value = getRandomValue();
test(comp, value, pattern);
}
}
Aggregations