HHH-14857 - Deprecations in preparation for 6

This commit is contained in:
Steve Ebersole 2021-10-21 13:52:33 -05:00
parent 54ea27a4d5
commit e4b56b9271
6 changed files with 71 additions and 9 deletions

View File

@ -8,11 +8,16 @@ package org.hibernate;
import java.util.Locale;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_ENTITY_MODE;
import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
/**
* Defines the representation modes available for entities.
*
* @author Steve Ebersole
* @deprecated To be removed in 6.0 in favor of `ManagedTypeRepresentationStrategy`
* and `RepresentationMode`
*/
@Deprecated
public enum EntityMode {
/**
* The {@code pojo} entity mode describes an entity model made up of entity classes (loosely) following
@ -58,4 +63,23 @@ public enum EntityMode {
return valueOf( entityMode.toUpperCase( Locale.ENGLISH ) );
}
public static EntityMode fromSetting(Object setting) {
if ( setting != null ) {
DEPRECATION_LOGGER.deprecatedSetting( DEFAULT_ENTITY_MODE );
}
if ( setting == null || setting == POJO ) {
return POJO;
}
if ( setting instanceof EntityMode ) {
return ( (EntityMode) setting );
}
if ( setting instanceof String ) {
return parse( (String) setting );
}
return POJO;
}
}

View File

@ -130,6 +130,7 @@ import static org.hibernate.cfg.AvailableSettings.WRAP_RESULT_SETS;
import static org.hibernate.cfg.AvailableSettings.DISCARD_PC_ON_CLOSE;
import static org.hibernate.engine.config.spi.StandardConverters.BOOLEAN;
import static org.hibernate.internal.CoreLogging.messageLogger;
import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
/**
* In-flight state of {@link org.hibernate.boot.spi.SessionFactoryOptions}
@ -330,10 +331,11 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
this.entityNotFoundDelegate = StandardEntityNotFoundDelegate.INSTANCE;
this.identifierRollbackEnabled = cfgService.getSetting( USE_IDENTIFIER_ROLLBACK, BOOLEAN, false );
this.defaultEntityMode = EntityMode.parse( (String) configurationSettings.get( DEFAULT_ENTITY_MODE ) );
this.checkNullability = cfgService.getSetting( CHECK_NULLABILITY, BOOLEAN, true );
this.initializeLazyStateOutsideTransactions = cfgService.getSetting( ENABLE_LAZY_LOAD_NO_TRANS, BOOLEAN, false );
this.defaultEntityMode = EntityMode.fromSetting( configurationSettings.get( DEFAULT_ENTITY_MODE ) );
this.multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configurationSettings );
this.currentTenantIdentifierResolver = strategySelector.resolveStrategy(
CurrentTenantIdentifierResolver.class,
@ -475,7 +477,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
null
);
if ( oldSetting != null ) {
DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting(
DEPRECATION_LOGGER.deprecatedSetting(
org.hibernate.jpa.AvailableSettings.DISCARD_PC_ON_CLOSE,
DISCARD_PC_ON_CLOSE
);
@ -562,7 +564,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
() -> {
final Object oldSetting = configurationSettings.get( org.hibernate.jpa.AvailableSettings.INTERCEPTOR );
if ( oldSetting != null ) {
DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting(
DEPRECATION_LOGGER.deprecatedSetting(
org.hibernate.jpa.AvailableSettings.INTERCEPTOR,
INTERCEPTOR
);
@ -583,7 +585,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
() -> {
final Object oldSetting = configurationSettings.get( org.hibernate.jpa.AvailableSettings.SESSION_INTERCEPTOR );
if ( oldSetting != null ) {
DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting(
DEPRECATION_LOGGER.deprecatedSetting(
org.hibernate.jpa.AvailableSettings.SESSION_INTERCEPTOR,
SESSION_SCOPED_INTERCEPTOR
);
@ -659,7 +661,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
ConnectionReleaseMode specifiedReleaseMode,
Map configurationSettings,
TransactionCoordinatorBuilder transactionCoordinatorBuilder) {
DeprecationLogger.DEPRECATION_LOGGER.logUseOfDeprecatedConnectionHandlingSettings();
DEPRECATION_LOGGER.logUseOfDeprecatedConnectionHandlingSettings();
final ConnectionAcquisitionMode effectiveAcquisitionMode = specifiedAcquisitionMode == null
? ConnectionAcquisitionMode.AS_NEEDED

View File

@ -7,16 +7,31 @@
package org.hibernate.boot.jaxb.hbm.internal;
import org.hibernate.EntityMode;
import org.hibernate.internal.log.DeprecationLogger;
import org.hibernate.internal.util.StringHelper;
/**
* @author Steve Ebersole
* @deprecated for removal in 6.0
*/
@Deprecated
public class EntityModeConverter {
public static EntityMode fromXml(String name) {
return EntityMode.parse( name );
final EntityMode entityMode = EntityMode.parse( name );
if ( StringHelper.isNotEmpty( name ) ) {
DeprecationLogger.DEPRECATION_LOGGER.info(
"XML mapping specified an entity-mode - `%s`. Starting in 6.0 this is simply inferred from the entity/composite mapping"
);
}
return entityMode;
}
public static String toXml(EntityMode entityMode) {
return ( null == entityMode ) ? null : entityMode.getExternalName();
if ( entityMode == null ) {
return null;
}
DeprecationLogger.DEPRECATION_LOGGER.info(
"XML mapping specified an entity-mode - `%s`. Starting in 6.0 this is simply inferred from the entity/composite mapping"
);
return entityMode.getExternalName();
}
}

View File

@ -324,10 +324,22 @@ public abstract class AbstractEntitySourceImpl
return jaxbEntityMapping.isSelectBeforeUpdate();
}
/**
* @deprecated to be removed in 6.0. Starting in 6.0 the mode is inferred
* from the entity-type mapping
*/
@Deprecated
protected EntityMode determineEntityMode() {
return StringHelper.isNotEmpty( entityNamingSource.getClassName() ) ? EntityMode.POJO : EntityMode.MAP;
}
/**
* @deprecated to be removed in 6.0. Starting in 6.0 the mode is inferred
* from the entity-type mapping
*
* See `ManagedTypeRepresentationStrategy` and `RepresentationMode` in 6.0
*/
@Deprecated
@Override
public Map<EntityMode, String> getTuplizerClassMap() {
return tuplizerClassMap;

View File

@ -1409,7 +1409,10 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings {
/**
* The EntityMode in which set the Session opened from the SessionFactory.
*
* @deprecated An entity-type has one "mode" relative to any SessionFactory.
*/
@Deprecated
String DEFAULT_ENTITY_MODE = "hibernate.default_entity_mode";
/**

View File

@ -297,4 +297,10 @@ public interface DeprecationLogger extends BasicLogger {
)
void deprecatedJmxBeanRegistration(String name);
@LogMessage(level = WARN)
@Message(
id = 90000031,
value = "Encountered deprecated setting [%s] which is planned for removal"
)
void deprecatedSetting(String setting);
}