|
17 | 17 | package io.objectbox;
|
18 | 18 |
|
19 | 19 | import java.io.Serializable;
|
20 |
| -import java.util.Collection; |
| 20 | +import java.util.Date; |
21 | 21 |
|
22 | 22 | import javax.annotation.Nullable;
|
23 | 23 |
|
24 | 24 | import io.objectbox.annotation.apihint.Internal;
|
25 | 25 | import io.objectbox.converter.PropertyConverter;
|
26 | 26 | import io.objectbox.exception.DbException;
|
27 |
| -import io.objectbox.query.QueryCondition; |
28 |
| -import io.objectbox.query.QueryCondition.PropertyCondition; |
29 |
| -import io.objectbox.query.QueryCondition.PropertyCondition.Operation; |
| 27 | +import io.objectbox.query.PropertyQueryCondition; |
| 28 | +import io.objectbox.query.PropertyQueryConditionImpl.ByteArrayCondition; |
| 29 | +import io.objectbox.query.PropertyQueryConditionImpl.DoubleCondition; |
| 30 | +import io.objectbox.query.PropertyQueryConditionImpl.DoubleDoubleCondition; |
| 31 | +import io.objectbox.query.PropertyQueryConditionImpl.IntArrayCondition; |
| 32 | +import io.objectbox.query.PropertyQueryConditionImpl.LongArrayCondition; |
| 33 | +import io.objectbox.query.PropertyQueryConditionImpl.LongCondition; |
| 34 | +import io.objectbox.query.PropertyQueryConditionImpl.LongLongCondition; |
| 35 | +import io.objectbox.query.PropertyQueryConditionImpl.NullCondition; |
| 36 | +import io.objectbox.query.PropertyQueryConditionImpl.StringArrayCondition; |
| 37 | +import io.objectbox.query.PropertyQueryConditionImpl.StringCondition; |
| 38 | +import io.objectbox.query.PropertyQueryConditionImpl.StringCondition.Operation; |
| 39 | +import io.objectbox.query.QueryBuilder.StringOrder; |
30 | 40 |
|
31 | 41 | /**
|
32 | 42 | * Meta data describing a property of an ObjectBox entity.
|
@@ -90,71 +100,208 @@ public Property(EntityInfo<ENTITY> entity, int ordinal, int id, Class<?> type, S
|
90 | 100 | this.customType = customType;
|
91 | 101 | }
|
92 | 102 |
|
93 |
| - /** Creates an "equal ('=')" condition for this property. */ |
94 |
| - public QueryCondition eq(Object value) { |
95 |
| - return new PropertyCondition(this, Operation.EQUALS, value); |
| 103 | + /** Creates an "IS NULL" condition for this property. */ |
| 104 | + public PropertyQueryCondition<ENTITY> isNull() { |
| 105 | + return new NullCondition<>(this, NullCondition.Operation.IS_NULL); |
96 | 106 | }
|
97 | 107 |
|
98 |
| - /** Creates an "not equal ('<>')" condition for this property. */ |
99 |
| - public QueryCondition notEq(Object value) { |
100 |
| - return new PropertyCondition(this, Operation.NOT_EQUALS, value); |
| 108 | + /** Creates an "IS NOT NULL" condition for this property. */ |
| 109 | + public PropertyQueryCondition<ENTITY> notNull() { |
| 110 | + return new NullCondition<>(this, NullCondition.Operation.NOT_NULL); |
101 | 111 | }
|
102 | 112 |
|
103 |
| - /** Creates an "BETWEEN ... AND ..." condition for this property. */ |
104 |
| - public QueryCondition between(Object value1, Object value2) { |
105 |
| - Object[] values = {value1, value2}; |
106 |
| - return new PropertyCondition(this, Operation.BETWEEN, values); |
| 113 | + /** Creates an "equal ('=')" condition for this property. */ |
| 114 | + public PropertyQueryCondition<ENTITY> equal(boolean value) { |
| 115 | + return new LongCondition<>(this, LongCondition.Operation.EQUAL, value); |
107 | 116 | }
|
108 | 117 |
|
109 |
| - /** Creates an "IN (..., ..., ...)" condition for this property. */ |
110 |
| - public QueryCondition in(Object... inValues) { |
111 |
| - return new PropertyCondition(this, Operation.IN, inValues); |
| 118 | + /** Creates a "not equal ('<>')" condition for this property. */ |
| 119 | + public PropertyQueryCondition<ENTITY> notEqual(boolean value) { |
| 120 | + return new LongCondition<>(this, LongCondition.Operation.NOT_EQUAL, value); |
112 | 121 | }
|
113 | 122 |
|
114 | 123 | /** Creates an "IN (..., ..., ...)" condition for this property. */
|
115 |
| - public QueryCondition in(Collection<?> inValues) { |
116 |
| - return in(inValues.toArray()); |
| 124 | + public PropertyQueryCondition<ENTITY> oneOf(int[] values) { |
| 125 | + return new IntArrayCondition<>(this, IntArrayCondition.Operation.IN, values); |
117 | 126 | }
|
118 | 127 |
|
119 |
| - /** Creates an "greater than ('>')" condition for this property. */ |
120 |
| - public QueryCondition gt(Object value) { |
121 |
| - return new PropertyCondition(this, Operation.GREATER_THAN, value); |
| 128 | + /** Creates a "NOT IN (..., ..., ...)" condition for this property. */ |
| 129 | + public PropertyQueryCondition<ENTITY> notOneOf(int[] values) { |
| 130 | + return new IntArrayCondition<>(this, IntArrayCondition.Operation.NOT_IN, values); |
122 | 131 | }
|
123 | 132 |
|
124 |
| - /** Creates an "less than ('<')" condition for this property. */ |
125 |
| - public QueryCondition lt(Object value) { |
126 |
| - return new PropertyCondition(this, Operation.LESS_THAN, value); |
| 133 | + /** Creates an "equal ('=')" condition for this property. */ |
| 134 | + public PropertyQueryCondition<ENTITY> equal(long value) { |
| 135 | + return new LongCondition<>(this, LongCondition.Operation.EQUAL, value); |
127 | 136 | }
|
128 | 137 |
|
129 |
| - /** Creates an "IS NULL" condition for this property. */ |
130 |
| - public QueryCondition isNull() { |
131 |
| - return new PropertyCondition(this, Operation.IS_NULL, null); |
| 138 | + /** Creates a "not equal ('<>')" condition for this property. */ |
| 139 | + public PropertyQueryCondition<ENTITY> notEqual(long value) { |
| 140 | + return new LongCondition<>(this, LongCondition.Operation.NOT_EQUAL, value); |
132 | 141 | }
|
133 | 142 |
|
134 |
| - /** Creates an "IS NOT NULL" condition for this property. */ |
135 |
| - public QueryCondition isNotNull() { |
136 |
| - return new PropertyCondition(this, Operation.IS_NOT_NULL, null); |
| 143 | + /** Creates a "greater than ('>')" condition for this property. */ |
| 144 | + public PropertyQueryCondition<ENTITY> greater(long value) { |
| 145 | + return new LongCondition<>(this, LongCondition.Operation.GREATER, value); |
137 | 146 | }
|
138 | 147 |
|
139 |
| - /** |
140 |
| - * @see io.objectbox.query.QueryBuilder#contains(Property, String) |
141 |
| - */ |
142 |
| - public QueryCondition contains(String value) { |
143 |
| - return new PropertyCondition(this, Operation.CONTAINS, value); |
| 148 | + /** Creates a "less than ('<')" condition for this property. */ |
| 149 | + public PropertyQueryCondition<ENTITY> less(long value) { |
| 150 | + return new LongCondition<>(this, LongCondition.Operation.LESS, value); |
144 | 151 | }
|
145 | 152 |
|
146 |
| - /** |
147 |
| - * @see io.objectbox.query.QueryBuilder#startsWith(Property, String) |
148 |
| - */ |
149 |
| - public QueryCondition startsWith(String value) { |
150 |
| - return new PropertyCondition(this, Operation.STARTS_WITH, value); |
| 153 | + /** Creates an "IN (..., ..., ...)" condition for this property. */ |
| 154 | + public PropertyQueryCondition<ENTITY> oneOf(long[] values) { |
| 155 | + return new LongArrayCondition<>(this, LongArrayCondition.Operation.IN, values); |
| 156 | + } |
| 157 | + |
| 158 | + /** Creates a "NOT IN (..., ..., ...)" condition for this property. */ |
| 159 | + public PropertyQueryCondition<ENTITY> notOneOf(long[] values) { |
| 160 | + return new LongArrayCondition<>(this, LongArrayCondition.Operation.NOT_IN, values); |
| 161 | + } |
| 162 | + |
| 163 | + /** Creates an "BETWEEN ... AND ..." condition for this property. */ |
| 164 | + public PropertyQueryCondition<ENTITY> between(long lowerBoundary, long upperBoundary) { |
| 165 | + return new LongLongCondition<>(this, LongLongCondition.Operation.BETWEEN, lowerBoundary, upperBoundary); |
151 | 166 | }
|
152 | 167 |
|
153 | 168 | /**
|
154 |
| - * @see io.objectbox.query.QueryBuilder#endsWith(Property, String) |
| 169 | + * Calls {@link #between(double, double)} with {@code value - tolerance} as lower bound and |
| 170 | + * {@code value + tolerance} as upper bound. |
155 | 171 | */
|
156 |
| - public QueryCondition endsWith(String value) { |
157 |
| - return new PropertyCondition(this, Operation.ENDS_WITH, value); |
| 172 | + public PropertyQueryCondition<ENTITY> equal(double value, double tolerance) { |
| 173 | + return new DoubleDoubleCondition<>(this, DoubleDoubleCondition.Operation.BETWEEN, |
| 174 | + value - tolerance, value + tolerance); |
| 175 | + } |
| 176 | + |
| 177 | + /** Creates a "greater than ('>')" condition for this property. */ |
| 178 | + public PropertyQueryCondition<ENTITY> greater(double value) { |
| 179 | + return new DoubleCondition<>(this, DoubleCondition.Operation.GREATER, value); |
| 180 | + } |
| 181 | + |
| 182 | + /** Creates a "less than ('<')" condition for this property. */ |
| 183 | + public PropertyQueryCondition<ENTITY> less(double value) { |
| 184 | + return new DoubleCondition<>(this, DoubleCondition.Operation.LESS, value); |
| 185 | + } |
| 186 | + |
| 187 | + /** Creates an "BETWEEN ... AND ..." condition for this property. */ |
| 188 | + public PropertyQueryCondition<ENTITY> between(double lowerBoundary, double upperBoundary) { |
| 189 | + return new DoubleDoubleCondition<>(this, DoubleDoubleCondition.Operation.BETWEEN, |
| 190 | + lowerBoundary, upperBoundary); |
| 191 | + } |
| 192 | + |
| 193 | + /** Creates an "equal ('=')" condition for this property. */ |
| 194 | + public PropertyQueryCondition<ENTITY> equal(Date value) { |
| 195 | + return new LongCondition<>(this, LongCondition.Operation.EQUAL, value); |
| 196 | + } |
| 197 | + |
| 198 | + /** Creates a "not equal ('<>')" condition for this property. */ |
| 199 | + public PropertyQueryCondition<ENTITY> notEqual(Date value) { |
| 200 | + return new LongCondition<>(this, LongCondition.Operation.NOT_EQUAL, value); |
| 201 | + } |
| 202 | + |
| 203 | + /** Creates a "greater than ('>')" condition for this property. */ |
| 204 | + public PropertyQueryCondition<ENTITY> greater(Date value) { |
| 205 | + return new LongCondition<>(this, LongCondition.Operation.GREATER, value); |
| 206 | + } |
| 207 | + |
| 208 | + /** Creates a "less than ('<')" condition for this property. */ |
| 209 | + public PropertyQueryCondition<ENTITY> less(Date value) { |
| 210 | + return new LongCondition<>(this, LongCondition.Operation.LESS, value); |
| 211 | + } |
| 212 | + |
| 213 | + /** Creates an "BETWEEN ... AND ..." condition for this property. */ |
| 214 | + public PropertyQueryCondition<ENTITY> between(Date lowerBoundary, Date upperBoundary) { |
| 215 | + return new LongLongCondition<>(this, LongLongCondition.Operation.BETWEEN, lowerBoundary, upperBoundary); |
| 216 | + } |
| 217 | + |
| 218 | + /** Creates an "equal ('=')" condition for this property. */ |
| 219 | + public PropertyQueryCondition<ENTITY> equal(String value) { |
| 220 | + return new StringCondition<>(this, StringCondition.Operation.EQUAL, value); |
| 221 | + } |
| 222 | + |
| 223 | + /** Creates an "equal ('=')" condition for this property. */ |
| 224 | + public PropertyQueryCondition<ENTITY> equal(String value, StringOrder order) { |
| 225 | + return new StringCondition<>(this, StringCondition.Operation.EQUAL, value, order); |
| 226 | + } |
| 227 | + |
| 228 | + /** Creates a "not equal ('<>')" condition for this property. */ |
| 229 | + public PropertyQueryCondition<ENTITY> notEqual(String value) { |
| 230 | + return new StringCondition<>(this, StringCondition.Operation.NOT_EQUAL, value); |
| 231 | + } |
| 232 | + |
| 233 | + /** Creates a "not equal ('<>')" condition for this property. */ |
| 234 | + public PropertyQueryCondition<ENTITY> notEqual(String value, StringOrder order) { |
| 235 | + return new StringCondition<>(this, StringCondition.Operation.NOT_EQUAL, value, order); |
| 236 | + } |
| 237 | + |
| 238 | + /** Creates a "greater than ('>')" condition for this property. */ |
| 239 | + public PropertyQueryCondition<ENTITY> greater(String value) { |
| 240 | + return new StringCondition<>(this, StringCondition.Operation.GREATER, value); |
| 241 | + } |
| 242 | + |
| 243 | + /** Creates a "greater than ('>')" condition for this property. */ |
| 244 | + public PropertyQueryCondition<ENTITY> greater(String value, StringOrder order) { |
| 245 | + return new StringCondition<>(this, StringCondition.Operation.GREATER, value, order); |
| 246 | + } |
| 247 | + |
| 248 | + /** Creates a "less than ('<')" condition for this property. */ |
| 249 | + public PropertyQueryCondition<ENTITY> less(String value) { |
| 250 | + return new StringCondition<>(this, StringCondition.Operation.LESS, value); |
| 251 | + } |
| 252 | + |
| 253 | + /** Creates a "less than ('<')" condition for this property. */ |
| 254 | + public PropertyQueryCondition<ENTITY> less(String value, StringOrder order) { |
| 255 | + return new StringCondition<>(this, StringCondition.Operation.LESS, value, order); |
| 256 | + } |
| 257 | + |
| 258 | + public PropertyQueryCondition<ENTITY> contains(String value) { |
| 259 | + return new StringCondition<>(this, StringCondition.Operation.CONTAINS, value); |
| 260 | + } |
| 261 | + |
| 262 | + public PropertyQueryCondition<ENTITY> contains(String value, StringOrder order) { |
| 263 | + return new StringCondition<>(this, StringCondition.Operation.CONTAINS, value, order); |
| 264 | + } |
| 265 | + |
| 266 | + public PropertyQueryCondition<ENTITY> startsWith(String value) { |
| 267 | + return new StringCondition<>(this, Operation.STARTS_WITH, value); |
| 268 | + } |
| 269 | + |
| 270 | + public PropertyQueryCondition<ENTITY> startsWith(String value, StringOrder order) { |
| 271 | + return new StringCondition<>(this, Operation.STARTS_WITH, value, order); |
| 272 | + } |
| 273 | + |
| 274 | + public PropertyQueryCondition<ENTITY> endsWith(String value) { |
| 275 | + return new StringCondition<>(this, Operation.ENDS_WITH, value); |
| 276 | + } |
| 277 | + |
| 278 | + public PropertyQueryCondition<ENTITY> endsWith(String value, StringOrder order) { |
| 279 | + return new StringCondition<>(this, Operation.ENDS_WITH, value, order); |
| 280 | + } |
| 281 | + |
| 282 | + /** Creates an "IN (..., ..., ...)" condition for this property. */ |
| 283 | + public PropertyQueryCondition<ENTITY> oneOf(String[] values) { |
| 284 | + return new StringArrayCondition<>(this, StringArrayCondition.Operation.IN, values); |
| 285 | + } |
| 286 | + |
| 287 | + /** Creates an "IN (..., ..., ...)" condition for this property. */ |
| 288 | + public PropertyQueryCondition<ENTITY> oneOf(String[] values, StringOrder order) { |
| 289 | + return new StringArrayCondition<>(this, StringArrayCondition.Operation.IN, values, order); |
| 290 | + } |
| 291 | + |
| 292 | + /** Creates an "equal ('=')" condition for this property. */ |
| 293 | + public PropertyQueryCondition<ENTITY> equal(byte[] value) { |
| 294 | + return new ByteArrayCondition<>(this, ByteArrayCondition.Operation.EQUAL, value); |
| 295 | + } |
| 296 | + |
| 297 | + /** Creates a "greater than ('>')" condition for this property. */ |
| 298 | + public PropertyQueryCondition<ENTITY> greater(byte[] value) { |
| 299 | + return new ByteArrayCondition<>(this, ByteArrayCondition.Operation.GREATER, value); |
| 300 | + } |
| 301 | + |
| 302 | + /** Creates a "less than ('<')" condition for this property. */ |
| 303 | + public PropertyQueryCondition<ENTITY> less(byte[] value) { |
| 304 | + return new ByteArrayCondition<>(this, ByteArrayCondition.Operation.LESS, value); |
158 | 305 | }
|
159 | 306 |
|
160 | 307 | @Internal
|
|
0 commit comments