mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-10-09 16:49:36 +00:00
Polishing
This commit is contained in:
+6
-5
@@ -398,15 +398,16 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage
|
||||
* Determine the PersistenceUnitInfo to use for the EntityManagerFactory
|
||||
* created by this bean.
|
||||
* <p>The default implementation reads in all persistence unit infos from
|
||||
* {@code persistence.xml}, as defined in the JPA specification.
|
||||
* If no entity manager name was specified, it takes the first info in the
|
||||
* array as returned by the reader. Otherwise, it checks for a matching name.
|
||||
* {@code persistence.xml}, as defined in the JPA specification, selecting a unit
|
||||
* by name. If no persistence unit name was specified, it takes the default one
|
||||
* if configured, or otherwise the first persistence unit as found by the reader.
|
||||
* @param persistenceUnitManager the PersistenceUnitManager to obtain from
|
||||
* @return the chosen PersistenceUnitInfo
|
||||
*/
|
||||
protected PersistenceUnitInfo determinePersistenceUnitInfo(PersistenceUnitManager persistenceUnitManager) {
|
||||
if (getPersistenceUnitName() != null) {
|
||||
return persistenceUnitManager.obtainPersistenceUnitInfo(getPersistenceUnitName());
|
||||
String persistenceUnitName = getPersistenceUnitName();
|
||||
if (persistenceUnitName != null) {
|
||||
return persistenceUnitManager.obtainPersistenceUnitInfo(persistenceUnitName);
|
||||
}
|
||||
else {
|
||||
return persistenceUnitManager.obtainDefaultPersistenceUnitInfo();
|
||||
|
||||
+17
-17
@@ -193,7 +193,7 @@ public class DefaultPersistenceUnitManager
|
||||
|
||||
/**
|
||||
* Set the {@link PersistenceManagedTypes} to use to build the list of managed types
|
||||
* as an alternative to entity scanning.
|
||||
* for the default persistence unit, as an alternative to entity scanning.
|
||||
* @param managedTypes the managed types
|
||||
* @since 6.0
|
||||
*/
|
||||
@@ -540,33 +540,33 @@ public class DefaultPersistenceUnitManager
|
||||
* @see #setPackagesToScan
|
||||
*/
|
||||
private SpringPersistenceUnitInfo buildDefaultPersistenceUnitInfo() {
|
||||
SpringPersistenceUnitInfo scannedUnit = new SpringPersistenceUnitInfo();
|
||||
SpringPersistenceUnitInfo defaultUnit = new SpringPersistenceUnitInfo();
|
||||
if (this.defaultPersistenceUnitName != null) {
|
||||
scannedUnit.setPersistenceUnitName(this.defaultPersistenceUnitName);
|
||||
defaultUnit.setPersistenceUnitName(this.defaultPersistenceUnitName);
|
||||
}
|
||||
scannedUnit.setExcludeUnlistedClasses(true);
|
||||
defaultUnit.setExcludeUnlistedClasses(true);
|
||||
|
||||
if (this.managedTypes != null) {
|
||||
applyManagedTypes(scannedUnit, this.managedTypes);
|
||||
applyManagedTypes(defaultUnit, this.managedTypes);
|
||||
}
|
||||
else if (this.packagesToScan != null) {
|
||||
PersistenceManagedTypesScanner scanner = new PersistenceManagedTypesScanner(
|
||||
this.resourcePatternResolver, this.managedClassNameFilter);
|
||||
applyManagedTypes(scannedUnit, scanner.scan(this.packagesToScan));
|
||||
applyManagedTypes(defaultUnit, scanner.scan(this.packagesToScan));
|
||||
}
|
||||
|
||||
if (this.mappingResources != null) {
|
||||
for (String mappingFileName : this.mappingResources) {
|
||||
scannedUnit.addMappingFileName(mappingFileName);
|
||||
defaultUnit.addMappingFileName(mappingFileName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Resource ormXml = getOrmXmlForDefaultPersistenceUnit();
|
||||
if (ormXml != null) {
|
||||
scannedUnit.addMappingFileName(DEFAULT_ORM_XML_RESOURCE);
|
||||
if (scannedUnit.getPersistenceUnitRootUrl() == null) {
|
||||
defaultUnit.addMappingFileName(DEFAULT_ORM_XML_RESOURCE);
|
||||
if (defaultUnit.getPersistenceUnitRootUrl() == null) {
|
||||
try {
|
||||
scannedUnit.setPersistenceUnitRootUrl(
|
||||
defaultUnit.setPersistenceUnitRootUrl(
|
||||
PersistenceUnitReader.determinePersistenceUnitRootUrl(ormXml));
|
||||
}
|
||||
catch (IOException ex) {
|
||||
@@ -576,7 +576,7 @@ public class DefaultPersistenceUnitManager
|
||||
}
|
||||
}
|
||||
|
||||
return scannedUnit;
|
||||
return defaultUnit;
|
||||
}
|
||||
|
||||
private void applyManagedTypes(SpringPersistenceUnitInfo scannedUnit, PersistenceManagedTypes managedTypes) {
|
||||
@@ -639,9 +639,9 @@ public class DefaultPersistenceUnitManager
|
||||
|
||||
|
||||
/**
|
||||
* Return the specified PersistenceUnitInfo from this manager's cache
|
||||
* of processed persistence units, keeping it in the cache (i.e. not
|
||||
* 'obtaining' it for use but rather just accessing it for post-processing).
|
||||
* Return the specified {@link MutablePersistenceUnitInfo} from this manager's cache
|
||||
* of processed persistence units, keeping it in the cache (i.e. not 'obtaining' it
|
||||
* for use but rather just accessing it for post-processing).
|
||||
* <p>This can be used in {@link #postProcessPersistenceUnitInfo} implementations,
|
||||
* detecting existing persistence units of the same name and potentially merging them.
|
||||
* @param persistenceUnitName the name of the desired persistence unit
|
||||
@@ -654,12 +654,12 @@ public class DefaultPersistenceUnitManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook method allowing subclasses to customize each PersistenceUnitInfo.
|
||||
* Hook method allowing subclasses to customize each {@link MutablePersistenceUnitInfo}.
|
||||
* <p>The default implementation delegates to all registered PersistenceUnitPostProcessors.
|
||||
* It is usually preferable to register further entity classes, jar files etc there
|
||||
* rather than in a subclass of this manager, to be able to reuse the post-processors.
|
||||
* @param pui the chosen PersistenceUnitInfo, as read from {@code persistence.xml}.
|
||||
* Passed in as MutablePersistenceUnitInfo.
|
||||
* @param pui the chosen persistence unit configuration, as read from
|
||||
* {@code persistence.xml}. Passed in as MutablePersistenceUnitInfo.
|
||||
* @see #setPersistenceUnitPostProcessors
|
||||
*/
|
||||
protected void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui) {
|
||||
|
||||
+4
-3
@@ -33,9 +33,10 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Spring's base implementation of the JPA
|
||||
* Spring's mutable equivalent of the JPA
|
||||
* {@link jakarta.persistence.spi.PersistenceUnitInfo} interface,
|
||||
* used to bootstrap an {@code EntityManagerFactory} in a container.
|
||||
* This is the type exposed to {@link PersistenceUnitPostProcessor}.
|
||||
*
|
||||
* <p>This implementation is largely a JavaBean, offering mutators
|
||||
* for all standard {@code PersistenceUnitInfo} properties.
|
||||
@@ -57,10 +58,10 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo {
|
||||
private PersistenceUnitTransactionType transactionType;
|
||||
|
||||
@Nullable
|
||||
private DataSource nonJtaDataSource;
|
||||
private DataSource jtaDataSource;
|
||||
|
||||
@Nullable
|
||||
private DataSource jtaDataSource;
|
||||
private DataSource nonJtaDataSource;
|
||||
|
||||
private final List<String> mappingFileNames = new ArrayList<>();
|
||||
|
||||
|
||||
+1
@@ -57,6 +57,7 @@ public interface PersistenceManagedTypes {
|
||||
@Nullable
|
||||
URL getPersistenceUnitRootUrl();
|
||||
|
||||
|
||||
/**
|
||||
* Create an instance using the specified managed class names.
|
||||
* @param managedClassNames the managed class names
|
||||
|
||||
+2
@@ -40,6 +40,7 @@ class SimplePersistenceManagedTypes implements PersistenceManagedTypes {
|
||||
|
||||
SimplePersistenceManagedTypes(List<String> managedClassNames, List<String> managedPackages,
|
||||
@Nullable URL persistenceUnitRootUrl) {
|
||||
|
||||
this.managedClassNames = managedClassNames;
|
||||
this.managedPackages = managedPackages;
|
||||
this.persistenceUnitRootUrl = persistenceUnitRootUrl;
|
||||
@@ -49,6 +50,7 @@ class SimplePersistenceManagedTypes implements PersistenceManagedTypes {
|
||||
this(managedClassNames, managedPackages, null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> getManagedClassNames() {
|
||||
return this.managedClassNames;
|
||||
|
||||
Reference in New Issue
Block a user