Changeset 7911
- Timestamp:
- Feb 17, 2021, 12:56:26 PM (2 years ago)
- Location:
- trunk/src/core/net/sf/basedb/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/ItemContext.java
r7895 r7911 2376 2376 if (rowIdList != null) 2377 2377 { 2378 rowIdList. intersect((IdListRestriction)r);2378 rowIdList.mergeAnd((IdListRestriction)r); 2379 2379 r = null; 2380 2380 } -
trunk/src/core/net/sf/basedb/core/query/IdListRestriction.java
r7772 r7911 34 34 35 35 id IN (a, b, c, ....) 36 id NOT IN (a, b, c, ....) 36 37 37 38 @author nicklas … … 42 43 { 43 44 44 private final Set<Integer> idList; 45 private boolean notIn; 46 private Set<Integer> idList; 45 47 private final Expression idExpression; 46 48 47 49 public IdListRestriction() 48 50 { 49 this(new HashSet<>()); 51 this(false, new HashSet<>()); 52 } 53 54 /** 55 @since 3.18 56 */ 57 public IdListRestriction(boolean notIn) 58 { 59 this(notIn, new HashSet<>()); 50 60 } 51 61 52 62 public IdListRestriction(Set<Integer> idList) 53 63 { 64 this(false, idList); 65 } 66 67 /** 68 @since 3.18 69 */ 70 public IdListRestriction(boolean notIn, Set<Integer> idList) 71 { 72 this.notIn = notIn; 54 73 this.idList = new HashSet<>(idList); 55 74 this.idExpression = Hql.property("id"); … … 60 79 { 61 80 String idString = idList.size() == 0 ? "0" : Values.getString(idList, ", ", true); 62 return "(" + idExpression.toQl(query, dc) + " IN(" + idString + "))";81 return "(" + idExpression.toQl(query, dc) + (notIn ? " NOT IN " : " IN ") +"(" + idString + "))"; 63 82 } 64 83 … … 72 91 { 73 92 String idString = idList.size() == 0 ? "0" : Values.getString(idList, ", ", true); 74 return idExpression.toString() + " IN(" + idString + ")";93 return idExpression.toString() + (notIn ? " NOT IN " : " IN ") + "(" + idString + ")"; 75 94 } 76 95 … … 78 97 Merge this id list with another list. This list will now 79 98 contain the combined set of ids from both lists. 99 NOTE! This method ignore the 'notIn' setting for both lists. 80 100 */ 81 101 public void union(IdListRestriction other) … … 87 107 Merge this id list with another list. This list will 88 108 now contain only the ids that are found in both lists. 109 NOTE! This method ignore the 'notIn' setting for both lists. 89 110 */ 90 111 public void intersect(IdListRestriction other) … … 93 114 } 94 115 116 /** 117 Merge this id list with another list by removing 118 ids that are found in the other list. 119 NOTE! This method ignore the 'notIn' setting for both lists. 120 */ 121 public void remove(IdListRestriction other) 122 { 123 this.idList.removeAll(other.idList); 124 } 125 126 /** 127 Merge this list with another list with AND logic respecting 128 the notIn setting. This may cause the list of ids and notIn 129 setting of this list to change. 130 @since 3.18 131 */ 132 public void mergeAnd(IdListRestriction other) 133 { 134 if (notIn == other.notIn) 135 { 136 if (notIn) 137 { 138 // NOT IN(A,B) AND NOT IN(B,C) --> NOT IN(A,B,C) 139 // Merge with UNION and keep notIn setting 140 union(other); 141 } 142 else 143 { 144 // IN(A,B) AND IN(B,C) --> IN(B) 145 // Merge with INTERSECT and keep notIn setting 146 intersect(other); 147 } 148 } 149 else 150 { 151 if (notIn) 152 { 153 // NOT IN(A,B) AND IN(B,C) --> IN(C) 154 // Swap, merge with REMOVE and change notIn setting 155 Set<Integer> tmp = new HashSet<>(other.idList); 156 tmp.removeAll(idList); 157 idList = tmp; 158 notIn = false; 159 } 160 else 161 { 162 // IN(A,B) AND NOT IN(B,C) --> IN(A) 163 // Merge with REMOVE and keep notIn setting 164 remove(other); 165 } 166 } 167 } 95 168 96 169 }
Note: See TracChangeset
for help on using the changeset viewer.