1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.backend.jpa;
20
21 import jakarta.persistence.EntityManager;
22 import jakarta.persistence.EntityManagerFactory;
23 import jakarta.persistence.PersistenceException;
24
25 public class MCREntityManagerProvider {
26
27 private static EntityManagerFactory factory;
28
29 private static MCRSessionContext context;
30
31 private static PersistenceException initException;
32
33 public static EntityManagerFactory getEntityManagerFactory() {
34 return factory;
35 }
36
37 public static EntityManager getCurrentEntityManager() {
38 if (context == null && initException != null) {
39 throw initException;
40 }
41 return context.getCurrentEntityManager();
42 }
43
44 static void init(EntityManagerFactory factory) {
45 MCREntityManagerProvider.factory = factory;
46 context = new MCRSessionContext(factory);
47 }
48
49 static void init(PersistenceException e) {
50 initException = e;
51 }
52
53 }