|
|
@ -16,6 +16,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.autoconfigure.orm.jpa;
|
|
|
|
package org.springframework.boot.autoconfigure.orm.jpa;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
@ -30,6 +31,9 @@ import org.springframework.beans.factory.ObjectProvider;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
|
|
|
|
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
|
|
|
|
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
|
|
|
|
import org.springframework.boot.jdbc.SchemaManagementProvider;
|
|
|
|
import org.springframework.boot.jdbc.SchemaManagementProvider;
|
|
|
|
|
|
|
|
import org.springframework.boot.jdbc.metadata.CompositeDataSourcePoolMetadataProvider;
|
|
|
|
|
|
|
|
import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadata;
|
|
|
|
|
|
|
|
import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadataProvider;
|
|
|
|
import org.springframework.boot.orm.jpa.hibernate.SpringJtaPlatform;
|
|
|
|
import org.springframework.boot.orm.jpa.hibernate.SpringJtaPlatform;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.jndi.JndiLocatorDelegate;
|
|
|
|
import org.springframework.jndi.JndiLocatorDelegate;
|
|
|
@ -56,6 +60,8 @@ class HibernateJpaConfiguration extends JpaBaseConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
private static final String JTA_PLATFORM = "hibernate.transaction.jta.platform";
|
|
|
|
private static final String JTA_PLATFORM = "hibernate.transaction.jta.platform";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String PROVIDER_DISABLES_AUTOCOMMIT = "hibernate.connection.provider_disables_autocommit";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* {@code NoJtaPlatform} implementations for various Hibernate versions.
|
|
|
|
* {@code NoJtaPlatform} implementations for various Hibernate versions.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -73,14 +79,19 @@ class HibernateJpaConfiguration extends JpaBaseConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
private final HibernateDefaultDdlAutoProvider defaultDdlAutoProvider;
|
|
|
|
private final HibernateDefaultDdlAutoProvider defaultDdlAutoProvider;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private DataSourcePoolMetadataProvider poolMetadataProvider;
|
|
|
|
|
|
|
|
|
|
|
|
HibernateJpaConfiguration(DataSource dataSource, JpaProperties jpaProperties,
|
|
|
|
HibernateJpaConfiguration(DataSource dataSource, JpaProperties jpaProperties,
|
|
|
|
ObjectProvider<JtaTransactionManager> jtaTransactionManager,
|
|
|
|
ObjectProvider<JtaTransactionManager> jtaTransactionManager,
|
|
|
|
ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers,
|
|
|
|
ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers,
|
|
|
|
|
|
|
|
ObjectProvider<Collection<DataSourcePoolMetadataProvider>> metadataProviders,
|
|
|
|
ObjectProvider<List<SchemaManagementProvider>> providers) {
|
|
|
|
ObjectProvider<List<SchemaManagementProvider>> providers) {
|
|
|
|
super(dataSource, jpaProperties, jtaTransactionManager,
|
|
|
|
super(dataSource, jpaProperties, jtaTransactionManager,
|
|
|
|
transactionManagerCustomizers);
|
|
|
|
transactionManagerCustomizers);
|
|
|
|
this.defaultDdlAutoProvider = new HibernateDefaultDdlAutoProvider(
|
|
|
|
this.defaultDdlAutoProvider = new HibernateDefaultDdlAutoProvider(
|
|
|
|
providers.getIfAvailable(Collections::emptyList));
|
|
|
|
providers.getIfAvailable(Collections::emptyList));
|
|
|
|
|
|
|
|
this.poolMetadataProvider = new CompositeDataSourcePoolMetadataProvider(
|
|
|
|
|
|
|
|
metadataProviders.getIfAvailable());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -103,6 +114,9 @@ class HibernateJpaConfiguration extends JpaBaseConfiguration {
|
|
|
|
if (!vendorProperties.containsKey(JTA_PLATFORM)) {
|
|
|
|
if (!vendorProperties.containsKey(JTA_PLATFORM)) {
|
|
|
|
configureJtaPlatform(vendorProperties);
|
|
|
|
configureJtaPlatform(vendorProperties);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!vendorProperties.containsKey(PROVIDER_DISABLES_AUTOCOMMIT)) {
|
|
|
|
|
|
|
|
configureProviderDisablesAutocommit(vendorProperties);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void configureJtaPlatform(Map<String, Object> vendorProperties)
|
|
|
|
private void configureJtaPlatform(Map<String, Object> vendorProperties)
|
|
|
@ -124,6 +138,19 @@ class HibernateJpaConfiguration extends JpaBaseConfiguration {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void configureProviderDisablesAutocommit(Map<String, Object> vendorProperties) {
|
|
|
|
|
|
|
|
if (isDataSourceAutoCommitDisabled() && !isJta()) {
|
|
|
|
|
|
|
|
vendorProperties.put(PROVIDER_DISABLES_AUTOCOMMIT, "true");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isDataSourceAutoCommitDisabled() {
|
|
|
|
|
|
|
|
DataSourcePoolMetadata poolMetadata = this.poolMetadataProvider
|
|
|
|
|
|
|
|
.getDataSourcePoolMetadata(getDataSource());
|
|
|
|
|
|
|
|
return poolMetadata != null
|
|
|
|
|
|
|
|
&& Boolean.FALSE.equals(poolMetadata.getDefaultAutoCommit());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean runningOnWebSphere() {
|
|
|
|
private boolean runningOnWebSphere() {
|
|
|
|
return ClassUtils.isPresent(
|
|
|
|
return ClassUtils.isPresent(
|
|
|
|
"com.ibm.websphere.jtaextensions." + "ExtendedJTATransaction",
|
|
|
|
"com.ibm.websphere.jtaextensions." + "ExtendedJTATransaction",
|
|
|
|