Author: steve.ebersole(a)jboss.com
Date: 2009-11-18 20:34:35 -0500 (Wed, 18 Nov 2009)
New Revision: 18008
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/LocateFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/ParameterizedFunctionExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SubstringFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/TrimFunction.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/components/ComponentCriteriaTest.java
core/trunk/entitymanager/src/test/resources/log4j.properties
Log:
HHH-4586 - Jpa2.0 Criteria API lower function missing parameter
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-11-18
22:13:03 UTC (rev 18007)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/CastFunction.java 2009-11-19
01:34:35 UTC (rev 18008)
@@ -25,6 +25,7 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.expression.ExpressionImpl;
/**
@@ -57,4 +58,9 @@
Helper.possibleParameter( getCastSource(), registry );
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ // HHH-4590
+ // todo : how to handle these, espeically if in the select...
+ return super.render( renderingContext );
+ }
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LocateFunction.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LocateFunction.java 2009-11-18
22:13:03 UTC (rev 18007)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LocateFunction.java 2009-11-19
01:34:35 UTC (rev 18008)
@@ -27,7 +27,9 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
+import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Models the ANSI SQL <tt>LOCATE</tt> function.
@@ -95,4 +97,19 @@
Helper.possibleParameter( getStart(), registry );
Helper.possibleParameter( getString(), registry );
}
+
+ @Override
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append( "locate(" )
+ .append( ( (ExpressionImplementor) getPattern() ).render( renderingContext ) )
+ .append( ',' )
+ .append( ( (ExpressionImplementor) getString() ).render( renderingContext ) );
+ if ( getStart() != null ) {
+ buffer.append( ',' )
+ .append( ( (ExpressionImplementor) getStart() ).render( renderingContext ) );
+ }
+ buffer.append( ')' );
+ return buffer.toString();
+ }
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/ParameterizedFunctionExpression.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/ParameterizedFunctionExpression.java 2009-11-18
22:13:03 UTC (rev 18007)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/ParameterizedFunctionExpression.java 2009-11-19
01:34:35 UTC (rev 18008)
@@ -30,7 +30,9 @@
import org.hibernate.ejb.criteria.ParameterContainer;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
+import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Support for functions with parameters.
@@ -86,4 +88,15 @@
}
}
+ @Override
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append( getFunctionName() )
+ .append( '(' );
+ for ( Expression argument : argumentExpressions ) {
+ buffer.append( ( (ExpressionImplementor) argument ).render( renderingContext ) );
+ }
+ buffer.append( ')' );
+ return buffer.toString();
+ }
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SubstringFunction.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SubstringFunction.java 2009-11-18
22:13:03 UTC (rev 18007)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SubstringFunction.java 2009-11-19
01:34:35 UTC (rev 18008)
@@ -27,7 +27,9 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
+import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Models the ANSI SQL <tt>SUBSTRING</tt> function.
@@ -102,4 +104,17 @@
Helper.possibleParameter( getValue(), registry );
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append( "substring(" )
+ .append( ( (ExpressionImplementor) getValue() ).render( renderingContext ) )
+ .append( ',' )
+ .append( ( (ExpressionImplementor) getStart() ).render( renderingContext ) );
+ if ( getLength() != null ) {
+ buffer.append( ',' )
+ .append( ( (ExpressionImplementor) getLength() ).render( renderingContext ) );
+ }
+ buffer.append( ')' );
+ return buffer.toString();
+ }
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/TrimFunction.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/TrimFunction.java 2009-11-18
22:13:03 UTC (rev 18007)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/TrimFunction.java 2009-11-19
01:34:35 UTC (rev 18008)
@@ -27,7 +27,9 @@
import javax.persistence.criteria.CriteriaBuilder.Trimspec;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
+import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Models the ANSI SQL <tt>TRIM</tt> function.
@@ -110,4 +112,16 @@
Helper.possibleParameter( getTrimSource(), registry );
}
+ @Override
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return new StringBuilder()
+ .append( "trim(" )
+ .append( trimspec.name() )
+ .append( ' ' )
+ .append( ( (ExpressionImplementor) trimCharacter ).render( renderingContext ) )
+ .append( " from " )
+ .append( ( (ExpressionImplementor) trimSource ).render( renderingContext ) )
+ .append( ')' )
+ .toString();
+ }
}
Modified:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/components/ComponentCriteriaTest.java
===================================================================
---
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/components/ComponentCriteriaTest.java 2009-11-18
22:13:03 UTC (rev 18007)
+++
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/components/ComponentCriteriaTest.java 2009-11-19
01:34:35 UTC (rev 18008)
@@ -28,6 +28,7 @@
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
+import javax.persistence.criteria.Expression;
import org.hibernate.ejb.test.TestCase;
@@ -65,4 +66,23 @@
em.getTransaction().commit();
em.close();
}
+
+ public void testParameterizedFunctions() {
+ // HHH-4586
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaBuilder cb = em.getCriteriaBuilder();
+ // lower
+ CriteriaQuery<Client> cq = cb.createQuery( Client.class );
+ Root<Client> root = cq.from( Client.class );
+ cq.where( cb.equal( cb.lower( root.get( Client_.name ).get( Name_.lastName )
),"test" ) );
+ em.createQuery( cq ).getResultList();
+ // upper
+ cq = cb.createQuery( Client.class );
+ root = cq.from( Client.class );
+ cq.where( cb.equal( cb.upper( root.get( Client_.name ).get( Name_.lastName )
),"test" ) );
+ em.createQuery( cq ).getResultList();
+ em.getTransaction().commit();
+ em.close();
+ }
}
Modified: core/trunk/entitymanager/src/test/resources/log4j.properties
===================================================================
--- core/trunk/entitymanager/src/test/resources/log4j.properties 2009-11-18 22:13:03 UTC
(rev 18007)
+++ core/trunk/entitymanager/src/test/resources/log4j.properties 2009-11-19 01:34:35 UTC
(rev 18008)
@@ -35,7 +35,7 @@
### log JDBC bind parameters ###
#log4j.logger.org.hibernate.type=info
-log4j.logger.org.hibernate.type=debug
+log4j.logger.org.hibernate.type=trace
### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=debug
Show replies by date