public void testSampleDomainQuery8() throws Exception { QueryFactory qf = getQueryFactory(); // all the transactions that happened in January 2013 Query q = qf.from(getModelFactory().getTransactionImplClass()) .having("date").between(makeDate("2013-01-01"), makeDate("2013-01-31")) .build(); List<Transaction> list = q.list(); assertEquals(4, list.size()); for (Transaction t : list) { assertTrue(t.getDate().compareTo(makeDate("2013-01-31")) <= 0); assertTrue(t.getDate().compareTo(makeDate("2013-01-01")) >= 0); } }
public void testBetween1() throws Exception { QueryFactory qf = getQueryFactory(); // all the transactions that happened in January 2013 Query q = qf.from(getModelFactory().getTransactionImplClass()) .having("date").between(makeDate("2013-01-01"), makeDate("2013-01-31")) .build(); List<Transaction> list = q.list(); assertEquals(4, list.size()); for (Transaction t : list) { assertTrue(t.getDate().compareTo(makeDate("2013-01-31")) <= 0); assertTrue(t.getDate().compareTo(makeDate("2013-01-01")) >= 0); } }
public void testDateGrouping1() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getTransactionImplClass()) .select("date") .having("date").between(makeDate("2013-02-15"), makeDate("2013-03-15")) .groupBy("date") .build(); List<Object[]> list = q.list(); assertEquals(1, list.size()); assertEquals(1, list.get(0).length); assertEquals(makeDate("2013-02-27"), list.get(0)[0]); }
public void testBetween3() throws Exception { QueryFactory qf = getQueryFactory(); // all the transactions that happened in January 2013 Query q = qf.from(getModelFactory().getTransactionImplClass()) .having("date").between(makeDate("2013-01-01"), makeDate("2013-01-31")).includeLower(false) .build(); List<Transaction> list = q.list(); assertEquals(3, list.size()); for (Transaction t : list) { assertTrue(t.getDate().compareTo(makeDate("2013-01-31")) <= 0); assertTrue(t.getDate().compareTo(makeDate("2013-01-01")) > 0); } }
public void testBetween2() throws Exception { QueryFactory qf = getQueryFactory(); // all the transactions that happened in January 2013 Query q = qf.from(getModelFactory().getTransactionImplClass()) .having("date").between(makeDate("2013-01-01"), makeDate("2013-01-31")).includeUpper(false) .build(); List<Transaction> list = q.list(); assertEquals(3, list.size()); for (Transaction t : list) { assertTrue(t.getDate().compareTo(makeDate("2013-01-31")) < 0); assertTrue(t.getDate().compareTo(makeDate("2013-01-01")) >= 0); } }
public void testDateFilteringWithGroupBy() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getTransactionImplClass()) .select("date") .having("date").between(makeDate("2013-02-15"), makeDate("2013-03-15")) .groupBy("date") .build(); List<Object[]> list = q.list(); assertEquals(1, list.size()); assertEquals(1, list.get(0).length); assertEquals(java.util.Date.class, list.get(0)[0].getClass()); assertEquals(makeDate("2013-02-27"), list.get(0)[0]); }
public void testSampleDomainQuery9() throws Exception { QueryFactory qf = getQueryFactory(); // all the transactions that happened in January 2013, projected by date field only Query q = qf.from(getModelFactory().getTransactionImplClass()) .select("date") .having("date").between(makeDate("2013-01-01"), makeDate("2013-01-31")) .build(); List<Object[]> list = q.list(); assertEquals(4, list.size()); assertEquals(1, list.get(0).length); assertEquals(1, list.get(1).length); assertEquals(1, list.get(2).length); assertEquals(1, list.get(3).length); for (int i = 0; i < 4; i++) { Date d = (Date) list.get(i)[0]; assertTrue(d.compareTo(makeDate("2013-01-31")) <= 0); assertTrue(d.compareTo(makeDate("2013-01-01")) >= 0); } }
public void testDuplicateDateProjection() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getTransactionImplClass()) .select("id", "date", "date") .having("description").eq("Hotel") .build(); List<Object[]> list = q.list(); assertEquals(1, list.size()); assertEquals(3, list.get(0).length); assertEquals(3, list.get(0)[0]); assertEquals(makeDate("2013-02-27"), list.get(0)[1]); assertEquals(makeDate("2013-02-27"), list.get(0)[2]); }
public void testAggregateDate() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getTransactionImplClass()) .select(count("date"), min("date")) .having("description").eq("Hotel") .groupBy("id") .build(); List<Object[]> list = q.list(); assertEquals(1, list.size()); assertEquals(2, list.get(0).length); assertEquals(1L, list.get(0)[0]); assertEquals(java.util.Date.class, list.get(0)[1].getClass()); assertEquals(makeDate("2013-02-27"), list.get(0)[1]); }
public void testSampleDomainQuery28() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getAccountImplClass()) .orderBy("id", SortOrder.ASC) .having("creationDate").lte(makeDate("2013-01-20")) .build(); List<Account> list = q.list(); assertEquals(3, list.size()); assertEquals(1, list.get(0).getId()); assertEquals(2, list.get(1).getId()); assertEquals(3, list.get(2).getId()); }
public void testSampleDomainQuery26() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getAccountImplClass()) .having("creationDate").eq(makeDate("2013-01-20")) .build(); List<Account> list = q.list(); assertEquals(1, list.size()); assertEquals(3, list.get(0).getId()); }
public void testSampleDomainQuery29() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getAccountImplClass()) .having("creationDate").gt(makeDate("2013-01-04")) .build(); List<Account> list = q.list(); assertEquals(1, list.size()); assertEquals(3, list.get(0).getId()); }
public void testSampleDomainQuery27() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getAccountImplClass()) .orderBy("id", SortOrder.ASC) .having("creationDate").lt(makeDate("2013-01-20")) .build(); List<Account> list = q.list(); assertEquals(2, list.size()); assertEquals(1, list.get(0).getId()); assertEquals(2, list.get(1).getId()); }
public void testDateGrouping2() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getTransactionImplClass()) .select(count("date"), min("date")) .having("description").eq("Hotel") .groupBy("id") .build(); List<Object[]> list = q.list(); assertEquals(1, list.size()); assertEquals(2, list.get(0).length); assertEquals(1L, list.get(0)[0]); assertEquals(makeDate("2013-02-27"), list.get(0)[1]); }
public void testDateGrouping3() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getTransactionImplClass()) .select(min("date"), count("date")) .having("description").eq("Hotel") .groupBy("id") .build(); List<Object[]> list = q.list(); assertEquals(1, list.size()); assertEquals(2, list.get(0).length); assertEquals(makeDate("2013-02-27"), list.get(0)[0]); assertEquals(1L, list.get(0)[1]); }
public void testDateParam() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getAccountImplClass()) .having("creationDate").eq(param("param1")) .build().setParameter("param1", makeDate("2013-01-03")); List<Account> list = q.list(); assertEquals(1, list.size()); assertEquals(1, list.get(0).getId()); }
@Test public void testComplexQuery() throws Exception { QueryFactory qf = getQueryFactory(); Query q = qf.from(getModelFactory().getTransactionImplClass()) .select(avg("amount"), sum("amount"), count("date"), min("date"), max("accountId")) .having("isDebit").eq(param("param")) .orderBy(avg("amount"), SortOrder.DESC).orderBy(count("date"), SortOrder.DESC) .orderBy(max("amount"), SortOrder.ASC) .build(); q.setParameter("param", true); List<Object[]> list = q.list(); assertEquals(1, list.size()); assertEquals(5, list.get(0).length); assertEquals(143.50909d, (Double) list.get(0)[0], 0.0001d); assertEquals(7893d, (Double) list.get(0)[1], 0.0001d); assertEquals(55L, list.get(0)[2]); assertEquals(java.util.Date.class, list.get(0)[3].getClass()); assertEquals(makeDate("2013-01-01"), list.get(0)[3]); assertEquals(2, list.get(0)[4]); }
account1.setId(1); account1.setDescription("John Doe's first bank account"); account1.setCreationDate(makeDate("2013-01-03")); account2.setCreationDate(makeDate("2013-01-04")); account3.setCreationDate(makeDate("2013-01-20")); transaction0.setAccountId(1); transaction0.setAmount(1800); transaction0.setDate(makeDate("2012-09-07")); transaction0.setDebit(false); transaction0.setValid(true); transaction1.setAccountId(1); transaction1.setAmount(1500); transaction1.setDate(makeDate("2013-01-05")); transaction1.setDebit(true); transaction1.setValid(true); transaction2.setAccountId(1); transaction2.setAmount(23); transaction2.setDate(makeDate("2013-01-09")); transaction2.setDebit(true); transaction2.setValid(true); transaction3.setAccountId(2); transaction3.setAmount(45); transaction3.setDate(makeDate("2013-02-27"));