Search in sources :

Example 11 with CompareMode

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);
}
Also used : Constraint(org.h2.constraint.Constraint)

Example 12 with 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;
}
Also used : Expression(org.h2.expression.Expression) Value(org.h2.value.Value) CompareMode(org.h2.value.CompareMode) HashSet(java.util.HashSet)

Example 13 with CompareMode

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);
}
Also used : CompareMode(org.h2.value.CompareMode)

Example 14 with CompareMode

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);
    }
}
Also used : CompareMode(org.h2.value.CompareMode) CompareLike(org.h2.expression.CompareLike)

Aggregations

CompareMode (org.h2.value.CompareMode)10 Value (org.h2.value.Value)7 ArrayList (java.util.ArrayList)2 Expression (org.h2.expression.Expression)2 PageDataIndex (org.h2.index.PageDataIndex)2 PageDelegateIndex (org.h2.index.PageDelegateIndex)2 IndexColumn (org.h2.table.IndexColumn)2 RegularTable (org.h2.table.RegularTable)2 Table (org.h2.table.Table)2 ValueArray (org.h2.value.ValueArray)2 ValueString (org.h2.value.ValueString)2 BigInteger (java.math.BigInteger)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 PriorityQueue (java.util.PriorityQueue)1 Random (java.util.Random)1 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)1 CreateTableData (org.h2.command.ddl.CreateTableData)1 Constraint (org.h2.constraint.Constraint)1