@@ -117,6 +117,8 @@ public class DefaultPersistenceUnitManager
117
117
118
118
private DataSource defaultDataSource ;
119
119
120
+ private DataSource defaultJtaDataSource ;
121
+
120
122
private PersistenceUnitPostProcessor [] persistenceUnitPostProcessors ;
121
123
122
124
private LoadTimeWeaver loadTimeWeaver ;
@@ -241,9 +243,9 @@ public DataSourceLookup getDataSourceLookup() {
241
243
}
242
244
243
245
/**
244
- * Specify the JDBC DataSource that the JPA persistence provider is supposed
245
- * to use for accessing the database if none has been specified in
246
- * <code>persistence.xml</code> .
246
+ * Specify the JDBC DataSource that the JPA persistence provider is supposed to use
247
+ * for accessing the database if none has been specified in <code>persistence.xml</code>.
248
+ * This variant indicates no special transaction setup, i.e. typical resource-local .
247
249
* <p>In JPA speak, a DataSource passed in here will be uses as "nonJtaDataSource"
248
250
* on the PersistenceUnitInfo passed to the PersistenceProvider, provided that
249
251
* none has been registered before.
@@ -254,20 +256,39 @@ public void setDefaultDataSource(DataSource defaultDataSource) {
254
256
}
255
257
256
258
/**
257
- * Return the JDBC DataSource that the JPA persistence provider is supposed
258
- * to use for accessing the database if none has been specified in
259
- * <code>persistence.xml</code>.
259
+ * Return the JDBC DataSource that the JPA persistence provider is supposed to use
260
+ * for accessing the database if none has been specified in <code>persistence.xml</code>.
260
261
*/
261
262
public DataSource getDefaultDataSource () {
262
263
return this .defaultDataSource ;
263
264
}
264
265
266
+ /**
267
+ * Specify the JDBC DataSource that the JPA persistence provider is supposed to use
268
+ * for accessing the database if none has been specified in <code>persistence.xml</code>.
269
+ * This variant indicates that JTA is supposed to be used as transaction type.
270
+ * <p>In JPA speak, a DataSource passed in here will be uses as "jtaDataSource"
271
+ * on the PersistenceUnitInfo passed to the PersistenceProvider, provided that
272
+ * none has been registered before.
273
+ * @see javax.persistence.spi.PersistenceUnitInfo#getJtaDataSource()
274
+ */
275
+ public void setDefaultJtaDataSource (DataSource defaultJtaDataSource ) {
276
+ this .defaultJtaDataSource = defaultJtaDataSource ;
277
+ }
278
+
279
+ /**
280
+ * Return the JTA-aware DataSource that the JPA persistence provider is supposed to use
281
+ * for accessing the database if none has been specified in <code>persistence.xml</code>.
282
+ */
283
+ public DataSource getDefaultJtaDataSource () {
284
+ return this .defaultJtaDataSource ;
285
+ }
286
+
265
287
/**
266
288
* Set the PersistenceUnitPostProcessors to be applied to each
267
289
* PersistenceUnitInfo that has been parsed by this manager.
268
- * <p>Such post-processors can, for example, register further entity
269
- * classes and jar files, in addition to the metadata read in from
270
- * <code>persistence.xml</code>.
290
+ * <p>Such post-processors can, for example, register further entity classes and
291
+ * jar files, in addition to the metadata read from <code>persistence.xml</code>.
271
292
*/
272
293
public void setPersistenceUnitPostProcessors (PersistenceUnitPostProcessor ... postProcessors ) {
273
294
this .persistenceUnitPostProcessors = postProcessors ;
@@ -342,6 +363,9 @@ public void preparePersistenceUnitInfos() {
342
363
if (pui .getPersistenceUnitRootUrl () == null ) {
343
364
pui .setPersistenceUnitRootUrl (determineDefaultPersistenceUnitRootUrl ());
344
365
}
366
+ if (pui .getJtaDataSource () == null ) {
367
+ pui .setJtaDataSource (this .defaultJtaDataSource );
368
+ }
345
369
if (pui .getNonJtaDataSource () == null ) {
346
370
pui .setNonJtaDataSource (this .defaultDataSource );
347
371
}
0 commit comments