Joaquín Reñé
2025-10-07 146a0fb8b0e90f9196e569152f649baf60d6cc8f
securis/src/main/java/net/curisit/securis/ioc/EntityManagerProvider.java
....@@ -1,3 +1,6 @@
1
+/*
2
+* Copyright @ 2013 CurisTEC, S.A.S. All Rights Reserved.
3
+*/
14 package net.curisit.securis.ioc;
25
36 import jakarta.enterprise.context.ApplicationScoped;
....@@ -8,16 +11,38 @@
811 import org.apache.logging.log4j.LogManager;
912 import org.apache.logging.log4j.Logger;
1013
14
+/**
15
+* EntityManagerProvider
16
+* <p>
17
+* Simple provider for JPA {@link EntityManager} instances using the
18
+* persistence unit "localdb". Creates an {@link EntityManagerFactory}
19
+* once per application and returns a fresh {@link EntityManager} per call.
20
+*
21
+* Note:
22
+* - Callers are responsible for closing the obtained EntityManager.
23
+*
24
+* @author JRA
25
+* Last reviewed by JRA on Oct 5, 2025.
26
+*/
1127 @ApplicationScoped
1228 public class EntityManagerProvider {
1329
1430 @SuppressWarnings("unused")
15
- private static final Logger log = LogManager.getLogger(EntityManagerProvider.class);
31
+ private static final Logger log = LogManager.getLogger(EntityManagerProvider.class);
1632
33
+ /**
34
+ * entityManagerFactory<p>
35
+ * Application-wide EMF built from persistence.xml PU "localdb".
36
+ */
1737 private final EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("localdb");
1838
39
+ /**
40
+ * getEntityManager<p>
41
+ * Create a new {@link EntityManager}.
42
+ *
43
+ * @return a new EntityManager; caller must close it
44
+ */
1945 public EntityManager getEntityManager() {
2046 return entityManagerFactory.createEntityManager();
2147 }
22
-
2348 }