mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
Improve date/time templates
This commit is contained in:
parent
7b979b1583
commit
d03cd3c72d
@ -82,6 +82,7 @@ public class EclipseLinkTemplates extends JPQLTemplates {
|
||||
add(Ops.DateTimeOps.YEAR, "extract(year from {0})");
|
||||
|
||||
add(Ops.DateTimeOps.YEAR_MONTH, "extract(year from {0}) * 100 + extract(month from {0})");
|
||||
add(Ops.DateTimeOps.YEAR_WEEK, "extract(year from {0}) * 100 + extract(week from {0})");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -131,6 +131,7 @@ public class JPQLTemplates extends Templates {
|
||||
add(Ops.DateTimeOps.YEAR, "year({0})");
|
||||
|
||||
add(Ops.DateTimeOps.YEAR_MONTH, "year({0}) * 100 + month({0})", Precedence.ARITH_LOW);
|
||||
add(Ops.DateTimeOps.YEAR_WEEK, "year({0}) * 100 + week({0})", Precedence.ARITH_LOW);
|
||||
|
||||
// path types
|
||||
add(PathType.PROPERTY, "{0}.{1s}");
|
||||
|
||||
@ -547,13 +547,24 @@ public abstract class AbstractJPATest {
|
||||
assertEquals(2000, query().from(cat).select(cat.birthdate.year()).fetchFirst().intValue());
|
||||
assertEquals(200002, query().from(cat).select(cat.birthdate.yearMonth()).fetchFirst().intValue());
|
||||
assertEquals(2, query().from(cat).select(cat.birthdate.month()).fetchFirst().intValue());
|
||||
//query().from(cat).select(cat.birthdate.week());
|
||||
assertEquals(2, query().from(cat).select(cat.birthdate.dayOfMonth()).fetchFirst().intValue());
|
||||
assertEquals(3, query().from(cat).select(cat.birthdate.hour()).fetchFirst().intValue());
|
||||
assertEquals(4, query().from(cat).select(cat.birthdate.minute()).fetchFirst().intValue());
|
||||
assertEquals(0, query().from(cat).select(cat.birthdate.second()).fetchFirst().intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Date_YearWeek() {
|
||||
int value = query().from(cat).select(cat.birthdate.yearWeek()).fetchFirst();
|
||||
assertTrue(value == 200006 || value == 200005);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Date_Week() {
|
||||
int value = query().from(cat).select(cat.birthdate.week()).fetchFirst();
|
||||
assertTrue(value == 6 || value == 5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn(ORACLE)
|
||||
public void Divide() {
|
||||
@ -700,8 +711,8 @@ public abstract class AbstractJPATest {
|
||||
.from(author)
|
||||
.join(author.books, book)
|
||||
.transform(GroupBy
|
||||
.groupBy(author.id)
|
||||
.as(GroupBy.list(QPair.create(book.id, book.title))));
|
||||
.groupBy(author.id)
|
||||
.as(GroupBy.list(QPair.create(book.id, book.title))));
|
||||
|
||||
for (Entry<Long, List<Pair<Long, String>>> entry : map.entrySet()) {
|
||||
System.out.println("author = " + entry.getKey());
|
||||
@ -888,7 +899,7 @@ public abstract class AbstractJPATest {
|
||||
|
||||
@Test
|
||||
public void Limit_and_offset() {
|
||||
List<String> names3 = Arrays.asList("Felix123","Mary_123");
|
||||
List<String> names3 = Arrays.asList("Felix123", "Mary_123");
|
||||
assertEquals(names3, query().from(cat).orderBy(cat.name.asc()).limit(2).offset(2).select(cat.name).fetch());
|
||||
}
|
||||
|
||||
@ -1136,16 +1147,16 @@ public abstract class AbstractJPATest {
|
||||
@NoBatooJPA
|
||||
public void Order_NullsFirst() {
|
||||
assertNull(query().from(cat)
|
||||
.orderBy(cat.dateField.asc().nullsFirst())
|
||||
.select(cat.dateField).fetchFirst());
|
||||
.orderBy(cat.dateField.asc().nullsFirst())
|
||||
.select(cat.dateField).fetchFirst());
|
||||
}
|
||||
|
||||
@Test
|
||||
@NoBatooJPA
|
||||
public void Order_NullsLast() {
|
||||
assertNotNull(query().from(cat)
|
||||
.orderBy(cat.dateField.asc().nullsLast())
|
||||
.select(cat.dateField).fetchFirst());
|
||||
.orderBy(cat.dateField.asc().nullsLast())
|
||||
.select(cat.dateField).fetchFirst());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1596,7 +1607,7 @@ public abstract class AbstractJPATest {
|
||||
@Test
|
||||
@NoOpenJPA
|
||||
public void Type_Order() {
|
||||
assertEquals(Arrays.asList(10,1,2,3,4,5,6),
|
||||
assertEquals(Arrays.asList(10, 1, 2, 3, 4, 5, 6),
|
||||
query().from(animal).orderBy(JPAExpressions.type(animal).asc(), animal.id.asc())
|
||||
.select(animal.id).fetch());
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user