Tests for binding composite-valued query parameters
This commit is contained in:
parent
6d9bcd09c1
commit
1c100f5af0
|
@ -119,6 +119,7 @@ import org.hibernate.service.ServiceRegistry;
|
|||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.java.spi.JdbcTypeRecommendationException;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
@ -898,36 +899,14 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext {
|
|||
|
||||
@Override
|
||||
public <T> JpaCriteriaParameter<T> parameter(Class<T> paramClass) {
|
||||
if ( Collection.class.isAssignableFrom( paramClass ) ) {
|
||||
// a Collection-valued, multi-valued parameter
|
||||
return new JpaCriteriaParameter(
|
||||
new MultiValueParameterType( Collection.class ),
|
||||
true,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
if ( paramClass.isArray() ) {
|
||||
// an array-valued, multi-valued parameter
|
||||
return new JpaCriteriaParameter(
|
||||
new MultiValueParameterType( Object[].class ),
|
||||
true,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
return new JpaCriteriaParameter<>(
|
||||
getTypeConfiguration().standardBasicTypeForJavaType( paramClass ),
|
||||
false,
|
||||
this
|
||||
);
|
||||
return parameter( paramClass, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> JpaCriteriaParameter<T> parameter(Class<T> paramClass, String name) {
|
||||
|
||||
if ( Collection.class.isAssignableFrom( paramClass ) ) {
|
||||
// a multi-valued parameter
|
||||
// a Collection-valued, multi-valued parameter
|
||||
return new JpaCriteriaParameter(
|
||||
name,
|
||||
new MultiValueParameterType<>( Collection.class ),
|
||||
|
@ -946,13 +925,13 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext {
|
|||
);
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
return new JpaCriteriaParameter<>(
|
||||
name,
|
||||
getTypeConfiguration().standardBasicTypeForJavaType( paramClass ),
|
||||
false,
|
||||
this
|
||||
);
|
||||
try {
|
||||
final BasicType<T> basicType = getTypeConfiguration().standardBasicTypeForJavaType( paramClass );
|
||||
return new JpaCriteriaParameter<>( name, basicType, false, this );
|
||||
}
|
||||
catch (JdbcTypeRecommendationException e) {
|
||||
return new JpaCriteriaParameter<>( name, null, false, this );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,8 +29,8 @@ public class JavaTypeDescriptorBasicAdaptor<T> extends AbstractClassTypeDescript
|
|||
|
||||
@Override
|
||||
public JdbcTypeDescriptor getRecommendedJdbcType(JdbcTypeDescriptorIndicators context) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Recommended SqlTypeDescriptor not known for this Java type : " + getJavaType().getTypeName()
|
||||
throw new JdbcTypeRecommendationException(
|
||||
"Could not determine recommended JdbcTypeDescriptor for `" + getJavaType().getTypeName() + "`"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* 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.type.descriptor.java.spi;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
|
||||
/**
|
||||
* Exception indicating {@link JavaTypeDescriptor#getRecommendedJdbcType} could not
|
||||
* determine a recommended JDBC type descriptor
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class JdbcTypeRecommendationException extends HibernateException {
|
||||
public JdbcTypeRecommendationException(String message) {
|
||||
super( message );
|
||||
}
|
||||
|
||||
public JdbcTypeRecommendationException(String message, Throwable cause) {
|
||||
super( message, cause );
|
||||
}
|
||||
}
|
|
@ -22,7 +22,6 @@ import org.hibernate.query.criteria.JpaRoot;
|
|||
import org.hibernate.query.spi.QueryImplementor;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.NotImplementedYet;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -52,7 +51,6 @@ public class CompositeParameterTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@NotImplementedYet
|
||||
public void testSimplePredicateCriteria(SessionFactoryScope scope) {
|
||||
final HibernateCriteriaBuilder builder = scope.getSessionFactory().getCriteriaBuilder();
|
||||
final JpaMetamodel jpaMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getJpaMetamodel();
|
||||
|
@ -77,7 +75,6 @@ public class CompositeParameterTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@NotImplementedYet
|
||||
public void testInPredicateCriteria(SessionFactoryScope scope) {
|
||||
final HibernateCriteriaBuilder builder = scope.getSessionFactory().getCriteriaBuilder();
|
||||
final JpaMetamodel jpaMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getJpaMetamodel();
|
||||
|
@ -102,7 +99,6 @@ public class CompositeParameterTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@NotImplementedYet
|
||||
public void testDeTypedInPredicateCriteria(SessionFactoryScope scope) {
|
||||
final HibernateCriteriaBuilder builder = scope.getSessionFactory().getCriteriaBuilder();
|
||||
final JpaMetamodel jpaMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getJpaMetamodel();
|
||||
|
|
Loading…
Reference in New Issue