Replace in to equals. (#203)

This commit is contained in:
Kavin 2022-02-28 22:46:15 +00:00 committed by GitHub
parent df526016df
commit 597e861159
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,7 +10,6 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.JoinType; import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import java.util.List;
public class DatabaseHelper { public class DatabaseHelper {
@ -18,7 +17,7 @@ public class DatabaseHelper {
CriteriaBuilder cb = s.getCriteriaBuilder(); CriteriaBuilder cb = s.getCriteriaBuilder();
CriteriaQuery<User> cr = cb.createQuery(User.class); CriteriaQuery<User> cr = cb.createQuery(User.class);
Root<User> root = cr.from(User.class); Root<User> root = cr.from(User.class);
cr.select(root).where(root.get("sessionId").in(session)); cr.select(root).where(cb.equal(root.get("sessionId"), session));
return s.createQuery(cr).uniqueResult(); return s.createQuery(cr).uniqueResult();
} }
@ -28,7 +27,7 @@ public class DatabaseHelper {
CriteriaQuery<User> cr = cb.createQuery(User.class); CriteriaQuery<User> cr = cb.createQuery(User.class);
Root<User> root = cr.from(User.class); Root<User> root = cr.from(User.class);
root.fetch("subscribed_ids", JoinType.INNER); root.fetch("subscribed_ids", JoinType.INNER);
cr.select(root).where(root.get("sessionId").in(session)); cr.select(root).where(cb.equal(root.get("sessionId"), session));
return s.createQuery(cr).uniqueResult(); return s.createQuery(cr).uniqueResult();
} }
@ -37,35 +36,16 @@ public class DatabaseHelper {
CriteriaBuilder cb = s.getCriteriaBuilder(); CriteriaBuilder cb = s.getCriteriaBuilder();
CriteriaQuery<Channel> cr = cb.createQuery(Channel.class); CriteriaQuery<Channel> cr = cb.createQuery(Channel.class);
Root<Channel> root = cr.from(Channel.class); Root<Channel> root = cr.from(Channel.class);
cr.select(root).where(root.get("uploader_id").in(id)); cr.select(root).where(cb.equal(root.get("uploader_id"), id));
return s.createQuery(cr).uniqueResult(); return s.createQuery(cr).uniqueResult();
} }
public static final List<Channel> getChannelFromIds(Session s, List<String> id) {
CriteriaBuilder cb = s.getCriteriaBuilder();
CriteriaQuery<Channel> cr = cb.createQuery(Channel.class);
Root<Channel> root = cr.from(Channel.class);
cr.select(root).where(root.get("uploader_id").in(id));
return s.createQuery(cr).getResultList();
}
public static final List<Video> getVideosFromChannelIds(Session s, List<String> id) {
CriteriaBuilder cb = s.getCriteriaBuilder();
CriteriaQuery<Video> cr = cb.createQuery(Video.class);
Root<Video> root = cr.from(Video.class);
root.fetch("channel", JoinType.INNER);
cr.select(root).where(root.get("channel").get("uploader_id").in(id));
return s.createQuery(cr).getResultList();
}
public static final Video getVideoFromId(Session s, String id) { public static final Video getVideoFromId(Session s, String id) {
CriteriaBuilder cb = s.getCriteriaBuilder(); CriteriaBuilder cb = s.getCriteriaBuilder();
CriteriaQuery<Video> cr = cb.createQuery(Video.class); CriteriaQuery<Video> cr = cb.createQuery(Video.class);
Root<Video> root = cr.from(Video.class); Root<Video> root = cr.from(Video.class);
cr.select(root).where(root.get("id").in(id)); cr.select(root).where(cb.equal(root.get("id"), id));
return s.createQuery(cr).uniqueResult(); return s.createQuery(cr).uniqueResult();
} }
@ -74,7 +54,7 @@ public class DatabaseHelper {
CriteriaBuilder cb = s.getCriteriaBuilder(); CriteriaBuilder cb = s.getCriteriaBuilder();
CriteriaQuery<PubSub> cr = cb.createQuery(PubSub.class); CriteriaQuery<PubSub> cr = cb.createQuery(PubSub.class);
Root<PubSub> root = cr.from(PubSub.class); Root<PubSub> root = cr.from(PubSub.class);
cr.select(root).where(root.get("id").in(id)); cr.select(root).where(cb.equal(root.get("id"), id));
return s.createQuery(cr).uniqueResult(); return s.createQuery(cr).uniqueResult();
} }