[hibernate-commits] Hibernate SVN: r18538 - in core/trunk/entitymanager/src: test/java/org/hibernate/ejb/criteria/basic and 1 other directory.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Wed Jan 13 07:47:56 EST 2010
Author: steve.ebersole at jboss.com
Date: 2010-01-13 07:47:55 -0500 (Wed, 13 Jan 2010)
New Revision: 18538
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java
Log:
HHH-4785 - BinaryArithmeticOperation reverses incoming arguments
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java 2010-01-13 12:20:43 UTC (rev 18537)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java 2010-01-13 12:47:55 UTC (rev 18538)
@@ -115,19 +115,19 @@
* @param criteriaBuilder The builder for query components.
* @param resultType The operation result type
* @param operator The operator (type of operation).
+ * @param lhs The left-hand operand.
* @param rhs The right-hand operand
- * @param lhs The left-hand operand.
*/
public BinaryArithmeticOperation(
CriteriaBuilderImpl criteriaBuilder,
Class<N> resultType,
Operation operator,
- Expression<? extends N> rhs,
- Expression<? extends N> lhs) {
+ Expression<? extends N> lhs,
+ Expression<? extends N> rhs) {
super( criteriaBuilder, resultType );
this.operator = operator;
+ this.lhs = lhs;
this.rhs = rhs;
- this.lhs = lhs;
}
/**
@@ -136,40 +136,40 @@
* @param criteriaBuilder The builder for query components.
* @param javaType The operation result type
* @param operator The operator (type of operation).
- * @param rhs The right-hand operand
- * @param lhs The left-hand operand (the literal).
+ * @param lhs The left-hand operand
+ * @param rhs The right-hand operand (the literal)
*/
public BinaryArithmeticOperation(
CriteriaBuilderImpl criteriaBuilder,
Class<N> javaType,
Operation operator,
- Expression<? extends N> rhs,
- N lhs) {
+ Expression<? extends N> lhs,
+ N rhs) {
super( criteriaBuilder, javaType );
this.operator = operator;
- this.rhs = rhs;
- this.lhs = new LiteralExpression<N>( criteriaBuilder, lhs );
+ this.lhs = lhs;
+ this.rhs = new LiteralExpression<N>( criteriaBuilder, rhs );
}
/**
- * Creates an arithmethic operation based on an expression and a literal.
+ * Creates an arithmetic operation based on an expression and a literal.
*
* @param criteriaBuilder The builder for query components.
* @param javaType The operation result type
* @param operator The operator (type of operation).
- * @param rhs The right-hand operand (the literal).
- * @param lhs The left-hand operand
+ * @param lhs The left-hand operand (the literal)
+ * @param rhs The right-hand operand
*/
public BinaryArithmeticOperation(
CriteriaBuilderImpl criteriaBuilder,
Class<N> javaType,
Operation operator,
- N rhs,
- Expression<? extends N> lhs) {
+ N lhs,
+ Expression<? extends N> rhs) {
super( criteriaBuilder, javaType );
this.operator = operator;
- this.rhs = new LiteralExpression<N>( criteriaBuilder, rhs );
- this.lhs = lhs;
+ this.lhs = new LiteralExpression<N>( criteriaBuilder, lhs );
+ this.rhs = rhs;
}
public Operation getOperator() {
return operator;
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java 2010-01-13 12:47:55 UTC (rev 18538)
@@ -0,0 +1,83 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.ejb.criteria.basic;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import javax.persistence.EntityManager;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+
+import org.hibernate.ejb.metamodel.AbstractMetamodelSpecificTest;
+import org.hibernate.ejb.metamodel.Product;
+
+/**
+ * Tests that various expressions operate as expected
+ *
+ * @author Steve Ebersole
+ */
+public class ExpressionsTest extends AbstractMetamodelSpecificTest {
+ private CriteriaBuilder builder;
+
+ @Override
+ public void setUp() {
+ super.setUp();
+ builder = factory.getCriteriaBuilder();
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ Product product = new Product();
+ product.setId( "product1" );
+ product.setPrice( 1.23d );
+ product.setQuantity( 2 );
+ product.setPartNumber( Integer.MAX_VALUE + 1 );
+ product.setRating( 1.999f );
+ product.setSomeBigInteger( BigInteger.valueOf( 987654321 ) );
+ product.setSomeBigDecimal( BigDecimal.valueOf( 987654.321 ) );
+ em.persist( product );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ @Override
+ public void tearDown() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ em.createQuery( "delete Product" ).executeUpdate();
+ em.getTransaction().commit();
+ em.close();
+ super.tearDown();
+ }
+
+ public void testDiff() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Integer> criteria = builder.createQuery( Integer.class );
+ criteria.from( Product.class );
+ criteria.select( builder.diff( builder.literal( 5 ), builder.literal( 2 ) ) );
+ Integer result = em.createQuery( criteria ).getSingleResult();
+ assertEquals( Integer.valueOf( 3 ), result );
+ em.getTransaction().commit();
+ em.close();
+ }
+}
More information about the hibernate-commits
mailing list