@@ -52,6 +52,30 @@ public static EntityManagerFactory createAutoclosingEntityManagerFactory(final C
52
52
return createAutoclosingEntityManagerFactory (classLoaderSource , persistenceUnitName , null );
53
53
}
54
54
55
+ /**
56
+ * Creates a new {@link EntityManagerFactory} with default-parameters or
57
+ * parameters given via environment variables.
58
+ * <p>
59
+ * Runs Liquibase-update to apply any changes.<br>
60
+ * Installs a shutdown-hook that ensures that the connection to the database is
61
+ * properly closed.
62
+ *
63
+ * @param classLoaderSource the source of the class-loader to use
64
+ * @param persistenceUnitName the name of the persistence-unit to use (from your
65
+ * persistence.xml)
66
+ * @param masterFileName the master-file (should not end with -master since
67
+ * this would auto-load it using the non-specific
68
+ * method)
69
+ * @return an {@link EntityManagerFactory}
70
+ * @throws RdbUtilException if the database could not have been opened by
71
+ * Liquibase.
72
+ */
73
+ public static EntityManagerFactory createSpecificAutoclosingEntityManagerFactory (final Class <?> classLoaderSource ,
74
+ final String persistenceUnitName , final String masterFileName ) throws RdbUtilException {
75
+ return createSpecificAutoclosingEntityManagerFactory (classLoaderSource , persistenceUnitName , null ,
76
+ masterFileName );
77
+ }
78
+
55
79
/**
56
80
* Creates a new {@link EntityManagerFactory} with default-parameters or
57
81
* parameters given via environment variables.
@@ -70,8 +94,33 @@ public static EntityManagerFactory createAutoclosingEntityManagerFactory(final C
70
94
*/
71
95
public static EntityManagerFactory createAutoclosingEntityManagerFactory (final Class <?> classLoaderSource ,
72
96
final String persistenceUnitName , final String prefix ) throws RdbUtilException {
97
+ return createSpecificAutoclosingEntityManagerFactory (classLoaderSource , persistenceUnitName , prefix , "-master" );
98
+ }
99
+
100
+ /**
101
+ * Creates a new {@link EntityManagerFactory} with default-parameters or
102
+ * parameters given via environment variables.
103
+ * <p>
104
+ * Runs liquibase-update to apply any changes.<br>
105
+ * Installs a shutdown-hook that ensures that the connection to the database is
106
+ * properly closed.
107
+ *
108
+ * @param classLoaderSource the source of the class-loader to use
109
+ * @param persistenceUnitName the name of the persistence-unit to use (from your
110
+ * persistence.xml)
111
+ * @param prefix the prefix
112
+ * @param masterFileName the master-file (should not end with -master since
113
+ * this would auto-load it using the non-specific
114
+ * method)
115
+ * @return an {@link EntityManagerFactory}
116
+ * @throws RdbUtilException if the database could not have been opened by
117
+ * liquibase.
118
+ */
119
+ public static EntityManagerFactory createSpecificAutoclosingEntityManagerFactory (final Class <?> classLoaderSource ,
120
+ final String persistenceUnitName , final String prefix , final String masterFileName )
121
+ throws RdbUtilException {
73
122
Map <String , String > properties = getProperties (prefix );
74
- liquibaseUpdate (classLoaderSource , properties );
123
+ liquibaseUpdate (classLoaderSource , properties , masterFileName );
75
124
EntityManagerFactory factory = Persistence .createEntityManagerFactory (persistenceUnitName , properties );
76
125
ShutdownHook .register (() -> {
77
126
if (factory != null && factory .isOpen ())
@@ -90,8 +139,8 @@ private static Map<String, String> getProperties(final String prefix) {
90
139
return result ;
91
140
}
92
141
93
- private static void liquibaseUpdate (final Class <?> classLoaderSource , final Map <String , String > properties )
94
- throws RdbUtilException {
142
+ public static void liquibaseUpdate (final Class <?> classLoaderSource , final Map <String , String > properties ,
143
+ final String masterFileName ) throws RdbUtilException {
95
144
Connection connection ;
96
145
try {
97
146
log .info ("getting connection from DriverManager" );
@@ -103,7 +152,7 @@ private static void liquibaseUpdate(final Class<?> classLoaderSource, final Map<
103
152
.findCorrectDatabaseImplementation (new JdbcConnection (connection ));
104
153
log .info ("scanning file-system for master-changelog files" );
105
154
List <Path > masterLogFiles = Resources .walk (classLoaderSource ,
106
- path -> path .toString ().endsWith ("-master .xml" ));
155
+ path -> path .toString ().endsWith (masterFileName + " .xml" ));
107
156
for (Path p : masterLogFiles )
108
157
log .info ("found file [{}]" , p .toString ());
109
158
if (masterLogFiles .size () == 0 )
0 commit comments