ํ
์ด๋ธ์ ์์ฒด ์กฐ์ธ์ด ์๋ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค.
์ฟผ๋ฆฌํฉํ ๋ฆฌ
.select(queryBase.getColumns())
.from(entityPath)
.leftJoin(QTodoEntity.todoEntity.parentLocation, QTodoEntity.todoEntity)
.leftJoin(QTodoEntity.locationEntity.country, QCountryEntity.countryEntity)
.where(queryBase.getFilters())
.orderBy(queryBase.getOrderBy())
.offset(queryBase.getOffset())
.limit(queryBase.getLimit())
.์ ์ฑ
()
.๊ฐ์ธ()
.map(queryBase::mapRow)
.collect(์์ง๊ธฐ.toList());
์ผ์ชฝ ์กฐ์ธ์์ ์์ฑ๋ QTodoEntity์ ๋ณ์นญ์ ์ฟผ๋ฆฌ์ ๋ชจ๋ ๊ณณ์์ ์ฌ์ฉ๋ฉ๋๋ค. ์ ํํ ๋ ์์ฑ๋ ๋ณ์นญ์ ์ฌ์ฉํด์ผ ํฉ๋๋ค.
์ฟผ๋ฆฌ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
todo1.id, todo1.name, todo1.custom, todo1.selfChild ์ ํ todo todoOn ์ผ์ชฝ ์ธ๋ถ ์กฐ์ธ todoOnSelect.selfChild=todo1.id์์ Todo todo1 ์ ํ
ํ์ง๋ง ์ฟผ๋ฆฌ๋ -
todoOnSelect.id, todoOnSelect.name, todoOnSelect.custom, todoOnSelect.selfChild๋ฅผ Todo์์ ์ ํ todoOnSelect ์ผ์ชฝ ์ธ๋ถ ์กฐ์ธ todo todo1 on todoOnSelect.selfChild=todo1.id
์ด๊ฒ์ ๋ฒ๊ทธ๊ฐ ์๋๋๋ค.
์ด๊ฒ์ ๋ฒ๊ทธ๊ฐ ์๋๋๋ค.
์ด๋ป๊ฒ ํด๊ฒฐํ์ จ๋์? ๋์ผํ ๋ฌธ์ ๊ฐ ์๋๋ฐ where ์ ์ด 'from' ๋ณ์นญ ๋์ 'left join' ๋ณ์นญ์ ์ฌ์ฉํ๊ณ ์์ผ๋ฉฐ ๊ฒฐ๊ณผ๊ฐ ์๋ชป๋์์ต๋๋ค.
๋๋ ์ป๊ณ ์๋ค :
select count(sub.id) from category c
left join category sub on c.id = sub.id
where sub.type='A'
๊ทธ๊ฒ์ํด์ผํ๋ค:
select count(c.id) from category c
left join category sub on c.id = sub.id
where c.type='A'
๋ค์์ queryDsl์
๋๋ค.
QCategory category = QCategory.category;
query.from(category)
.leftJoin(category.subcategory, QCategory.category)
.where(category.type.equalsIgnoreCase("A"))
.fetchCount();
๊ฐ์ฌ ํด์
๋ค์๊ณผ ๊ฐ์ด ์๋ํ์ญ์์ค -
QCategory ์นดํ
๊ณ ๋ฆฌ = QCategory.category;
QCategory subCategory = ์๋ก์ด QCategory("ํ์");
query.from(์นดํ
๊ณ ๋ฆฌ)
.leftJoin(category.subcategory, subCategory)
.where(category.type.equalsIgnoreCase("A"))
.fetchCount();
์ด๊ฒ์ subCategory์ ๋ณ์นญ์ ์ ๊ณตํ๊ณ where ์ ์์ ์ผ์ชฝ ์กฐ์ธ๋ ํญ๋ชฉ์ด ์๋ ๊ธฐ๋ณธ ํญ๋ชฉ์ ์ ํํฉ๋๋ค.
๋ค์๊ณผ ๊ฐ์ด ์๋ํ์ญ์์ค -
QCategory ์นดํ ๊ณ ๋ฆฌ = QCategory.category;
QCategory subCategory = ์๋ก์ด QCategory("ํ์");
query.from(์นดํ ๊ณ ๋ฆฌ)
.leftJoin(category.subcategory, subCategory)
.where(category.type.equalsIgnoreCase("A"))
.fetchCount();์ด๊ฒ์ subCategory์ ๋ณ์นญ์ ์ ๊ณตํ๊ณ where ์ ์์ ์ผ์ชฝ ์กฐ์ธ๋ ํญ๋ชฉ์ด ์๋ ๊ธฐ๋ณธ ํญ๋ชฉ์ ์ ํํฉ๋๋ค.
๊ทธ๊ฒ์ด ์๋ํ๋ ์ด์ ๋ ํ์คํ์ง ์์ง๋ง ํ์คํ ํธ๋ฆญ์ ์ํํ์ต๋๋ค.
์ ๋ง ๊ณ ๋ง์ต๋๋ค!
:)
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋ค์๊ณผ ๊ฐ์ด ์๋ํ์ญ์์ค -
QCategory ์นดํ ๊ณ ๋ฆฌ = QCategory.category;
QCategory subCategory = ์๋ก์ด QCategory("ํ์");
query.from(์นดํ ๊ณ ๋ฆฌ)
.leftJoin(category.subcategory, subCategory)
.where(category.type.equalsIgnoreCase("A"))
.fetchCount();
์ด๊ฒ์ subCategory์ ๋ณ์นญ์ ์ ๊ณตํ๊ณ where ์ ์์ ์ผ์ชฝ ์กฐ์ธ๋ ํญ๋ชฉ์ด ์๋ ๊ธฐ๋ณธ ํญ๋ชฉ์ ์ ํํฉ๋๋ค.