remove some more deprecated stuff from Environment

and refresh its Javadoc
This commit is contained in:
Gavin King 2022-01-21 15:18:02 +01:00
parent 329b2fc9c4
commit 2df71bb7ab
6 changed files with 45 additions and 116 deletions

View File

@ -437,9 +437,6 @@ The https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibern
`*hibernate.bytecode.use_reflection_optimizer*` (e.g. `true` or `false` (default value)):: `*hibernate.bytecode.use_reflection_optimizer*` (e.g. `true` or `false` (default value))::
Should we use reflection optimization? The reflection optimizer implements the https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibernate/bytecode/spi/ReflectionOptimizer.html[`ReflectionOptimizer`] interface and improves entity instantiation and property getter/setter calls. Should we use reflection optimization? The reflection optimizer implements the https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibernate/bytecode/spi/ReflectionOptimizer.html[`ReflectionOptimizer`] interface and improves entity instantiation and property getter/setter calls.
`*hibernate.bytecode.enforce_legacy_proxy_classnames*` (e.g. `true` or `false` (default value))::
Some other libraries, such as Spring, used to depend on a specific naming pattern used for proxy classes generated at runtime. Set this to `true` to have proxy class names conform to the old pattern.
[[configurations-query]] [[configurations-query]]
=== Query settings === Query settings

View File

