[#894] Move functions from Field<?> to new org.jooq.impl.SQL and make them static - moved decode function
This commit is contained in:
parent
057068aef6
commit
c4dd556887
@ -5657,28 +5657,27 @@ public abstract class jOOQAbstractTest<
|
||||
// ---------------------------------------------------------------------
|
||||
// DECODE
|
||||
// ---------------------------------------------------------------------
|
||||
assertEquals(null, create().select(sNull.decode(sNull, sNull)).fetchOne(0));
|
||||
assertEquals(null, create().select(decode(sNull, sNull, sNull)).fetchOne(0));
|
||||
assertEquals(null, create().select(decode(iNull, val(2), val(1))).fetchOne(0));
|
||||
assertEquals(Integer.valueOf(1), create().select(decode(iNull, val(2), val(1), val(1))).fetchOne(0));
|
||||
assertEquals(Integer.valueOf(1), create().select(decode(iNull, iNull, val(1))).fetchOne(0));
|
||||
assertEquals(Integer.valueOf(1), create().select(decode(iNull, iNull, val(1), val(2))).fetchOne(0));
|
||||
assertEquals(Integer.valueOf(1), create().select(decode(iNull, val(2), val(2), iNull, val(1))).fetchOne(0));
|
||||
assertEquals(Integer.valueOf(1), create().select(decode(iNull, val(2), val(2), iNull, val(1), val(3))).fetchOne(0));
|
||||
|
||||
assertEquals(null, create().select(iNull.decode(2, 1)).fetchOne(0));
|
||||
assertEquals(Integer.valueOf(1), create().select(iNull.decode(2, 1, 1)).fetchOne(0));
|
||||
assertEquals(Integer.valueOf(1), create().select(iNull.decode(iNull, val(1))).fetchOne(0));
|
||||
assertEquals(Integer.valueOf(1), create().select(iNull.decode(iNull, val(1), val(2))).fetchOne(0));
|
||||
assertEquals(Integer.valueOf(1), create().select(iNull.decode(val(2), val(2), iNull, val(1))).fetchOne(0));
|
||||
assertEquals(Integer.valueOf(1), create().select(iNull.decode(val(2), val(2), iNull, val(1), val(3))).fetchOne(0));
|
||||
|
||||
assertEquals(null, create().select(sNull.decode("2", "1")).fetchOne(0));
|
||||
assertEquals("1", create().select(sNull.decode("2", "1", "1")).fetchOne(0));
|
||||
assertEquals("1", create().select(sNull.decode(sNull, val("1"))).fetchOne(0));
|
||||
assertEquals("1", create().select(sNull.decode(sNull, val("1"), val("2"))).fetchOne(0));
|
||||
assertEquals("1", create().select(sNull.decode(val("2"), val("2"), sNull, val("1"))).fetchOne(0));
|
||||
assertEquals("1", create().select(sNull.decode(val("2"), val("2"), sNull, val("1"), val("3"))).fetchOne(0));
|
||||
assertEquals(null, create().select(decode(sNull, "2", "1")).fetchOne(0));
|
||||
assertEquals("1", create().select(decode(sNull, "2", "1", "1")).fetchOne(0));
|
||||
assertEquals("1", create().select(decode(sNull, sNull, val("1"))).fetchOne(0));
|
||||
assertEquals("1", create().select(decode(sNull, sNull, val("1"), val("2"))).fetchOne(0));
|
||||
assertEquals("1", create().select(decode(sNull, val("2"), val("2"), sNull, val("1"))).fetchOne(0));
|
||||
assertEquals("1", create().select(decode(sNull, val("2"), val("2"), sNull, val("1"), val("3"))).fetchOne(0));
|
||||
|
||||
Field<Integer> lang = TBook_LANGUAGE_ID().cast(Integer.class);
|
||||
Result<Record> result = create().select(
|
||||
lang.decode(1, "EN"),
|
||||
lang.decode(1, "EN", "Other"),
|
||||
lang.decode(1, "EN", 2, "DE"),
|
||||
lang.decode(1, "EN", 2, "DE", "Other"))
|
||||
decode(lang, 1, "EN"),
|
||||
decode(lang, 1, "EN", "Other"),
|
||||
decode(lang, 1, "EN", 2, "DE"),
|
||||
decode(lang, 1, "EN", 2, "DE", "Other"))
|
||||
.from(TBook())
|
||||
.orderBy(TBook_ID()).fetch();
|
||||
|
||||
|
||||
@ -332,64 +332,6 @@ public interface Field<T> extends NamedTypeProviderQueryPart<T>, AliasProvider<F
|
||||
*/
|
||||
Field<T> mod(Field<? extends Number> value);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// General functions created from this field
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Gets the Oracle-style
|
||||
* <code>DECODE(expression, search, result[, search , result]... [, default])</code>
|
||||
* function
|
||||
*
|
||||
* @see #decode(Field, Field, Field[])
|
||||
*/
|
||||
<Z> Field<Z> decode(T search, Z result);
|
||||
|
||||
/**
|
||||
* Gets the Oracle-style
|
||||
* <code>DECODE(expression, search, result[, search , result]... [, default])</code>
|
||||
* function
|
||||
*
|
||||
* @see #decode(Field, Field, Field[])
|
||||
*/
|
||||
<Z> Field<Z> decode(T search, Z result, Object... more);
|
||||
|
||||
/**
|
||||
* Gets the Oracle-style
|
||||
* <code>DECODE(expression, search, result[, search , result]... [, default])</code>
|
||||
* function
|
||||
*
|
||||
* @see #decode(Field, Field, Field[])
|
||||
*/
|
||||
<Z> Field<Z> decode(Field<T> search, Field<Z> result);
|
||||
|
||||
/**
|
||||
* Gets the Oracle-style
|
||||
* <code>DECODE(expression, search, result[, search , result]... [, default])</code>
|
||||
* function
|
||||
* <p>
|
||||
* Returns the dialect's equivalent to DECODE:
|
||||
* <ul>
|
||||
* <li>Oracle <a
|
||||
* href="http://www.techonthenet.com/oracle/functions/decode.php">DECODE</a></li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Other dialects: <code><pre>
|
||||
* CASE WHEN [this = search] THEN [result],
|
||||
* [WHEN more... THEN more...]
|
||||
* [ELSE more...]
|
||||
* END
|
||||
* </pre></code>
|
||||
*
|
||||
* @param search the mandatory first search parameter
|
||||
* @param result the mandatory first result parameter
|
||||
* @param more the optional parameters. If <code>more.length</code> is even,
|
||||
* then it is assumed that it contains more search/result pairs.
|
||||
* If <code>more.length</code> is odd, then it is assumed that it
|
||||
* contains more search/result pairs plus a default at the end.
|
||||
*/
|
||||
<Z> Field<Z> decode(Field<T> search, Field<Z> result, Field<?>... more);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Conditions created from this field
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@ -280,33 +280,6 @@ abstract class AbstractField<T> extends AbstractNamedTypeProviderQueryPart<T> im
|
||||
return new Mod<T>(this, nullSafe(value));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Other functions created from this field
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final <Z> Field<Z> decode(T search, Z result) {
|
||||
return decode(search, result, new Object[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <Z> Field<Z> decode(T search, Z result, Object... more) {
|
||||
return decode(
|
||||
val(search),
|
||||
val(result),
|
||||
vals(more).toArray(new Field<?>[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <Z> Field<Z> decode(Field<T> search, Field<Z> result) {
|
||||
return decode(nullSafe(search), nullSafe(result), new Field<?>[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <Z> Field<Z> decode(Field<T> search, Field<Z> result, Field<?>... more) {
|
||||
return new Decode<T, Z>(this, nullSafe(search), nullSafe(result), nullSafe(more));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Conditions created from this field
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@ -1174,7 +1174,7 @@ public class Factory implements FactoryOperations {
|
||||
* @see Field#decode(Field, Field, Field[])
|
||||
*/
|
||||
public static <Z, T> Field<Z> decode(T value, T search, Z result) {
|
||||
return val(value).decode(search, result);
|
||||
return decode(value, search, result, new Object[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1185,7 +1185,7 @@ public class Factory implements FactoryOperations {
|
||||
* @see Field#decode(Field, Field, Field[])
|
||||
*/
|
||||
public static <Z, T> Field<Z> decode(T value, T search, Z result, Object... more) {
|
||||
return val(value).decode(search, result, more);
|
||||
return decode(val(value), val(search), val(result), vals(more).toArray(new Field[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1196,18 +1196,39 @@ public class Factory implements FactoryOperations {
|
||||
* @see Field#decode(Field, Field, Field[])
|
||||
*/
|
||||
public static <Z, T> Field<Z> decode(Field<T> value, Field<T> search, Field<Z> result) {
|
||||
return nullSafe(value).decode(nullSafe(search), nullSafe(result));
|
||||
return decode(nullSafe(value), nullSafe(search), nullSafe(result), new Field[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Oracle-style
|
||||
* <code>DECODE(expression, search, result[, search , result]... [, default])</code>
|
||||
* function
|
||||
* <p>
|
||||
* Returns the dialect's equivalent to DECODE:
|
||||
* <ul>
|
||||
* <li>Oracle <a
|
||||
* href="http://www.techonthenet.com/oracle/functions/decode.php">DECODE</a></li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Other dialects: <code><pre>
|
||||
* CASE WHEN [this = search] THEN [result],
|
||||
* [WHEN more... THEN more...]
|
||||
* [ELSE more...]
|
||||
* END
|
||||
* </pre></code>
|
||||
*
|
||||
* @param value The value to decode
|
||||
* @param search the mandatory first search parameter
|
||||
* @param result the mandatory first result candidate parameter
|
||||
* @param more the optional parameters. If <code>more.length</code> is even,
|
||||
* then it is assumed that it contains more search/result pairs.
|
||||
* If <code>more.length</code> is odd, then it is assumed that it
|
||||
* contains more search/result pairs plus a default at the end. *
|
||||
*
|
||||
* @see Field#decode(Field, Field, Field[])
|
||||
*/
|
||||
public static <Z, T> Field<Z> decode(Field<T> value, Field<T> search, Field<Z> result, Field<?>... more) {
|
||||
return nullSafe(value).decode(nullSafe(search), nullSafe(result), nullSafe(more));
|
||||
return new Decode<T, Z>(nullSafe(value), nullSafe(search), nullSafe(result), nullSafe(more));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -194,9 +194,6 @@ public class jOOQTest {
|
||||
assertEquals(
|
||||
FIELD_ID1.between((Integer) null, null),
|
||||
FIELD_ID1.between((Field<Integer>) null, null));
|
||||
assertEquals(
|
||||
FIELD_ID1.decode((Integer) null, null),
|
||||
FIELD_ID1.decode((Field<Integer>) null, null));
|
||||
assertEquals(
|
||||
FIELD_ID1.div((Integer) null),
|
||||
FIELD_ID1.div((Field<Integer>) null));
|
||||
@ -353,6 +350,9 @@ public class jOOQTest {
|
||||
assertEquals(
|
||||
Factory.decode((Integer) null, null, null),
|
||||
Factory.decode((Field<Integer>) null, null, null));
|
||||
assertEquals(
|
||||
Factory.decode((Integer) null, null, null),
|
||||
Factory.decode((Field<Integer>) null, null, null));
|
||||
assertEquals(
|
||||
Factory.deg((Integer) null),
|
||||
Factory.deg((Field<Integer>) null));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user