clause.append(" AND ( ( e.isConfidential = false ) ");
如果确实如此,其余的查询句子永远不会被执行? 在这种情况下真的有用吗?
clause.append(" OR ( e.coordinatorId = (:userId) )");
clause.append(" OR ( e.status <> 'APPROVED' AND e.status <> 'CLOSED') ");
clause.append(" OR ( e.id IN (SELECT a.meetingId FROM Attendant a where a.userId = (:userId) ) )");
查询1。 ......
clause.append(" AND ( ( e.isConfidential = false ) ");
clause.append(" OR ( e.coordinatorId = (:userId) )");
clause.append(" OR ( e.status <> 'APPROVED' AND e.status <> 'CLOSED') ");
clause.append(" OR ( e.id IN (SELECT a.meetingId FROM Attendant a where a.userId = (:userId) ) )");
clause.append(" ) ");
queryParameters.put("userId", userId);
查询2 ......
clause.append(" AND ( ( e.isConfidential = false ) ");
clause.append(" OR ( (e.isConfidential = true) AND (e.coordinatorId = (:userId)) )");
clause.append(" OR ( (e.isConfidential = true) AND (e.coordinatorId <> (:userId)) AND (e.status <> 'APPROVED') AND (e.status <> 'CLOSED')) ");
clause.append(" OR ( (e.isConfidential = true) AND (e.coordinatorId <> (:userId)) AND (e.status = 'APPROVED') AND (e.status = 'CLOSED')
AND e.id IN (SELECT a.meetingId FROM Attendant a where a.userId = (:userId) ) )");
clause.append(" ) ");
queryParameters.put("userId", userId);
答案 0 :(得分:0)
所以AND / OR逻辑的工作原理如下;
True AND True = True
True AND False = False
False AND False = False
True OR True = True
True OR False = True
False OR False = False
所以只需按部分解析每个位;
True AND (False OR (True AND (False OR True)))
与;相同;
True AND (False OR (True AND True))
与;相同;
True AND (False OR True)
与;相同;
True AND True
与;相同;
True
我不能评论查询是否正确,除非我理解它的用途 - 但是乍一看语法看起来还不错。
您是否在执行时收到任何错误消息?