@ -8,14 +8,12 @@ package org.hibernate.bytecode.internal.bytebuddy;
import java.util.Collections; import java.util.Collections;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.bytecode.spi.BasicProxyFactory; import org.hibernate.bytecode.spi.BasicProxyFactory;
import org.hibernate.cfg.Environment;
import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.proxy.ProxyConfiguration; import org.hibernate.proxy.ProxyConfiguration;
@ -27,7 +25,7 @@ import net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy;
public class BasicProxyFactoryImpl implements BasicProxyFactory { public class BasicProxyFactoryImpl implements BasicProxyFactory {
private static final Class[] NO_INTERFACES = ArrayHelper.EMPTY_CLASS_ARRAY; private static final Class[] NO_INTERFACES = ArrayHelper.EMPTY_CLASS_ARRAY;
private static final String PROXY_NAMING_SUFFIX = Environment.useLegacyProxyClassnames() ? "HibernateBasicProxy$" : "HibernateBasicProxy"; private static final String PROXY_NAMING_SUFFIX = "HibernateBasicProxy";
private final Class proxyClass; private final Class proxyClass;
private final ProxyConfiguration.Interceptor interceptor; private final ProxyConfiguration.Interceptor interceptor;

View File

@ -846,16 +846,6 @@ public interface AvailableSettings {
*/ */
String USE_REFLECTION_OPTIMIZER = "hibernate.bytecode.use_reflection_optimizer"; String USE_REFLECTION_OPTIMIZER = "hibernate.bytecode.use_reflection_optimizer";
/**
* Configure the global BytecodeProvider implementation to generate class names matching the
* existing naming patterns.
* It is not a good idea to rely on a classname to check if a class is an Hibernate proxy,
* yet some frameworks are currently relying on this.
* This option is disabled by default and will log a deprecation warning when enabled.
*/
String ENFORCE_LEGACY_PROXY_CLASSNAMES = "hibernate.bytecode.enforce_legacy_proxy_classnames";
/** /**
* Controls the base integer for binding JDBC-style ({@code ?}) ordinal * Controls the base integer for binding JDBC-style ({@code ?}) ordinal
* parameters when the Hibernate SessionFactory is bootstrapped via the native * parameters when the Hibernate SessionFactory is bootstrapped via the native

View File

@ -8,15 +8,12 @@ package org.hibernate.cfg;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Version; import org.hibernate.Version;
import org.hibernate.bytecode.spi.BytecodeProvider; import org.hibernate.bytecode.spi.BytecodeProvider;
import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.log.UnsupportedLogger;
import org.hibernate.internal.util.ConfigHelper; import org.hibernate.internal.util.ConfigHelper;
import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.internal.util.config.ConfigurationHelper;
@ -24,114 +21,105 @@ import org.jboss.logging.Logger;
/** /**
* Provides access to configuration info passed in {@code Properties} objects. * Provides access to configuration properties passed in {@link Properties} objects.
* <p> * <p>
* Hibernate has two property scopes: * Hibernate has two property scopes:
* <ul> * <ul>
* <li><em>Factory-level</em> properties may be passed to the {@code SessionFactory} when it * <li><em>Factory-level</em> properties are specified when a
* is instantiated. Each instance might have different property values. If no * {@link org.hibernate.SessionFactory} is configured and instantiated. Each instance
* properties are specified, the factory calls {@code Environment.getProperties()}. * might have different property values.
* <li><em>System-level</em> properties are shared by all factory instances and are always * <li><em>System-level</em> properties are shared by all factory instances and are
* determined by the {@code Environment} properties. * always determined by the {@code Environment} properties in {@link #getProperties()}.
* </ul> * </ul>
* The only system-level properties are {@value #USE_REFLECTION_OPTIMIZER} and
* {@value #BYTECODE_PROVIDER}.
* <p> * <p>
* The only system-level property is {@value #USE_REFLECTION_OPTIMIZER}.
* </p>
* {@code Environment} properties are populated by calling {@link System#getProperties()} * {@code Environment} properties are populated by calling {@link System#getProperties()}
* and then from a resource named {@code /hibernate.properties} if it exists. System * and then from a resource named {@code /hibernate.properties}, if it exists. System
* properties override properties specified in {@code hibernate.properties}. * properties override properties specified in {@code hibernate.properties}.
* <p> * <p>
* The {@link org.hibernate.SessionFactory} is controlled by the following properties. * The {@link org.hibernate.SessionFactory} obtains properties from:
* Properties may be either be {@link System} properties, properties defined in a * <ul>
* resource named {@code /hibernate.properties} or an instance of * <li>{@link System#getProperties() system properties},
* {@link java.util.Properties} passed to {@link Configuration#addProperties(Properties)}. * <li>properties defined in a resource named {@code /hibernate.properties}, and
* <p> * <li>any instance of {@link Properties} passed to {@link Configuration#addProperties}.
* </ul>
* <table> * <table>
* <tr><td><b>property</b></td><td><b>meaning</b></td></tr> * <tr><td><b>Property</b></td><td><b>Interpretation</b></td></tr>
* <tr> * <tr>
* <td>{@code hibernate.dialect}</td> * <td>{@value #DIALECT}</td>
* <td>classname of {@link org.hibernate.dialect.Dialect} subclass</td> * <td>name of {@link org.hibernate.dialect.Dialect} subclass</td>
* </tr> * </tr>
* <tr> * <tr>
* <td>{@code hibernate.connection.provider_class}</td> * <td>{@value #CONNECTION_PROVIDER}</td>
* <td>name of a {@link org.hibernate.engine.jdbc.connections.spi.ConnectionProvider} * <td>name of a {@link org.hibernate.engine.jdbc.connections.spi.ConnectionProvider}
* subclass (if not specified heuristics are used)</td> * subclass (if not specified heuristics are used)</td>
* </tr> * </tr>
* <tr><td>{@code hibernate.connection.username}</td><td>database username</td></tr> * <tr><td>{@value #USER}</td><td>database username</td></tr>
* <tr><td>{@code hibernate.connection.password}</td><td>database password</td></tr> * <tr><td>{@value #PASS}</td><td>database password</td></tr>
* <tr> * <tr>
* <td>{@code hibernate.connection.url}</td> * <td>{@value #URL}</td>
* <td>JDBC URL (when using {@link java.sql.DriverManager})</td> * <td>JDBC URL (when using {@link java.sql.DriverManager})</td>
* </tr> * </tr>
* <tr> * <tr>
* <td>{@code hibernate.connection.driver_class}</td> * <td>{@value #DRIVER}</td>
* <td>classname of JDBC driver</td> * <td>classname of JDBC driver</td>
* </tr> * </tr>
* <tr> * <tr>
* <td>{@code hibernate.connection.isolation}</td> * <td>{@value #ISOLATION}</td>
* <td>JDBC transaction isolation level (only when using * <td>JDBC transaction isolation level (only when using
* {@link java.sql.DriverManager}) * {@link java.sql.DriverManager})
* </td> * </td>
* </tr> * </tr>
* <td>{@code hibernate.connection.pool_size}</td> * <td>{@value #POOL_SIZE}</td>
* <td>the maximum size of the connection pool (only when using * <td>the maximum size of the connection pool (only when using
* {@link java.sql.DriverManager}) * {@link java.sql.DriverManager})
* </td> * </td>
* </tr> * </tr>
* <tr> * <tr>
* <td>{@code hibernate.connection.datasource}</td> * <td>{@value #DATASOURCE}</td>
* <td>datasource JNDI name (when using {@link javax.sql.DataSource})</td> * <td>datasource JNDI name (when using {@link javax.sql.DataSource})</td>
* </tr> * </tr>
* <tr> * <tr>
* <td>{@code hibernate.jndi.url}</td><td>JNDI {@link javax.naming.InitialContext} URL</td> * <td>{@value #JNDI_URL}</td><td>JNDI {@link javax.naming.InitialContext} URL</td>
* </tr> * </tr>
* <tr> * <tr>
* <td>{@code hibernate.jndi.class}</td><td>JNDI {@link javax.naming.InitialContext} classname</td> * <td>{@value #JNDI_CLASS}</td><td>JNDI {@link javax.naming.InitialContext} class name</td>
* </tr> * </tr>
* <tr> * <tr>
* <td>{@code hibernate.max_fetch_depth}</td> * <td>{@value #MAX_FETCH_DEPTH}</td>
* <td>maximum depth of outer join fetching</td> * <td>maximum depth of outer join fetching</td>
* </tr> * </tr>
* <tr> * <tr>
* <td>{@code hibernate.jdbc.batch_size}</td> * <td>{@value #STATEMENT_BATCH_SIZE}</td>
* <td>enable use of JDBC2 batch API for drivers which support it</td> * <td>enable use of JDBC2 batch API for drivers which support it</td>
* </tr> * </tr>
* <tr> * <tr>
* <td>{@code hibernate.jdbc.fetch_size}</td> * <td>{@value #STATEMENT_FETCH_SIZE}</td>
* <td>set the JDBC fetch size</td> * <td>set the JDBC fetch size</td>
* </tr> * </tr>
* <tr> * <tr>
* <td>{@code hibernate.jdbc.use_scrollable_resultset}</td> * <td>{@value #USE_GET_GENERATED_KEYS}</td>
* <td>enable use of JDBC2 scrollable resultsets (you only need to specify * <td>enable use of JDBC3 {@link java.sql.PreparedStatement#getGeneratedKeys()}
* this property when using user supplied connections)</td> * to retrieve natively generated keys after insert. Requires JDBC3+ driver and
* JRE1.4+</td>
* </tr> * </tr>
* <tr> * <tr>
* <td>{@code hibernate.jdbc.use_getGeneratedKeys}</td> * <td>{@value #HBM2DDL_AUTO}</td>
* <td>enable use of JDBC3 PreparedStatement.getGeneratedKeys() to retrieve
* natively generated keys after insert. Requires JDBC3+ driver and JRE1.4+</td>
* </tr>
* <tr>
* <td>{@code hibernate.hbm2ddl.auto}</td>
* <td>enable auto DDL export</td> * <td>enable auto DDL export</td>
* </tr> * </tr>
* <tr> * <tr>
* <td>{@code hibernate.default_schema}</td> * <td>{@value #DEFAULT_SCHEMA}</td>
* <td>use given schema name for unqualified tables (always optional)</td> * <td>use given schema name for unqualified tables (always optional)</td>
* </tr> * </tr>
* <tr> * <tr>
* <td>{@code hibernate.default_catalog}</td> * <td>{@value #DEFAULT_CATALOG}</td>
* <td>use given catalog name for unqualified tables (always optional)</td> * <td>use given catalog name for unqualified tables (always optional)</td>
* </tr> * </tr>
* <tr> * <tr>
* <td>{@code hibernate.session_factory_name}</td> * <td>{@value #JTA_PLATFORM}</td>
* <td>If set, the factory attempts to bind this name to itself in the * <td>name of {@link org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform}
* JNDI context. This name is also used to support cross JVM {@code * implementation</td>
* Session} (de)serialization.</td>
* </tr>
* <tr>
* <td>{@code hibernate.transaction.jta.platform}</td>
* <td>classname of {@link org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform}
* implementor</td>
* </tr> * </tr>
* </table> * </table>
* *
@ -143,7 +131,6 @@ public final class Environment implements AvailableSettings {
private static final BytecodeProvider BYTECODE_PROVIDER_INSTANCE; private static final BytecodeProvider BYTECODE_PROVIDER_INSTANCE;
private static final boolean ENABLE_REFLECTION_OPTIMIZER; private static final boolean ENABLE_REFLECTION_OPTIMIZER;
private static final boolean ENABLE_LEGACY_PROXY_CLASSNAMES;
private static final Properties GLOBAL_PROPERTIES; private static final Properties GLOBAL_PROPERTIES;
@ -193,26 +180,9 @@ public final class Environment implements AvailableSettings {
LOG.usingReflectionOptimizer(); LOG.usingReflectionOptimizer();
} }
ENABLE_LEGACY_PROXY_CLASSNAMES = ConfigurationHelper.getBoolean( ENFORCE_LEGACY_PROXY_CLASSNAMES, GLOBAL_PROPERTIES );
if ( ENABLE_LEGACY_PROXY_CLASSNAMES ) {
final UnsupportedLogger unsupportedLogger = Logger.getMessageLogger( UnsupportedLogger.class, Environment.class.getName() );
unsupportedLogger.usingLegacyClassnamesForProxies();
}
BYTECODE_PROVIDER_INSTANCE = buildBytecodeProvider( GLOBAL_PROPERTIES ); BYTECODE_PROVIDER_INSTANCE = buildBytecodeProvider( GLOBAL_PROPERTIES );
} }
/**
* This will be removed soon; currently just returns false as no known JVM exhibits this bug
* and is also able to run this version of Hibernate ORM.
* @deprecated removed as unnecessary
* @return false
*/
@Deprecated
public static boolean jvmHasTimestampBug() {
return false;
}
/** /**
* Should we use reflection optimization? * Should we use reflection optimization?
* *
@ -245,15 +215,6 @@ public final class Environment implements AvailableSettings {
return BYTECODE_PROVIDER_INSTANCE; return BYTECODE_PROVIDER_INSTANCE;
} }
/**
* @return True if global option org.hibernate.cfg.AvailableSettings#ENFORCE_LEGACY_PROXY_CLASSNAMES was enabled
* @deprecated This option will be removed soon and should not be relied on.
*/
@Deprecated
public static boolean useLegacyProxyClassnames() {
return ENABLE_LEGACY_PROXY_CLASSNAMES;
}
/** /**
* Disallow instantiation * Disallow instantiation
*/ */
@ -262,9 +223,8 @@ public final class Environment implements AvailableSettings {
} }
/** /**
* Return {@code System} properties, extended by any properties specified * The {@link System#getProperties() system properties}, extended with all
* in {@code hibernate.properties}. * additional properties specified in {@code hibernate.properties}.
* @return Properties
*/ */
public static Properties getProperties() { public static Properties getProperties() {
Properties copy = new Properties(); Properties copy = new Properties();
@ -272,15 +232,6 @@ public final class Environment implements AvailableSettings {
return copy; return copy;
} }
/**
* @deprecated Use {@link ConnectionProviderInitiator#toIsolationNiceName} instead
*/
@Deprecated
public static String isolationLevelToString(int isolation) {
return ConnectionProviderInitiator.toIsolationNiceName( isolation );
}
public static final String BYTECODE_PROVIDER_NAME_BYTEBUDDY = "bytebuddy"; public static final String BYTECODE_PROVIDER_NAME_BYTEBUDDY = "bytebuddy";
public static final String BYTECODE_PROVIDER_NAME_NONE = "none"; public static final String BYTECODE_PROVIDER_NAME_NONE = "none";
public static final String BYTECODE_PROVIDER_NAME_DEFAULT = BYTECODE_PROVIDER_NAME_BYTEBUDDY; public static final String BYTECODE_PROVIDER_NAME_DEFAULT = BYTECODE_PROVIDER_NAME_BYTEBUDDY;

View File

@ -28,10 +28,4 @@ import static org.jboss.logging.Logger.Level.WARN;
@ValidIdRange( min = 90002001, max = 90003000 ) @ValidIdRange( min = 90002001, max = 90003000 )
public interface UnsupportedLogger { public interface UnsupportedLogger {
@LogMessage(level = WARN)
@Message(value = "Global configuration option '" + AvailableSettings.ENFORCE_LEGACY_PROXY_CLASSNAMES + "' was enabled. " +
"Generated proxies will use backwards compatible classnames. This option is unsupported and will be removed.",
id = 90002001)
void usingLegacyClassnamesForProxies();
} }

View File

@ -16,7 +16,6 @@ import java.util.function.Function;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.bytecode.internal.bytebuddy.ByteBuddyState; import org.hibernate.bytecode.internal.bytebuddy.ByteBuddyState;
import org.hibernate.cfg.Environment;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
@ -35,7 +34,7 @@ import static org.hibernate.internal.CoreLogging.messageLogger;
public class ByteBuddyProxyHelper implements Serializable { public class ByteBuddyProxyHelper implements Serializable {
private static final CoreMessageLogger LOG = messageLogger( ByteBuddyProxyHelper.class ); private static final CoreMessageLogger LOG = messageLogger( ByteBuddyProxyHelper.class );
private static final String PROXY_NAMING_SUFFIX = Environment.useLegacyProxyClassnames() ? "HibernateProxy$" : "HibernateProxy"; private static final String PROXY_NAMING_SUFFIX = "HibernateProxy";
private final ByteBuddyState byteBuddyState; private final ByteBuddyState byteBuddyState;