74
74
import org .springframework .data .repository .query .FluentQuery .FetchableFluentQuery ;
75
75
import org .springframework .data .repository .query .ReturnedType ;
76
76
import org .springframework .data .support .PageableExecutionUtils ;
77
+ import org .springframework .data .util .Lazy ;
77
78
import org .springframework .data .util .ProxyUtils ;
78
79
import org .springframework .data .util .Streamable ;
79
80
import org .springframework .lang .Contract ;
104
105
* @author Diego Krupitza
105
106
* @author Seol-JY
106
107
* @author Joshua Chen
107
- * @author Dockerel
108
+ * @author Giheon Do
108
109
*/
109
110
@ Repository
110
111
@ Transactional (readOnly = true )
@@ -122,8 +123,8 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
122
123
private final EntityManager entityManager ;
123
124
private final PersistenceProvider provider ;
124
125
125
- private final String deleteAllQueryString ;
126
- private final String countQueryString ;
126
+ private final Lazy < String > deleteAllQueryString ;
127
+ private final Lazy < String > countQueryString ;
127
128
128
129
private @ Nullable CrudMethodMetadata metadata ;
129
130
private ProjectionFactory projectionFactory ;
@@ -145,8 +146,11 @@ public SimpleJpaRepository(JpaEntityInformation<T, ?> entityInformation, EntityM
145
146
this .provider = PersistenceProvider .fromEntityManager (entityManager );
146
147
this .projectionFactory = new SpelAwareProxyProjectionFactory ();
147
148
148
- this .deleteAllQueryString = getDeleteAllQueryString ();
149
- this .countQueryString = getCountQueryString ();
149
+ this .deleteAllQueryString = Lazy
150
+ .of (() -> getQueryString (DELETE_ALL_QUERY_STRING , entityInformation .getEntityName ()));
151
+ this .countQueryString = Lazy
152
+ .of (() -> getQueryString (String .format (COUNT_QUERY_STRING , provider .getCountQueryPlaceholder (), "%s" ),
153
+ entityInformation .getEntityName ()));
150
154
}
151
155
152
156
/**
@@ -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 ) {
@@ -325,7 +319,7 @@ public void deleteAll() {
325
319
@ Transactional
326
320
public void deleteAllInBatch () {
327
321
328
- Query query = entityManager .createQuery (deleteAllQueryString );
322
+ Query query = entityManager .createQuery (deleteAllQueryString . get () );
329
323
330
324
applyQueryHints (query );
331
325
@@ -646,7 +640,7 @@ public <S extends T, R> R findBy(Example<S> example, Function<FetchableFluentQue
646
640
@ Override
647
641
public long count () {
648
642
649
- TypedQuery <Long > query = entityManager .createQuery (countQueryString , Long .class );
643
+ TypedQuery <Long > query = entityManager .createQuery (countQueryString . get () , Long .class );
650
644
651
645
applyQueryHintsForCount (query );
652
646
0 commit comments