@@ -157,9 +157,7 @@ public synchronized void close() {
157
157
* Builds the query and closes this QueryBuilder.
158
158
*/
159
159
public Query <T > build () {
160
- if (handle == 0 ) {
161
- throw new IllegalStateException ("This QueryBuilder has already been closed. Please use a new instance." );
162
- }
160
+ verifyHandle ();
163
161
if (combineNextWith != Operator .NONE ) {
164
162
throw new IllegalStateException ("Incomplete logic condition. Use or()/and() between two conditions only." );
165
163
}
@@ -169,6 +167,12 @@ public Query<T> build() {
169
167
return query ;
170
168
}
171
169
170
+ private void verifyHandle () {
171
+ if (handle == 0 ) {
172
+ throw new IllegalStateException ("This QueryBuilder has already been closed. Please use a new instance." );
173
+ }
174
+ }
175
+
172
176
/**
173
177
* Specifies given property to be used for sorting.
174
178
* Shorthand for {@link #order(Property, int)} with flags equal to 0.
@@ -211,6 +215,7 @@ public QueryBuilder<T> orderDesc(Property property) {
211
215
* @see #orderDesc(Property)
212
216
*/
213
217
public QueryBuilder <T > order (Property property , int flags ) {
218
+ verifyHandle ();
214
219
if (combineNextWith != Operator .NONE ) {
215
220
throw new IllegalStateException (
216
221
"An operator is pending. Use operators like and() and or() only between two conditions." );
@@ -346,106 +351,126 @@ private void checkCombineCondition(long currentCondition) {
346
351
}
347
352
348
353
public QueryBuilder <T > isNull (Property property ) {
354
+ verifyHandle ();
349
355
checkCombineCondition (nativeNull (handle , property .getId ()));
350
356
return this ;
351
357
}
352
358
353
359
public QueryBuilder <T > notNull (Property property ) {
360
+ verifyHandle ();
354
361
checkCombineCondition (nativeNotNull (handle , property .getId ()));
355
362
return this ;
356
363
}
357
364
358
365
public QueryBuilder <T > equal (Property property , long value ) {
366
+ verifyHandle ();
359
367
checkCombineCondition (nativeEqual (handle , property .getId (), value ));
360
368
return this ;
361
369
}
362
370
363
371
public QueryBuilder <T > equal (Property property , boolean value ) {
372
+ verifyHandle ();
364
373
checkCombineCondition (nativeEqual (handle , property .getId (), value ? 1 : 0 ));
365
374
return this ;
366
375
}
367
376
368
377
/** @throws NullPointerException if given value is null. Use {@link #isNull(Property)} instead. */
369
378
public QueryBuilder <T > equal (Property property , Date value ) {
379
+ verifyHandle ();
370
380
checkCombineCondition (nativeEqual (handle , property .getId (), value .getTime ()));
371
381
return this ;
372
382
}
373
383
374
384
public QueryBuilder <T > notEqual (Property property , long value ) {
385
+ verifyHandle ();
375
386
checkCombineCondition (nativeNotEqual (handle , property .getId (), value ));
376
387
return this ;
377
388
}
378
389
379
390
public QueryBuilder <T > notEqual (Property property , boolean value ) {
391
+ verifyHandle ();
380
392
checkCombineCondition (nativeNotEqual (handle , property .getId (), value ? 1 : 0 ));
381
393
return this ;
382
394
}
383
395
384
396
/** @throws NullPointerException if given value is null. Use {@link #isNull(Property)} instead. */
385
397
public QueryBuilder <T > notEqual (Property property , Date value ) {
398
+ verifyHandle ();
386
399
checkCombineCondition (nativeNotEqual (handle , property .getId (), value .getTime ()));
387
400
return this ;
388
401
}
389
402
390
403
public QueryBuilder <T > less (Property property , long value ) {
404
+ verifyHandle ();
391
405
checkCombineCondition (nativeLess (handle , property .getId (), value ));
392
406
return this ;
393
407
}
394
408
395
409
public QueryBuilder <T > greater (Property property , long value ) {
410
+ verifyHandle ();
396
411
checkCombineCondition (nativeGreater (handle , property .getId (), value ));
397
412
return this ;
398
413
}
399
414
400
415
public QueryBuilder <T > less (Property property , Date value ) {
416
+ verifyHandle ();
401
417
checkCombineCondition (nativeLess (handle , property .getId (), value .getTime ()));
402
418
return this ;
403
419
}
404
420
405
421
/** @throws NullPointerException if given value is null. Use {@link #isNull(Property)} instead. */
406
422
public QueryBuilder <T > greater (Property property , Date value ) {
423
+ verifyHandle ();
407
424
checkCombineCondition (nativeGreater (handle , property .getId (), value .getTime ()));
408
425
return this ;
409
426
}
410
427
411
428
public QueryBuilder <T > between (Property property , long value1 , long value2 ) {
429
+ verifyHandle ();
412
430
checkCombineCondition (nativeBetween (handle , property .getId (), value1 , value2 ));
413
431
return this ;
414
432
}
415
433
416
434
/** @throws NullPointerException if one of the given values is null. */
417
435
public QueryBuilder <T > between (Property property , Date value1 , Date value2 ) {
436
+ verifyHandle ();
418
437
checkCombineCondition (nativeBetween (handle , property .getId (), value1 .getTime (), value2 .getTime ()));
419
438
return this ;
420
439
}
421
440
422
441
// FIXME DbException: invalid unordered_map<K, T> key
423
442
public QueryBuilder <T > in (Property property , long [] values ) {
443
+ verifyHandle ();
424
444
checkCombineCondition (nativeIn (handle , property .getId (), values , false ));
425
445
return this ;
426
446
}
427
447
428
448
public QueryBuilder <T > in (Property property , int [] values ) {
449
+ verifyHandle ();
429
450
checkCombineCondition (nativeIn (handle , property .getId (), values , false ));
430
451
return this ;
431
452
}
432
453
433
454
public QueryBuilder <T > notIn (Property property , long [] values ) {
455
+ verifyHandle ();
434
456
checkCombineCondition (nativeIn (handle , property .getId (), values , true ));
435
457
return this ;
436
458
}
437
459
438
460
public QueryBuilder <T > notIn (Property property , int [] values ) {
461
+ verifyHandle ();
439
462
checkCombineCondition (nativeIn (handle , property .getId (), values , true ));
440
463
return this ;
441
464
}
442
465
443
466
public QueryBuilder <T > equal (Property property , String value ) {
467
+ verifyHandle ();
444
468
checkCombineCondition (nativeEqual (handle , property .getId (), value , false ));
445
469
return this ;
446
470
}
447
471
448
472
// Help people with floating point equality...
473
+
449
474
/**
450
475
* Floating point equality is non-trivial; this is just a convenience for
451
476
* {@link #between(Property, double, double)} with parameters(property, value - tolerance, value + tolerance).
@@ -457,61 +482,73 @@ public QueryBuilder<T> equal(Property property, double value, double tolerance)
457
482
}
458
483
459
484
public QueryBuilder <T > notEqual (Property property , String value ) {
485
+ verifyHandle ();
460
486
checkCombineCondition (nativeNotEqual (handle , property .getId (), value , false ));
461
487
return this ;
462
488
}
463
489
464
490
public QueryBuilder <T > contains (Property property , String value ) {
491
+ verifyHandle ();
465
492
checkCombineCondition (nativeContains (handle , property .getId (), value , false ));
466
493
return this ;
467
494
}
468
495
469
496
public QueryBuilder <T > startsWith (Property property , String value ) {
497
+ verifyHandle ();
470
498
checkCombineCondition (nativeStartsWith (handle , property .getId (), value , false ));
471
499
return this ;
472
500
}
473
501
474
502
public QueryBuilder <T > endsWith (Property property , String value ) {
503
+ verifyHandle ();
475
504
checkCombineCondition (nativeEndsWith (handle , property .getId (), value , false ));
476
505
return this ;
477
506
}
478
507
479
508
public QueryBuilder <T > equal (Property property , String value , StringOrder order ) {
509
+ verifyHandle ();
480
510
checkCombineCondition (nativeEqual (handle , property .getId (), value , order == StringOrder .CASE_SENSITIVE ));
481
511
return this ;
482
512
}
483
513
484
514
public QueryBuilder <T > notEqual (Property property , String value , StringOrder order ) {
515
+ verifyHandle ();
485
516
checkCombineCondition (nativeNotEqual (handle , property .getId (), value , order == StringOrder .CASE_SENSITIVE ));
486
517
return this ;
487
518
}
488
519
489
520
public QueryBuilder <T > contains (Property property , String value , StringOrder order ) {
521
+ verifyHandle ();
490
522
checkCombineCondition (nativeContains (handle , property .getId (), value , order == StringOrder .CASE_SENSITIVE ));
491
523
return this ;
492
524
}
493
525
494
526
public QueryBuilder <T > startsWith (Property property , String value , StringOrder order ) {
527
+ verifyHandle ();
495
528
checkCombineCondition (nativeStartsWith (handle , property .getId (), value , order == StringOrder .CASE_SENSITIVE ));
496
529
return this ;
497
530
}
498
531
499
532
public QueryBuilder <T > endsWith (Property property , String value , StringOrder order ) {
533
+ verifyHandle ();
500
534
checkCombineCondition (nativeEndsWith (handle , property .getId (), value , order == StringOrder .CASE_SENSITIVE ));
501
535
return this ;
502
536
}
503
537
504
538
public QueryBuilder <T > less (Property property , double value ) {
539
+ verifyHandle ();
505
540
checkCombineCondition (nativeLess (handle , property .getId (), value ));
506
541
return this ;
507
542
}
508
543
509
544
public QueryBuilder <T > greater (Property property , double value ) {
545
+ verifyHandle ();
510
546
checkCombineCondition (nativeGreater (handle , property .getId (), value ));
511
547
return this ;
512
548
}
513
549
514
550
public QueryBuilder <T > between (Property property , double value1 , double value2 ) {
551
+ verifyHandle ();
515
552
checkCombineCondition (nativeBetween (handle , property .getId (), value1 , value2 ));
516
553
return this ;
517
554
}
0 commit comments