73
73
import org .springframework .data .repository .query .FluentQuery .FetchableFluentQuery ;
74
74
import org .springframework .data .repository .query .ReturnedType ;
75
75
import org .springframework .data .support .PageableExecutionUtils ;
76
+ import org .springframework .data .util .Lazy ;
76
77
import org .springframework .data .util .ProxyUtils ;
77
78
import org .springframework .data .util .Streamable ;
78
79
import org .springframework .lang .Nullable ;
103
104
* @author Diego Krupitza
104
105
* @author Seol-JY
105
106
* @author Joshua Chen
106
- * @author Dockerel
107
+ * @author Giheon Do
107
108
*/
108
109
@ Repository
109
110
@ Transactional (readOnly = true )
@@ -121,8 +122,8 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
121
122
private final EntityManager entityManager ;
122
123
private final PersistenceProvider provider ;
123
124
124
- private final String deleteAllQueryString ;
125
- private final String countQueryString ;
125
+ private final Lazy < String > deleteAllQueryString ;
126
+ private final Lazy < String > countQueryString ;
126
127
127
128
private @ Nullable CrudMethodMetadata metadata ;
128
129
private ProjectionFactory projectionFactory ;
@@ -144,8 +145,11 @@ public SimpleJpaRepository(JpaEntityInformation<T, ?> entityInformation, EntityM
144
145
this .provider = PersistenceProvider .fromEntityManager (entityManager );
145
146
this .projectionFactory = new SpelAwareProxyProjectionFactory ();
146
147
147
- this .deleteAllQueryString = getDeleteAllQueryString ();
148
- this .countQueryString = getCountQueryString ();
148
+ this .deleteAllQueryString = Lazy
149
+ .of (() -> getQueryString (DELETE_ALL_QUERY_STRING , entityInformation .getEntityName ()));
150
+ this .countQueryString = Lazy
151
+ .of (() -> getQueryString (String .format (COUNT_QUERY_STRING , provider .getCountQueryPlaceholder (), "%s" ),
152
+ entityInformation .getEntityName ()));
149
153
}
150
154
151
155
/**
@@ -188,16 +192,6 @@ protected Class<T> getDomainClass() {
188
192
return entityInformation .getJavaType ();
189
193
}
190
194
191
- private String getDeleteAllQueryString () {
192
- return getQueryString (DELETE_ALL_QUERY_STRING , entityInformation .getEntityName ());
193
- }
194
-
195
- private String getCountQueryString () {
196
-
197
- String countQuery = String .format (COUNT_QUERY_STRING , provider .getCountQueryPlaceholder (), "%s" );
198
- return getQueryString (countQuery , entityInformation .getEntityName ());
199
- }
200
-
201
195
@ Override
202
196
@ Transactional
203
197
public void deleteById (ID id ) {
@@ -316,7 +310,7 @@ public void deleteAll() {
316
310
@ Transactional
317
311
public void deleteAllInBatch () {
318
312
319
- Query query = entityManager .createQuery (deleteAllQueryString );
313
+ Query query = entityManager .createQuery (deleteAllQueryString . get () );
320
314
321
315
applyQueryHints (query );
322
316
@@ -638,7 +632,7 @@ public <S extends T, R> R findBy(Example<S> example, Function<FetchableFluentQue
638
632
@ Override
639
633
public long count () {
640
634
641
- TypedQuery <Long > query = entityManager .createQuery (countQueryString , Long .class );
635
+ TypedQuery <Long > query = entityManager .createQuery (countQueryString . get () , Long .class );
642
636
643
637
applyQueryHintsForCount (query );
644
638
0 commit comments