AttributeConverter로 적용하는 필드에 대해 그룹함수 적용은 어떤 방식으로 해야할까요?
373
작성한 질문수 1
안녕하십니까 집합 함수 적용에 관해 궁금한 점이 있어서 질문 드립니다.
아래와 같이 AttributeConverter 적용 필드의 경우에는 QueryDSL로 집합함수 적용이 가능한 방법이 있는지 궁금합니다.
public class Product {
public enum ProductStatus { PROCEEDING, SOLD_OUT;}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "PRODUCT_ID")
private Long id;
@Column(name = "TITLE")
private String title;
@Column(name = "PRICE")
private Money price;
}
public class Money {
public static final Money ZERO = Money.wons(0);
private final BigDecimal amount;
public static Money wons(long amount) {
return new Money(BigDecimal.valueOf(amount));
}
public static Money wons(double amount) {
return new Money(BigDecimal.valueOf(amount));
}
public static <T> Money sum(Collection<T> bags, Function<T, Money> monetary) {
return bags.stream().map(bag -> monetary.apply(bag)).reduce(Money.ZERO, Money::plus);
}
Money(BigDecimal amount) {
this.amount = amount;
}
public Money plus(Money amount) {
return new Money(this.amount.add(amount.amount));
}
public Money minus(Money amount) {
return new Money(this.amount.subtract(amount.amount));
}
public Money times(double percent) {
return new Money(this.amount.multiply(BigDecimal.valueOf(percent)));
}
public Money divide(double divisor) {
return new Money(amount.divide(BigDecimal.valueOf(divisor)));
}
public boolean isLessThan(Money other) {
return amount.compareTo(other.amount) < 0;
}
public boolean isGreaterThan(Money other) {
return amount.compareTo(other.amount) > 0;
}
public BigDecimal getAmount() {
return amount;
}
public Long longValue() {
return amount.longValue();
}
public Double doubleValue() {
return amount.doubleValue();
}
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (!(object instanceof Money)) {
return false;
}
Money other = (Money)object;
return Objects.equals(amount.doubleValue(), other.amount.doubleValue());
}
public int hashCode() {
return Objects.hashCode(amount);
}
public String toString() {
return amount.toString() + "원";
}
}
@Converter(autoApply = true)
public class MoneyConverter implements AttributeConverter<Money, Long> {
@Override
public Long convertToDatabaseColumn(Money money) {
return money.getAmount().longValue();
}
@Override
public Money convertToEntityAttribute(Long amount) {
return Money.wons(amount);
}
}
답변 1
join에대해 질문드립니다.
0
11
1
SpringBoot 4.X에서의 Querydsl 설정
0
158
2
querydsl 오픈소스에 대한 질문
1
101
1
예제에서의 카운트 쿼리에서 join문과 where문은 필요없지 않나요?
0
127
1
Querydsl 6.X버전에 대해서 어떻게 생각하시나요?
0
349
2
여러 테이블 조인하여 통계치를 구하고자 할 때 어떤 방법이 더 효율적일까요
1
86
1
fetchResults()는 더이상 권장되지 않는다는데 맞나요?
0
172
1
querydsl sum() 메서드 없어요.
0
169
2
build 디렉터리 생성
0
152
2
자바 ORM 표준 JPA 프로그래밍 - 기본편 듣고 바로 학습해도 괜찮을까요?
0
123
2
현재 Querydsl에서 from절 서브쿼리를 지원하나요?
0
99
1
오타 제보 드립니다.
0
79
2
벌크 연산과 flush, clear
0
85
1
Run As Intellij 로 변경시 Q타입 import 불가
0
95
1
QHello import하기 문제 발생
0
157
2
등록된 함수 보는법(H2Dialect) 질문
0
76
2
5.0부터 Querydsl은 향후 fetchCount() , fetchResult() 를 지원하지 않기로 결정했다고 하는데 이에 맞는 강의
1
209
2
[환경설정 PDF 부트 3.0이후 설명 질문] build.gradle에 compileQuerydsl을 정의하지 않은 상태에서 Gradle->Tasks->other->compileQuerydsl을 클릭하라고 하는 이유가 무엇인가요??
1
213
1
querydsl 설정 문제
0
228
2
quey dsl 설정부분
0
168
2
count 쿼리 관련 질문입니다!
0
79
1
stringtemplate를 이용하여 where절 검색 방법 질문 드립니다.
0
98
1
답변부탁드리겠습니다.
0
95
2
(OrderSpecifier)관련 내용 어디있을가요
0
68
1





