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

View File

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

View File

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