7474import org .springframework .data .repository .query .FluentQuery .FetchableFluentQuery ;
7575import org .springframework .data .repository .query .ReturnedType ;
7676import org .springframework .data .support .PageableExecutionUtils ;
77+ import org .springframework .data .util .Lazy ;
7778import org .springframework .data .util .ProxyUtils ;
7879import org .springframework .data .util .Streamable ;
7980import org .springframework .lang .Contract ;
104105 * @author Diego Krupitza
105106 * @author Seol-JY
106107 * @author Joshua Chen
107- * @author Dockerel
108+ * @author Giheon Do
108109 */
109110@ Repository
110111@ Transactional (readOnly = true )
@@ -122,8 +123,8 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
122123 private final EntityManager entityManager ;
123124 private final PersistenceProvider provider ;
124125
125- private final String deleteAllQueryString ;
126- private final String countQueryString ;
126+ private final Lazy < String > deleteAllQueryString ;
127+ private final Lazy < String > countQueryString ;
127128
128129 private @ Nullable CrudMethodMetadata metadata ;
129130 private ProjectionFactory projectionFactory ;
@@ -145,8 +146,11 @@ public SimpleJpaRepository(JpaEntityInformation<T, ?> entityInformation, EntityM
145146 this .provider = PersistenceProvider .fromEntityManager (entityManager );
146147 this .projectionFactory = new SpelAwareProxyProjectionFactory ();
147148
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 ()));
150154 }
151155
152156 /**
@@ -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 ) {
@@ -325,7 +319,7 @@ public void deleteAll() {
325319 @ Transactional
326320 public void deleteAllInBatch () {
327321
328- Query query = entityManager .createQuery (deleteAllQueryString );
322+ Query query = entityManager .createQuery (deleteAllQueryString . get () );
329323
330324 applyQueryHints (query );
331325
@@ -646,7 +640,7 @@ public <S extends T, R> R findBy(Example<S> example, Function<FetchableFluentQue
646640 @ Override
647641 public long count () {
648642
649- TypedQuery <Long > query = entityManager .createQuery (countQueryString , Long .class );
643+ TypedQuery <Long > query = entityManager .createQuery (countQueryString . get () , Long .class );
650644
651645 applyQueryHintsForCount (query );
652646
0 commit comments