HHH-12058 - Criteria LiteralHandlingMode can only be configured programatically. We need to support String-based configurations as well.
This commit is contained in:
parent
29fc5903e3
commit
1cb10729b0
|
@ -778,11 +778,8 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
|
|||
true
|
||||
);
|
||||
|
||||
this.criteriaLiteralHandlingMode = strategySelector.resolveStrategy(
|
||||
LiteralHandlingMode.class,
|
||||
configurationSettings.get( CRITERIA_LITERAL_HANDLING_MODE ),
|
||||
LiteralHandlingMode.AUTO,
|
||||
(clazz) -> LiteralHandlingMode.AUTO
|
||||
this.criteriaLiteralHandlingMode = LiteralHandlingMode.interpret(
|
||||
configurationSettings.get( CRITERIA_LITERAL_HANDLING_MODE )
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.query.criteria;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
|
||||
/**
|
||||
* This enum defines how literals are handled by JPA Criteria.
|
||||
*
|
||||
|
@ -25,5 +27,33 @@ public enum LiteralHandlingMode {
|
|||
|
||||
AUTO,
|
||||
BIND,
|
||||
INLINE
|
||||
INLINE;
|
||||
|
||||
/**
|
||||
* 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'."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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.test.criteria.literal;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@RequiresDialect(H2Dialect.class)
|
||||
public class CriteriaLiteralHandlingModeInlineShortNameLowercaseTest extends AbstractCriteriaLiteralHandlingModeTest {
|
||||
|
||||
@Override
|
||||
protected Map getConfig() {
|
||||
Map config = super.getConfig();
|
||||
config.put(
|
||||
AvailableSettings.CRITERIA_LITERAL_HANDLING_MODE,
|
||||
"inline"
|
||||
);
|
||||
return config;
|
||||
}
|
||||
|
||||
protected String expectedSQL() {
|
||||
return "select 'abc' as col_0_0_, abstractcr0_.name as col_1_0_ from Book abstractcr0_ where abstractcr0_.id=1 and abstractcr0_.name='Vlad''s High-Performance Java Persistence'";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* 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.test.criteria.literal;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@RequiresDialect(H2Dialect.class)
|
||||
public class CriteriaLiteralHandlingModeInlineShortNameUppercaseTest extends AbstractCriteriaLiteralHandlingModeTest {
|
||||
|
||||
@Override
|
||||
protected Map getConfig() {
|
||||
Map config = super.getConfig();
|
||||
config.put(
|
||||
AvailableSettings.CRITERIA_LITERAL_HANDLING_MODE,
|
||||
"INLINE"
|
||||
);
|
||||
return config;
|
||||
}
|
||||
|
||||
protected String expectedSQL() {
|
||||
return "select 'abc' as col_0_0_, abstractcr0_.name as col_1_0_ from Book abstractcr0_ where abstractcr0_.id=1 and abstractcr0_.name='Vlad''s High-Performance Java Persistence'";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue