@@ -99,7 +99,7 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
99
99
private static final String ID_MUST_NOT_BE_NULL = "The given id must not be null" ;
100
100
101
101
private final JpaEntityInformation <T , ?> entityInformation ;
102
- private final EntityManager em ;
102
+ private final EntityManager entityManager ;
103
103
private final PersistenceProvider provider ;
104
104
105
105
private @ Nullable CrudMethodMetadata metadata ;
@@ -117,18 +117,18 @@ public SimpleJpaRepository(JpaEntityInformation<T, ?> entityInformation, EntityM
117
117
Assert .notNull (entityManager , "EntityManager must not be null" );
118
118
119
119
this .entityInformation = entityInformation ;
120
- this .em = entityManager ;
120
+ this .entityManager = entityManager ;
121
121
this .provider = PersistenceProvider .fromEntityManager (entityManager );
122
122
}
123
123
124
124
/**
125
125
* Creates a new {@link SimpleJpaRepository} to manage objects of the given domain type.
126
126
*
127
127
* @param domainClass must not be {@literal null}.
128
- * @param em must not be {@literal null}.
128
+ * @param entityManager must not be {@literal null}.
129
129
*/
130
- public SimpleJpaRepository (Class <T > domainClass , EntityManager em ) {
131
- this (JpaEntityInformationSupport .getEntityInformation (domainClass , em ), em );
130
+ public SimpleJpaRepository (Class <T > domainClass , EntityManager entityManager ) {
131
+ this (JpaEntityInformationSupport .getEntityInformation (domainClass , entityManager ), entityManager );
132
132
}
133
133
134
134
/**
@@ -188,14 +188,14 @@ public void delete(T entity) {
188
188
189
189
Class <?> type = ProxyUtils .getUserClass (entity );
190
190
191
- T existing = (T ) em .find (type , entityInformation .getId (entity ));
191
+ T existing = (T ) entityManager .find (type , entityInformation .getId (entity ));
192
192
193
193
// if the entity to be deleted doesn't exist, delete is a NOOP
194
194
if (existing == null ) {
195
195
return ;
196
196
}
197
197
198
- em .remove (em .contains (entity ) ? entity : em .merge (entity ));
198
+ entityManager .remove (entityManager .contains (entity ) ? entity : entityManager .merge (entity ));
199
199
}
200
200
201
201
@ Override
@@ -230,7 +230,7 @@ public void deleteAllByIdInBatch(Iterable<ID> ids) {
230
230
String queryString = String .format (DELETE_ALL_QUERY_BY_ID_STRING , entityInformation .getEntityName (),
231
231
entityInformation .getIdAttribute ().getName ());
232
232
233
- Query query = em .createQuery (queryString );
233
+ Query query = entityManager .createQuery (queryString );
234
234
235
235
/*
236
236
* Some JPA providers require {@code ids} to be a {@link Collection} so we must convert if it's not already.
@@ -271,7 +271,8 @@ public void deleteAllInBatch(Iterable<T> entities) {
271
271
return ;
272
272
}
273
273
274
- applyAndBind (getQueryString (DELETE_ALL_QUERY_STRING , entityInformation .getEntityName ()), entities , em )
274
+ applyAndBind (getQueryString (DELETE_ALL_QUERY_STRING , entityInformation .getEntityName ()), entities ,
275
+ entityManager )
275
276
.executeUpdate ();
276
277
}
277
278
@@ -288,7 +289,7 @@ public void deleteAll() {
288
289
@ Transactional
289
290
public void deleteAllInBatch () {
290
291
291
- Query query = em .createQuery (getDeleteAllQueryString ());
292
+ Query query = entityManager .createQuery (getDeleteAllQueryString ());
292
293
293
294
applyQueryHints (query );
294
295
@@ -303,13 +304,13 @@ public Optional<T> findById(ID id) {
303
304
Class <T > domainType = getDomainClass ();
304
305
305
306
if (metadata == null ) {
306
- return Optional .ofNullable (em .find (domainType , id ));
307
+ return Optional .ofNullable (entityManager .find (domainType , id ));
307
308
}
308
309
309
310
LockModeType type = metadata .getLockModeType ();
310
311
Map <String , Object > hints = getHints ();
311
312
312
- return Optional .ofNullable (type == null ? em .find (domainType , id , hints ) : em .find (domainType , id , type , hints ));
313
+ return Optional .ofNullable (type == null ? entityManager .find (domainType , id , hints ) : entityManager .find (domainType , id , type , hints ));
313
314
}
314
315
315
316
@ Deprecated
@@ -332,7 +333,7 @@ public T getById(ID id) {
332
333
public T getReferenceById (ID id ) {
333
334
334
335
Assert .notNull (id , ID_MUST_NOT_BE_NULL );
335
- return em .getReference (getDomainClass (), id );
336
+ return entityManager .getReference (getDomainClass (), id );
336
337
}
337
338
338
339
@ Override
@@ -349,7 +350,7 @@ public boolean existsById(ID id) {
349
350
Iterable <String > idAttributeNames = entityInformation .getIdAttributeNames ();
350
351
String existsQuery = QueryUtils .getExistsQueryString (entityName , placeholder , idAttributeNames );
351
352
352
- TypedQuery <Long > query = em .createQuery (existsQuery , Long .class );
353
+ TypedQuery <Long > query = entityManager .createQuery (existsQuery , Long .class );
353
354
354
355
applyQueryHints (query );
355
356
@@ -456,20 +457,20 @@ public List<T> findAll(Specification<T> spec, Sort sort) {
456
457
@ Override
457
458
public boolean exists (Specification <T > spec ) {
458
459
459
- CriteriaQuery <Integer > cq = this .em .getCriteriaBuilder () //
460
+ CriteriaQuery <Integer > cq = this .entityManager .getCriteriaBuilder () //
460
461
.createQuery (Integer .class ) //
461
- .select (this .em .getCriteriaBuilder ().literal (1 ));
462
+ .select (this .entityManager .getCriteriaBuilder ().literal (1 ));
462
463
463
464
applySpecificationToCriteria (spec , getDomainClass (), cq );
464
465
465
- TypedQuery <Integer > query = applyRepositoryMethodMetadata (this .em .createQuery (cq ));
466
+ TypedQuery <Integer > query = applyRepositoryMethodMetadata (this .entityManager .createQuery (cq ));
466
467
return query .setMaxResults (1 ).getResultList ().size () == 1 ;
467
468
}
468
469
469
470
@ Override
470
471
public long delete (Specification <T > spec ) {
471
472
472
- CriteriaBuilder builder = this .em .getCriteriaBuilder ();
473
+ CriteriaBuilder builder = this .entityManager .getCriteriaBuilder ();
473
474
CriteriaDelete <T > delete = builder .createCriteriaDelete (getDomainClass ());
474
475
475
476
if (spec != null ) {
@@ -480,7 +481,7 @@ public long delete(Specification<T> spec) {
480
481
}
481
482
}
482
483
483
- return this .em .createQuery (delete ).executeUpdate ();
484
+ return this .entityManager .createQuery (delete ).executeUpdate ();
484
485
}
485
486
486
487
@ Override
@@ -522,7 +523,7 @@ private <S extends T, R> R doFindBy(Specification<T> spec, Class<T> domainClass,
522
523
SpecificationScrollDelegate <T > scrollDelegate = new SpecificationScrollDelegate <>(scrollFunction ,
523
524
entityInformation );
524
525
FetchableFluentQuery <T > fluentQuery = new FetchableFluentQueryBySpecification <>(spec , domainClass , finder ,
525
- scrollDelegate , this ::count , this ::exists , this .em );
526
+ scrollDelegate , this ::count , this ::exists , this .entityManager );
526
527
527
528
return queryFunction .apply ((FetchableFluentQuery <S >) fluentQuery );
528
529
}
@@ -549,13 +550,13 @@ public <S extends T> long count(Example<S> example) {
549
550
public <S extends T > boolean exists (Example <S > example ) {
550
551
551
552
Specification <S > spec = new ExampleSpecification <>(example , this .escapeCharacter );
552
- CriteriaQuery <Integer > cq = this .em .getCriteriaBuilder () //
553
+ CriteriaQuery <Integer > cq = this .entityManager .getCriteriaBuilder () //
553
554
.createQuery (Integer .class ) //
554
- .select (this .em .getCriteriaBuilder ().literal (1 ));
555
+ .select (this .entityManager .getCriteriaBuilder ().literal (1 ));
555
556
556
557
applySpecificationToCriteria (spec , example .getProbeType (), cq );
557
558
558
- TypedQuery <Integer > query = applyRepositoryMethodMetadata (this .em .createQuery (cq ));
559
+ TypedQuery <Integer > query = applyRepositoryMethodMetadata (this .entityManager .createQuery (cq ));
559
560
return query .setMaxResults (1 ).getResultList ().size () == 1 ;
560
561
}
561
562
@@ -595,7 +596,7 @@ public <S extends T, R> R findBy(Example<S> example, Function<FetchableFluentQue
595
596
@ Override
596
597
public long count () {
597
598
598
- TypedQuery <Long > query = em .createQuery (getCountQueryString (), Long .class );
599
+ TypedQuery <Long > query = entityManager .createQuery (getCountQueryString (), Long .class );
599
600
600
601
applyQueryHintsForCount (query );
601
602
@@ -614,10 +615,10 @@ public <S extends T> S save(S entity) {
614
615
Assert .notNull (entity , "Entity must not be null" );
615
616
616
617
if (entityInformation .isNew (entity )) {
617
- em .persist (entity );
618
+ entityManager .persist (entity );
618
619
return entity ;
619
620
} else {
620
- return em .merge (entity );
621
+ return entityManager .merge (entity );
621
622
}
622
623
}
623
624
@@ -659,7 +660,7 @@ public <S extends T> List<S> saveAllAndFlush(Iterable<S> entities) {
659
660
@ Transactional
660
661
@ Override
661
662
public void flush () {
662
- em .flush ();
663
+ entityManager .flush ();
663
664
}
664
665
665
666
/**
@@ -742,7 +743,7 @@ protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Sort sort) {
742
743
*/
743
744
protected <S extends T > TypedQuery <S > getQuery (@ Nullable Specification <S > spec , Class <S > domainClass , Sort sort ) {
744
745
745
- CriteriaBuilder builder = em .getCriteriaBuilder ();
746
+ CriteriaBuilder builder = entityManager .getCriteriaBuilder ();
746
747
CriteriaQuery <S > query = builder .createQuery (domainClass );
747
748
748
749
Root <S > root = applySpecificationToCriteria (spec , domainClass , query );
@@ -752,7 +753,7 @@ protected <S extends T> TypedQuery<S> getQuery(@Nullable Specification<S> spec,
752
753
query .orderBy (toOrders (sort , root , builder ));
753
754
}
754
755
755
- return applyRepositoryMethodMetadata (em .createQuery (query ));
756
+ return applyRepositoryMethodMetadata (entityManager .createQuery (query ));
756
757
}
757
758
758
759
/**
@@ -774,7 +775,7 @@ protected TypedQuery<Long> getCountQuery(@Nullable Specification<T> spec) {
774
775
*/
775
776
protected <S extends T > TypedQuery <Long > getCountQuery (@ Nullable Specification <S > spec , Class <S > domainClass ) {
776
777
777
- CriteriaBuilder builder = em .getCriteriaBuilder ();
778
+ CriteriaBuilder builder = entityManager .getCriteriaBuilder ();
778
779
CriteriaQuery <Long > query = builder .createQuery (Long .class );
779
780
780
781
Root <S > root = applySpecificationToCriteria (spec , domainClass , query );
@@ -788,7 +789,7 @@ protected <S extends T> TypedQuery<Long> getCountQuery(@Nullable Specification<S
788
789
// Remove all Orders the Specifications might have applied
789
790
query .orderBy (Collections .emptyList ());
790
791
791
- return applyRepositoryMethodMetadataForCount (em .createQuery (query ));
792
+ return applyRepositoryMethodMetadataForCount (entityManager .createQuery (query ));
792
793
}
793
794
794
795
/**
@@ -825,7 +826,7 @@ private <S, U extends T> Root<U> applySpecificationToCriteria(@Nullable Specific
825
826
return root ;
826
827
}
827
828
828
- CriteriaBuilder builder = em .getCriteriaBuilder ();
829
+ CriteriaBuilder builder = entityManager .getCriteriaBuilder ();
829
830
Predicate predicate = spec .toPredicate (root , query , builder );
830
831
831
832
if (predicate != null ) {
@@ -855,7 +856,7 @@ private void applyQueryHints(Query query) {
855
856
return ;
856
857
}
857
858
858
- getQueryHints ().withFetchGraphs (em ).forEach (query ::setHint );
859
+ getQueryHints ().withFetchGraphs (entityManager ).forEach (query ::setHint );
859
860
applyComment (metadata , query ::setHint );
860
861
}
861
862
@@ -884,7 +885,7 @@ private Map<String, Object> getHints() {
884
885
885
886
Map <String , Object > hints = new HashMap <>();
886
887
887
- getQueryHints ().withFetchGraphs (em ).forEach (hints ::put );
888
+ getQueryHints ().withFetchGraphs (entityManager ).forEach (hints ::put );
888
889
889
890
if (metadata != null ) {
890
891
applyComment (metadata , hints ::put );
0 commit comments