@SuppressWarnings("unchecked") @Test @Override public void Union() { NumberExpression<Integer> one = NumberTemplate.ONE; NumberExpression<Integer> two = NumberTemplate.TWO; NumberExpression<Integer> three = NumberTemplate.THREE; Path<Integer> col1 = new SimplePath<Integer>(Integer.class, "col1"); Union union = query.union(sq().unique(one.as(col1)), sq().unique(two), sq().unique(three)); assertEquals( "(select 1 as col1)\n" + "union\n" + "(select 2)\n" + "union\n" + "(select 3)", union.toString()); }
@SuppressWarnings("unchecked") public <A extends Number & Comparable<A>> Collection<Predicate> numeric( NumberExpression<A> expr, NumberExpression<A> other, A knownValue) { List<Predicate> rv = new ArrayList<Predicate>(); for (NumberExpression<?> num : projections.numeric(expr, other, knownValue, true)) { rv.add(num.lt(expr)); } rv.add(expr.ne(other)); rv.add(expr.ne(knownValue)); rv.add(expr.goe(other)); rv.add(expr.goe(knownValue)); rv.add(expr.gt(other)); rv.add(expr.gt(knownValue)); rv.add(expr.loe(other)); rv.add(expr.loe(knownValue)); rv.add(expr.lt(other)); rv.add(expr.lt(knownValue)); rv.add(expr.in(1, 2, 3)); rv.add(expr.in(1l, 2l, 3l)); if (expr.getType().equals(Integer.class)) { NumberExpression<Integer> eint = (NumberExpression) expr; rv.add(eint.between(1, 2)); rv.add(eint.notBetween(1, 2)); rv.add(eint.mod(5).eq(0)); } else if (expr.getType().equals(Double.class)) { NumberExpression<Double> edouble = (NumberExpression) expr; rv.add(edouble.between(1.0, 2.0)); rv.add(edouble.notBetween(1.0, 2.0)); } else if (expr.getType().equals(Long.class)) { NumberExpression<Long> elong = (NumberExpression) expr; rv.add(elong.mod(5l).eq(0l)); } // rv.add(expr.in(IntervalImpl.create(0, 100))); return ImmutableList.copyOf(rv); }
@SuppressWarnings("unchecked") @Override public <RT extends Number & Comparable<?>> NumberSubQuery<RT> unique( NumberExpression<RT> projection) { return new NumberSubQuery<RT>((Class) projection.getType(), uniqueProjection(projection)); }