@Override public <T extends Number & Comparable<T>> Path<T> createNumberPath(Class<T> type, PathMetadata metadata) { return Expressions.numberPath(type, metadata); }
/** * Create a new variable path * * @param arg alias * @param <D> * @return expression */ @SuppressWarnings("unchecked") public static <D extends Number & Comparable<D>> NumberPath<D> var(D arg) { return Expressions.numberPath((Class<D>) arg.getClass(), "var" + arg.getClass().getSimpleName() + arg); }
Expressions.enumPath(Gender.class, "e"), Expressions.stringPath("s")}); args.put(FactoryExpression.class, Projections.tuple(Expressions.stringPath("str"))); args.put(GroupExpression.class, GroupBy.avg(Expressions.numberPath(Integer.class, "num"))); args.put(Number.class, 1); args.put(Operator.class, Ops.AND);
@Test public void numberPathClassOfTString() { assertEquals("variable", Expressions.numberPath(Integer.class, "variable").toString()); }
@Test public void numberPathClassOfTPathOfQString() { assertEquals("variable.property", Expressions.numberPath(Integer.class, Expressions.path(Object.class, "variable"), "property").toString()); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Before public void setUp() { num = Expressions.numberPath(Integer.class, "num"); str = Expressions.stringPath("str"); date = Expressions.datePath(Date.class, "date"); QueryMixin<?> query = new QueryMixin<Void>(); query.from(num, str); // TODO sub }
@Test public void number_conversion() { StringPath strPath = Expressions.stringPath("strPath"); NumberPath<Integer> intPath = Expressions.numberPath(Integer.class, "intPath"); QTuple qTuple = Projections.tuple(strPath, intPath); NumberConversions<Tuple> conversions = new NumberConversions<Tuple>(qTuple); Tuple tuple = conversions.newInstance("a", Long.valueOf(3)); assertEquals("a", tuple.get(strPath)); assertEquals(Integer.valueOf(3), tuple.get(intPath)); }
@Test public void signature() { StringPath str = Expressions.stringPath("str"); NumberPath<BigDecimal> bigd = Expressions.numberPath(BigDecimal.class, "bigd"); ResultTransformer<Map<String, SortedMap<BigDecimal, SortedMap<BigDecimal, Map<String, String>>>>> resultTransformer = GroupBy.groupBy(str).as( GroupBy.sortedMap(bigd, GroupBy.sortedMap(bigd, GroupBy.map(str, str), Ordering.natural().nullsLast()), Ordering.natural().nullsFirst())); assertNotNull(resultTransformer); }
@Test public void safe_number_conversion() { StringPath strPath = Expressions.stringPath("strPath"); NumberPath<Integer> intPath = Expressions.numberPath(Integer.class, "intPath"); QTuple qTuple = Projections.tuple(strPath, intPath); NumberConversions<Tuple> conversions = new NumberConversions<Tuple>(qTuple); assertNotNull(conversions.newInstance(1, 2)); }
@Test public void serialize() throws ClassNotFoundException, IOException { QTuple e = new QTuple(Expressions.stringPath("x"), Expressions.numberPath(Integer.class, "y")); serialize(e); serialize(e.newInstance("a",1)); }
@Test public void keep_last() { //MIN(salary) KEEP (DENSE_RANK FIRST ORDER BY commission_pct) OVER (PARTITION BY department_id) NumberPath<Long> path = Expressions.numberPath(Long.class, "path"); NumberPath<Long> path2 = Expressions.numberPath(Long.class, "path2"); NumberPath<Long> path3 = Expressions.numberPath(Long.class, "path3"); assertEquals( "min(path) keep (dense_rank last order by path2 asc) over (partition by path3)", toString(SQLExpressions.min(path).keepLast().orderBy(path2).over().partitionBy(path3))); }
@Test public void in() { JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT); serializer.handle(Expressions.numberPath(Integer.class, "id").in(Arrays.asList(1, 2))); assertEquals("id in (?1)", serializer.toString()); }
@Override public List<AuditStatsDto> countByUser(Predicate predicate) { NumberPath<Long> aliasCount = Expressions.numberPath(Long.class, "userCount"); QAudit qAudit = QAudit.audit; return from(qAudit) .select(Projections.constructor(AuditStatsDto.class, qAudit.user, qAudit.user.count().as(aliasCount))) .where(predicate) .groupBy(qAudit.user) .orderBy(aliasCount.desc()) .fetch(); }
@Test public void numeric_operations() { NumberPath<Integer> intPath = Expressions.numberPath(Integer.class, "intPath"); NumberPath<Integer> intPath2 = Expressions.numberPath(Integer.class, "intPath2"); SQLSerializer serializer = new SQLSerializer(new Configuration(SQLTemplates.DEFAULT)); serializer.handle(intPath.subtract(intPath2.add(2))); assertEquals("intPath - (intPath2 + ?)", serializer.toString()); }
@Test public void normalizeNumericArgs() { JPQLSerializer serializer = new JPQLSerializer(HQLTemplates.DEFAULT); NumberPath<Double> doublePath = Expressions.numberPath(Double.class, "doublePath"); serializer.handle(doublePath.add(1)); serializer.handle(doublePath.between((float) 1.0, 1L)); serializer.handle(doublePath.lt((byte) 1)); for (Object constant : serializer.getConstantToLabel().keySet()) { assertEquals(Double.class, constant.getClass()); } }
@Test @SkipForQuoted @IncludeIn(ORACLE) public void count_all_Oracle() { expectedQuery = "select count(*) rc from EMPLOYEE e"; NumberPath<Long> rowCount = Expressions.numberPath(Long.class, "rc"); assertEquals(10, query().from(employee).select(Wildcard.count.as(rowCount)).fetchOne().intValue()); }
@Test public void rows_unboundedPreceding() { NumberPath<Long> path = Expressions.numberPath(Long.class, "path"); WindowFunction<Long> wf = SQLExpressions.sum(path).over().orderBy(path); assertEquals("sum(path) over (order by path asc rows unbounded preceding)", toString(wf.rows().unboundedPreceding())); }
@Test @NoHibernate // https://hibernate.atlassian.net/browse/HHH-1902 public void groupBy_select() { // select length(my_column) as column_size from my_table group by column_size NumberPath<Integer> length = Expressions.numberPath(Integer.class, "len"); assertEquals(ImmutableList.of(4, 6, 7, 8), query().select(cat.name.length().as(length)).from(cat).orderBy(length.asc()).groupBy(length).fetch()); }
@Test public void order_by_count() { NumberPath<Long> count = Expressions.numberPath(Long.class, "c"); query().from(cat) .groupBy(cat.id) .orderBy(count.asc()) .select(cat.id, cat.id.count().as(count)).fetch(); }
@Test public void leftJoinWithoutCodeGeneration() { SQLQuery<?> sqlQuery = queryForMYSQLTemplate(); PathBuilder<Object> customerPath = new PathBuilder<Object>(Object.class, "customer"); PathBuilder<Object> deptPath = new PathBuilder<Object>(Object.class, "department"); Path<Object> deptAliasPath = new PathBuilder<Object>(Object.class, "d"); sqlQuery = sqlQuery.from(customerPath.as("c")); NumberPath<Long> idPath = Expressions.numberPath(Long.class, deptAliasPath, "id"); sqlQuery = sqlQuery.leftJoin(deptPath, deptAliasPath).select(idPath); assertEquals("select d.id from customer as c left join department as d", sqlQuery.toString()); }