7373import org .springframework .data .repository .query .FluentQuery .FetchableFluentQuery ;
7474import org .springframework .data .repository .query .ReturnedType ;
7575import org .springframework .data .support .PageableExecutionUtils ;
76+ import org .springframework .data .util .Lazy ;
7677import org .springframework .data .util .ProxyUtils ;
7778import org .springframework .data .util .Streamable ;
7879import org .springframework .lang .Nullable ;
103104 * @author Diego Krupitza
104105 * @author Seol-JY
105106 * @author Joshua Chen
106- * @author Dockerel
107+ * @author Giheon Do
107108 */
108109@ Repository
109110@ Transactional (readOnly = true )
@@ -121,8 +122,8 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
121122 private final EntityManager entityManager ;
122123 private final PersistenceProvider provider ;
123124
124- private final String deleteAllQueryString ;
125- private final String countQueryString ;
125+ private final Lazy < String > deleteAllQueryString ;
126+ private final Lazy < String > countQueryString ;
126127
127128 private @ Nullable CrudMethodMetadata metadata ;
128129 private ProjectionFactory projectionFactory ;
@@ -144,8 +145,11 @@ public SimpleJpaRepository(JpaEntityInformation<T, ?> entityInformation, EntityM
144145 this .provider = PersistenceProvider .fromEntityManager (entityManager );
145146 this .projectionFactory = new SpelAwareProxyProjectionFactory ();
146147
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 ()));
149153 }
150154
151155 /**
@@ -188,16 +192,6 @@ protected Class<T> getDomainClass() {
188192 return entityInformation .getJavaType ();
189193 }
190194
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-
201195 @ Override
202196 @ Transactional
203197 public void deleteById (ID id ) {
@@ -316,7 +310,7 @@ public void deleteAll() {
316310 @ Transactional
317311 public void deleteAllInBatch () {
318312
319- Query query = entityManager .createQuery (deleteAllQueryString );
313+ Query query = entityManager .createQuery (deleteAllQueryString . get () );
320314
321315 applyQueryHints (query );
322316
@@ -638,7 +632,7 @@ public <S extends T, R> R findBy(Example<S> example, Function<FetchableFluentQue
638632 @ Override
639633 public long count () {
640634
641- TypedQuery <Long > query = entityManager .createQuery (countQueryString , Long .class );
635+ TypedQuery <Long > query = entityManager .createQuery (countQueryString . get () , Long .class );
642636
643637 applyQueryHintsForCount (query );
644638
0 commit comments