Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.hibernate.MappingException;
import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataBuilder;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.SessionFactoryBuilder;
Expand Down Expand Up @@ -470,9 +469,9 @@ public Configuration configure(File configFile) throws HibernateException {
* @param highlightSql should logged SQL be highlighted with pretty colors
*/
public Configuration showSql(boolean showSql, boolean formatSql, boolean highlightSql) {
setProperty( AvailableSettings.SHOW_SQL, Boolean.toString(showSql) );
setProperty( AvailableSettings.FORMAT_SQL, Boolean.toString(formatSql) );
setProperty( AvailableSettings.HIGHLIGHT_SQL, Boolean.toString(highlightSql) );
setProperty( JdbcSettings.SHOW_SQL, Boolean.toString(showSql) );
setProperty( JdbcSettings.FORMAT_SQL, Boolean.toString(formatSql) );
setProperty( JdbcSettings.HIGHLIGHT_SQL, Boolean.toString(highlightSql) );
return this;
}

Expand All @@ -482,7 +481,7 @@ public Configuration showSql(boolean showSql, boolean formatSql, boolean highlig
* @param action the {@link Action}
*/
public Configuration setSchemaExportAction(Action action) {
setProperty( AvailableSettings.HBM2DDL_AUTO, action.getExternalHbm2ddlName() );
setProperty( SchemaToolingSettings.HBM2DDL_AUTO, action.getExternalHbm2ddlName() );
return this;
}

Expand All @@ -493,8 +492,8 @@ public Configuration setSchemaExportAction(Action action) {
* @param pass the password
*/
public Configuration setCredentials(String user, String pass) {
setProperty( AvailableSettings.USER, user );
setProperty( AvailableSettings.PASS, pass );
setProperty( JdbcSettings.USER, user );
setProperty( JdbcSettings.PASS, pass );
return this;
}

Expand All @@ -514,7 +513,7 @@ public Configuration setJdbcUrl(String url) {
* @param jndiName the JNDI name of the datasource
*/
public Configuration setDatasource(String jndiName) {
setProperty( AvailableSettings.DATASOURCE, jndiName );
setProperty( JdbcSettings.DATASOURCE, jndiName );
return this;
}

Expand All @@ -524,7 +523,7 @@ public Configuration setDatasource(String jndiName) {
* @param transactionType the {@link PersistenceUnitTransactionType}
*/
public Configuration setTransactionType(PersistenceUnitTransactionType transactionType) {
setProperty( AvailableSettings.JAKARTA_TRANSACTION_TYPE, transactionType.toString() );
setProperty( PersistenceSettings.JAKARTA_TRANSACTION_TYPE, transactionType.toString() );
return this;
}

Expand Down Expand Up @@ -783,8 +782,8 @@ public Configuration addAnnotatedClass(Class<?> annotatedClass) {
*
* @return this (for method chaining)
*/
public Configuration addAnnotatedClasses(Class... annotatedClasses) {
for (Class annotatedClass : annotatedClasses) {
public Configuration addAnnotatedClasses(Class<?>... annotatedClasses) {
for ( var annotatedClass : annotatedClasses ) {
addAnnotatedClass( annotatedClass );
}
return this;
Expand Down Expand Up @@ -814,7 +813,7 @@ public Configuration addPackage(String packageName) throws MappingException {
* @throws MappingException in case there is an error in the mapping data
*/
public Configuration addPackages(String... packageNames) throws MappingException {
for (String packageName : packageNames) {
for ( String packageName : packageNames ) {
addPackage( packageName );
}
return this;
Expand Down Expand Up @@ -1078,8 +1077,8 @@ public SessionFactory buildSessionFactory(ServiceRegistry serviceRegistry) throw
.forEach( metadataBuilder::applyAttributeConverter );
}

final Metadata metadata = metadataBuilder.build();
final SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
final var metadata = metadataBuilder.build();
final var sessionFactoryBuilder = metadata.getSessionFactoryBuilder();

if ( interceptor != null && interceptor != EmptyInterceptor.INSTANCE ) {
sessionFactoryBuilder.applyInterceptor( interceptor );
Expand Down Expand Up @@ -1130,7 +1129,7 @@ public SessionFactory buildSessionFactory(ServiceRegistry serviceRegistry) throw
public SessionFactory buildSessionFactory() throws HibernateException {
log.trace( "Building session factory using internal StandardServiceRegistryBuilder" );
standardServiceRegistryBuilder.applySettings( properties );
StandardServiceRegistry serviceRegistry = standardServiceRegistryBuilder.build();
var serviceRegistry = standardServiceRegistryBuilder.build();
try {
return buildSessionFactory( serviceRegistry );
}
Expand Down
36 changes: 17 additions & 19 deletions hibernate-core/src/main/java/org/hibernate/cfg/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
package org.hibernate.cfg;

import java.io.IOException;
import java.io.InputStream;
import java.lang.invoke.MethodHandles;
import java.util.Properties;

import org.hibernate.HibernateException;
import org.hibernate.Internal;
import org.hibernate.Version;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ConfigHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;

import org.jboss.logging.Logger;

import static org.hibernate.internal.util.ConfigHelper.getResourceAsStream;
import static org.hibernate.internal.util.config.ConfigurationHelper.maskOut;

/**
* Provides access to configuration properties passed in {@link Properties} objects.
* <p>
Expand Down Expand Up @@ -141,30 +141,28 @@ public final class Environment implements AvailableSettings {
GLOBAL_PROPERTIES = new Properties();

try {
InputStream stream = ConfigHelper.getResourceAsStream( "/hibernate.properties" );
try {
GLOBAL_PROPERTIES.load(stream);
LOG.propertiesLoaded( ConfigurationHelper.maskOut( GLOBAL_PROPERTIES, PASS ) );
}
catch (Exception e) {
LOG.unableToLoadProperties();
}
finally {
try{
stream.close();
try (var stream = getResourceAsStream("/hibernate.properties")) {
try {
GLOBAL_PROPERTIES.load(stream);
LOG.propertiesLoaded( maskOut( GLOBAL_PROPERTIES,
PASS, JAKARTA_JDBC_PASSWORD, JPA_JDBC_PASSWORD ) );
}
catch (IOException ioe){
LOG.unableToCloseStreamError( ioe );
catch (Exception e) {
LOG.unableToLoadProperties();
}
}
catch (IOException ioe) {
LOG.unableToCloseStreamError( ioe );
}
}
catch (HibernateException he) {
LOG.propertiesNotFound();
}

try {
final Properties systemProperties = System.getProperties();
// Must be thread-safe in case an application changes System properties during Hibernate initialization.
final var systemProperties = System.getProperties();
// Must be thread-safe in case an application changes
// System properties during Hibernate initialization.
// See HHH-8383.
synchronized (systemProperties) {
GLOBAL_PROPERTIES.putAll(systemProperties);
Expand All @@ -187,7 +185,7 @@ private Environment() {
* with all additional properties specified in {@code hibernate.properties}.
*/
public static Properties getProperties() {
final Properties copy = new Properties();
final var copy = new Properties();
copy.putAll(GLOBAL_PROPERTIES);
return copy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.batch.spi.BatchBuilder;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.profile.FetchProfile;
Expand Down Expand Up @@ -137,11 +136,9 @@
import static java.util.Collections.unmodifiableSet;
import static org.hibernate.cfg.AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS;
import static org.hibernate.internal.FetchProfileHelper.addFetchProfiles;
import static org.hibernate.internal.SessionFactorySettings.deprecationCheck;
import static org.hibernate.internal.SessionFactorySettings.determineJndiName;
import static org.hibernate.internal.SessionFactorySettings.getMaskedSettings;
import static org.hibernate.internal.SessionFactorySettings.getSessionFactoryName;
import static org.hibernate.internal.SessionFactorySettings.getSettings;
import static org.hibernate.internal.SessionFactorySettings.maskOutSensitiveInformation;
import static org.hibernate.jpa.HibernateHints.HINT_TENANT_ID;
import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer;
import static org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT;
Expand Down Expand Up @@ -239,9 +236,7 @@ public SessionFactoryImpl(

jdbcServices = serviceRegistry.requireService( JdbcServices.class );

settings = getSettings( options, serviceRegistry );
maskOutSensitiveInformation( settings );
deprecationCheck( settings );
settings = getMaskedSettings( options, serviceRegistry );
LOG.instantiatingFactory( uuid, settings );

sqlStringGenerationContext = createSqlStringGenerationContext( bootMetamodel, options, jdbcServices );
Expand Down Expand Up @@ -457,13 +452,8 @@ private void disintegrate(Exception startupException, IntegratorObserver integra

private SessionBuilderImpl createDefaultSessionOpenOptionsIfPossible() {
final var tenantIdResolver = getCurrentTenantIdentifierResolver();
if ( tenantIdResolver == null ) {
return withOptions();
}
else {
//Don't store a default SessionBuilder when a CurrentTenantIdentifierResolver is provided
return null;
}
// Don't store a default SessionBuilder when a CurrentTenantIdentifierResolver is provided
return tenantIdResolver == null ? withOptions() : null;
}

private SessionBuilderImpl buildTemporarySessionOpenOptions() {
Expand Down Expand Up @@ -821,16 +811,16 @@ public void close() {
}

if ( runtimeMetamodels != null && runtimeMetamodels.getMappingMetamodel() != null ) {
final JdbcConnectionAccess jdbcConnectionAccess = jdbcServices.getBootstrapJdbcConnectionAccess();
final var jdbcConnectionAccess = jdbcServices.getBootstrapJdbcConnectionAccess();
runtimeMetamodels.getMappingMetamodel().forEachEntityDescriptor(
entityPersister -> {
if ( entityPersister.getSqmMultiTableMutationStrategy() != null ) {
entityPersister.getSqmMultiTableMutationStrategy()
.release( this, jdbcConnectionAccess );
final var mutationStrategy = entityPersister.getSqmMultiTableMutationStrategy();
final var insertStrategy = entityPersister.getSqmMultiTableInsertStrategy();
if ( mutationStrategy != null ) {
mutationStrategy.release( this, jdbcConnectionAccess );
}
if ( entityPersister.getSqmMultiTableInsertStrategy() != null ) {
entityPersister.getSqmMultiTableInsertStrategy()
.release( this, jdbcConnectionAccess );
if ( insertStrategy != null ) {
insertStrategy.release( this, jdbcConnectionAccess );
}
}
);
Expand Down Expand Up @@ -964,7 +954,7 @@ public StatisticsImplementor getStatistics() {
}

public FilterDefinition getFilterDefinition(String filterName) {
final FilterDefinition filterDefinition = filters.get( filterName );
final var filterDefinition = filters.get( filterName );
if ( filterDefinition == null ) {
throw new UnknownFilterException( filterName );
}
Expand Down Expand Up @@ -1092,7 +1082,7 @@ public static Interceptor configuredInterceptor(Interceptor interceptor, boolean
}

// prefer the SessionFactory-scoped interceptor, prefer that to any Session-scoped interceptor prototype
final Interceptor optionsInterceptor = options.getInterceptor();
final var optionsInterceptor = options.getInterceptor();
if ( optionsInterceptor != null && optionsInterceptor != EmptyInterceptor.INSTANCE ) {
return optionsInterceptor;
}
Expand Down Expand Up @@ -1144,20 +1134,20 @@ public SessionBuilderImpl(SessionFactoryImpl sessionFactory) {
this.sessionFactory = sessionFactory;

// set up default builder values...
final SessionFactoryOptions sessionFactoryOptions = sessionFactory.getSessionFactoryOptions();
statementInspector = sessionFactoryOptions.getStatementInspector();
connectionHandlingMode = sessionFactoryOptions.getPhysicalConnectionHandlingMode();
autoClose = sessionFactoryOptions.isAutoCloseSessionEnabled();
defaultBatchFetchSize = sessionFactoryOptions.getDefaultBatchFetchSize();
subselectFetchEnabled = sessionFactoryOptions.isSubselectFetchEnabled();
identifierRollback = sessionFactoryOptions.isIdentifierRollbackEnabled();
final var options = sessionFactory.getSessionFactoryOptions();
statementInspector = options.getStatementInspector();
connectionHandlingMode = options.getPhysicalConnectionHandlingMode();
autoClose = options.isAutoCloseSessionEnabled();
defaultBatchFetchSize = options.getDefaultBatchFetchSize();
subselectFetchEnabled = options.isSubselectFetchEnabled();
identifierRollback = options.isIdentifierRollbackEnabled();

final var currentTenantIdentifierResolver =
sessionFactory.getCurrentTenantIdentifierResolver();
if ( currentTenantIdentifierResolver != null ) {
tenantIdentifier = currentTenantIdentifierResolver.resolveCurrentTenantIdentifier();
}
jdbcTimeZone = sessionFactoryOptions.getJdbcTimeZone();
jdbcTimeZone = options.getJdbcTimeZone();
}


Expand Down Expand Up @@ -1223,10 +1213,9 @@ public PhysicalConnectionHandlingMode getPhysicalConnectionHandlingMode() {

@Override
public String getTenantIdentifier() {
if ( tenantIdentifier == null ) {
return null;
}
return sessionFactory.getTenantIdentifierJavaType().toString( tenantIdentifier );
return tenantIdentifier != null
? sessionFactory.getTenantIdentifierJavaType().toString( tenantIdentifier )
: null;
}

@Override
Expand Down
Loading