Author: steve.ebersole(a)jboss.com
Date: 2009-12-15 13:09:53 -0500 (Tue, 15 Dec 2009)
New Revision: 18230
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryCompiler.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CastFunction.java
Log:
HHH-4590 - CASTs from CriteriaBuilder.toXXX methods still need to be fleshed out
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryCompiler.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryCompiler.java 2009-12-15
17:28:51 UTC (rev 18229)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryCompiler.java 2009-12-15
18:09:53 UTC (rev 18230)
@@ -39,6 +39,9 @@
import javax.persistence.criteria.ParameterExpression;
import org.hibernate.ejb.HibernateEntityManagerImplementor;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.type.Type;
+import org.hibernate.type.TypeFactory;
import org.hibernate.util.StringHelper;
/**
@@ -61,6 +64,8 @@
public void registerExplicitParameter(ParameterExpression<?>
criteriaQueryParameter, String jpaqlParameterName);
public void registerImplicitParameterBinding(ImplicitParameterBinding binding);
+
+ public String getCastType(Class javaType);
}
public static interface RenderedCriteriaQuery {
@@ -106,6 +111,25 @@
public void registerImplicitParameterBinding(ImplicitParameterBinding binding) {
implicitParameterBindings.add( binding );
}
+
+ public String getCastType(Class javaType) {
+ SessionFactoryImplementor factory =
+ ( SessionFactoryImplementor ) entityManager.getFactory().getSessionFactory();
+ Type hibernateType = TypeFactory.heuristicType( javaType.getName() );
+ if ( hibernateType == null ) {
+ throw new IllegalArgumentException(
+ "Could not convert java type [" + javaType.getName() + "] to
Hibernate type"
+ );
+ }
+ int[] sqlTypeCodes = hibernateType.sqlTypes( factory );
+ if ( sqlTypeCodes.length != 1 ) {
+ throw new IllegalArgumentException(
+ "Invalid Hibernate Type [" + hibernateType.getName() +
+ "] for cast : more than one column spanned"
+ );
+ }
+ return factory.getDialect().getCastTypeName( sqlTypeCodes[0] );
+ }
};
RenderedCriteriaQuery renderedCriteriaQuery = criteriaQueryImpl.render(
renderingContext );
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CastFunction.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CastFunction.java 2009-12-15
17:28:51 UTC (rev 18229)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CastFunction.java 2009-12-15
18:09:53 UTC (rev 18230)
@@ -58,9 +58,12 @@
Helper.possibleParameter( getCastSource(), registry );
}
+ @Override
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
- // HHH-4590
- // todo : how to handle these, espeically if in the select...
- return super.render( renderingContext );
+ return CAST_NAME + '(' +
+ castSource.render( renderingContext ) +
+ " as " +
+ renderingContext.getCastType( getJavaType() ) +
+ ')';
}
}
Show replies by date