QueryDsl 로 통계를 만들면서 Date 타입의 regDt로 groupBy 를 해야했다.
StringTemplate datePath = Expressions.stringTemplate("to_char({0}, '{1s}')",
something.regDt, ConstantImpl.create("YYYYMMDD"));
//...
.groupBy(datePath, something.keyword).orderBy(datePath.desc())
.select(datePath, something.keyword).fetch();
StringTemplate 을 사용해서 oracle 특화 to_char 함수를 사용하였다.
다음으로 mysql 전환을 해야했다.
동일한 기능을 위해 다음의 코드를 작성했다.
StringTemplate datePath = Expressions.stringTemplate("DATE_FORMAT({0}, '{1s}')",
something.regDt, ConstantImpl.create("%Y%m%d"));
최종으로는 DB 관련 bean을 생성자를 통해 주입하여 그 정보로 분기처리하면서 StringTemplate를 리턴하는 Util을 만들었다.
궁금한 점은 자동으로 DB에 따라 이걸 변경해 주는 기능은 없을까???
'개발자 > TIL' 카테고리의 다른 글
[JPA] @Transactional로 DB 커밋 분리하기 (0) | 2020.12.04 |
---|---|
이펙티브 자바 - 하 (0) | 2020.07.15 |
[Docker] Window 도커로 프로젝트 실행하기 1 (0) | 2020.06.27 |
이펙티브 자바 - 상 (0) | 2020.05.06 |
Eclipse maven 프로젝트 build (0) | 2019.10.28 |