@@ -94,7 +94,7 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
94
94
private static final String ID_MUST_NOT_BE_NULL = "The given id must not be null" ;
95
95
96
96
private final JpaEntityInformation <T , ?> entityInformation ;
97
- private final EntityManager em ;
97
+ private final EntityManager entityManager ;
98
98
private final PersistenceProvider provider ;
99
99
100
100
private @ Nullable CrudMethodMetadata metadata ;
@@ -112,18 +112,18 @@ public SimpleJpaRepository(JpaEntityInformation<T, ?> entityInformation, EntityM
112
112
Assert .notNull (entityManager , "EntityManager must not be null" );
113
113
114
114
this .entityInformation = entityInformation ;
115
- this .em = entityManager ;
115
+ this .entityManager = entityManager ;
116
116
this .provider = PersistenceProvider .fromEntityManager (entityManager );
117
117
}
118
118
119
119
/**
120
120
* Creates a new {@link SimpleJpaRepository} to manage objects of the given domain type.
121
121
*
122
122
* @param domainClass must not be {@literal null}.
123
- * @param em must not be {@literal null}.
123
+ * @param entityManager must not be {@literal null}.
124
124
*/
125
- public SimpleJpaRepository (Class <T > domainClass , EntityManager em ) {
126
- this (JpaEntityInformationSupport .getEntityInformation (domainClass , em ), em );
125
+ public SimpleJpaRepository (Class <T > domainClass , EntityManager entityManager ) {
126
+ this (JpaEntityInformationSupport .getEntityInformation (domainClass , entityManager ), entityManager );
127
127
}
128
128
129
129
/**
@@ -183,14 +183,14 @@ public void delete(T entity) {
183
183
184
184
Class <?> type = ProxyUtils .getUserClass (entity );
185
185
186
- T existing = (T ) em .find (type , entityInformation .getId (entity ));
186
+ T existing = (T ) entityManager .find (type , entityInformation .getId (entity ));
187
187
188
188
// if the entity to be deleted doesn't exist, delete is a NOOP
189
189
if (existing == null ) {
190
190
return ;
191
191
}
192
192
193
- em .remove (em .contains (entity ) ? entity : em .merge (entity ));
193
+ entityManager .remove (entityManager .contains (entity ) ? entity : entityManager .merge (entity ));
194
194
}
195
195
196
196
@ Override
@@ -225,7 +225,7 @@ public void deleteAllByIdInBatch(Iterable<ID> ids) {
225
225
String queryString = String .format (DELETE_ALL_QUERY_BY_ID_STRING , entityInformation .getEntityName (),
226
226
entityInformation .getIdAttribute ().getName ());
227
227
228
- Query query = em .createQuery (queryString );
228
+ Query query = entityManager .createQuery (queryString );
229
229
230
230
/*
231
231
* Some JPA providers require {@code ids} to be a {@link Collection} so we must convert if it's not already.
@@ -266,7 +266,8 @@ public void deleteAllInBatch(Iterable<T> entities) {
266
266
return ;
267
267
}
268
268
269
- applyAndBind (getQueryString (DELETE_ALL_QUERY_STRING , entityInformation .getEntityName ()), entities , em )
269
+ applyAndBind (getQueryString (DELETE_ALL_QUERY_STRING , entityInformation .getEntityName ()), entities ,
270
+ entityManager )
270
271
.executeUpdate ();
271
272
}
272
273
@@ -283,7 +284,7 @@ public void deleteAll() {
283
284
@ Transactional
284
285
public void deleteAllInBatch () {
285
286
286
- Query query = em .createQuery (getDeleteAllQueryString ());
287
+ Query query = entityManager .createQuery (getDeleteAllQueryString ());
287
288
288
289
applyQueryHints (query );
289
290
@@ -298,13 +299,13 @@ public Optional<T> findById(ID id) {
298
299
Class <T > domainType = getDomainClass ();
299
300
300
301
if (metadata == null ) {
301
- return Optional .ofNullable (em .find (domainType , id ));
302
+ return Optional .ofNullable (entityManager .find (domainType , id ));
302
303
}
303
304
304
305
LockModeType type = metadata .getLockModeType ();
305
306
Map <String , Object > hints = getHints ();
306
307
307
- return Optional .ofNullable (type == null ? em .find (domainType , id , hints ) : em .find (domainType , id , type , hints ));
308
+ return Optional .ofNullable (type == null ? entityManager .find (domainType , id , hints ) : entityManager .find (domainType , id , type , hints ));
308
309
}
309
310
310
311
@ Deprecated
@@ -327,7 +328,7 @@ public T getById(ID id) {
327
328
public T getReferenceById (ID id ) {
328
329
329
330
Assert .notNull (id , ID_MUST_NOT_BE_NULL );
330
- return em .getReference (getDomainClass (), id );
331
+ return entityManager .getReference (getDomainClass (), id );
331
332
}
332
333
333
334
@ Override
@@ -344,7 +345,7 @@ public boolean existsById(ID id) {
344
345
Iterable <String > idAttributeNames = entityInformation .getIdAttributeNames ();
345
346
String existsQuery = QueryUtils .getExistsQueryString (entityName , placeholder , idAttributeNames );
346
347
347
- TypedQuery <Long > query = em .createQuery (existsQuery , Long .class );
348
+ TypedQuery <Long > query = entityManager .createQuery (existsQuery , Long .class );
348
349
349
350
applyQueryHints (query );
350
351
@@ -470,13 +471,13 @@ public <S extends T> long count(Example<S> example) {
470
471
public <S extends T > boolean exists (Example <S > example ) {
471
472
472
473
Specification <S > spec = new ExampleSpecification <>(example , this .escapeCharacter );
473
- CriteriaQuery <Integer > cq = this .em .getCriteriaBuilder () //
474
+ CriteriaQuery <Integer > cq = this .entityManager .getCriteriaBuilder () //
474
475
.createQuery (Integer .class ) //
475
- .select (this .em .getCriteriaBuilder ().literal (1 ));
476
+ .select (this .entityManager .getCriteriaBuilder ().literal (1 ));
476
477
477
478
applySpecificationToCriteria (spec , example .getProbeType (), cq );
478
479
479
- TypedQuery <Integer > query = applyRepositoryMethodMetadata (this .em .createQuery (cq ));
480
+ TypedQuery <Integer > query = applyRepositoryMethodMetadata (this .entityManager .createQuery (cq ));
480
481
return query .setMaxResults (1 ).getResultList ().size () == 1 ;
481
482
}
482
483
@@ -565,7 +566,7 @@ public <S extends T, R> R findBy(Specification<T> spec, Function<FetchableFluent
565
566
@ Override
566
567
public long count () {
567
568
568
- TypedQuery <Long > query = em .createQuery (getCountQueryString (), Long .class );
569
+ TypedQuery <Long > query = entityManager .createQuery (getCountQueryString (), Long .class );
569
570
570
571
applyQueryHintsForCount (query );
571
572
@@ -584,10 +585,10 @@ public <S extends T> S save(S entity) {
584
585
Assert .notNull (entity , "Entity must not be null" );
585
586
586
587
if (entityInformation .isNew (entity )) {
587
- em .persist (entity );
588
+ entityManager .persist (entity );
588
589
return entity ;
589
590
} else {
590
- return em .merge (entity );
591
+ return entityManager .merge (entity );
591
592
}
592
593
}
593
594
@@ -629,7 +630,7 @@ public <S extends T> List<S> saveAllAndFlush(Iterable<S> entities) {
629
630
@ Transactional
630
631
@ Override
631
632
public void flush () {
632
- em .flush ();
633
+ entityManager .flush ();
633
634
}
634
635
635
636
/**
@@ -712,7 +713,7 @@ protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Sort sort) {
712
713
*/
713
714
protected <S extends T > TypedQuery <S > getQuery (@ Nullable Specification <S > spec , Class <S > domainClass , Sort sort ) {
714
715
715
- CriteriaBuilder builder = em .getCriteriaBuilder ();
716
+ CriteriaBuilder builder = entityManager .getCriteriaBuilder ();
716
717
CriteriaQuery <S > query = builder .createQuery (domainClass );
717
718
718
719
Root <S > root = applySpecificationToCriteria (spec , domainClass , query );
@@ -722,7 +723,7 @@ protected <S extends T> TypedQuery<S> getQuery(@Nullable Specification<S> spec,
722
723
query .orderBy (toOrders (sort , root , builder ));
723
724
}
724
725
725
- return applyRepositoryMethodMetadata (em .createQuery (query ));
726
+ return applyRepositoryMethodMetadata (entityManager .createQuery (query ));
726
727
}
727
728
728
729
/**
@@ -744,7 +745,7 @@ protected TypedQuery<Long> getCountQuery(@Nullable Specification<T> spec) {
744
745
*/
745
746
protected <S extends T > TypedQuery <Long > getCountQuery (@ Nullable Specification <S > spec , Class <S > domainClass ) {
746
747
747
- CriteriaBuilder builder = em .getCriteriaBuilder ();
748
+ CriteriaBuilder builder = entityManager .getCriteriaBuilder ();
748
749
CriteriaQuery <Long > query = builder .createQuery (Long .class );
749
750
750
751
Root <S > root = applySpecificationToCriteria (spec , domainClass , query );
@@ -758,7 +759,7 @@ protected <S extends T> TypedQuery<Long> getCountQuery(@Nullable Specification<S
758
759
// Remove all Orders the Specifications might have applied
759
760
query .orderBy (Collections .emptyList ());
760
761
761
- return applyRepositoryMethodMetadataForCount (em .createQuery (query ));
762
+ return applyRepositoryMethodMetadataForCount (entityManager .createQuery (query ));
762
763
}
763
764
764
765
/**
@@ -795,7 +796,7 @@ private <S, U extends T> Root<U> applySpecificationToCriteria(@Nullable Specific
795
796
return root ;
796
797
}
797
798
798
- CriteriaBuilder builder = em .getCriteriaBuilder ();
799
+ CriteriaBuilder builder = entityManager .getCriteriaBuilder ();
799
800
Predicate predicate = spec .toPredicate (root , query , builder );
800
801
801
802
if (predicate != null ) {
@@ -825,7 +826,7 @@ private void applyQueryHints(Query query) {
825
826
return ;
826
827
}
827
828
828
- getQueryHints ().withFetchGraphs (em ).forEach (query ::setHint );
829
+ getQueryHints ().withFetchGraphs (entityManager ).forEach (query ::setHint );
829
830
applyComment (metadata , query ::setHint );
830
831
}
831
832
@@ -854,7 +855,7 @@ private Map<String, Object> getHints() {
854
855
855
856
Map <String , Object > hints = new HashMap <>();
856
857
857
- getQueryHints ().withFetchGraphs (em ).forEach (hints ::put );
858
+ getQueryHints ().withFetchGraphs (entityManager ).forEach (hints ::put );
858
859
859
860
if (metadata != null ) {
860
861
applyComment (metadata , hints ::put );
0 commit comments