HHH-12454 - o.h.boot.spi.SessionFactoryOptions#getJpaCompliance() returns an immutable copy

This commit is contained in:
Andrea Boriero 2018-04-09 16:43:01 +01:00 committed by Steve Ebersole
parent 6cefa865b0
commit b6ee633c53
5 changed files with 219 additions and 70 deletions

View File

@ -36,7 +36,7 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.annotations.reflection.JPAMetadataProvider;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.jpa.internal.JpaComplianceImpl;
import org.hibernate.jpa.internal.MutableJpaComplianceImpl;
import org.hibernate.jpa.spi.MutableJpaCompliance;
import org.hibernate.type.spi.TypeConfiguration;
@ -91,7 +91,7 @@ public class BootstrapContextImpl implements BootstrapContext {
final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class );
final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );
this.jpaCompliance = new JpaComplianceImpl( configService.getSettings(), false );
this.jpaCompliance = new MutableJpaComplianceImpl( configService.getSettings(), false );
this.scanOptions = new StandardScanOptions(
(String) configService.getSettings().get( AvailableSettings.SCANNER_DISCOVERY ),
false

View File

@ -975,7 +975,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
@Override
public JpaCompliance getJpaCompliance() {
return jpaCompliance;
return jpaCompliance.immutableCopy();
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -6,64 +6,35 @@
*/
package org.hibernate.jpa.internal;
import java.util.Map;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.jpa.spi.MutableJpaCompliance;
import org.hibernate.jpa.spi.JpaCompliance;
/**
* @author Steve Ebersole
* @author Andrea Boriero
*/
public class JpaComplianceImpl implements MutableJpaCompliance {
public class JpaComplianceImpl implements JpaCompliance {
private boolean queryCompliance;
private boolean transactionCompliance;
private boolean listCompliance;
private boolean closedCompliance;
private boolean proxyCompliance;
private boolean cachingCompliance;
private final boolean globalGeneratorNameScopeCompliance;
private boolean globalGeneratorNameScopeCompliance;
@SuppressWarnings("ConstantConditions")
public JpaComplianceImpl(Map configurationSettings, boolean jpaByDefault) {
final Object legacyQueryCompliance = configurationSettings.get( AvailableSettings.JPAQL_STRICT_COMPLIANCE );
queryCompliance = ConfigurationHelper.getBoolean(
AvailableSettings.JPA_QUERY_COMPLIANCE,
configurationSettings,
ConfigurationHelper.toBoolean( legacyQueryCompliance, jpaByDefault )
);
transactionCompliance = ConfigurationHelper.getBoolean(
AvailableSettings.JPA_TRANSACTION_COMPLIANCE,
configurationSettings,
jpaByDefault
);
listCompliance = ConfigurationHelper.getBoolean(
AvailableSettings.JPA_LIST_COMPLIANCE,
configurationSettings,
jpaByDefault
);
closedCompliance = ConfigurationHelper.getBoolean(
AvailableSettings.JPA_CLOSED_COMPLIANCE,
configurationSettings,
jpaByDefault
);
proxyCompliance = ConfigurationHelper.getBoolean(
AvailableSettings.JPA_PROXY_COMPLIANCE,
configurationSettings,
jpaByDefault
);
cachingCompliance = ConfigurationHelper.getBoolean(
AvailableSettings.JPA_CACHING_COMPLIANCE,
configurationSettings,
jpaByDefault
);
globalGeneratorNameScopeCompliance = ConfigurationHelper.getBoolean(
AvailableSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE,
configurationSettings,
jpaByDefault
);
private JpaComplianceImpl(
boolean queryCompliance,
boolean transactionCompliance,
boolean listCompliance,
boolean closedCompliance,
boolean proxyCompliance,
boolean cachingCompliance,
boolean globalGeneratorNameScopeCompliance) {
this.queryCompliance = queryCompliance;
this.transactionCompliance = transactionCompliance;
this.listCompliance = listCompliance;
this.closedCompliance = closedCompliance;
this.proxyCompliance = proxyCompliance;
this.cachingCompliance = cachingCompliance;
this.globalGeneratorNameScopeCompliance = globalGeneratorNameScopeCompliance;
}
@Override
@ -101,30 +72,63 @@ public class JpaComplianceImpl implements MutableJpaCompliance {
return globalGeneratorNameScopeCompliance;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Mutators
public static class JpaComplianceBuilder {
private boolean queryCompliance;
private boolean transactionCompliance;
private boolean listCompliance;
private boolean closedCompliance;
private boolean proxyCompliance;
private boolean cachingCompliance;
private boolean globalGeneratorNameScopeCompliance;
public void setQueryCompliance(boolean queryCompliance) {
this.queryCompliance = queryCompliance;
}
public JpaComplianceBuilder() {
}
public void setTransactionCompliance(boolean transactionCompliance) {
this.transactionCompliance = transactionCompliance;
}
public JpaComplianceBuilder setQueryCompliance(boolean queryCompliance) {
this.queryCompliance = queryCompliance;
return this;
}
public void setListCompliance(boolean listCompliance) {
this.listCompliance = listCompliance;
}
public JpaComplianceBuilder setTransactionCompliance(boolean transactionCompliance) {
this.transactionCompliance = transactionCompliance;
return this;
}
public void setClosedCompliance(boolean closedCompliance) {
this.closedCompliance = closedCompliance;
}
public JpaComplianceBuilder setListCompliance(boolean listCompliance) {
this.listCompliance = listCompliance;
return this;
}
public void setProxyCompliance(boolean proxyCompliance) {
this.proxyCompliance = proxyCompliance;
}
public JpaComplianceBuilder setClosedCompliance(boolean closedCompliance) {
this.closedCompliance = closedCompliance;
return this;
}
public void setCachingCompliance(boolean cachingCompliance) {
this.cachingCompliance = cachingCompliance;
public JpaComplianceBuilder setProxyCompliance(boolean proxyCompliance) {
this.proxyCompliance = proxyCompliance;
return this;
}
public JpaComplianceBuilder setCachingCompliance(boolean cachingCompliance) {
this.cachingCompliance = cachingCompliance;
return this;
}
public JpaComplianceBuilder setGlobalGeneratorNameCompliance(boolean globalGeneratorNameCompliance) {
this.globalGeneratorNameScopeCompliance = globalGeneratorNameCompliance;
return this;
}
JpaCompliance createJpaCompliance() {
return new JpaComplianceImpl(
queryCompliance,
transactionCompliance,
listCompliance,
closedCompliance,
proxyCompliance,
cachingCompliance,
globalGeneratorNameScopeCompliance
);
}
}
}

View File

@ -0,0 +1,143 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.internal;
import java.util.Map;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.jpa.spi.JpaCompliance;
import org.hibernate.jpa.spi.MutableJpaCompliance;
/**
* @author Steve Ebersole
*/
public class MutableJpaComplianceImpl implements MutableJpaCompliance {
private boolean queryCompliance;
private boolean transactionCompliance;
private boolean listCompliance;
private boolean closedCompliance;
private boolean proxyCompliance;
private boolean cachingCompliance;
private final boolean globalGeneratorNameScopeCompliance;
@SuppressWarnings("ConstantConditions")
public MutableJpaComplianceImpl(Map configurationSettings, boolean jpaByDefault) {
final Object legacyQueryCompliance = configurationSettings.get( AvailableSettings.JPAQL_STRICT_COMPLIANCE );
queryCompliance = ConfigurationHelper.getBoolean(
AvailableSettings.JPA_QUERY_COMPLIANCE,
configurationSettings,
ConfigurationHelper.toBoolean( legacyQueryCompliance, jpaByDefault )
);
transactionCompliance = ConfigurationHelper.getBoolean(
AvailableSettings.JPA_TRANSACTION_COMPLIANCE,
configurationSettings,
jpaByDefault
);
listCompliance = ConfigurationHelper.getBoolean(
AvailableSettings.JPA_LIST_COMPLIANCE,
configurationSettings,
jpaByDefault
);
closedCompliance = ConfigurationHelper.getBoolean(
AvailableSettings.JPA_CLOSED_COMPLIANCE,
configurationSettings,
jpaByDefault
);
proxyCompliance = ConfigurationHelper.getBoolean(
AvailableSettings.JPA_PROXY_COMPLIANCE,
configurationSettings,
jpaByDefault
);
cachingCompliance = ConfigurationHelper.getBoolean(
AvailableSettings.JPA_CACHING_COMPLIANCE,
configurationSettings,
jpaByDefault
);
globalGeneratorNameScopeCompliance = ConfigurationHelper.getBoolean(
AvailableSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE,
configurationSettings,
jpaByDefault
);
}
@Override
public boolean isJpaQueryComplianceEnabled() {
return queryCompliance;
}
@Override
public boolean isJpaTransactionComplianceEnabled() {
return transactionCompliance;
}
@Override
public boolean isJpaListComplianceEnabled() {
return listCompliance;
}
@Override
public boolean isJpaClosedComplianceEnabled() {
return closedCompliance;
}
@Override
public boolean isJpaProxyComplianceEnabled() {
return proxyCompliance;
}
@Override
public boolean isJpaCacheComplianceEnabled() {
return cachingCompliance;
}
@Override
public boolean isGlobalGeneratorScopeEnabled() {
return globalGeneratorNameScopeCompliance;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Mutators
public void setQueryCompliance(boolean queryCompliance) {
this.queryCompliance = queryCompliance;
}
public void setTransactionCompliance(boolean transactionCompliance) {
this.transactionCompliance = transactionCompliance;
}
public void setListCompliance(boolean listCompliance) {
this.listCompliance = listCompliance;
}
public void setClosedCompliance(boolean closedCompliance) {
this.closedCompliance = closedCompliance;
}
public void setProxyCompliance(boolean proxyCompliance) {
this.proxyCompliance = proxyCompliance;
}
public void setCachingCompliance(boolean cachingCompliance) {
this.cachingCompliance = cachingCompliance;
}
@Override
public JpaCompliance immutableCopy() {
JpaComplianceImpl.JpaComplianceBuilder builder = new JpaComplianceImpl.JpaComplianceBuilder();
builder.setQueryCompliance( queryCompliance )
.setTransactionCompliance( transactionCompliance )
.setListCompliance( listCompliance )
.setClosedCompliance( closedCompliance )
.setProxyCompliance( proxyCompliance )
.setCachingCompliance( cachingCompliance )
.setGlobalGeneratorNameCompliance( globalGeneratorNameScopeCompliance );
return builder.createJpaCompliance();
}
}

View File

@ -21,4 +21,6 @@ public interface MutableJpaCompliance extends JpaCompliance {
void setProxyCompliance(boolean proxyCompliance);
void setCachingCompliance(boolean cachingCompliance);
JpaCompliance immutableCopy();
}