Skip to content

Commit

Permalink
[CHORE] jpql 코드 주석 제거 #108
Browse files Browse the repository at this point in the history
  • Loading branch information
jun02160 committed Oct 24, 2023
1 parent 6c21511 commit 3817b62
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,49 +30,17 @@ public class ParentchildDao {

public Optional<Parentchild> findByUserId(Long userId) {

/*String jpql = "SELECT pc FROM Parentchild pc " +
"JOIN User u ON u.parentChild = pc " +
"WHERE u.id = :id";
try {
Parentchild parentchild = em.createQuery(jpql, Parentchild.class)
.setParameter("id", userId)
.getSingleResult();
return Optional.ofNullable(parentchild);
} catch (NoResultException e) {
return Optional.empty();
} finally {
em.close();
}*/

return Optional.ofNullable(queryFactory
.selectFrom(parentchild)
.leftJoin(user.parentChild, parentchild)
.where(
userIdEq(userId)
)
.fetchOne());

}

public Optional<User> findMatchUserByUserId(Long userId) {

/*String jpql = "SELECT u FROM User u " +
"JOIN User uc ON uc.parentChild = u.parentChild " +
"WHERE uc.id = :id AND uc.id != u.id";
try {
User user = em.createQuery(jpql, User.class)
.setParameter("id", userId)
.getSingleResult();
return Optional.ofNullable(user);
} catch (NoResultException e) {
return Optional.empty();
} finally {
em.close();
}*/

QUser uc = new QUser("uc");

return Optional.ofNullable(queryFactory
Expand All @@ -81,38 +49,10 @@ public Optional<User> findMatchUserByUserId(Long userId) {
.join(uc).on(uc.parentChild.eq(user.parentChild))
.where(uc.id.eq(userId).and(uc.id.ne(user.id)))
.fetchOne());


/*QUser userSub = new QUser("userSub");
return Optional.ofNullable(queryFactory
.selectFrom(user)
.where(user.parentChild.eq(
JPAExpressions
.select(userSub.parentChild)
.from(userSub)
.fetchOne()),
userIdEq(userId)
)
.fetchOne());*/
}

public List<String> findFcmTokensById(Long parentchildId) {

/*String jpql = "SELECT u.fcmToken FROM User u " +
"JOIN Parentchild pc ON pc.id = u.parentChild.id " +
"WHERE pc.id = :id";
try {
return em.createQuery(jpql, String.class)
.setParameter("id", parentchildId)
.getResultList();
} catch (NoResultException e) {
return new ArrayList<>();
} finally {
em.close();
}
*/
return queryFactory
.select(user.fcmToken)
.from(user)
Expand All @@ -121,7 +61,6 @@ public List<String> findFcmTokensById(Long parentchildId) {
parentchildIdEq(parentchildId)
)
.fetch();

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,6 @@ public class QnADao {

// 유저 아이디로 QnA 리스트 조회하기
public List<QnA> findQnASByUserId(Long userId) {
/*log.info("jpql 실행 전");
String jpql = "SELECT q FROM Parentchild pc " +
"JOIN pc.qnaList q " +
"LEFT JOIN User u ON u.parentChild.id = pc.id " +
"WHERE u.id = :id";
try {
TypedQuery<QnA> query = em.createQuery(jpql, QnA.class);
log.info("query 실행 성공: {}", query);
List<QnA> qnaList = query
.setParameter("id", userId)
.getResultList();
log.info("query 실행 결과: {}", qnaList.toString());
return Optional.of(qnaList);
} catch (NoResultException e) {
return Optional.empty();
} finally {
em.close();
}*/

return queryFactory
.select(parentchild.qnaList)
.from(parentchild)
Expand Down

0 comments on commit 3817b62

Please sign in to comment.