[hibernate-commits] Hibernate SVN: r11488 - trunk/Hibernate3/test/org/hibernate/test/sql/hand/custom.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue May 8 18:21:46 EDT 2007


Author: steve.ebersole at jboss.com
Date: 2007-05-08 18:21:46 -0400 (Tue, 08 May 2007)
New Revision: 11488

Added:
   trunk/Hibernate3/test/org/hibernate/test/sql/hand/custom/CustomStoredProcTestSupport.java
Log:
HHH-2301 : IDENTITY + custom insert SQL (Scott Rankin and Gail Badner)

Added: trunk/Hibernate3/test/org/hibernate/test/sql/hand/custom/CustomStoredProcTestSupport.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/sql/hand/custom/CustomStoredProcTestSupport.java	                        (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/sql/hand/custom/CustomStoredProcTestSupport.java	2007-05-08 22:21:46 UTC (rev 11488)
@@ -0,0 +1,83 @@
+package org.hibernate.test.sql.hand.custom;
+
+import java.sql.SQLException;
+import java.util.List;
+
+import org.hibernate.HibernateException;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.test.sql.hand.Employment;
+import org.hibernate.test.sql.hand.Organization;
+import org.hibernate.test.sql.hand.Person;
+
+/**
+ * Abstract test case defining tests of stored procedure support.
+ *
+ * @author Gail Badner
+ */
+public abstract class CustomStoredProcTestSupport extends CustomSQLTestSupport {
+
+	public CustomStoredProcTestSupport(String name) {
+		super( name );
+	}
+
+	public void testScalarStoredProcedure() throws HibernateException, SQLException {
+		Session s = openSession();
+		Query namedQuery = s.getNamedQuery( "simpleScalar" );
+		namedQuery.setLong( "number", 43 );
+		List list = namedQuery.list();
+		Object o[] = ( Object[] ) list.get( 0 );
+		assertEquals( o[0], "getAll" );
+		assertEquals( o[1], new Long( 43 ) );
+		s.close();
+	}
+
+	public void testParameterHandling() throws HibernateException, SQLException {
+		Session s = openSession();
+
+		Query namedQuery = s.getNamedQuery( "paramhandling" );
+		namedQuery.setLong( 0, 10 );
+		namedQuery.setLong( 1, 20 );
+		List list = namedQuery.list();
+		Object[] o = ( Object[] ) list.get( 0 );
+		assertEquals( o[0], new Long( 10 ) );
+		assertEquals( o[1], new Long( 20 ) );
+
+		namedQuery = s.getNamedQuery( "paramhandling_mixed" );
+		namedQuery.setLong( 0, 10 );
+		namedQuery.setLong( "second", 20 );
+		list = namedQuery.list();
+		o = ( Object[] ) list.get( 0 );
+		assertEquals( o[0], new Long( 10 ) );
+		assertEquals( o[1], new Long( 20 ) );
+		s.close();
+	}
+
+	public void testEntityStoredProcedure() throws HibernateException, SQLException {
+		Session s = openSession();
+		Transaction t = s.beginTransaction();
+
+		Organization ifa = new Organization( "IFA" );
+		Organization jboss = new Organization( "JBoss" );
+		Person gavin = new Person( "Gavin" );
+		Employment emp = new Employment( gavin, jboss, "AU" );
+		s.persist( ifa );
+		s.persist( jboss );
+		s.persist( gavin );
+		s.persist( emp );
+
+		Query namedQuery = s.getNamedQuery( "selectAllEmployments" );
+		List list = namedQuery.list();
+		assertTrue( list.get( 0 ) instanceof Employment );
+		s.delete( emp );
+		s.delete( ifa );
+		s.delete( jboss );
+		s.delete( gavin );
+
+		t.commit();
+		s.close();
+	}
+
+
+}




More information about the hibernate-commits mailing list