HHH-14617 remove QueryLiteralRendering and LiteralHandlingMode
This commit is contained in:
parent
b51fb9fe03
commit
2e875f9b8a
|
@ -501,19 +501,6 @@ Can reference a
|
|||
This configuration property can be used to disable parameters validation performed by `org.hibernate.query.Query#setParameter` when the Session is bootstrapped via JPA
|
||||
`javax.persistence.EntityManagerFactory`.
|
||||
|
||||
`*hibernate.criteria.literal_handling_mode*` (e.g. `AUTO` (default value), `BIND` or `INLINE`)::
|
||||
By default, Criteria queries use bind parameters for any literal that is not a numeric value.
|
||||
However, to increase the likelihood of JDBC statement caching, you might want to use bind parameters for numeric values too.
|
||||
+
|
||||
The `org.hibernate.query.criteria.LiteralHandlingMode#BIND` mode will use bind variables for any literal value.
|
||||
The `org.hibernate.query.criteria.LiteralHandlingMode#INLINE` mode will inline literal values as is.
|
||||
+
|
||||
To prevent SQL injection, never use `org.hibernate.query.criteria.LiteralHandlingMode#INLINE` with String variables.
|
||||
Always use constants with the `org.hibernate.query.criteria.LiteralHandlingMode#INLINE` mode.
|
||||
+
|
||||
Valid options are defined by the `org.hibernate.query.criteria.LiteralHandlingMode` enum.
|
||||
The default value is `org.hibernate.query.criteria.LiteralHandlingMode#AUTO`.
|
||||
|
||||
`*hibernate.criteria.value_handling_mode*` (e.g. `BIND` (default value) or `INLINE`)::
|
||||
By default, Criteria queries uses bind parameters for any value passed through the JPA Criteria API.
|
||||
+
|
||||
|
|
|
@ -56,7 +56,6 @@ import org.hibernate.jpa.spi.MutableJpaCompliance;
|
|||
import org.hibernate.loader.BatchFetchStyle;
|
||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||
import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode;
|
||||
import org.hibernate.query.criteria.LiteralHandlingMode;
|
||||
import org.hibernate.query.criteria.ValueHandlingMode;
|
||||
import org.hibernate.query.hql.HqlTranslator;
|
||||
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
|
||||
|
@ -85,7 +84,6 @@ import static org.hibernate.cfg.AvailableSettings.CALLABLE_NAMED_PARAMS_ENABLED;
|
|||
import static org.hibernate.cfg.AvailableSettings.CHECK_NULLABILITY;
|
||||
import static org.hibernate.cfg.AvailableSettings.CONNECTION_HANDLING;
|
||||
import static org.hibernate.cfg.AvailableSettings.CONVENTIONAL_JAVA_CONSTANTS;
|
||||
import static org.hibernate.cfg.AvailableSettings.CRITERIA_LITERAL_HANDLING_MODE;
|
||||
import static org.hibernate.cfg.AvailableSettings.CRITERIA_VALUE_HANDLING_MODE;
|
||||
import static org.hibernate.cfg.AvailableSettings.CUSTOM_ENTITY_DIRTINESS_STRATEGY;
|
||||
import static org.hibernate.cfg.AvailableSettings.DEFAULT_BATCH_FETCH_SIZE;
|
||||
|
@ -248,7 +246,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
|||
private boolean wrapResultSetsEnabled;
|
||||
private TimeZone jdbcTimeZone;
|
||||
private boolean queryParametersValidationEnabled;
|
||||
private LiteralHandlingMode criteriaLiteralHandlingMode;
|
||||
private ValueHandlingMode criteriaValueHandlingMode;
|
||||
private ImmutableEntityUpdateQueryHandlingMode immutableEntityUpdateQueryHandlingMode;
|
||||
|
||||
|
@ -537,9 +534,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
|||
true
|
||||
);
|
||||
|
||||
this.criteriaLiteralHandlingMode = LiteralHandlingMode.interpret(
|
||||
configurationSettings.get( CRITERIA_LITERAL_HANDLING_MODE )
|
||||
);
|
||||
this.criteriaValueHandlingMode = ValueHandlingMode.interpret(
|
||||
configurationSettings.get( CRITERIA_VALUE_HANDLING_MODE )
|
||||
);
|
||||
|
@ -1135,11 +1129,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
|||
return this.queryParametersValidationEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiteralHandlingMode getCriteriaLiteralHandlingMode() {
|
||||
return this.criteriaLiteralHandlingMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueHandlingMode getCriteriaValueHandlingMode() {
|
||||
return criteriaValueHandlingMode;
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.hibernate.jpa.spi.JpaCompliance;
|
|||
import org.hibernate.loader.BatchFetchStyle;
|
||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||
import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode;
|
||||
import org.hibernate.query.criteria.LiteralHandlingMode;
|
||||
import org.hibernate.query.criteria.ValueHandlingMode;
|
||||
import org.hibernate.query.hql.HqlTranslator;
|
||||
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
|
||||
|
@ -410,11 +409,6 @@ public class AbstractDelegatingSessionFactoryOptions implements SessionFactoryOp
|
|||
return delegate.isQueryParametersValidationEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiteralHandlingMode getCriteriaLiteralHandlingMode() {
|
||||
return delegate.getCriteriaLiteralHandlingMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueHandlingMode getCriteriaValueHandlingMode() {
|
||||
return delegate.getCriteriaValueHandlingMode();
|
||||
|
|
|
@ -30,8 +30,6 @@ import org.hibernate.jpa.spi.JpaCompliance;
|
|||
import org.hibernate.loader.BatchFetchStyle;
|
||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||
import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode;
|
||||
import org.hibernate.query.QueryLiteralRendering;
|
||||
import org.hibernate.query.criteria.LiteralHandlingMode;
|
||||
import org.hibernate.query.criteria.ValueHandlingMode;
|
||||
import org.hibernate.query.spi.QueryEngineOptions;
|
||||
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
|
||||
|
@ -269,18 +267,10 @@ public interface SessionFactoryOptions extends QueryEngineOptions {
|
|||
return isJpaBootstrap();
|
||||
}
|
||||
|
||||
default LiteralHandlingMode getCriteriaLiteralHandlingMode() {
|
||||
return LiteralHandlingMode.AUTO;
|
||||
}
|
||||
|
||||
default ValueHandlingMode getCriteriaValueHandlingMode() {
|
||||
return ValueHandlingMode.BIND;
|
||||
}
|
||||
|
||||
default QueryLiteralRendering getQueryLiteralRenderingMode() {
|
||||
return getCriteriaLiteralHandlingMode().getCounterpart();
|
||||
}
|
||||
|
||||
JpaCompliance getJpaCompliance();
|
||||
|
||||
boolean isFailOnPaginationOverCollectionFetchEnabled();
|
||||
|
|
|
@ -1988,26 +1988,6 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings {
|
|||
*/
|
||||
String VALIDATE_QUERY_PARAMETERS = "hibernate.query.validate_parameters";
|
||||
|
||||
/**
|
||||
* By default, Criteria queries uses bind parameters for any literal that is not a numeric value.
|
||||
*
|
||||
* However, to increase the likelihood of JDBC statement caching,
|
||||
* you might want to use bind parameters for numeric values too.
|
||||
* The {@link org.hibernate.query.criteria.LiteralHandlingMode#BIND} mode will use bind variables for any literal value.
|
||||
*
|
||||
* The {@link org.hibernate.query.criteria.LiteralHandlingMode#INLINE} mode will inline literal values as-is.
|
||||
* To prevent SQL injection, never use {@link org.hibernate.query.criteria.LiteralHandlingMode#INLINE} with String variables.
|
||||
* Always use constants with the {@link org.hibernate.query.criteria.LiteralHandlingMode#INLINE} mode.
|
||||
* </p>
|
||||
* Valid options are defined by the {@link org.hibernate.query.criteria.LiteralHandlingMode} enum.
|
||||
* </p>
|
||||
* The default value is {@link org.hibernate.query.criteria.LiteralHandlingMode#AUTO}
|
||||
*
|
||||
* @since 5.2.12
|
||||
* @see org.hibernate.query.criteria.LiteralHandlingMode
|
||||
*/
|
||||
String CRITERIA_LITERAL_HANDLING_MODE = "hibernate.criteria.literal_handling_mode";
|
||||
|
||||
/**
|
||||
* By default, Criteria queries uses bind parameters for any value passed through the JPA Criteria API.
|
||||
*
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
/*
|
||||
* 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.query;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.hibernate.query.criteria.LiteralHandlingMode;
|
||||
|
||||
/**
|
||||
* Defines possible ways we can handle query literals in terms of JDBC.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*
|
||||
* @since 6.0
|
||||
*/
|
||||
public enum QueryLiteralRendering {
|
||||
/**
|
||||
* The default - more-or-less an alias for {@link #AS_PARAM_OUTSIDE_SELECT}
|
||||
*/
|
||||
AUTO( "auto" ),
|
||||
|
||||
/**
|
||||
* Always render as a SQL literal, never a parameter
|
||||
*/
|
||||
AS_LITERAL( "literal" ),
|
||||
|
||||
/**
|
||||
* Always as a parameter, never as a literal
|
||||
*/
|
||||
AS_PARAM( "param" ),
|
||||
|
||||
/**
|
||||
* As a parameter when the literal occurs outside the SELECT clause,
|
||||
* otherwise render as a SQL literal.
|
||||
*
|
||||
* Technically this should be called something like AS_PARAM_UNLESS_SELECTED. If the literal is used as an argument
|
||||
* to a function call in the select-clause, for example, we'd still want to render as a parameter.
|
||||
*/
|
||||
AS_PARAM_OUTSIDE_SELECT( "param-outside-select" );
|
||||
|
||||
private final String externalForm;
|
||||
|
||||
QueryLiteralRendering(String externalForm) {
|
||||
this.externalForm = externalForm;
|
||||
}
|
||||
|
||||
public String toExternalForm() {
|
||||
return externalForm;
|
||||
}
|
||||
|
||||
public static QueryLiteralRendering fromExternalForm(Object externalValue) {
|
||||
if ( externalValue != null ) {
|
||||
|
||||
if ( externalValue instanceof QueryLiteralRendering ) {
|
||||
return (QueryLiteralRendering) externalValue;
|
||||
}
|
||||
|
||||
if ( externalValue instanceof LiteralHandlingMode ) {
|
||||
return ( (LiteralHandlingMode) externalValue ).getCounterpart();
|
||||
}
|
||||
|
||||
final String externalValueString = externalValue.toString().trim().toLowerCase( Locale.ROOT );
|
||||
if ( externalValueString.isEmpty() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( AS_LITERAL.externalForm.equals( externalValueString ) ) {
|
||||
return AS_LITERAL;
|
||||
}
|
||||
|
||||
if ( AS_PARAM.externalForm.equals( externalValueString ) ) {
|
||||
return AS_PARAM;
|
||||
}
|
||||
|
||||
if ( AS_PARAM_OUTSIDE_SELECT.externalForm.equals( externalValueString ) ) {
|
||||
return AS_PARAM_OUTSIDE_SELECT;
|
||||
}
|
||||
|
||||
try {
|
||||
final LiteralHandlingMode legacy = LiteralHandlingMode.interpret( externalValue );
|
||||
return legacy.getCounterpart();
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
// the default...
|
||||
return AS_PARAM_OUTSIDE_SELECT;
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* 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.query.criteria;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.query.QueryLiteralRendering;
|
||||
|
||||
/**
|
||||
* This enum defines how literals are handled by JPA Criteria.
|
||||
*
|
||||
* By default ({@code AUTO}), Criteria queries uses bind parameters for any literal that is not a numeric value.
|
||||
*
|
||||
* However, to increase the likelihood of JDBC statement caching,
|
||||
* you might want to use bind parameters for numeric values too.
|
||||
* The {@code BIND} mode will use bind variables for any literal value.
|
||||
*
|
||||
* The {@code INLINE} mode will inline literal values as-is.
|
||||
* To prevent SQL injection, never use {@code INLINE} with String variables.
|
||||
* Always use constants with the {@code INLINE} mode.
|
||||
*
|
||||
* @author Vlad Mihalcea
|
||||
*
|
||||
* @deprecated since 6.0, Use {@link QueryLiteralRendering} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public enum LiteralHandlingMode {
|
||||
AUTO( QueryLiteralRendering.AUTO ),
|
||||
BIND( QueryLiteralRendering.AS_PARAM_OUTSIDE_SELECT ),
|
||||
INLINE( QueryLiteralRendering.AS_LITERAL );
|
||||
|
||||
private final QueryLiteralRendering counterpart;
|
||||
|
||||
LiteralHandlingMode(QueryLiteralRendering counterpart) {
|
||||
this.counterpart = counterpart;
|
||||
}
|
||||
|
||||
public QueryLiteralRendering getCounterpart() {
|
||||
return counterpart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interpret the configured literalHandlingMode value.
|
||||
* Valid values are either a {@link LiteralHandlingMode} object or its String representation.
|
||||
* For string values, the matching is case insensitive, so you can use either {@code AUTO} or {@code auto}.
|
||||
*
|
||||
* @param literalHandlingMode configured {@link LiteralHandlingMode} representation
|
||||
* @return associated {@link LiteralHandlingMode} object
|
||||
*/
|
||||
public static LiteralHandlingMode interpret(Object literalHandlingMode) {
|
||||
if ( literalHandlingMode == null ) {
|
||||
return AUTO;
|
||||
}
|
||||
else if ( literalHandlingMode instanceof LiteralHandlingMode ) {
|
||||
return (LiteralHandlingMode) literalHandlingMode;
|
||||
}
|
||||
else if ( literalHandlingMode instanceof String ) {
|
||||
for ( LiteralHandlingMode value : values() ) {
|
||||
if ( value.name().equalsIgnoreCase( (String) literalHandlingMode ) ) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new HibernateException(
|
||||
"Unrecognized literal_handling_mode value : " + literalHandlingMode
|
||||
+ ". Supported values include 'auto', 'inline', and 'bind'."
|
||||
);
|
||||
}
|
||||
}
|
|
@ -60,7 +60,6 @@ import org.hibernate.query.internal.QueryHelper;
|
|||
import org.hibernate.query.spi.QueryEngine;
|
||||
import org.hibernate.query.sqm.NodeBuilder;
|
||||
import org.hibernate.query.sqm.SqmExpressable;
|
||||
import org.hibernate.query.sqm.SqmPathSource;
|
||||
import org.hibernate.query.sqm.SqmQuerySource;
|
||||
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
|
||||
import org.hibernate.query.sqm.spi.SqmCreationContext;
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.Map;
|
|||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.query.criteria.LiteralHandlingMode;
|
||||
import org.hibernate.query.criteria.ValueHandlingMode;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
|
||||
|
@ -24,8 +24,8 @@ public class CriteriaLiteralHandlingModeBindTest extends AbstractCriteriaLiteral
|
|||
protected Map getConfig() {
|
||||
Map config = super.getConfig();
|
||||
config.put(
|
||||
AvailableSettings.CRITERIA_LITERAL_HANDLING_MODE,
|
||||
LiteralHandlingMode.BIND
|
||||
AvailableSettings.CRITERIA_VALUE_HANDLING_MODE,
|
||||
ValueHandlingMode.BIND
|
||||
);
|
||||
return config;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public class CriteriaLiteralHandlingModeInlineShortNameLowercaseTest extends Abs
|
|||
protected Map getConfig() {
|
||||
Map config = super.getConfig();
|
||||
config.put(
|
||||
AvailableSettings.CRITERIA_LITERAL_HANDLING_MODE,
|
||||
AvailableSettings.CRITERIA_VALUE_HANDLING_MODE,
|
||||
"inline"
|
||||
);
|
||||
return config;
|
||||
|
|
|
@ -10,7 +10,6 @@ import java.util.Map;
|
|||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.query.criteria.LiteralHandlingMode;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
|
||||
|
@ -24,7 +23,7 @@ public class CriteriaLiteralHandlingModeInlineShortNameUppercaseTest extends Abs
|
|||
protected Map getConfig() {
|
||||
Map config = super.getConfig();
|
||||
config.put(
|
||||
AvailableSettings.CRITERIA_LITERAL_HANDLING_MODE,
|
||||
AvailableSettings.CRITERIA_VALUE_HANDLING_MODE,
|
||||
"INLINE"
|
||||
);
|
||||
return config;
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.Map;
|
|||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.query.criteria.LiteralHandlingMode;
|
||||
import org.hibernate.query.criteria.ValueHandlingMode;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
|
||||
|
@ -24,8 +24,8 @@ public class CriteriaLiteralHandlingModeInlineTest extends AbstractCriteriaLiter
|
|||
protected Map getConfig() {
|
||||
Map config = super.getConfig();
|
||||
config.put(
|
||||
AvailableSettings.CRITERIA_LITERAL_HANDLING_MODE,
|
||||
LiteralHandlingMode.INLINE
|
||||
AvailableSettings.CRITERIA_VALUE_HANDLING_MODE,
|
||||
ValueHandlingMode.INLINE
|
||||
);
|
||||
return config;
|
||||
}
|
||||
|
|
|
@ -9,9 +9,8 @@ package org.hibernate.jpa.test.criteria.literal;
|
|||
import java.util.Map;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.dialect.MySQLDialect;
|
||||
import org.hibernate.query.criteria.LiteralHandlingMode;
|
||||
import org.hibernate.query.criteria.ValueHandlingMode;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
|
||||
|
@ -25,8 +24,8 @@ public class MySQLCriteriaLiteralHandlingModeInlineTest extends AbstractCriteria
|
|||
protected Map getConfig() {
|
||||
Map config = super.getConfig();
|
||||
config.put(
|
||||
AvailableSettings.CRITERIA_LITERAL_HANDLING_MODE,
|
||||
LiteralHandlingMode.INLINE
|
||||
AvailableSettings.CRITERIA_VALUE_HANDLING_MODE,
|
||||
ValueHandlingMode.INLINE
|
||||
);
|
||||
return config;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.hibernate.cfg.AvailableSettings;
|
|||
import org.hibernate.dialect.DB2Dialect;
|
||||
import org.hibernate.dialect.DerbyDialect;
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.query.criteria.LiteralHandlingMode;
|
||||
import org.hibernate.query.criteria.ValueHandlingMode;
|
||||
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
@ -132,7 +132,7 @@ public class SelectCaseLiteralHandlingBindTest extends BaseEntityManagerFunction
|
|||
@Override
|
||||
protected Map getConfig() {
|
||||
Map config = super.getConfig();
|
||||
config.put( AvailableSettings.CRITERIA_LITERAL_HANDLING_MODE, LiteralHandlingMode.BIND );
|
||||
config.put( AvailableSettings.CRITERIA_VALUE_HANDLING_MODE, ValueHandlingMode.BIND );
|
||||
return config;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
|||
import org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl;
|
||||
import org.hibernate.metamodel.MappingMetamodel;
|
||||
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
|
||||
import org.hibernate.query.criteria.LiteralHandlingMode;
|
||||
import org.hibernate.query.criteria.ValueHandlingMode;
|
||||
import org.hibernate.query.hql.HqlTranslator;
|
||||
import org.hibernate.query.hql.internal.StandardHqlTranslator;
|
||||
|
|
Loading…
Reference in New Issue