@SuppressWarnings("unchecked") @Override public final <Z> Field<Z> cast(DataType<Z> type) { // [#473] Prevent unnecessary casts if (getDataType().equals(type)) return (Field<Z>) this; else return new Cast<Z>(this, type); }
@SuppressWarnings("unchecked") @Override public final <Z> Field<Z> cast(DataType<Z> type) { // [#473] Prevent unnecessary casts if (getDataType().equals(type)) { return (Field<Z>) this; } else { return new Cast<Z>(this, type); } }
@SuppressWarnings("unchecked") @Override public final <Z> Field<Z> coerce(DataType<Z> type) { // [#473] Prevent unnecessary coercions if (getDataType().equals(type)) return (Field<Z>) this; else return new Coerce<Z>(this, type); }
@SuppressWarnings("unchecked") private final <Z extends Number> Field<Z> numeric() { if (getDataType().isNumeric()) { return (Field<Z>) this; } else { return (Field<Z>) cast(BigDecimal.class); } }
@SuppressWarnings("unchecked") private final <Z extends java.util.Date> Field<Z> date() { if (getDataType().isTemporal()) { return (Field<Z>) this; } else { return (Field<Z>) cast(Timestamp.class); } }
/** * This default implementation is known to be overridden by * <code>Expression</code> to generate neater expressions */ @Override public Field<T> mul(Field<? extends Number> value) { return new Expression<T>(MULTIPLY, this, nullSafe(value, getDataType())); }
@Override public final Condition compare(Comparator comparator, Field<T> field) { switch (comparator) { case IS_DISTINCT_FROM: case IS_NOT_DISTINCT_FROM: return new IsDistinctFrom<T>(this, nullSafe(field, getDataType()), comparator); default: return new CompareCondition(this, nullSafe(field, getDataType()), comparator); } }
@SuppressWarnings("unchecked") private final <Z extends Number> Field<Z> numeric() { if (getDataType().isNumeric()) { return (Field<Z>) this; } else { return (Field<Z>) cast(BigDecimal.class); } }
@Override public final LikeEscapeStep notLike(Field<String> field) { return new CompareCondition(this, nullSafe(field, getDataType()), NOT_LIKE); }
@Override public final BetweenAndStep<T> between(Field<T> minValue) { return new BetweenCondition<T>(this, nullSafe(minValue, getDataType()), false, false); }
@Override public final Condition lessThan(Field<T> field) { return compare(LESS, nullSafe(field, getDataType())); }
@SuppressWarnings("unchecked") private final Field<String> varchar() { if (getDataType().isString()) { return (Field<String>) this; } else { return cast(String.class); } }
@SuppressWarnings("unchecked") private final Field<String> varchar() { if (getDataType().isString()) { return (Field<String>) this; } else { return cast(String.class); } }
@SuppressWarnings("unchecked") private final <Z extends java.util.Date> Field<Z> date() { if (getDataType().isTemporal()) { return (Field<Z>) this; } else { return (Field<Z>) cast(Timestamp.class); } }
@Override public final LikeEscapeStep like(Field<String> field) { return new CompareCondition(this, nullSafe(field, getDataType()), LIKE); }
@Override public final Condition notEqual(Field<T> field) { return compare(NOT_EQUALS, nullSafe(field, getDataType())); }
@Override public final Condition compare(Comparator comparator, Select<? extends Record1<T>> query) { return compare(comparator, new ScalarSubquery<T>(query, getDataType())); }
@SuppressWarnings("unchecked") @Override public final <T> AggregateFilterStep<T> withinGroupOrderBy(OrderField<T> field) { DataType<T> type = field instanceof SortFieldImpl ? ((SortFieldImpl<T>) field).getField().getDataType() : field instanceof Field ? ((AbstractField<T>) field).getDataType() : (DataType<T>) SQLDataType.NUMERIC; return new Function<T>("mode", type).withinGroupOrderBy(field); } }
@SuppressWarnings({ "unchecked" }) @Override public final Condition isFalse() { Class<?> type = getType(); if (type == String.class) return ((Field<String>) this).in(Tools.inline(FALSE_VALUES.toArray(EMPTY_STRING))); else if (Number.class.isAssignableFrom(type)) return ((Field<Number>) this).equal(inline((Number) getDataType().convert(0))); else if (Boolean.class.isAssignableFrom(type)) return ((Field<Boolean>) this).equal(inline(false)); else return cast(String.class).in(Tools.inline(FALSE_VALUES.toArray(EMPTY_STRING))); }
@SuppressWarnings({ "unchecked" }) @Override public final Condition isTrue() { Class<?> type = getType(); if (type == String.class) return ((Field<String>) this).in(Tools.inline(TRUE_VALUES.toArray(EMPTY_STRING))); else if (Number.class.isAssignableFrom(type)) return ((Field<Number>) this).equal(inline((Number) getDataType().convert(1))); else if (Boolean.class.isAssignableFrom(type)) return ((Field<Boolean>) this).equal(inline(true)); else return cast(String.class).in(TRUE_VALUES); }