Hibernate SVN: r19464 - in core/branches/Branch_3_3_2_GA_CP: testsuite/src/test/java/org/hibernate/test/querycache and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-05-10 21:48:17 -0400 (Mon, 10 May 2010)
New Revision: 19464
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/cache/StandardQueryCache.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java
Log:
JBPAPP-4224 HHH-5210 Query Cache effective only after closing the session that created the cache
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/cache/StandardQueryCache.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/cache/StandardQueryCache.java 2010-05-11 01:44:32 UTC (rev 19463)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/cache/StandardQueryCache.java 2010-05-11 01:48:17 UTC (rev 19464)
@@ -88,7 +88,7 @@
return false;
}
else {
- Long ts = new Long( session.getTimestamp() );
+ Long ts = new Long( session.getFactory().getSettings().getRegionFactory().nextTimestamp());
if ( log.isDebugEnabled() ) {
log.debug( "caching query results in region: " + cacheRegion.getName() + "; timestamp=" + ts );
Modified: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java 2010-05-11 01:44:32 UTC (rev 19463)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java 2010-05-11 01:48:17 UTC (rev 19464)
@@ -1,6 +1,7 @@
//$Id: QueryCacheTest.java 10977 2006-12-12 23:28:04Z steve.ebersole(a)jboss.com $
package org.hibernate.test.querycache;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -41,6 +42,48 @@
public static Test suite() {
return new FunctionalTestClassTestSuite( QueryCacheTest.class );
}
+ //https://jira.jboss.org/jira/browse/JBPAPP-4224
+ public void testHitCacheInSameSession() {
+ getSessions().evictQueries();
+ getSessions().getStatistics().clear();
+ Session s = openSession();
+ List list = new ArrayList();
+ s.beginTransaction();
+ for ( int i = 0; i < 3; i++ ) {
+ Item a = new Item();
+ a.setName( "a" + i );
+ a.setDescription( "a" + i );
+ list.add( a );
+ s.persist( a );
+ }
+ s.getTransaction().commit();
+
+// s.close();
+// s=openSession();
+
+ s.beginTransaction();
+ String queryString = "from Item";
+ // this query will hit the database and create the cache
+ s.createQuery( queryString ).setCacheable( true ).list();
+ s.getTransaction().commit();
+
+ s.beginTransaction();
+ //and this one SHOULD served by the cache
+ s.createQuery( queryString ).setCacheable( true ).list();
+ s.getTransaction().commit();
+ QueryStatistics qs = s.getSessionFactory().getStatistics().getQueryStatistics( queryString );
+ assertEquals( 1, qs.getCacheHitCount() );
+ assertEquals( 1, qs.getCachePutCount() );
+ s.close();
+ s = openSession();
+ s.beginTransaction();
+ for(Object obj:list){
+ s.delete( obj );
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ }
public void testQueryCacheInvalidation() throws Exception {
14 years, 8 months
Hibernate SVN: r19463 - in core/branches/Branch_3_5: testsuite/src/test/java/org/hibernate/test/querycache and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-05-10 21:44:32 -0400 (Mon, 10 May 2010)
New Revision: 19463
Modified:
core/branches/Branch_3_5/core/src/main/java/org/hibernate/cache/StandardQueryCache.java
core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java
Log:
HHH-5210 Query Cache effective only after closing the session that created the cache
Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/cache/StandardQueryCache.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/cache/StandardQueryCache.java 2010-05-11 01:41:38 UTC (rev 19462)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/cache/StandardQueryCache.java 2010-05-11 01:44:32 UTC (rev 19463)
@@ -88,7 +88,7 @@
return false;
}
else {
- Long ts = new Long( session.getTimestamp() );
+ Long ts = new Long( session.getFactory().getSettings().getRegionFactory().nextTimestamp());
if ( log.isDebugEnabled() ) {
log.debug( "caching query results in region: " + cacheRegion.getName() + "; timestamp=" + ts );
Modified: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java 2010-05-11 01:41:38 UTC (rev 19462)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java 2010-05-11 01:44:32 UTC (rev 19463)
@@ -1,6 +1,7 @@
//$Id: QueryCacheTest.java 10977 2006-12-12 23:28:04Z steve.ebersole(a)jboss.com $
package org.hibernate.test.querycache;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -41,6 +42,48 @@
public static Test suite() {
return new FunctionalTestClassTestSuite( QueryCacheTest.class );
}
+ //https://jira.jboss.org/jira/browse/JBPAPP-4224
+ public void testHitCacheInSameSession() {
+ getSessions().evictQueries();
+ getSessions().getStatistics().clear();
+ Session s = openSession();
+ List list = new ArrayList();
+ s.beginTransaction();
+ for ( int i = 0; i < 3; i++ ) {
+ Item a = new Item();
+ a.setName( "a" + i );
+ a.setDescription( "a" + i );
+ list.add( a );
+ s.persist( a );
+ }
+ s.getTransaction().commit();
+
+// s.close();
+// s=openSession();
+
+ s.beginTransaction();
+ String queryString = "from Item";
+ // this query will hit the database and create the cache
+ s.createQuery( queryString ).setCacheable( true ).list();
+ s.getTransaction().commit();
+
+ s.beginTransaction();
+ //and this one SHOULD served by the cache
+ s.createQuery( queryString ).setCacheable( true ).list();
+ s.getTransaction().commit();
+ QueryStatistics qs = s.getSessionFactory().getStatistics().getQueryStatistics( queryString );
+ assertEquals( 1, qs.getCacheHitCount() );
+ assertEquals( 1, qs.getCachePutCount() );
+ s.close();
+ s = openSession();
+ s.beginTransaction();
+ for(Object obj:list){
+ s.delete( obj );
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ }
public void testQueryCacheInvalidation() throws Exception {
14 years, 8 months
Hibernate SVN: r19462 - in core/trunk: testsuite/src/test/java/org/hibernate/test/querycache and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-05-10 21:41:38 -0400 (Mon, 10 May 2010)
New Revision: 19462
Modified:
core/trunk/core/src/main/java/org/hibernate/cache/StandardQueryCache.java
core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java
Log:
HHH-5210 Query Cache effective only after closing the session that created the cache
Modified: core/trunk/core/src/main/java/org/hibernate/cache/StandardQueryCache.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cache/StandardQueryCache.java 2010-05-11 00:49:20 UTC (rev 19461)
+++ core/trunk/core/src/main/java/org/hibernate/cache/StandardQueryCache.java 2010-05-11 01:41:38 UTC (rev 19462)
@@ -88,7 +88,7 @@
return false;
}
else {
- Long ts = Long.valueOf( session.getTimestamp() );
+ Long ts = new Long( session.getFactory().getSettings().getRegionFactory().nextTimestamp());
if ( log.isDebugEnabled() ) {
log.debug( "caching query results in region: " + cacheRegion.getName() + "; timestamp=" + ts );
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java 2010-05-11 00:49:20 UTC (rev 19461)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/querycache/QueryCacheTest.java 2010-05-11 01:41:38 UTC (rev 19462)
@@ -1,6 +1,7 @@
//$Id: QueryCacheTest.java 10977 2006-12-12 23:28:04Z steve.ebersole(a)jboss.com $
package org.hibernate.test.querycache;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -41,6 +42,48 @@
public static Test suite() {
return new FunctionalTestClassTestSuite( QueryCacheTest.class );
}
+ //https://jira.jboss.org/jira/browse/JBPAPP-4224
+ public void testHitCacheInSameSession() {
+ getSessions().evictQueries();
+ getSessions().getStatistics().clear();
+ Session s = openSession();
+ List list = new ArrayList();
+ s.beginTransaction();
+ for ( int i = 0; i < 3; i++ ) {
+ Item a = new Item();
+ a.setName( "a" + i );
+ a.setDescription( "a" + i );
+ list.add( a );
+ s.persist( a );
+ }
+ s.getTransaction().commit();
+
+// s.close();
+// s=openSession();
+
+ s.beginTransaction();
+ String queryString = "from Item";
+ // this query will hit the database and create the cache
+ s.createQuery( queryString ).setCacheable( true ).list();
+ s.getTransaction().commit();
+
+ s.beginTransaction();
+ //and this one SHOULD served by the cache
+ s.createQuery( queryString ).setCacheable( true ).list();
+ s.getTransaction().commit();
+ QueryStatistics qs = s.getSessionFactory().getStatistics().getQueryStatistics( queryString );
+ assertEquals( 1, qs.getCacheHitCount() );
+ assertEquals( 1, qs.getCachePutCount() );
+ s.close();
+ s = openSession();
+ s.beginTransaction();
+ for(Object obj:list){
+ s.delete( obj );
+ }
+ s.getTransaction().commit();
+ s.close();
+
+ }
public void testQueryCacheInvalidation() throws Exception {
14 years, 8 months
Hibernate SVN: r19461 - core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2010-05-10 20:49:20 -0400 (Mon, 10 May 2010)
New Revision: 19461
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/MappingsNonLazy.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetNonLazyTest.java
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/Child.java
core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/Mappings.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetTest.java
Log:
HHH-3799 : Added test for PersistentSet does not honor hashcode/equals contract when loaded eagerly
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/Child.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/Child.java 2010-05-11 00:41:09 UTC (rev 19460)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/Child.java 2010-05-11 00:49:20 UTC (rev 19461)
@@ -8,6 +8,7 @@
public class Child {
private String name;
private Parent parent;
+ private String description;
public Child() {
}
@@ -31,4 +32,38 @@
public void setParent(Parent parent) {
this.parent = parent;
}
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ Child child = ( Child ) o;
+
+ if ( description != null ? ! description.equals( child.description ) : child.description != null ) {
+ return false;
+ }
+ if ( ! name.equals( child.name ) ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result = name.hashCode();
+ result = 31 * result + ( description != null ? description.hashCode() : 0 );
+ return result;
+ }
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/Mappings.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/Mappings.hbm.xml 2010-05-11 00:41:09 UTC (rev 19460)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/Mappings.hbm.xml 2010-05-11 00:49:20 UTC (rev 19461)
@@ -32,6 +32,7 @@
<class name="Child">
<id name="name" column="NAME" type="string"/>
<many-to-one name="parent" class="Parent" cascade="none" />
+ <property name="description" type="string"/>
</class>
<class name="Container">
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/MappingsNonLazy.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/MappingsNonLazy.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/MappingsNonLazy.hbm.xml 2010-05-11 00:49:20 UTC (rev 19461)
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+ ~ Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ ~
+ ~ 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, v. 2.1. This program is distributed in the
+ ~ hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ ~ distribution; if not, write to the Free Software Foundation, Inc.,
+ ~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ ~
+ ~ Red Hat Author(s): Steve Ebersole
+ -->
+<hibernate-mapping package="org.hibernate.test.collection.set">
+
+ <class name="Parent">
+ <id name="name" column="NAME" type="string" />
+
+ <set name="children" inverse="true" cascade="all" lazy="false">
+ <key column="PARENT" />
+ <one-to-many class="Child" />
+ </set>
+ </class>
+
+ <class name="Child">
+ <id name="name" column="NAME" type="string"/>
+ <many-to-one name="parent" class="Parent" cascade="none" lazy="false" />
+ <property name="description" type="string"/>
+ </class>
+
+ <class name="Container">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="name" column="NAME" type="string"/>
+ <set name="contents" table="CONTENTS" lazy="false">
+ <key column="CONTAINER_ID"/>
+ <composite-element class="Container$Content">
+ <property name="name" column="NAME" type="string"/>
+ </composite-element>
+ </set>
+ </class>
+
+</hibernate-mapping>
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetNonLazyTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetNonLazyTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetNonLazyTest.java 2010-05-11 00:49:20 UTC (rev 19461)
@@ -0,0 +1,65 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.test.collection.set;
+
+import java.util.HashSet;
+
+import junit.framework.Test;
+
+import org.hibernate.Session;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.collection.PersistentSet;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.stat.CollectionStatistics;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class PersistentSetNonLazyTest extends PersistentSetTest {
+ public PersistentSetNonLazyTest(String name) {
+ super( name );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "collection/set/MappingsNonLazy.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( PersistentSetNonLazyTest.class );
+ }
+
+ public void testLoadChildCheckParentContainsChildCache() {
+ reportSkip( "known to fail with non-lazy collection using query cache",
+ "support for non-lazy collections using query cache"
+ );
+ }
+
+ public void testLoadChildCheckParentContainsChildCacheFailureExpected() {
+ super.testLoadChildCheckParentContainsChildCache();
+ }
+}
\ No newline at end of file
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetTest.java 2010-05-11 00:41:09 UTC (rev 19460)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetTest.java 2010-05-11 00:49:20 UTC (rev 19461)
@@ -4,10 +4,12 @@
import junit.framework.Test;
+import org.hibernate.CacheMode;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.collection.PersistentSet;
+import org.hibernate.criterion.Restrictions;
import org.hibernate.junit.functional.FunctionalTestCase;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.stat.CollectionStatistics;
@@ -273,4 +275,110 @@
session.getTransaction().commit();
session.close();
}
+
+ public void testLoadChildCheckParentContainsChildCache() {
+ Parent parent = new Parent( "p1" );
+ Child child = new Child( "c1" );
+ child.setDescription( "desc1" );
+ parent.getChildren().add( child );
+ child.setParent( parent );
+ Child otherChild = new Child( "c2" );
+ otherChild.setDescription( "desc2" );
+ parent.getChildren().add( otherChild );
+ otherChild.setParent( parent );
+
+ Session session = openSession();
+ session.beginTransaction();
+ session.save( parent );
+ session.getTransaction().commit();
+
+ session = openSession();
+ session.beginTransaction();
+ parent = ( Parent ) session.get( Parent.class, parent.getName() );
+ assertTrue( parent.getChildren().contains( child ) );
+ assertTrue( parent.getChildren().contains( otherChild ) );
+ session.getTransaction().commit();
+
+ session = openSession();
+ session.beginTransaction();
+
+ child = ( Child ) session.get( Child.class, child.getName() );
+ assertTrue( child.getParent().getChildren().contains( child ) );
+ session.clear();
+
+ child = ( Child ) session.createCriteria( Child.class, child.getName() )
+ .setCacheable( true )
+ .add( Restrictions.idEq( "c1" ) )
+ .uniqueResult();
+ assertTrue( child.getParent().getChildren().contains( child ) );
+ assertTrue( child.getParent().getChildren().contains( otherChild ) );
+ session.clear();
+
+ child = ( Child ) session.createCriteria( Child.class, child.getName() )
+ .setCacheable( true )
+ .add( Restrictions.idEq( "c1" ) )
+ .uniqueResult();
+ assertTrue( child.getParent().getChildren().contains( child ) );
+ assertTrue( child.getParent().getChildren().contains( otherChild ) );
+ session.clear();
+
+ child = ( Child ) session.createQuery( "from Child where name = 'c1'" )
+ .setCacheable( true )
+ .uniqueResult();
+ assertTrue( child.getParent().getChildren().contains( child ) );
+
+ child = ( Child ) session.createQuery( "from Child where name = 'c1'" )
+ .setCacheable( true )
+ .uniqueResult();
+ assertTrue( child.getParent().getChildren().contains( child ) );
+
+ session.delete( child.getParent() );
+ session.getTransaction().commit();
+ session.close();
+ }
+
+ public void testLoadChildCheckParentContainsChildNoCache() {
+ Parent parent = new Parent( "p1" );
+ Child child = new Child( "c1" );
+ parent.getChildren().add( child );
+ child.setParent( parent );
+ Child otherChild = new Child( "c2" );
+ parent.getChildren().add( otherChild );
+ otherChild.setParent( parent );
+
+ Session session = openSession();
+ session.beginTransaction();
+ session.save( parent );
+ session.getTransaction().commit();
+
+ session = openSession();
+ session.beginTransaction();
+ session.setCacheMode( CacheMode.IGNORE );
+ parent = ( Parent ) session.get( Parent.class, parent.getName() );
+ assertTrue( parent.getChildren().contains( child ) );
+ assertTrue( parent.getChildren().contains( otherChild ) );
+ session.getTransaction().commit();
+
+ session = openSession();
+ session.beginTransaction();
+ session.setCacheMode( CacheMode.IGNORE );
+
+ child = ( Child ) session.get( Child.class, child.getName() );
+ assertTrue( child.getParent().getChildren().contains( child ) );
+ session.clear();
+
+ child = ( Child ) session.createCriteria( Child.class, child.getName() )
+ .add( Restrictions.idEq( "c1" ) )
+ .uniqueResult();
+ assertTrue( child.getParent().getChildren().contains( child ) );
+ assertTrue( child.getParent().getChildren().contains( otherChild ) );
+ session.clear();
+
+ child = ( Child ) session.createQuery( "from Child where name = 'c1'" ).uniqueResult();
+ assertTrue( child.getParent().getChildren().contains( child ) );
+
+ session.delete( child.getParent() );
+ session.getTransaction().commit();
+ session.close();
+ }
}
14 years, 8 months
Hibernate SVN: r19460 - core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2010-05-10 20:41:09 -0400 (Mon, 10 May 2010)
New Revision: 19460
Added:
core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/MappingsNonLazy.hbm.xml
core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetNonLazyTest.java
Log:
HHH-3799 : Added test for PersistentSet does not honor hashcode/equals contract when loaded eagerly (forgotten files)
Added: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/MappingsNonLazy.hbm.xml
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/MappingsNonLazy.hbm.xml (rev 0)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/MappingsNonLazy.hbm.xml 2010-05-11 00:41:09 UTC (rev 19460)
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+ ~ Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ ~
+ ~ 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, v. 2.1. This program is distributed in the
+ ~ hope that it will be useful, but WITHOUT A 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, v.2.1 along with this
+ ~ distribution; if not, write to the Free Software Foundation, Inc.,
+ ~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ ~
+ ~ Red Hat Author(s): Steve Ebersole
+ -->
+<hibernate-mapping package="org.hibernate.test.collection.set">
+
+ <class name="Parent">
+ <id name="name" column="NAME" type="string" />
+
+ <set name="children" inverse="true" cascade="all" lazy="false">
+ <key column="PARENT" />
+ <one-to-many class="Child" />
+ </set>
+ </class>
+
+ <class name="Child">
+ <id name="name" column="NAME" type="string"/>
+ <many-to-one name="parent" class="Parent" cascade="none" lazy="false" />
+ <property name="description" type="string"/>
+ </class>
+
+ <class name="Container">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="name" column="NAME" type="string"/>
+ <set name="contents" table="CONTENTS" lazy="false">
+ <key column="CONTAINER_ID"/>
+ <composite-element class="Container$Content">
+ <property name="name" column="NAME" type="string"/>
+ </composite-element>
+ </set>
+ </class>
+
+</hibernate-mapping>
Added: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetNonLazyTest.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetNonLazyTest.java (rev 0)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetNonLazyTest.java 2010-05-11 00:41:09 UTC (rev 19460)
@@ -0,0 +1,65 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.test.collection.set;
+
+import java.util.HashSet;
+
+import junit.framework.Test;
+
+import org.hibernate.Session;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.collection.PersistentSet;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.stat.CollectionStatistics;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class PersistentSetNonLazyTest extends PersistentSetTest {
+ public PersistentSetNonLazyTest(String name) {
+ super( name );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "collection/set/MappingsNonLazy.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( PersistentSetNonLazyTest.class );
+ }
+
+ public void testLoadChildCheckParentContainsChildCache() {
+ reportSkip( "known to fail with non-lazy collection using query cache",
+ "support for non-lazy collections using query cache"
+ );
+ }
+
+ public void testLoadChildCheckParentContainsChildCacheFailureExpected() {
+ super.testLoadChildCheckParentContainsChildCache();
+ }
+}
\ No newline at end of file
14 years, 8 months
Hibernate SVN: r19459 - core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2010-05-10 20:29:12 -0400 (Mon, 10 May 2010)
New Revision: 19459
Modified:
core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/Child.java
core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/Mappings.hbm.xml
core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetTest.java
Log:
HHH-3799 : Added test for PersistentSet does not honor hashcode/equals contract when loaded eagerly
Modified: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/Child.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/Child.java 2010-05-10 22:18:47 UTC (rev 19458)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/Child.java 2010-05-11 00:29:12 UTC (rev 19459)
@@ -8,6 +8,7 @@
public class Child {
private String name;
private Parent parent;
+ private String description;
public Child() {
}
@@ -31,4 +32,38 @@
public void setParent(Parent parent) {
this.parent = parent;
}
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ Child child = ( Child ) o;
+
+ if ( description != null ? ! description.equals( child.description ) : child.description != null ) {
+ return false;
+ }
+ if ( ! name.equals( child.name ) ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result = name.hashCode();
+ result = 31 * result + ( description != null ? description.hashCode() : 0 );
+ return result;
+ }
}
Modified: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/Mappings.hbm.xml
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/Mappings.hbm.xml 2010-05-10 22:18:47 UTC (rev 19458)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/Mappings.hbm.xml 2010-05-11 00:29:12 UTC (rev 19459)
@@ -32,6 +32,7 @@
<class name="Child">
<id name="name" column="NAME" type="string"/>
<many-to-one name="parent" class="Parent" cascade="none" />
+ <property name="description" type="string"/>
</class>
<class name="Container">
Modified: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetTest.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetTest.java 2010-05-10 22:18:47 UTC (rev 19458)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/collection/set/PersistentSetTest.java 2010-05-11 00:29:12 UTC (rev 19459)
@@ -4,10 +4,12 @@
import junit.framework.Test;
+import org.hibernate.CacheMode;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.collection.PersistentSet;
+import org.hibernate.criterion.Restrictions;
import org.hibernate.junit.functional.FunctionalTestCase;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.stat.CollectionStatistics;
@@ -273,4 +275,110 @@
session.getTransaction().commit();
session.close();
}
+
+ public void testLoadChildCheckParentContainsChildCache() {
+ Parent parent = new Parent( "p1" );
+ Child child = new Child( "c1" );
+ child.setDescription( "desc1" );
+ parent.getChildren().add( child );
+ child.setParent( parent );
+ Child otherChild = new Child( "c2" );
+ otherChild.setDescription( "desc2" );
+ parent.getChildren().add( otherChild );
+ otherChild.setParent( parent );
+
+ Session session = openSession();
+ session.beginTransaction();
+ session.save( parent );
+ session.getTransaction().commit();
+
+ session = openSession();
+ session.beginTransaction();
+ parent = ( Parent ) session.get( Parent.class, parent.getName() );
+ assertTrue( parent.getChildren().contains( child ) );
+ assertTrue( parent.getChildren().contains( otherChild ) );
+ session.getTransaction().commit();
+
+ session = openSession();
+ session.beginTransaction();
+
+ child = ( Child ) session.get( Child.class, child.getName() );
+ assertTrue( child.getParent().getChildren().contains( child ) );
+ session.clear();
+
+ child = ( Child ) session.createCriteria( Child.class, child.getName() )
+ .setCacheable( true )
+ .add( Restrictions.idEq( "c1" ) )
+ .uniqueResult();
+ assertTrue( child.getParent().getChildren().contains( child ) );
+ assertTrue( child.getParent().getChildren().contains( otherChild ) );
+ session.clear();
+
+ child = ( Child ) session.createCriteria( Child.class, child.getName() )
+ .setCacheable( true )
+ .add( Restrictions.idEq( "c1" ) )
+ .uniqueResult();
+ assertTrue( child.getParent().getChildren().contains( child ) );
+ assertTrue( child.getParent().getChildren().contains( otherChild ) );
+ session.clear();
+
+ child = ( Child ) session.createQuery( "from Child where name = 'c1'" )
+ .setCacheable( true )
+ .uniqueResult();
+ assertTrue( child.getParent().getChildren().contains( child ) );
+
+ child = ( Child ) session.createQuery( "from Child where name = 'c1'" )
+ .setCacheable( true )
+ .uniqueResult();
+ assertTrue( child.getParent().getChildren().contains( child ) );
+
+ session.delete( child.getParent() );
+ session.getTransaction().commit();
+ session.close();
+ }
+
+ public void testLoadChildCheckParentContainsChildNoCache() {
+ Parent parent = new Parent( "p1" );
+ Child child = new Child( "c1" );
+ parent.getChildren().add( child );
+ child.setParent( parent );
+ Child otherChild = new Child( "c2" );
+ parent.getChildren().add( otherChild );
+ otherChild.setParent( parent );
+
+ Session session = openSession();
+ session.beginTransaction();
+ session.save( parent );
+ session.getTransaction().commit();
+
+ session = openSession();
+ session.beginTransaction();
+ session.setCacheMode( CacheMode.IGNORE );
+ parent = ( Parent ) session.get( Parent.class, parent.getName() );
+ assertTrue( parent.getChildren().contains( child ) );
+ assertTrue( parent.getChildren().contains( otherChild ) );
+ session.getTransaction().commit();
+
+ session = openSession();
+ session.beginTransaction();
+ session.setCacheMode( CacheMode.IGNORE );
+
+ child = ( Child ) session.get( Child.class, child.getName() );
+ assertTrue( child.getParent().getChildren().contains( child ) );
+ session.clear();
+
+ child = ( Child ) session.createCriteria( Child.class, child.getName() )
+ .add( Restrictions.idEq( "c1" ) )
+ .uniqueResult();
+ assertTrue( child.getParent().getChildren().contains( child ) );
+ assertTrue( child.getParent().getChildren().contains( otherChild ) );
+ session.clear();
+
+ child = ( Child ) session.createQuery( "from Child where name = 'c1'" ).uniqueResult();
+ assertTrue( child.getParent().getChildren().contains( child ) );
+
+ session.delete( child.getParent() );
+ session.getTransaction().commit();
+ session.close();
+ }
}
14 years, 8 months
Hibernate SVN: r19458 - in core/trunk/entitymanager/src: test/java/org/hibernate/ejb/criteria/basic and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2010-05-10 18:18:47 -0400 (Mon, 10 May 2010)
New Revision: 19458
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java
Log:
HHH-5078 : JPA criteria query numeric expressions produce wrong result (due to wrong bracketing)
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-05-10 22:11:45 UTC (rev 19457)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java 2010-05-10 22:18:47 UTC (rev 19458)
@@ -43,27 +43,27 @@
public static enum Operation {
ADD {
String apply(String lhs, String rhs) {
- return lhs + " + " + rhs;
+ return applyPrimitive( lhs, '+', rhs );
}
},
SUBTRACT {
String apply(String lhs, String rhs) {
- return lhs + " - " + rhs;
+ return applyPrimitive( lhs, '-', rhs );
}
},
MULTIPLY {
String apply(String lhs, String rhs) {
- return lhs + " * " + rhs;
+ return applyPrimitive( lhs, '*', rhs );
}
},
DIVIDE {
String apply(String lhs, String rhs) {
- return lhs + " / " + rhs;
+ return applyPrimitive( lhs, '/', rhs );
}
},
QUOT {
String apply(String lhs, String rhs) {
- return lhs + " / " + rhs;
+ return applyPrimitive( lhs, '/', rhs );
}
},
MOD {
@@ -73,6 +73,18 @@
}
};
abstract String apply(String lhs, String rhs);
+
+ private static final char LEFT_PAREN = '(';
+ private static final char RIGHT_PAREN = ')';
+ private static String applyPrimitive(String lhs, char operator, String rhs) {
+ return new StringBuffer( lhs.length() + rhs.length() + 3 )
+ .append( LEFT_PAREN )
+ .append( lhs )
+ .append( operator )
+ .append( rhs )
+ .append( RIGHT_PAREN )
+ .toString();
+ }
}
private final Operation operator;
Modified: 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 2010-05-10 22:11:45 UTC (rev 19457)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java 2010-05-10 22:18:47 UTC (rev 19458)
@@ -63,7 +63,7 @@
@Override
public void tearDown() throws Exception {
EntityManager em = getOrCreateEntityManager();
- em.getTransaction().begin();
+ em.getTransaction().begin();
em.createQuery( "delete Product" ).executeUpdate();
em.getTransaction().commit();
em.close();
@@ -153,4 +153,78 @@
em.getTransaction().commit();
em.close();
}
+
+ public void testDiffWithQuotient() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Number> criteria = builder.createQuery( Number.class );
+ criteria.from( Product.class );
+ criteria.select(
+ builder.quot(
+ builder.diff(
+ builder.literal( BigDecimal.valueOf( 2.0 ) ),
+ builder.literal( BigDecimal.valueOf( 1.0 ) )
+ ),
+ BigDecimal.valueOf( 2.0 )
+ )
+ );
+ Number result = em.createQuery( criteria ).getSingleResult();
+ assertEquals(0.5d, result.doubleValue(), 0.1d);
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testSumWithQuotient() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Number> criteria = builder.createQuery( Number.class );
+ criteria.from( Product.class );
+ criteria.select(
+ builder.quot(
+ builder.sum(
+ builder.literal( BigDecimal.valueOf( 0.0 ) ),
+ builder.literal( BigDecimal.valueOf( 1.0 ) )
+ ),
+ BigDecimal.valueOf( 2.0 )
+ )
+ );
+ Number result = em.createQuery( criteria ).getSingleResult();
+ assertEquals(0.5d, result.doubleValue(), 0.1d);
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testQuotientAndMultiply() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Number> criteria = builder.createQuery( Number.class );
+ criteria.from( Product.class );
+ criteria.select(
+ builder.quot(
+ builder.prod(
+ builder.literal( BigDecimal.valueOf( 10.0 ) ),
+ builder.literal( BigDecimal.valueOf( 5.0 ) )
+ ),
+ BigDecimal.valueOf( 2.0 )
+ )
+ );
+ Number result = em.createQuery( criteria ).getSingleResult();
+ assertEquals(25.0d, result.doubleValue(), 0.1d);
+
+ criteria.select(
+ builder.prod(
+ builder.quot(
+ builder.literal( BigDecimal.valueOf( 10.0 ) ),
+ builder.literal( BigDecimal.valueOf( 5.0 ) )
+ ),
+ BigDecimal.valueOf( 2.0 )
+ )
+ );
+ result = em.createQuery( criteria ).getSingleResult();
+ assertEquals(4.0d, result.doubleValue(), 0.1d);
+
+ em.getTransaction().commit();
+ em.close();
+ }
+
}
14 years, 8 months
Hibernate SVN: r19457 - in core/branches/Branch_3_5/entitymanager/src: test/java/org/hibernate/ejb/criteria/basic and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2010-05-10 18:11:45 -0400 (Mon, 10 May 2010)
New Revision: 19457
Modified:
core/branches/Branch_3_5/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java
core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java
Log:
HHH-5078 : JPA criteria query numeric expressions produce wrong result (due to wrong bracketing)
Modified: core/branches/Branch_3_5/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java
===================================================================
--- core/branches/Branch_3_5/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java 2010-05-10 21:48:24 UTC (rev 19456)
+++ core/branches/Branch_3_5/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java 2010-05-10 22:11:45 UTC (rev 19457)
@@ -43,27 +43,27 @@
public static enum Operation {
ADD {
String apply(String lhs, String rhs) {
- return lhs + " + " + rhs;
+ return applyPrimitive( lhs, '+', rhs );
}
},
SUBTRACT {
String apply(String lhs, String rhs) {
- return lhs + " - " + rhs;
+ return applyPrimitive( lhs, '-', rhs );
}
},
MULTIPLY {
String apply(String lhs, String rhs) {
- return lhs + " * " + rhs;
+ return applyPrimitive( lhs, '*', rhs );
}
},
DIVIDE {
String apply(String lhs, String rhs) {
- return lhs + " / " + rhs;
+ return applyPrimitive( lhs, '/', rhs );
}
},
QUOT {
String apply(String lhs, String rhs) {
- return lhs + " / " + rhs;
+ return applyPrimitive( lhs, '/', rhs );
}
},
MOD {
@@ -73,6 +73,18 @@
}
};
abstract String apply(String lhs, String rhs);
+
+ private static final char LEFT_PAREN = '(';
+ private static final char RIGHT_PAREN = ')';
+ private static String applyPrimitive(String lhs, char operator, String rhs) {
+ return new StringBuffer( lhs.length() + rhs.length() + 3 )
+ .append( LEFT_PAREN )
+ .append( lhs )
+ .append( operator )
+ .append( rhs )
+ .append( RIGHT_PAREN )
+ .toString();
+ }
}
private final Operation operator;
Modified: core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java
===================================================================
--- core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java 2010-05-10 21:48:24 UTC (rev 19456)
+++ core/branches/Branch_3_5/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java 2010-05-10 22:11:45 UTC (rev 19457)
@@ -63,7 +63,7 @@
@Override
public void tearDown() throws Exception {
EntityManager em = getOrCreateEntityManager();
- em.getTransaction().begin();
+ em.getTransaction().begin();
em.createQuery( "delete Product" ).executeUpdate();
em.getTransaction().commit();
em.close();
@@ -153,4 +153,78 @@
em.getTransaction().commit();
em.close();
}
+
+ public void testDiffWithQuotient() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Number> criteria = builder.createQuery( Number.class );
+ criteria.from( Product.class );
+ criteria.select(
+ builder.quot(
+ builder.diff(
+ builder.literal( BigDecimal.valueOf( 2.0 ) ),
+ builder.literal( BigDecimal.valueOf( 1.0 ) )
+ ),
+ BigDecimal.valueOf( 2.0 )
+ )
+ );
+ Number result = em.createQuery( criteria ).getSingleResult();
+ assertEquals(0.5d, result.doubleValue(), 0.1d);
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testSumWithQuotient() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Number> criteria = builder.createQuery( Number.class );
+ criteria.from( Product.class );
+ criteria.select(
+ builder.quot(
+ builder.sum(
+ builder.literal( BigDecimal.valueOf( 0.0 ) ),
+ builder.literal( BigDecimal.valueOf( 1.0 ) )
+ ),
+ BigDecimal.valueOf( 2.0 )
+ )
+ );
+ Number result = em.createQuery( criteria ).getSingleResult();
+ assertEquals(0.5d, result.doubleValue(), 0.1d);
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testQuotientAndMultiply() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Number> criteria = builder.createQuery( Number.class );
+ criteria.from( Product.class );
+ criteria.select(
+ builder.quot(
+ builder.prod(
+ builder.literal( BigDecimal.valueOf( 10.0 ) ),
+ builder.literal( BigDecimal.valueOf( 5.0 ) )
+ ),
+ BigDecimal.valueOf( 2.0 )
+ )
+ );
+ Number result = em.createQuery( criteria ).getSingleResult();
+ assertEquals(25.0d, result.doubleValue(), 0.1d);
+
+ criteria.select(
+ builder.prod(
+ builder.quot(
+ builder.literal( BigDecimal.valueOf( 10.0 ) ),
+ builder.literal( BigDecimal.valueOf( 5.0 ) )
+ ),
+ BigDecimal.valueOf( 2.0 )
+ )
+ );
+ result = em.createQuery( criteria ).getSingleResult();
+ assertEquals(4.0d, result.doubleValue(), 0.1d);
+
+ em.getTransaction().commit();
+ em.close();
+ }
+
}
14 years, 8 months