[hibernate-commits] Hibernate SVN: r19885 - in core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test: resulttransformer and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Jul 1 11:38:12 EDT 2010


Author: sharathjreddy
Date: 2010-07-01 11:38:12 -0400 (Thu, 01 Jul 2010)
New Revision: 19885

Added:
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/Contract.hbm.xml
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/Contract.java
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/PartnerA.java
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/PartnerB.java
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/ResultTransformerTest.java
Log:
HHH-3694 ResultTransformer not used when scroll() is used on a named SQLQuery


Added: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/Contract.hbm.xml
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/Contract.hbm.xml	                        (rev 0)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/Contract.hbm.xml	2010-07-01 15:38:12 UTC (rev 19885)
@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping>
+  <class name="org.hibernate.test.resulttransformer.Contract">
+    <id name="id" type="long">
+      <column name="id" />
+      <generator class="native" />
+    </id>
+    <property name="name" />
+    <many-to-one name="a"/>
+
+    <many-to-one name="b"/>
+    <sql-query name="testQuery">
+      <return alias="d" class="org.hibernate.test.resulttransformer.Contract"/>
+      <return-join alias="a" property="d.a"/>
+      <return-join alias="b" property="d.b"/>
+      <![CDATA[
+      select 
+        {d.*}, {a.*}, {b.*}
+      from 
+        Contract d, PartnerA a, PartnerB b
+      where d.a = a.id and d.b = b.id  
+      ]]>
+    </sql-query>
+  </class>
+  <class name="org.hibernate.test.resulttransformer.PartnerA">
+
+    <id name="id" type="long">
+      <column name="id" />
+      <generator class="native" />
+    </id>
+    <property name="name" />
+  </class>
+  <class name="org.hibernate.test.resulttransformer.PartnerB">
+    <id name="id" type="long">
+      <column name="id" />
+
+      <generator class="native" />
+    </id>
+    <property name="name" />
+  </class>
+</hibernate-mapping>
\ No newline at end of file

Added: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/Contract.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/Contract.java	                        (rev 0)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/Contract.java	2010-07-01 15:38:12 UTC (rev 19885)
@@ -0,0 +1,91 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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.test.resulttransformer;
+
+/**
+ * @author Sharath Reddy
+ *
+ */
+public class Contract {
+
+	private Long id;
+	private String name;
+	private PartnerA a;
+	private PartnerB b;
+	private Long custom1;
+
+	public Long getId()
+	{
+		return id;
+	}
+
+	public void setId(Long id)
+	{
+		this.id = id;
+	}
+
+	public String getName()
+	{
+		return name;
+	}
+
+	public void setName(String name)
+	{
+		this.name = name;
+	}
+
+	public PartnerA getA()
+	{
+		return a;
+	}
+
+	public void setA(PartnerA a)
+	{
+		this.a = a;
+	}
+
+	public PartnerB getB()
+	{
+		return b;
+	}
+
+	public void setB(PartnerB b)
+	{
+		this.b = b;
+	}
+
+	public Long getCustom1()
+	{
+		return custom1;
+	}
+
+	public void setCustom1(Long custom1)
+	{
+		this.custom1 = custom1;
+	}
+}

Added: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/PartnerA.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/PartnerA.java	                        (rev 0)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/PartnerA.java	2010-07-01 15:38:12 UTC (rev 19885)
@@ -0,0 +1,55 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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.test.resulttransformer;
+
+/**
+ * @author Sharath Reddy
+ *
+ */
+public class PartnerA {
+
+	private Long id;
+	private String name;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+}
\ No newline at end of file

Added: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/PartnerB.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/PartnerB.java	                        (rev 0)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/PartnerB.java	2010-07-01 15:38:12 UTC (rev 19885)
@@ -0,0 +1,55 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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.test.resulttransformer;
+
+/**
+ * @author Sharath Reddy
+ *
+ */
+public class PartnerB {
+
+	private Long id;
+	private String name;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+}

Added: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/ResultTransformerTest.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/ResultTransformerTest.java	                        (rev 0)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/resulttransformer/ResultTransformerTest.java	2010-07-01 15:38:12 UTC (rev 19885)
@@ -0,0 +1,108 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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.test.resulttransformer;
+
+import java.util.List;
+
+import org.hibernate.Query;
+import org.hibernate.ScrollableResults;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.transform.ResultTransformer;
+
+/**
+ * @author Sharath Reddy
+ *
+ */
+public class ResultTransformerTest extends FunctionalTestCase {
+
+	public ResultTransformerTest(String string) {
+		super(string);
+	}
+	
+	/**
+	 * HHH-3694 ResultTransformer not used when scroll() is used on a named SQLQuery
+	 */
+	public void testResultTransformerIsAppliedToScrollableResults() throws Exception
+	{
+		Session s = openSession();
+		Transaction tx = s.beginTransaction();
+
+		PartnerA a = new PartnerA();
+		a.setName("Partner A");
+		PartnerB b = new PartnerB();
+		b.setName("Partner B");
+		Contract obj1 = new Contract();
+		obj1.setName("Contract");
+		obj1.setA(a);
+		obj1.setB(b);
+		s.save(a);
+		s.save(b);
+		s.save(obj1);
+
+		tx.commit();
+		s.close();
+
+		s = openSession();
+
+		Query q = s.getNamedQuery(Contract.class.getName() + ".testQuery");
+		q.setFetchSize(100);
+		q.setResultTransformer(new ResultTransformer() {
+
+			private static final long serialVersionUID = -5815434828170704822L;
+
+			public Object transformTuple(Object[] arg0, String[] arg1)
+			{
+				// return only the PartnerA object from the query
+				return arg0[1];
+			}
+
+			@SuppressWarnings("unchecked")
+			public List transformList(List arg0)
+			{
+				return arg0;
+			}
+		});
+		ScrollableResults sr = q.scroll();
+		sr.first();
+		Object[] row = sr.get();
+		assertEquals(1, row.length);
+		Object obj = row[0];
+		assertTrue(obj instanceof PartnerA);
+		PartnerA obj2 = (PartnerA) obj;
+		assertEquals("Partner A", obj2.getName());
+		s.close();
+	}
+
+	public String[] getMappings() {
+		return new String[] { "resulttransformer/Contract.hbm.xml" };
+	}
+}
+
+



More information about the hibernate-commits mailing list