2222import java .util .stream .Stream ;
2323import java .util .stream .StreamSupport ;
2424
25+ import jakarta .persistence .EntityManager ;
2526import jakarta .persistence .EntityManagerFactory ;
2627import jakarta .persistence .metamodel .EntityType ;
2728
@@ -43,17 +44,24 @@ public EclipseStoreDataImporter(final EclipseStoreStorage eclipseStoreStorage)
4344 this .eclipseStoreStorage = eclipseStoreStorage ;
4445 }
4546
47+ @ SuppressWarnings ("java:S1452" )
4648 public List <SimpleEclipseStoreRepository <?, ?>> importData (final EntityManagerFactory ... entityManagerFactories )
4749 {
4850 return this .importData (Arrays .stream (entityManagerFactories ));
4951 }
5052
51- public List <SimpleEclipseStoreRepository <?, ?>> importData (final Iterable <EntityManagerFactory > entityManagerFactories )
53+ @ SuppressWarnings ("java:S1452" )
54+ public List <SimpleEclipseStoreRepository <?, ?>> importData (
55+ final Iterable <EntityManagerFactory > entityManagerFactories
56+ )
5257 {
5358 return this .importData (StreamSupport .stream (entityManagerFactories .spliterator (), false ));
5459 }
5560
56- public List <SimpleEclipseStoreRepository <?, ?>> importData (final Stream <EntityManagerFactory > entityManagerFactories )
61+ @ SuppressWarnings ({"java:S1452" , "java:S6204" })
62+ public List <SimpleEclipseStoreRepository <?, ?>> importData (
63+ final Stream <EntityManagerFactory > entityManagerFactories
64+ )
5765 {
5866 LOG .info ("Start importing data from JPA Repositories to EclipseStore..." );
5967
@@ -62,7 +70,7 @@ public EclipseStoreDataImporter(final EclipseStoreStorage eclipseStoreStorage)
6270 entityManagerFactories
6371 .map (this ::createEclipseStoreRepositoriesFromEntityManager )
6472 .toList ();
65- LOG .info (String . format ( "Found %d repositories to export data from." , allRepositories .size () ));
73+ LOG .info ("Found {} repositories to export data from." , allRepositories .size ());
6674
6775 // Now copy the data
6876 allRepositories .forEach (
@@ -89,28 +97,33 @@ private static <T> void copyData(
8997 {
9098 final String className = classRepositoryPair .domainClass .getName ();
9199
92- LOG .info (String .format ("Loading entities of %s..." , className ));
93- final List <T > existingEntitiesToExport =
94- entityManagerFactoryRepositoryListPair .entityManagerFactory .createEntityManager ()
95- .createQuery ("SELECT c FROM " + className + " c" )
96- .getResultList ();
97- LOG .info (String .format (
98- "Loaded %d entities of type %s to export." ,
99- existingEntitiesToExport .size (),
100- className
101- ));
102-
103- LOG .info (String .format (
104- "Saving %d entities of type %s to the EclipseStore Repository..." ,
105- existingEntitiesToExport .size (),
106- className
107- ));
108- classRepositoryPair .repository .saveAll (existingEntitiesToExport );
109- LOG .info (String .format (
110- "Done saving entities of type %s. The EclipseStore now holds %d entities of that type." ,
111- className ,
112- classRepositoryPair .repository .count ()
113- ));
100+ LOG .info ("Loading entities of {}..." , className );
101+ try (final EntityManager entityManager =
102+ entityManagerFactoryRepositoryListPair .entityManagerFactory .createEntityManager ())
103+ {
104+ final List <T > existingEntitiesToExport =
105+ entityManager
106+ .createQuery ("SELECT c FROM " + className + " c" , classRepositoryPair .domainClass )
107+ .getResultList ();
108+
109+ LOG .info (
110+ "Loaded {} entities of type {} to export." ,
111+ existingEntitiesToExport .size (),
112+ className
113+ );
114+
115+ LOG .info (
116+ "Saving {} entities of type {} to the EclipseStore Repository..." ,
117+ existingEntitiesToExport .size (),
118+ className
119+ );
120+ classRepositoryPair .repository .saveAll (existingEntitiesToExport );
121+ LOG .info (
122+ "Done saving entities of type {}. The EclipseStore now holds {} entities of that type." ,
123+ className ,
124+ classRepositoryPair .repository .count ()
125+ );
126+ }
114127 }
115128
116129 private EntityManagerFactoryRepositoryListPair createEclipseStoreRepositoriesFromEntityManager (
0 commit comments