34
34
import jakarta .persistence .TypedQuery ;
35
35
import jakarta .persistence .criteria .CriteriaBuilder ;
36
36
import jakarta .persistence .criteria .CriteriaQuery ;
37
- import jakarta .persistence .criteria .Order ;
38
37
import jakarta .persistence .criteria .ParameterExpression ;
39
38
import jakarta .persistence .criteria .Path ;
40
39
import jakarta .persistence .criteria .Predicate ;
@@ -212,13 +211,13 @@ public void deleteAllByIdInBatch(Iterable<ID> ids) {
212
211
}
213
212
214
213
if (entityInformation .hasCompositeId ()) {
215
- // XXX Hibernate just creates an empty Entity when doing the getById.
216
- // Others might do a select right away causing a big performance penalty.
217
- // See JavaDoc for getById.
214
+
218
215
List <T > entities = new ArrayList <>();
219
- ids .forEach (id -> entities .add (getById (id )));
216
+ // generate entity (proxies) without accessing the database.
217
+ ids .forEach (id -> entities .add (getReferenceById (id )));
220
218
deleteAllInBatch (entities );
221
219
} else {
220
+
222
221
String queryString = String .format (DELETE_ALL_QUERY_BY_ID_STRING , entityInformation .getEntityName (),
223
222
entityInformation .getIdAttribute ().getName ());
224
223
@@ -292,7 +291,6 @@ public Optional<T> findById(ID id) {
292
291
* Returns {@link QueryHints} with the query hints based on the current {@link CrudMethodMetadata} and potential
293
292
* {@link EntityGraph} information.
294
293
*
295
- * @return
296
294
*/
297
295
protected QueryHints getQueryHints () {
298
296
return metadata == null ? NoHints .INSTANCE : DefaultQueryHints .of (entityInformation , metadata );
@@ -377,7 +375,7 @@ public List<T> findAllById(Iterable<ID> ids) {
377
375
378
376
if (entityInformation .hasCompositeId ()) {
379
377
380
- List <T > results = new ArrayList <T >();
378
+ List <T > results = new ArrayList <>();
381
379
382
380
for (ID id : ids ) {
383
381
findById (id ).ifPresent (results ::add );
@@ -388,7 +386,7 @@ public List<T> findAllById(Iterable<ID> ids) {
388
386
389
387
Collection <ID > idCollection = Streamable .of (ids ).toList ();
390
388
391
- ByIdsSpecification <T > specification = new ByIdsSpecification <T >(entityInformation );
389
+ ByIdsSpecification <T > specification = new ByIdsSpecification <>(entityInformation );
392
390
TypedQuery <T > query = getQuery (specification , Sort .unsorted ());
393
391
394
392
return query .setParameter (specification .parameter , idCollection ).getResultList ();
@@ -403,7 +401,7 @@ public List<T> findAll(Sort sort) {
403
401
public Page <T > findAll (Pageable pageable ) {
404
402
405
403
if (isUnpaged (pageable )) {
406
- return new PageImpl <T >(findAll ());
404
+ return new PageImpl <>(findAll ());
407
405
}
408
406
409
407
return findAll ((Specification <T >) null , pageable );
@@ -428,7 +426,7 @@ public List<T> findAll(@Nullable Specification<T> spec) {
428
426
public Page <T > findAll (@ Nullable Specification <T > spec , Pageable pageable ) {
429
427
430
428
TypedQuery <T > query = getQuery (spec , pageable );
431
- return isUnpaged (pageable ) ? new PageImpl <T >(query .getResultList ())
429
+ return isUnpaged (pageable ) ? new PageImpl <>(query .getResultList ())
432
430
: readPage (query , getDomainClass (), pageable , spec );
433
431
}
434
432
@@ -442,7 +440,7 @@ public <S extends T> Optional<S> findOne(Example<S> example) {
442
440
443
441
try {
444
442
return Optional
445
- .of (getQuery (new ExampleSpecification <S >(example , escapeCharacter ), example .getProbeType (), Sort .unsorted ())
443
+ .of (getQuery (new ExampleSpecification <>(example , escapeCharacter ), example .getProbeType (), Sort .unsorted ())
446
444
.getSingleResult ());
447
445
} catch (NoResultException e ) {
448
446
return Optional .empty ();
@@ -452,7 +450,7 @@ public <S extends T> Optional<S> findOne(Example<S> example) {
452
450
@ Override
453
451
public <S extends T > long count (Example <S > example ) {
454
452
return executeCountQuery (
455
- getCountQuery (new ExampleSpecification <S >(example , escapeCharacter ), example .getProbeType ()));
453
+ getCountQuery (new ExampleSpecification <>(example , escapeCharacter ), example .getProbeType ()));
456
454
}
457
455
458
456
@ Override
@@ -468,13 +466,13 @@ public <S extends T> boolean exists(Example<S> example) {
468
466
469
467
@ Override
470
468
public <S extends T > List <S > findAll (Example <S > example ) {
471
- return getQuery (new ExampleSpecification <S >(example , escapeCharacter ), example .getProbeType (), Sort .unsorted ())
469
+ return getQuery (new ExampleSpecification <>(example , escapeCharacter ), example .getProbeType (), Sort .unsorted ())
472
470
.getResultList ();
473
471
}
474
472
475
473
@ Override
476
474
public <S extends T > List <S > findAll (Example <S > example , Sort sort ) {
477
- return getQuery (new ExampleSpecification <S >(example , escapeCharacter ), example .getProbeType (), sort )
475
+ return getQuery (new ExampleSpecification <>(example , escapeCharacter ), example .getProbeType (), sort )
478
476
.getResultList ();
479
477
}
480
478
@@ -548,7 +546,7 @@ public <S extends T> List<S> saveAll(Iterable<S> entities) {
548
546
549
547
Assert .notNull (entities , "Entities must not be null!" );
550
548
551
- List <S > result = new ArrayList <S >();
549
+ List <S > result = new ArrayList <>();
552
550
553
551
for (S entity : entities ) {
554
552
result .add (save (entity ));
@@ -580,7 +578,6 @@ public void flush() {
580
578
* @param query must not be {@literal null}.
581
579
* @param spec can be {@literal null}.
582
580
* @param pageable must not be {@literal null}.
583
- * @return
584
581
* @deprecated use {@link #readPage(TypedQuery, Class, Pageable, Specification)} instead
585
582
*/
586
583
@ Deprecated
@@ -596,7 +593,6 @@ protected Page<T> readPage(TypedQuery<T> query, Pageable pageable, @Nullable Spe
596
593
* @param domainClass must not be {@literal null}.
597
594
* @param spec can be {@literal null}.
598
595
* @param pageable can be {@literal null}.
599
- * @return
600
596
*/
601
597
protected <S extends T > Page <S > readPage (TypedQuery <S > query , final Class <S > domainClass , Pageable pageable ,
602
598
@ Nullable Specification <S > spec ) {
@@ -615,7 +611,6 @@ protected <S extends T> Page<S> readPage(TypedQuery<S> query, final Class<S> dom
615
611
*
616
612
* @param spec can be {@literal null}.
617
613
* @param pageable must not be {@literal null}.
618
- * @return
619
614
*/
620
615
protected TypedQuery <T > getQuery (@ Nullable Specification <T > spec , Pageable pageable ) {
621
616
@@ -629,7 +624,6 @@ protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Pageable pagea
629
624
* @param spec can be {@literal null}.
630
625
* @param domainClass must not be {@literal null}.
631
626
* @param pageable must not be {@literal null}.
632
- * @return
633
627
*/
634
628
protected <S extends T > TypedQuery <S > getQuery (@ Nullable Specification <S > spec , Class <S > domainClass ,
635
629
Pageable pageable ) {
@@ -643,7 +637,6 @@ protected <S extends T> TypedQuery<S> getQuery(@Nullable Specification<S> spec,
643
637
*
644
638
* @param spec can be {@literal null}.
645
639
* @param sort must not be {@literal null}.
646
- * @return
647
640
*/
648
641
protected TypedQuery <T > getQuery (@ Nullable Specification <T > spec , Sort sort ) {
649
642
return getQuery (spec , getDomainClass (), sort );
@@ -655,7 +648,6 @@ protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Sort sort) {
655
648
* @param spec can be {@literal null}.
656
649
* @param domainClass must not be {@literal null}.
657
650
* @param sort must not be {@literal null}.
658
- * @return
659
651
*/
660
652
protected <S extends T > TypedQuery <S > getQuery (@ Nullable Specification <S > spec , Class <S > domainClass , Sort sort ) {
661
653
@@ -676,7 +668,6 @@ protected <S extends T> TypedQuery<S> getQuery(@Nullable Specification<S> spec,
676
668
* Creates a new count query for the given {@link Specification}.
677
669
*
678
670
* @param spec can be {@literal null}.
679
- * @return
680
671
* @deprecated override {@link #getCountQuery(Specification, Class)} instead
681
672
*/
682
673
@ Deprecated
@@ -689,7 +680,6 @@ protected TypedQuery<Long> getCountQuery(@Nullable Specification<T> spec) {
689
680
*
690
681
* @param spec can be {@literal null}.
691
682
* @param domainClass must not be {@literal null}.
692
- * @return
693
683
*/
694
684
protected <S extends T > TypedQuery <Long > getCountQuery (@ Nullable Specification <S > spec , Class <S > domainClass ) {
695
685
@@ -705,7 +695,7 @@ protected <S extends T> TypedQuery<Long> getCountQuery(@Nullable Specification<S
705
695
}
706
696
707
697
// Remove all Orders the Specifications might have applied
708
- query .orderBy (Collections .< Order > emptyList ());
698
+ query .orderBy (Collections .emptyList ());
709
699
710
700
return em .createQuery (query );
711
701
}
@@ -716,7 +706,6 @@ protected <S extends T> TypedQuery<Long> getCountQuery(@Nullable Specification<S
716
706
* @param spec can be {@literal null}.
717
707
* @param domainClass must not be {@literal null}.
718
708
* @param query must not be {@literal null}.
719
- * @return
720
709
*/
721
710
private <S , U extends T > Root <U > applySpecificationToCriteria (@ Nullable Specification <U > spec , Class <U > domainClass ,
722
711
CriteriaQuery <S > query ) {
@@ -762,7 +751,6 @@ private void applyQueryHints(Query query) {
762
751
* Executes a count query and transparently sums up all values returned.
763
752
*
764
753
* @param query must not be {@literal null}.
765
- * @return
766
754
*/
767
755
private static long executeCountQuery (TypedQuery <Long > query ) {
768
756
@@ -830,8 +818,8 @@ private static class ExampleSpecification<T> implements Specification<T> {
830
818
/**
831
819
* Creates new {@link ExampleSpecification}.
832
820
*
833
- * @param example
834
- * @param escapeCharacter
821
+ * @param example the example to base the specification of. Must not be {@literal null}.
822
+ * @param escapeCharacter the escape character to use for like expressions. Must not be {@literal null}.
835
823
*/
836
824
ExampleSpecification (Example <T > example , EscapeCharacter escapeCharacter ) {
837
825
0 commit comments