[hibernate-commits] Hibernate SVN: r11485 - in branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql: check and 10 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Tue May 8 17:56:00 EDT 2007
Author: steve.ebersole at jboss.com
Date: 2007-05-08 17:56:00 -0400 (Tue, 08 May 2007)
New Revision: 11485
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/CheckSuite.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Dimension.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Employment.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/MonetaryAmount.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/MonetaryAmountUserType.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Order.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Organization.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Person.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Product.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/SpaceShip.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Speech.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/CustomSQLTestSupport.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/CustomStoredProcTestSupport.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/datadirect/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/datadirect/oracle/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/datadirect/oracle/DataDirectOracleCustomSQLTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/datadirect/oracle/StoredProcedures.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/db2/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/db2/DB2CustomSQLTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/db2/Mappings.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/mysql/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/mysql/Mappings.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/mysql/MySQLCustomSQLTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/oracle/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/oracle/Mappings.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/oracle/OracleCustomSQLTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/oracle/StoredProcedures.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/sybase/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/sybase/Mappings.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/sybase/SybaseCustomSQLTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/identity/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/identity/CustomInsertSQLWithIdentityColumnTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/identity/Mappings.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/query/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
Removed:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/DataDirectOracleSQLTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Db2Employment.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Db2SQLTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Dimension.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Employment.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/General.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/GeneralTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/HandSQLTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MSSQLEmployment.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MSSQLTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MonetaryAmount.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MonetaryAmountUserType.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MySQLEmployment.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MySQLTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/OracleDataDirectDriverStoredProcedures.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/OracleDriverStoredProcedures.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/OracleEmployment.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/OracleSQLTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Order.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Organization.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Person.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Product.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/SpaceShip.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Speech.java
Modified:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/NativeSqlSupportSuite.java
Log:
HHH-2301 : IDENTITY + custom insert SQL (Scott Rankin and Gail Badner)
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/DataDirectOracleSQLTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/DataDirectOracleSQLTest.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/DataDirectOracleSQLTest.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,32 +0,0 @@
-//$Id$
-package org.hibernate.test.sql;
-
-import junit.framework.Test;
-
-import org.hibernate.dialect.DataDirectOracle9Dialect;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
-
-/**
- * @author Max Rydahl Andersen
- */
-public class DataDirectOracleSQLTest extends HandSQLTest {
-
- public DataDirectOracleSQLTest(String str) {
- super(str);
- }
-
- public String[] getMappings() {
- return new String[] { "sql/OracleEmployment.hbm.xml", "sql/OracleDataDirectDriverStoredProcedures.hbm.xml" };
- }
-
- public static Test suite() {
- return new FunctionalTestClassTestSuite( DataDirectOracleSQLTest.class );
- }
-
- public boolean appliesTo(Dialect dialect) {
- return ( dialect instanceof DataDirectOracle9Dialect );
- }
-
-}
-
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Db2Employment.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Db2Employment.hbm.xml 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Db2Employment.hbm.xml 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,240 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<!--
-
- This mapping demonstrates the use of Hibernate with
- all-handwritten SQL!
-
- This version is for Sybase/mssql
--->
-<hibernate-mapping
- package="org.hibernate.test.sql"
- default-access="field">
-
- <class name="Organization" table="ORGANIZATION">
- <id name="id" unsaved-value="0" column="ORGID">
- <generator class="increment"/>
- </id>
- <property name="name" not-null="true" column="NAME"/>
- <set name="employments"
- inverse="true"
- order-by="DUMMY">
- <key column="EMPLOYER"/> <!-- only needed for DDL generation -->
- <one-to-many class="Employment"/>
- <loader query-ref="organizationEmployments"/>
- </set>
- <!-- query-list name="currentEmployments"
- query-ref="organizationCurrentEmployments"-->
- <loader query-ref="organization"/>
- <sql-insert>INSERT INTO ORGANIZATION (NAME, ORGID) VALUES ( UPPER(? || ''), ? )</sql-insert>
- <sql-update>UPDATE ORGANIZATION SET NAME=UPPER(? || '') WHERE ORGID=?</sql-update>
- <sql-delete>DELETE FROM ORGANIZATION WHERE ORGID=?</sql-delete>
- </class>
-
- <class name="Person" table="PERSON">
- <id name="id" unsaved-value="0" column="PERID">
- <generator class="increment"/>
- </id>
- <property name="name" not-null="true" column="NAME"/>
- <loader query-ref="person"/>
- <sql-insert>INSERT INTO PERSON (NAME, PERID) VALUES ( UPPER(? || ''), ? )</sql-insert>
- <sql-update>UPDATE PERSON SET NAME=UPPER(? || '') WHERE PERID=?</sql-update>
- <sql-delete>DELETE FROM PERSON WHERE PERID=?</sql-delete>
- </class>
-
- <class name="Employment" table="EMPLOYMENT">
- <id name="employmentId" unsaved-value="0" column="EMPID">
- <generator class="increment"/>
- </id>
- <many-to-one name="employee" column="EMPLOYEE" not-null="true" update="false"/>
- <many-to-one name="employer" column="EMPLOYER" not-null="true" update="false"/>
- <property name="startDate" column="STARTDATE" not-null="true" update="false" insert="false"/>
- <property name="endDate" column="ENDDATE" insert="false"/>
- <property name="regionCode" column="REGIONCODE" update="false"/>
- <property name="salary" type="org.hibernate.test.sql.MonetaryAmountUserType">
- <column name="VALUE" sql-type="float"/>
- <column name="CURRENCY"/>
- </property>
- <loader query-ref="employment"/>
- <sql-insert>
- INSERT INTO EMPLOYMENT
- (EMPLOYEE, EMPLOYER, STARTDATE, REGIONCODE, VALUE, CURRENCY, EMPID)
- <!-- inserting raw specific timestamp since using current date or current timestamp for some reason does not work with a timestamp column! -->
- VALUES (?, ?, TIMESTAMP ('2006-02-28 11:39:00'), UPPER(? || ''), ?, ?, ?)
- </sql-insert>
- <sql-update>UPDATE EMPLOYMENT SET ENDDATE=?, VALUE=?, CURRENCY=? WHERE EMPID=?</sql-update>
- <sql-delete>DELETE FROM EMPLOYMENT WHERE EMPID=?</sql-delete>
- </class>
-
- <resultset name="org-emp-regionCode">
- <return-scalar column="regionCode" type="string"/>
- <return alias="org" class="Organization"/>
- <return-join alias="emp" property="org.employments"/>
- </resultset>
-
- <resultset name="org-emp-person">
- <return alias="org" class="Organization"/>
- <return-join alias="emp" property="org.employments"/>
- <return-join alias="pers" property="emp.employee"/>
- </resultset>
-
- <sql-query name="person">
- <return alias="p" class="Person" lock-mode="upgrade"/>
- SELECT NAME AS {p.name}, PERID AS {p.id} FROM PERSON WHERE PERID=? /*FOR UPDATE*/
- </sql-query>
-
- <sql-query name="organization">
- <return alias="org" class="Organization"/>
- <return-join alias="emp" property="org.employments"/>
- SELECT {org.*}, {emp.*}
- FROM ORGANIZATION org
- LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER
- WHERE org.ORGID=?
- </sql-query>
-
-
- <!--sql-query name="organization">
- <return alias="org" class="Organization"/>
- SELECT NAME AS {org.name}, ORGID AS {org.id} FROM ORGANIZATION
- WHERE ORGID=?
- </sql-query-->
-
- <sql-query name="allOrganizationsWithEmployees" flush-mode="never">
- <return alias="org" class="Organization"/>
- SELECT DISTINCT org.NAME AS {org.name}, org.ORGID AS {org.id}
- FROM ORGANIZATION org
- INNER JOIN EMPLOYMENT e ON e.EMPLOYER = org.ORGID
- </sql-query>
-
-
-
-
-
- <sql-query name="employment">
- <return alias="emp" class="Employment"/>
- SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer},
- STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate},
- REGIONCODE as {emp.regionCode}, EMPID AS {emp.id}
- FROM EMPLOYMENT
- WHERE EMPID = ?
- </sql-query>
-
- <sql-query name="organizationEmployments">
- <load-collection alias="empcol" role="Organization.employments"/>
- SELECT {empcol.*}
- FROM EMPLOYMENT empcol
- WHERE EMPLOYER = :id
- ORDER BY STARTDATE ASC, EMPLOYEE ASC
- </sql-query>
-
-
- <sql-query name="organizationCurrentEmployments">
- <return alias="emp" class="Employment">
- <return-property name="salary">
- <!-- as multi column properties are not supported via the
- {}-syntax, we need to provide an explicit column list for salary via <return-property> -->
- <return-column name="VALUE"/>
- <return-column name="CURRENCY"/>
- </return-property>
- <!-- Here we are remapping endDate. Notice that we can still use {emp.endDate} in the SQL. -->
- <return-property name="endDate" column="myEndDate"/>
- </return>
- <synchronize table="EMPLOYMENT"/>
- SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer},
- STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate},
- REGIONCODE as {emp.regionCode}, EMPID AS {emp.id}, VALUE, CURRENCY
- FROM EMPLOYMENT
- WHERE EMPLOYER = :id AND ENDDATE IS NULL
- ORDER BY STARTDATE ASC
- </sql-query>
-
- <sql-query name="simpleScalar" callable="true">
- <return-scalar column="name" type="string"/>
- <return-scalar column="value" type="long"/>
- { call HIBDB2TST.simpleScalar(:number) }
- </sql-query>
-
- <sql-query name="paramhandling" callable="true">
- <return-scalar column="value" type="long"/>
- <return-scalar column="value2" type="long"/>
- { call HIBDB2TST.paramHandling(?,?) }
- </sql-query>
-
- <sql-query name="paramhandling_mixed" callable="true">
- <return-scalar column="value" type="long" />
- <return-scalar column="value2" type="long" />
- { call HIBDB2TST.paramHandling(?,:second) }
- </sql-query>
-
- <sql-query name="selectAllEmployments" callable="true">
- <return alias="" class="Employment">
- <return-property name="employee" column="EMPLOYEE"/>
- <return-property name="employer" column="EMPLOYER"/>
- <return-property name="startDate" column="STARTDATE"/>
- <return-property name="endDate" column="ENDDATE"/>
- <return-property name="regionCode" column="REGIONCODE"/>
- <return-property name="id" column="EMPID"/>
- <return-property name="salary">
- <!-- as multi column properties are not supported via the
- {}-syntax, we need to provide an explicit column list for salary via <return-property> -->
- <return-column name="VALUE"/>
- <return-column name="CURRENCY"/>
- </return-property>
- </return>
- { call HIBDB2TST.selectAllEmployments() }
- </sql-query>
-
- <!-- DB2 seem to *require* users to specify explicit schema/location when executing a stored procedure *stupid* -->
- <database-object>
- <create>CREATE SCHEMA HIBDB2TST</create>
- <drop>DROP SCHEMA HIBDB2TST RESTRICT</drop>
- </database-object>
-
- <database-object>
- <create>
- CREATE PROCEDURE HIBDB2TST.selectAllEmployments ()
- P1: BEGIN
- DECLARE C1 CURSOR WITH RETURN FOR
- SELECT EMPLOYEE, EMPLOYER, STARTDATE, ENDDATE,
- REGIONCODE, EMPID, VALUE, CURRENCY
- FROM EMPLOYMENT;
- OPEN C1;
- END P1
- </create>
- <drop>
- DROP PROCEDURE HIBDB2TST.selectAllEmployments
- </drop>
- </database-object>
-
-
- <database-object>
- <create>
- CREATE PROCEDURE HIBDB2TST.paramHandling (IN j SMALLINT, IN i SMALLINT)
- P1: BEGIN
- DECLARE C1 CURSOR WITH RETURN FOR
- SELECT j as value, i as value2 from sysibm.sysdummy1;
- OPEN C1;
- END P1
- </create>
- <drop>
- DROP PROCEDURE HIBDB2TST.paramHandling
- </drop>
- </database-object>
-
- <database-object>
- <create>
- CREATE PROCEDURE HIBDB2TST.simpleScalar (IN j SMALLINT)
- P1: BEGIN
- DECLARE C1 CURSOR WITH RETURN FOR
- SELECT j as value, 'getAll' as name from sysibm.sysdummy1;
- OPEN C1;
- END P1
- </create>
- <drop>
- DROP PROCEDURE HIBDB2TST.simpleScalar
- </drop>
- </database-object>
-</hibernate-mapping>
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Db2SQLTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Db2SQLTest.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Db2SQLTest.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,32 +0,0 @@
-//$Id$
-package org.hibernate.test.sql;
-
-import junit.framework.Test;
-
-import org.hibernate.dialect.DB2Dialect;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
-
-/**
- * @author Max Rydahl Andersen
- */
-public class Db2SQLTest extends HandSQLTest {
-
- public Db2SQLTest(String str) {
- super(str);
- }
-
- public String[] getMappings() {
- return new String[] { "sql/Db2Employment.hbm.xml" };
- }
-
- public static Test suite() {
- return new FunctionalTestClassTestSuite( Db2SQLTest.class );
- }
-
- public boolean appliesTo(Dialect dialect) {
- return ( dialect instanceof DB2Dialect);
- }
-
-}
-
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Dimension.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Dimension.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Dimension.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,31 +0,0 @@
-package org.hibernate.test.sql;
-
-/**
- * Used to mimic some tests from the JPA testsuite...
- *
- * @author Steve Ebersole
- */
-public class Dimension {
- private Long id;
- private int length;
- private int width;
-
- public Dimension() {}
-
- public Dimension(int length, int width) {
- this.length = length;
- this.width = width;
- }
-
- public Long getId() {
- return id;
- }
-
- public int getLength() {
- return length;
- }
-
- public int getWidth() {
- return width;
- }
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Employment.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Employment.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Employment.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,107 +0,0 @@
-//$Id$
-package org.hibernate.test.sql;
-
-import java.util.Date;
-
-/**
- * @author Gavin King
- */
-public class Employment {
- private long employmentId;
- private Person employee;
- private Organization employer;
- private Date startDate;
- private Date endDate;
- private String regionCode;
- private MonetaryAmount salary;
-
- public Employment() {}
-
- public Employment(Person employee, Organization employer, String regionCode) {
- this.employee = employee;
- this.employer = employer;
- this.startDate = new Date();
- this.regionCode = regionCode;
- employer.getEmployments().add(this);
- }
- /**
- * @return Returns the employee.
- */
- public Person getEmployee() {
- return employee;
- }
- /**
- * @param employee The employee to set.
- */
- public void setEmployee(Person employee) {
- this.employee = employee;
- }
- /**
- * @return Returns the employer.
- */
- public Organization getEmployer() {
- return employer;
- }
- /**
- * @param employer The employer to set.
- */
- public void setEmployer(Organization employer) {
- this.employer = employer;
- }
- /**
- * @return Returns the endDate.
- */
- public Date getEndDate() {
- return endDate;
- }
- /**
- * @param endDate The endDate to set.
- */
- public void setEndDate(Date endDate) {
- this.endDate = endDate;
- }
- /**
- * @return Returns the id.
- */
- public long getEmploymentId() {
- return employmentId;
- }
- /**
- * @param id The id to set.
- */
- public void setEmploymentId(long id) {
- this.employmentId = id;
- }
- /**
- * @return Returns the startDate.
- */
- public Date getStartDate() {
- return startDate;
- }
- /**
- * @param startDate The startDate to set.
- */
- public void setStartDate(Date startDate) {
- this.startDate = startDate;
- }
- /**
- * @return Returns the regionCode.
- */
- public String getRegionCode() {
- return regionCode;
- }
- /**
- * @param regionCode The regionCode to set.
- */
- public void setRegionCode(String regionCode) {
- this.regionCode = regionCode;
- }
-
- public MonetaryAmount getSalary() {
- return salary;
- }
-
- public void setSalary(MonetaryAmount salary) {
- this.salary = salary;
- }
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/General.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/General.hbm.xml 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/General.hbm.xml 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,264 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<!--
-
- This mapping demonstrates the use of Hibernate with
- all-handwritten SQL!
-
- This version is for Sybase/mssql
--->
-
-<hibernate-mapping package="org.hibernate.test.sql" default-access="field">
-
- <class name="Organization" table="ORGANIZATION">
- <id name="id" unsaved-value="0" column="ORGID">
- <generator class="increment"/>
- </id>
- <property name="name" column="NAME" not-null="true"/>
- <set lazy="true" name="employments"
- inverse="true">
- <key column="EMPLOYER"/> <!-- only needed for DDL generation -->
- <one-to-many class="Employment"/>
- </set>
- </class>
-
- <class name="Person" table="PERSON">
- <id name="id" unsaved-value="0" column="PERID">
- <generator class="increment"/>
- </id>
- <property name="name" column="NAME" not-null="true"/>
-
- </class>
-
- <class name="Employment" table="EMPLOYMENT">
- <id name="employmentId" unsaved-value="0" column="EMPID">
- <generator class="increment"/>
- </id>
- <many-to-one name="employee" column="EMPLOYEE" not-null="true" update="false"/>
- <many-to-one name="employer" column="EMPLOYER" not-null="true" update="false"/>
- <property name="startDate" column="STARTDATE" not-null="false"/>
- <property name="endDate" column="ENDDATE" insert="false"/>
- <property name="regionCode" column="REGIONCODE" update="false"/>
- <property name="salary" type="org.hibernate.test.sql.MonetaryAmountUserType">
- <column name="VALUE" sql-type="float"/>
- <column name="CURRENCY"/>
- </property>
- </class>
-
- <class name="Order" table="TBL_ORDER">
- <composite-id name="orderId" class="Order$OrderId">
- <key-property name="orgid"/>
- <key-property name="ordernumber"/>
- </composite-id>
-
- <many-to-one name="product">
- <column name="PROD_ORGID"/>
- <column name="PROD_NO"/>
- </many-to-one>
- <many-to-one name="person"/>
- </class>
-
- <class name="Product">
- <composite-id name="productId" class="Product$ProductId">
- <key-property name="orgid"/>
- <key-property name="productnumber"/>
- </composite-id>
-
- <property name="name"/>
-
- <set name="orders" inverse="true">
- <key>
- <column name="PROD_ORGID"/>
- <column name="PROD_NO"/>
- </key>
- <one-to-many class="Order"/>
- </set>
- </class>
-
- <class name="Dimension">
- <id name="id" type="long">
- <generator class="increment"/>
- </id>
- <property name="length" column="d_len"/>
- <property name="width" column="d_width"/>
- </class>
-
- <class name="SpaceShip">
- <id name="id" type="integer">
- <generator class="increment"/>
- </id>
- <property name="name" column="fld_name"/>
- <property name="model" column="fld_model"/>
- <property name="speed" column="fld_speed"/>
- <component name="dimensions">
- <property name="length" column="fld_length"/>
- <property name="width" column="fld_width"/>
- </component>
- </class>
-
- <class name="Speech">
- <id name="id" type="integer">
- <generator class="increment"/>
- </id>
- <property name="name" column="name"/>
- <property name="length" column="flength"/>
- </class>
-
- <resultset name="org-emp-regionCode">
- <return-scalar column="regionCode" type="string"/>
- <return alias="org" class="Organization"/>
- <return-join alias="emp" property="org.employments"/>
- </resultset>
-
- <resultset name="org-emp-person">
- <return alias="org" class="Organization"/>
- <return-join alias="emp" property="org.employments"/>
- <return-join alias="pers" property="emp.employee"/>
- </resultset>
-
-
- <resultset name="org-description">
- <return alias="org" class="Organization"/>
- <return-join alias="emp" property="org.employments"/>
- </resultset>
-
- <resultset name="spaceship-vol">
- <return alias="sps" class="SpaceShip">
- <return-property name="id" column="id"/>
- <return-property name="name" column="name"/>
- <return-property name="model" column="model"/>
- <return-property name="speed" column="speed"/>
- <return-property name="dimensions.length" column="length"/>
- <return-property name="dimensions.width" column="width"/>
- </return>
- <return-scalar column="surface"/>
- <return-scalar column="volume"/>
- </resultset>
-
- <resultset name="speech">
- <return alias="sp" class="Speech">
- <return-property name="id" column="id"/>
- <return-property name="name" column="name"/>
- <return-property name="length" column="flength"/>
- </return>
- <return-scalar column="scalarName"/>
- </resultset>
-
- <sql-query name="spaceship" resultset-ref="spaceship-vol">
- select id as id,
- fld_name as name,
- fld_model as model,
- fld_speed as speed,
- fld_length as length,
- fld_width as width,
- fld_length * fld_width as surface,
- fld_length * fld_width *10 as volume
- from SpaceShip
- </sql-query>
-
- <sql-query name="orgNamesOnly">
- <return-scalar column="NAME" type="string"/>
- SELECT org.NAME FROM ORGANIZATION org
- </sql-query>
-
- <sql-query name="orgNamesAndOrgs">
- <return-scalar column="thename" type="string"/>
- <return alias="org" class="Organization"/>
- SELECT org.NAME AS thename, org.NAME AS {org.name}, org.ORGID AS {org.id}
- FROM ORGANIZATION org
- ORDER BY thename
- </sql-query>
-
- <sql-query name="orgsAndOrgNames">
- <return alias="org" class="Organization"/>
- <return-scalar column="thename" type="string"/>
- SELECT org.NAME AS thename, org.NAME AS {org.name}, org.ORGID AS {org.id}
- FROM ORGANIZATION org
- ORDER BY thename
- </sql-query>
-
- <sql-query name="orgIdsAndOrgNames">
- <return-scalar column="orgid" type="long"/>
- <return-scalar column="thename" type="string"/>
- SELECT NAME AS thename, ORGID AS orgid
- FROM ORGANIZATION
- ORDER BY thename
- </sql-query>
-
- <sql-query name="AllEmploymentAsMapped">
- <return class="Employment"/>
- SELECT * FROM EMPLOYMENT
- </sql-query>
-
- <sql-query name="EmploymentAndPerson">
- <return class="Employment"/>
- <return class="Person"/>
- SELECT * FROM EMPLOYMENT, PERSON
- </sql-query>
-
- <sql-query name="organizationEmploymentsExplicitAliases">
- <load-collection alias="empcol" role="Organization.employments"/>
- SELECT empcol.EMPLOYER as {empcol.key}, empcol.EMPID as {empcol.element}, {empcol.element.*}
- FROM EMPLOYMENT empcol
- WHERE EMPLOYER = :id
- ORDER BY STARTDATE ASC, EMPLOYEE ASC
- </sql-query>
-
- <sql-query name="organizationreturnproperty">
- <return alias="org" class="Organization">
- <return-property name="id" column="ORGID"/>
- <return-property name="name" column="NAME"/>
- </return>
- <return-join alias="emp" property="org.employments">
- <return-property name="key" column="EMPLOYER"/>
- <return-property name="element" column="EMPID"/>
- <return-property name="element.employee" column="EMPLOYEE"/>
- <return-property name="element.employer" column="EMPLOYER"/>
- <return-property name="element.startDate" column="XSTARTDATE"/>
- <return-property name="element.endDate" column="ENDDATE"/>
- <return-property name="element.regionCode" column="REGIONCODE"/>
- <return-property name="element.employmentId" column="EMPID"/>
- <return-property name="element.salary">
- <return-column name="VALUE"/>
- <return-column name="CURRENCY"/>
- </return-property>
- </return-join>
- SELECT org.ORGID as orgid,
- org.NAME as name,
- emp.EMPLOYER as employer,
- emp.EMPID as empid,
- emp.EMPLOYEE as employee,
- emp.EMPLOYER as employer,
- emp.STARTDATE as xstartDate,
- emp.ENDDATE as endDate,
- emp.REGIONCODE as regionCode,
- emp.VALUE as VALUE,
- emp.CURRENCY as CURRENCY
- FROM ORGANIZATION org
- LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER
- </sql-query>
-
-
- <sql-query name="organizationautodetect" resultset-ref="org-description">
- <!-- equal to "organizationpropertyreturn" but since no {} nor return-property are used hibernate will fallback to use the columns directly from the mapping -->
- <return alias="org" class="Organization"/>
- <return-join alias="emp" property="org.employments"/>
- SELECT org.ORGID as orgid,
- org.NAME as name,
- emp.EMPLOYER as employer,
- emp.EMPID as empid,
- emp.EMPLOYEE as employee,
- emp.EMPLOYER as employer,
- emp.STARTDATE as startDate,
- emp.ENDDATE as endDate,
- emp.REGIONCODE as regionCode,
- emp.VALUE as VALUE,
- emp.CURRENCY as CURRENCY
- FROM ORGANIZATION org
- LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER
- </sql-query>
-
-</hibernate-mapping>
\ No newline at end of file
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/GeneralTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/GeneralTest.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/GeneralTest.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,608 +0,0 @@
-package org.hibernate.test.sql;
-
-import java.io.Serializable;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.Test;
-
-import org.hibernate.Hibernate;
-import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
-import org.hibernate.junit.functional.FunctionalTestCase;
-import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
-import org.hibernate.transform.DistinctRootEntityResultTransformer;
-import org.hibernate.transform.Transformers;
-import org.hibernate.transform.AliasToEntityMapResultTransformer;
-
-/**
- * @author Steve Ebersole
- */
-public class GeneralTest extends FunctionalTestCase {
-
- public GeneralTest(String x) {
- super( x );
- }
-
- public String[] getMappings() {
- return new String[] { "sql/General.hbm.xml" };
- }
-
- public void configure(Configuration cfg) {
- super.configure( cfg );
- cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
- }
-
- public static Test suite() {
- return new FunctionalTestClassTestSuite( GeneralTest.class );
- }
-
- protected String getOrganizationFetchJoinEmploymentSQL() {
- return "SELECT org.ORGID as {org.id}, " +
- " org.NAME as {org.name}, " +
- " emp.EMPLOYER as {emp.key}, " +
- " emp.EMPID as {emp.element}, " +
- " {emp.element.*} " +
- "FROM ORGANIZATION org " +
- " LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER";
- }
-
- protected String getOrganizationJoinEmploymentSQL() {
- return "SELECT org.ORGID as {org.id}, " +
- " org.NAME as {org.name}, " +
- " {emp.*} " +
- "FROM ORGANIZATION org " +
- " LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER";
- }
-
- protected String getEmploymentSQL() {
- return "SELECT * FROM EMPLOYMENT";
- }
-
- protected String getEmploymentSQLMixedScalarEntity() {
- return "SELECT e.*, e.employer as employerid FROM EMPLOYMENT e" ;
- }
-
- protected String getOrgEmpRegionSQL() {
- return "select {org.*}, {emp.*}, emp.REGIONCODE " +
- "from ORGANIZATION org " +
- " left outer join EMPLOYMENT emp on org.ORGID = emp.EMPLOYER";
- }
-
- protected String getOrgEmpPersonSQL() {
- return "select {org.*}, {emp.*}, {pers.*} " +
- "from ORGANIZATION org " +
- " join EMPLOYMENT emp on org.ORGID = emp.EMPLOYER " +
- " join PERSON pers on pers.PERID = emp.EMPLOYEE ";
- }
-
- public void testFailOnNoAddEntityOrScalar() {
- // Note: this passes, but for the wrong reason.
- // there is actually an exception thrown, but it is the database
- // throwing a sql exception because the SQL gets passed
- // "un-processed"...
- Session s = openSession();
- try {
- String sql = "select {org.*} " +
- "from organization org";
- s.createSQLQuery( sql ).list();
- fail( "Should throw an exception since no addEntity nor addScalar has been performed." );
- }
- catch( HibernateException he) {
- // expected behavior
- }
- finally {
- s.close();
- }
- }
-
- public void testManualSynchronization() {
- Session s = openSession();
- s.beginTransaction();
-
- sfi().getStatistics().clear();
-
- // create an Organization...
- Organization jboss = new Organization( "JBoss" );
- s.persist( jboss );
-
- // now query on Employment, this should not cause an auto-flush
- s.createSQLQuery( getEmploymentSQL() ).list();
- assertEquals( 0, sfi().getStatistics().getEntityInsertCount() );
-
- // now try to query on Employment but this time add Organization as a synchronized query space...
- s.createSQLQuery( getEmploymentSQL() ).addSynchronizedEntityClass( Organization.class ).list();
- assertEquals( 1, sfi().getStatistics().getEntityInsertCount() );
-
- // clean up
- s.delete( jboss );
- s.getTransaction().commit();
- s.close();
- }
-
- public void testSQLQueryInterface() {
- 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);
-
- List l = s.createSQLQuery( getOrgEmpRegionSQL() )
- .addEntity("org", Organization.class)
- .addJoin("emp", "org.employments")
- .addScalar("regionCode", Hibernate.STRING)
- .list();
- assertEquals( 2, l.size() );
-
- l = s.createSQLQuery( getOrgEmpPersonSQL() )
- .addEntity("org", Organization.class)
- .addJoin("emp", "org.employments")
- .addJoin("pers", "emp.employee")
- .list();
- assertEquals( l.size(), 1 );
-
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
-
- l = s.createSQLQuery( "select {org.*}, {emp.*} " +
- "from ORGANIZATION org " +
- " left outer join EMPLOYMENT emp on org.ORGID = emp.EMPLOYER, ORGANIZATION org2" )
- .addEntity("org", Organization.class)
- .addJoin("emp", "org.employments")
- .setResultTransformer(new DistinctRootEntityResultTransformer())
- .list();
- assertEquals( l.size(), 2 );
-
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
-
- s.delete(emp);
- s.delete(gavin);
- s.delete(ifa);
- s.delete(jboss);
-
- t.commit();
- s.close();
- }
-
- public void testResultSetMappingDefinition() {
- 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);
-
- List l = s.createSQLQuery( getOrgEmpRegionSQL() )
- .setResultSetMapping( "org-emp-regionCode" )
- .list();
- assertEquals( l.size(), 2 );
-
- l = s.createSQLQuery( getOrgEmpPersonSQL() )
- .setResultSetMapping( "org-emp-person" )
- .list();
- assertEquals( l.size(), 1 );
-
- s.delete(emp);
- s.delete(gavin);
- s.delete(ifa);
- s.delete(jboss);
-
- t.commit();
- s.close();
- }
-
- public void testScalarValues() throws Exception {
- Session s = openSession();
- Transaction t = s.beginTransaction();
-
- Organization ifa = new Organization( "IFA" );
- Organization jboss = new Organization( "JBoss" );
-
- Serializable idIfa = s.save( ifa );
- Serializable idJBoss = s.save( jboss );
-
- s.flush();
-
- List result = s.getNamedQuery( "orgNamesOnly" ).list();
- assertTrue( result.contains( "IFA" ) );
- assertTrue( result.contains( "JBoss" ) );
-
- result = s.getNamedQuery( "orgNamesOnly" ).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
- Map m = (Map) result.get(0);
- assertEquals( 2, result.size() );
- assertEquals( 1, m.size() );
- assertTrue( m.containsKey("NAME") );
-
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
-
- Iterator iter = s.getNamedQuery( "orgNamesAndOrgs" ).list().iterator();
- Object[] o = ( Object[] ) iter.next();
- assertEquals( o[0], "IFA" );
- assertEquals( ( ( Organization ) o[1] ).getName(), "IFA" );
- o = ( Object[] ) iter.next();
- assertEquals( o[0], "JBoss" );
- assertEquals( ( ( Organization ) o[1] ).getName(), "JBoss" );
-
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
-
- // test that the ordering of the results is truly based on the order in which they were defined
- iter = s.getNamedQuery( "orgsAndOrgNames" ).list().iterator();
- Object[] row = ( Object[] ) iter.next();
- assertEquals( "expecting non-scalar result first", Organization.class, row[0].getClass() );
- assertEquals( "expecting scalar result second", String.class, row[1].getClass() );
- assertEquals( ( ( Organization ) row[0] ).getName(), "IFA" );
- assertEquals( row[1], "IFA" );
- row = ( Object[] ) iter.next();
- assertEquals( "expecting non-scalar result first", Organization.class, row[0].getClass() );
- assertEquals( "expecting scalar result second", String.class, row[1].getClass() );
- assertEquals( ( ( Organization ) row[0] ).getName(), "JBoss" );
- assertEquals( row[1], "JBoss" );
- assertFalse( iter.hasNext() );
-
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
-
- iter = s.getNamedQuery( "orgIdsAndOrgNames" ).list().iterator();
- o = ( Object[] ) iter.next();
- assertEquals( o[1], "IFA" );
- assertEquals( o[0], idIfa );
- o = ( Object[] ) iter.next();
- assertEquals( o[1], "JBoss" );
- assertEquals( o[0], idJBoss );
-
- s.delete( ifa );
- s.delete( jboss );
- t.commit();
- s.close();
- }
-
- public void testMappedAliasStrategy() {
- 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");
- Serializable orgId = s.save(jboss);
- Serializable orgId2 = s.save(ifa);
- s.save(gavin);
- s.save(emp);
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- Query namedQuery = s.getNamedQuery("AllEmploymentAsMapped");
- List list = namedQuery.list();
- assertEquals(1,list.size());
- Employment emp2 = (Employment) list.get(0);
- assertEquals(emp2.getEmploymentId(), emp.getEmploymentId() );
- assertEquals(emp2.getStartDate().getDate(), emp.getStartDate().getDate() );
- assertEquals(emp2.getEndDate(), emp.getEndDate() );
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- Query sqlQuery = s.getNamedQuery("EmploymentAndPerson");
- sqlQuery.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
- list = sqlQuery.list();
- assertEquals(1,list.size() );
- Object res = list.get(0);
- assertClassAssignability(res.getClass(),Map.class);
- Map m = (Map) res;
- assertEquals(2,m.size());
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- sqlQuery = s.getNamedQuery("organizationreturnproperty");
- sqlQuery.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
- list = sqlQuery.list();
- assertEquals(2,list.size() );
- m = (Map) list.get(0);
- assertTrue(m.containsKey("org"));
- assertClassAssignability(m.get("org").getClass(), Organization.class);
- assertTrue(m.containsKey("emp"));
- assertClassAssignability(m.get("emp").getClass(), Employment.class);
- assertEquals(2, m.size());
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- namedQuery = s.getNamedQuery("EmploymentAndPerson");
- list = namedQuery.list();
- assertEquals(1,list.size() );
- Object[] objs = (Object[]) list.get(0);
- assertEquals(2, objs.length);
- emp2 = (Employment) objs[0];
- gavin = (Person) objs[1];
- s.delete(emp2);
- s.delete(jboss);
- s.delete(gavin);
- s.delete(ifa);
- t.commit();
- s.close();
- }
-
- /* test for native sql composite id joins which has never been implemented */
- public void testCompositeIdJoinsFailureExpected() {
- Session s = openSession();
- Transaction t = s.beginTransaction();
- Person person = new Person();
- person.setName( "Noob" );
-
- Product product = new Product();
- product.setProductId( new Product.ProductId() );
- product.getProductId().setOrgid( "x" );
- product.getProductId().setProductnumber( "1234" );
- product.setName( "Hibernate 3" );
-
- Order order = new Order();
- order.setOrderId( new Order.OrderId() );
- order.getOrderId().setOrdernumber( "1" );
- order.getOrderId().setOrgid( "y" );
-
- product.getOrders().add( order );
- order.setProduct( product );
- order.setPerson( person );
-
- s.save( product );
- s.save( order);
- s.save( person );
-
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- Product p = (Product) s.createQuery( "from Product p join fetch p.orders" ).list().get(0);
- assertTrue(Hibernate.isInitialized( p.getOrders()));
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- Object[] o = (Object[]) s.createSQLQuery( "select\r\n" +
- " product.orgid as {product.id.orgid}," +
- " product.productnumber as {product.id.productnumber}," +
- " {prod_orders}.orgid as orgid3_1_,\r\n" +
- " {prod_orders}.ordernumber as ordernum2_3_1_,\r\n" +
- " product.name as {product.name}," +
- " {prod_orders.element.*}" +
- /*" orders.PROD_NO as PROD4_3_1_,\r\n" +
- " orders.person as person3_1_,\r\n" +
- " orders.PROD_ORGID as PROD3_0__,\r\n" +
- " orders.PROD_NO as PROD4_0__,\r\n" +
- " orders.orgid as orgid0__,\r\n" +
- " orders.ordernumber as ordernum2_0__ \r\n" +*/
- " from\r\n" +
- " Product product \r\n" +
- " inner join\r\n" +
- " TBL_ORDER {prod_orders} \r\n" +
- " on product.orgid={prod_orders}.PROD_ORGID \r\n" +
- " and product.productnumber={prod_orders}.PROD_NO" )
- .addEntity( "product", Product.class )
- .addJoin( "prod_orders", "product.orders" )
- .list().get(0);
-
- p = (Product) o[0];
- assertTrue(Hibernate.isInitialized( p.getOrders() ));
- assertNotNull(p.getOrders().iterator().next());
- t.commit();
- s.close();
- }
-
- public void testAutoDetectAliasing() {
- 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");
- Serializable orgId = s.save(jboss);
- Serializable orgId2 = s.save(ifa);
- s.save(gavin);
- s.save(emp);
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- List list = s.createSQLQuery( getEmploymentSQL() )
- .addEntity( Employment.class.getName() )
- .list();
- assertEquals( 1,list.size() );
-
- Employment emp2 = (Employment) list.get(0);
- assertEquals(emp2.getEmploymentId(), emp.getEmploymentId() );
- assertEquals(emp2.getStartDate().getDate(), emp.getStartDate().getDate() );
- assertEquals(emp2.getEndDate(), emp.getEndDate() );
-
- s.clear();
-
- list = s.createSQLQuery( getEmploymentSQL() )
- .addEntity( Employment.class.getName() )
- .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
- .list();
- assertEquals( 1,list.size() );
- Map m = (Map) list.get(0);
- assertTrue(m.containsKey("Employment"));
- assertEquals(1,m.size());
-
- list = s.createSQLQuery(getEmploymentSQL()).list();
- assertEquals(1, list.size());
- Object[] o = (Object[]) list.get(0);
- assertEquals(8, o.length);
-
- list = s.createSQLQuery( getEmploymentSQL() ).setResultTransformer( new UpperCasedAliasToEntityMapResultTransformer() ).list();
- assertEquals(1, list.size());
- m = (Map) list.get(0);
- assertTrue(m.containsKey("EMPID"));
- assertTrue(m.containsKey("VALUE"));
- assertTrue(m.containsKey("ENDDATE"));
- assertEquals(8, m.size());
-
- list = s.createSQLQuery( getEmploymentSQLMixedScalarEntity() ).addScalar( "employerid" ).addEntity( Employment.class ).list();
- assertEquals(1, list.size());
- o = (Object[]) list.get(0);
- assertEquals(2, o.length);
- assertClassAssignability( o[0].getClass(), Number.class);
- assertClassAssignability( o[1].getClass(), Employment.class);
-
-
-
- Query queryWithCollection = s.getNamedQuery("organizationEmploymentsExplicitAliases");
- queryWithCollection.setLong("id", jboss.getId() );
- list = queryWithCollection.list();
- assertEquals(list.size(),1);
-
- s.clear();
-
- list = s.createSQLQuery( getOrganizationJoinEmploymentSQL() )
- .addEntity( "org", Organization.class )
- .addJoin( "emp", "org.employments" )
- .list();
- assertEquals( 2,list.size() );
-
- s.clear();
-
- list = s.createSQLQuery( getOrganizationFetchJoinEmploymentSQL() )
- .addEntity( "org", Organization.class )
- .addJoin( "emp", "org.employments" )
- .list();
- assertEquals( 2,list.size() );
-
- s.clear();
-
- // TODO : why twice?
- s.getNamedQuery( "organizationreturnproperty" ).list();
- list = s.getNamedQuery( "organizationreturnproperty" ).list();
- assertEquals( 2,list.size() );
-
- s.clear();
-
- list = s.getNamedQuery( "organizationautodetect" ).list();
- assertEquals( 2,list.size() );
-
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- s.delete(emp2);
-
- s.delete(jboss);
- s.delete(gavin);
- s.delete(ifa);
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- Dimension dim = new Dimension( 3, Integer.MAX_VALUE );
- s.save( dim );
- list = s.createSQLQuery( "select d_len * d_width as surface, d_len * d_width * 10 as volume from Dimension" ).list();
- s.delete( dim );
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- SpaceShip enterprise = new SpaceShip();
- enterprise.setModel( "USS" );
- enterprise.setName( "Entreprise" );
- enterprise.setSpeed( 50d );
- Dimension d = new Dimension(45, 10);
- enterprise.setDimensions( d );
- s.save( enterprise );
- Object[] result = (Object[]) s.getNamedQuery( "spaceship" ).uniqueResult();
- enterprise = (SpaceShip) result[0];
- assertTrue(50d == enterprise.getSpeed() );
- assertTrue( 450d == extractDoubleValue( result[1] ) );
- assertTrue( 4500d == extractDoubleValue( result[2] ) );
- s.delete( enterprise );
- t.commit();
- s.close();
-
- }
-
- public void testMixAndMatchEntityScalar() {
- Session s = openSession();
- Transaction t = s.beginTransaction();
- Speech speech = new Speech();
- speech.setLength( new Double( 23d ) );
- speech.setName( "Mine" );
- s.persist( speech );
- s.flush();
- s.clear();
-
- List l = s.createSQLQuery( "select name, id, flength, name as scalarName from Speech" )
- .setResultSetMapping( "speech" )
- .list();
- assertEquals( l.size(), 1 );
-
- t.rollback();
- s.close();
- }
-
- private double extractDoubleValue(Object value) {
- if ( value instanceof BigInteger ) {
- return ( ( BigInteger ) value ).doubleValue();
- }
- else if ( value instanceof BigDecimal ) {
- return ( ( BigDecimal ) value ).doubleValue();
- }
- else {
- return Double.valueOf( value.toString() ).doubleValue();
- }
- }
-
- private static class UpperCasedAliasToEntityMapResultTransformer extends AliasToEntityMapResultTransformer {
- public Object transformTuple(Object[] tuple, String[] aliases) {
- String[] ucAliases = new String[aliases.length];
- for ( int i = 0; i < aliases.length; i++ ) {
- ucAliases[i] = aliases[i].toUpperCase();
- }
- return super.transformTuple( tuple, ucAliases );
- }
- }
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/HandSQLTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/HandSQLTest.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/HandSQLTest.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,150 +0,0 @@
-package org.hibernate.test.sql;
-
-import java.io.Serializable;
-import java.sql.SQLException;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-
-import org.hibernate.HibernateException;
-import org.hibernate.LockMode;
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.junit.functional.DatabaseSpecificFunctionalTestCase;
-
-/**
- * @author Steve Ebersole
- */
-public abstract class HandSQLTest extends DatabaseSpecificFunctionalTestCase {
-
- public HandSQLTest(String name) {
- super( name );
- }
-
- public String getCacheConcurrencyStrategy() {
- return null;
- }
-
- public void testHandSQL() {
- 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" );
- Serializable orgId = s.save( jboss );
- s.save( ifa );
- s.save( gavin );
- s.save( emp );
- t.commit();
-
- t = s.beginTransaction();
- Person christian = new Person( "Christian" );
- s.save( christian );
- Employment emp2 = new Employment( christian, jboss, "EU" );
- s.save( emp2 );
- t.commit();
- s.close();
-
- getSessions().evict( Organization.class );
- getSessions().evict( Person.class );
- getSessions().evict( Employment.class );
-
- s = openSession();
- t = s.beginTransaction();
- jboss = ( Organization ) s.get( Organization.class, orgId );
- assertEquals( jboss.getEmployments().size(), 2 );
- emp = ( Employment ) jboss.getEmployments().iterator().next();
- gavin = emp.getEmployee();
- assertEquals( gavin.getName(), "GAVIN" );
- assertEquals( s.getCurrentLockMode( gavin ), LockMode.UPGRADE );
- emp.setEndDate( new Date() );
- Employment emp3 = new Employment( gavin, jboss, "US" );
- s.save( emp3 );
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- Iterator iter = s.getNamedQuery( "allOrganizationsWithEmployees" ).list().iterator();
- assertTrue( iter.hasNext() );
- Organization o = ( Organization ) iter.next();
- assertEquals( o.getEmployments().size(), 3 );
- Iterator iter2 = o.getEmployments().iterator();
- while ( iter2.hasNext() ) {
- Employment e = ( Employment ) iter2.next();
- s.delete( e );
- }
- iter2 = o.getEmployments().iterator();
- while ( iter2.hasNext() ) {
- Employment e = ( Employment ) iter2.next();
- s.delete( e.getEmployee() );
- }
- s.delete( o );
- assertFalse( iter.hasNext() );
- s.delete( ifa );
- t.commit();
- s.close();
- }
-
-
- 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();
- }
-
-
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MSSQLEmployment.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MSSQLEmployment.hbm.xml 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MSSQLEmployment.hbm.xml 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,221 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<!--
-
- This mapping demonstrates the use of Hibernate with
- all-handwritten SQL!
-
- This version is for Sybase/mssql
--->
-<hibernate-mapping
- package="org.hibernate.test.sql"
- default-access="field">
-
- <class name="Organization" table="ORGANIZATION">
- <id name="id" unsaved-value="0" column="ORGID">
- <generator class="increment"/>
- </id>
- <property name="name" not-null="true" column="NAME"/>
- <set name="employments"
- inverse="true"
- order-by="DUMMY">
- <key column="EMPLOYER"/> <!-- only needed for DDL generation -->
- <one-to-many class="Employment"/>
- <loader query-ref="organizationEmployments"/>
- </set>
- <!-- query-list name="currentEmployments"
- query-ref="organizationCurrentEmployments"-->
- <loader query-ref="organization"/>
- <sql-insert>INSERT INTO ORGANIZATION (NAME, ORGID) VALUES ( UPPER(?), ? )</sql-insert>
- <sql-update>UPDATE ORGANIZATION SET NAME=UPPER(?) WHERE ORGID=?</sql-update>
- <sql-delete>DELETE FROM ORGANIZATION WHERE ORGID=?</sql-delete>
- </class>
-
- <class name="Person" table="PERSON">
- <id name="id" unsaved-value="0" column="PERID">
- <generator class="increment"/>
- </id>
- <property name="name" not-null="true" column="NAME"/>
- <loader query-ref="person"/>
- <sql-insert>INSERT INTO PERSON (NAME, PERID) VALUES ( UPPER(?), ? )</sql-insert>
- <sql-update>UPDATE PERSON SET NAME=UPPER(?) WHERE PERID=?</sql-update>
- <sql-delete>DELETE FROM PERSON WHERE PERID=?</sql-delete>
- </class>
-
- <class name="Employment" table="EMPLOYMENT">
- <id name="employmentId" unsaved-value="0" column="EMPID">
- <generator class="increment"/>
- </id>
- <many-to-one name="employee" column="EMPLOYEE" not-null="true" update="false"/>
- <many-to-one name="employer" column="EMPLOYER" not-null="true" update="false"/>
- <property name="startDate" column="STARTDATE" not-null="true" update="false" insert="false"/>
- <property name="endDate" column="ENDDATE" insert="false"/>
- <property name="regionCode" column="REGIONCODE" update="false"/>
- <property name="salary" type="org.hibernate.test.sql.MonetaryAmountUserType">
- <column name="VALUE" sql-type="float"/>
- <column name="CURRENCY"/>
- </property>
- <loader query-ref="employment"/>
- <sql-insert>
- INSERT INTO EMPLOYMENT
- (EMPLOYEE, EMPLOYER, STARTDATE, REGIONCODE, VALUE, CURRENCY, EMPID)
- VALUES (?, ?, getdate(), UPPER(?), ?, ?, ?)
- </sql-insert>
- <sql-update>UPDATE EMPLOYMENT SET ENDDATE=?, VALUE=?, CURRENCY=? WHERE EMPID=?</sql-update>
- <sql-delete>DELETE FROM EMPLOYMENT WHERE EMPID=?</sql-delete>
- </class>
-
- <resultset name="org-emp-regionCode">
- <return-scalar column="regionCode" type="string"/>
- <return alias="org" class="Organization"/>
- <return-join alias="emp" property="org.employments"/>
- </resultset>
-
- <resultset name="org-emp-person">
- <return alias="org" class="Organization"/>
- <return-join alias="emp" property="org.employments"/>
- <return-join alias="pers" property="emp.employee"/>
- </resultset>
-
- <sql-query name="person">
- <return alias="p" class="Person" lock-mode="upgrade"/>
- SELECT NAME AS {p.name}, PERID AS {p.id} FROM PERSON WHERE PERID=? /*FOR UPDATE*/
- </sql-query>
-
- <sql-query name="organization">
- <return alias="org" class="Organization"/>
- <return-join alias="emp" property="org.employments"/>
- SELECT {org.*}, {emp.*}
- FROM ORGANIZATION org
- LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER
- WHERE org.ORGID=?
- </sql-query>
-
-
- <!--sql-query name="organization">
- <return alias="org" class="Organization"/>
- SELECT NAME AS {org.name}, ORGID AS {org.id} FROM ORGANIZATION
- WHERE ORGID=?
- </sql-query-->
-
- <sql-query name="allOrganizationsWithEmployees" flush-mode="never">
- <return alias="org" class="Organization"/>
- SELECT DISTINCT org.NAME AS {org.name}, org.ORGID AS {org.id}
- FROM ORGANIZATION org
- INNER JOIN EMPLOYMENT e ON e.EMPLOYER = org.ORGID
- </sql-query>
-
-
-
-
-
- <sql-query name="employment">
- <return alias="emp" class="Employment"/>
- SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer},
- STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate},
- REGIONCODE as {emp.regionCode}, EMPID AS {emp.id}
- FROM EMPLOYMENT
- WHERE EMPID = ?
- </sql-query>
-
- <sql-query name="organizationEmployments">
- <load-collection alias="empcol" role="Organization.employments"/>
- SELECT {empcol.*}
- FROM EMPLOYMENT empcol
- WHERE EMPLOYER = :id
- ORDER BY STARTDATE ASC, EMPLOYEE ASC
- </sql-query>
-
-
- <sql-query name="organizationCurrentEmployments">
- <return alias="emp" class="Employment">
- <return-property name="salary">
- <!-- as multi column properties are not supported via the
- {}-syntax, we need to provide an explicit column list for salary via <return-property> -->
- <return-column name="VALUE"/>
- <return-column name="CURRENCY"/>
- </return-property>
- <!-- Here we are remapping endDate. Notice that we can still use {emp.endDate} in the SQL. -->
- <return-property name="endDate" column="myEndDate"/>
- </return>
- <synchronize table="EMPLOYMENT"/>
- SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer},
- STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate},
- REGIONCODE as {emp.regionCode}, EMPID AS {emp.id}, VALUE, CURRENCY
- FROM EMPLOYMENT
- WHERE EMPLOYER = :id AND ENDDATE IS NULL
- ORDER BY STARTDATE ASC
- </sql-query>
-
- <sql-query name="simpleScalar" callable="true">
- <return-scalar column="name" type="string"/>
- <return-scalar column="value" type="long"/>
- { call simpleScalar(:number) }
- </sql-query>
-
- <sql-query name="paramhandling" callable="true">
- <return-scalar column="value" type="long"/>
- <return-scalar column="value2" type="long"/>
- { call paramHandling(?,?) }
- </sql-query>
-
- <sql-query name="paramhandling_mixed" callable="true">
- <return-scalar column="value" type="long" />
- <return-scalar column="value2" type="long" />
- { call paramHandling(?,:second) }
- </sql-query>
-
- <sql-query name="selectAllEmployments" callable="true">
- <return alias="" class="Employment">
- <return-property name="employee" column="EMPLOYEE"/>
- <return-property name="employer" column="EMPLOYER"/>
- <return-property name="startDate" column="STARTDATE"/>
- <return-property name="endDate" column="ENDDATE"/>
- <return-property name="regionCode" column="REGIONCODE"/>
- <return-property name="id" column="EMPID"/>
- <return-property name="salary">
- <!-- as multi column properties are not supported via the
- {}-syntax, we need to provide an explicit column list for salary via <return-property> -->
- <return-column name="VALUE"/>
- <return-column name="CURRENCY"/>
- </return-property>
- </return>
- { call selectAllEmployments() }
- </sql-query>
-
- <database-object>
- <create>
- CREATE PROCEDURE selectAllEmployments AS
- SELECT EMPLOYEE, EMPLOYER, STARTDATE, ENDDATE,
- REGIONCODE, EMPID, VALUE, CURRENCY
- FROM EMPLOYMENT
- </create>
- <drop>
- DROP PROCEDURE selectAllEmployments
- </drop>
- </database-object>
-
- <database-object>
- <create>
- CREATE PROCEDURE paramHandling @j int, @i int AS
- SELECT @j as value, @i as value2
- </create>
- <drop>
- DROP PROCEDURE paramHandling
- </drop>
- </database-object>
-
- <database-object>
- <create>
- CREATE PROCEDURE simpleScalar @number int AS
- SELECT @number as value, 'getAll' as name
- </create>
- <drop>
- DROP PROCEDURE simpleScalar
- </drop>
- </database-object>
-
-</hibernate-mapping>
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MSSQLTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MSSQLTest.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MSSQLTest.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,31 +0,0 @@
-//$Id$
-package org.hibernate.test.sql;
-
-import junit.framework.Test;
-
-import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.SybaseDialect;
-import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
-
-/**
- * @author Gavin King
- */
-public class MSSQLTest extends HandSQLTest {
-
- public MSSQLTest(String str) {
- super( str );
- }
-
- public String[] getMappings() {
- return new String[] {"sql/MSSQLEmployment.hbm.xml"};
- }
-
- public static Test suite() {
- return new FunctionalTestClassTestSuite( MSSQLTest.class );
- }
-
- public boolean appliesTo(Dialect dialect) {
- return ( dialect instanceof SybaseDialect );
- }
-}
-
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MonetaryAmount.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MonetaryAmount.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MonetaryAmount.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,78 +0,0 @@
-package org.hibernate.test.sql;
-
-import java.math.BigDecimal;
-import java.util.Currency;
-import java.io.Serializable;
-
-/**
- * Represents a monetary amount as value and currency.
- *
- * @author Gavin King <gavin at hibernate.org>
- * @author Christian Bauer <christian at hibernate.org>
- */
-public class MonetaryAmount implements Serializable {
-
- private final BigDecimal value;
- private final Currency currency;
-
- public MonetaryAmount(BigDecimal value, Currency currency) {
- this.value = value;
- this.currency = currency;
- }
-
- public Currency getCurrency() {
- return currency;
- }
-
- public BigDecimal getValue() {
- return value;
- }
-
- // ********************** Common Methods ********************** //
-
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof MonetaryAmount)) return false;
-
- final MonetaryAmount monetaryAmount = (MonetaryAmount) o;
-
- if (!currency.equals(monetaryAmount.currency)) return false;
- if (!value.equals(monetaryAmount.value)) return false;
-
- return true;
- }
-
- public int hashCode() {
- int result;
- result = value.hashCode();
- result = 29 * result + currency.hashCode();
- return result;
- }
-
- public String toString() {
- return "Value: '" + getValue() + "', " +
- "Currency: '" + getCurrency() + "'";
- }
-
- public int compareTo(Object o) {
- if (o instanceof MonetaryAmount) {
- // TODO: This would actually require some currency conversion magic
- return this.getValue().compareTo(((MonetaryAmount) o).getValue());
- }
- return 0;
- }
-
- // ********************** Business Methods ********************** //
-
- public static MonetaryAmount fromString(String amount, String currencyCode) {
- return new MonetaryAmount(new BigDecimal(amount),
- Currency.getInstance(currencyCode));
- }
-
- public static MonetaryAmount convert(MonetaryAmount amount,
- Currency toConcurrency) {
- // TODO: This requires some conversion magic and is therefore broken
- return new MonetaryAmount(amount.getValue(), toConcurrency);
- }
-
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MonetaryAmountUserType.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MonetaryAmountUserType.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MonetaryAmountUserType.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,85 +0,0 @@
-package org.hibernate.test.sql;
-
-import java.io.Serializable;
-import java.math.BigDecimal;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.util.Currency;
-
-import org.hibernate.HibernateException;
-import org.hibernate.usertype.UserType;
-
-/**
- * This is a simple Hibernate custom mapping type for MonetaryAmount value types.
- * <p>
- *
- * @author Max & Christian
- */
-public class MonetaryAmountUserType
- implements UserType {
-
- private static final int[] SQL_TYPES = {Types.NUMERIC, Types.VARCHAR };
-
- public int[] sqlTypes() { return SQL_TYPES; }
-
- public Class returnedClass() { return MonetaryAmount.class; }
-
- public boolean isMutable() { return false; }
-
- public Object deepCopy(Object value) {
- return value; // MonetaryAmount is immutable
- }
-
- public boolean equals(Object x, Object y) {
- if (x == y) return true;
- if (x == null || y == null) return false;
- return x.equals(y);
- }
-
- public Object nullSafeGet(ResultSet resultSet,
- String[] names,
- Object owner)
- throws HibernateException, SQLException {
-
- BigDecimal value = resultSet.getBigDecimal(names[0]);
- if (resultSet.wasNull()) return null;
- String cur = resultSet.getString(names[1]);
- Currency userCurrency = Currency.getInstance(cur);
-
- return new MonetaryAmount(value, userCurrency);
- }
-
- public void nullSafeSet(PreparedStatement statement,
- Object value,
- int index)
- throws HibernateException, SQLException {
-
- if (value == null) {
- statement.setNull(index, Types.NUMERIC);
- statement.setNull(index+1, Types.VARCHAR);
- } else {
- MonetaryAmount currency = (MonetaryAmount)value;
- statement.setBigDecimal(index, currency.getValue());
- statement.setString(index+1, currency.getCurrency().getCurrencyCode());
- }
- }
-
- public Serializable disassemble(Object value) throws HibernateException {
- return (Serializable) value;
- }
-
- public Object assemble(Serializable cached, Object owner) throws HibernateException {
- return cached;
- }
-
- public Object replace(Object original, Object target, Object owner)
- throws HibernateException {
- return original;
- }
-
- public int hashCode(Object x) throws HibernateException {
- return x.hashCode();
- }
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MySQLEmployment.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MySQLEmployment.hbm.xml 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MySQLEmployment.hbm.xml 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,220 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<!--
-
- This mapping demonstrates the use of Hibernate with
- all-handwritten SQL!
-
- This version is for MySQL
--->
-
-<hibernate-mapping
- package="org.hibernate.test.sql"
- default-access="field">
-
- <class name="Organization">
- <id name="id" unsaved-value="0" column="orgid">
- <generator class="increment"/>
- </id>
- <property name="name" not-null="true"/>
- <set name="employments"
- inverse="true"
- order-by="DUMMY">
- <key column="employer"/> <!-- only needed for DDL generation -->
- <one-to-many class="Employment"/>
- <loader query-ref="organizationEmployments"/>
- </set>
- <!-- query-list name="currentEmployments"
- query-ref="organizationCurrentEmployments"-->
- <loader query-ref="organization"/>
- <sql-insert>INSERT INTO ORGANIZATION (NAME, ORGID) VALUES ( UPPER(?), ? )</sql-insert>
- <sql-update>UPDATE ORGANIZATION SET NAME=UPPER(?) WHERE ORGID=?</sql-update>
- <sql-delete>DELETE FROM ORGANIZATION WHERE ORGID=?</sql-delete>
- </class>
-
- <class name="Person">
- <id name="id" unsaved-value="0" column="perid">
- <generator class="increment"/>
- </id>
- <property name="name" not-null="true"/>
- <loader query-ref="person"/>
- <sql-insert>INSERT INTO PERSON (NAME, PERID) VALUES ( UPPER(?), ? )</sql-insert>
- <sql-update>UPDATE PERSON SET NAME=UPPER(?) WHERE PERID=?</sql-update>
- <sql-delete>DELETE FROM PERSON WHERE PERID=?</sql-delete>
- </class>
-
- <class name="Employment">
- <id name="employmentId" unsaved-value="0" column="empid">
- <generator class="increment"/>
- </id>
- <many-to-one name="employee" not-null="true" update="false"/>
- <many-to-one name="employer" not-null="true" update="false"/>
- <property name="startDate" not-null="true" update="false" insert="false"/>
- <property name="endDate" insert="false"/>
- <property name="regionCode" update="false"/>
- <property name="salary" type="org.hibernate.test.sql.MonetaryAmountUserType">
- <column name="VALUE" sql-type="float"/>
- <column name="CURRENCY"/>
- </property>
- <loader query-ref="employment"/>
- <sql-insert>
- INSERT INTO EMPLOYMENT
- (EMPLOYEE, EMPLOYER, STARTDATE, REGIONCODE, VALUE, CURRENCY, EMPID)
- VALUES (?, ?, now(), UPPER(?), ?, ?, ?)
- </sql-insert>
- <sql-update>UPDATE EMPLOYMENT SET ENDDATE=?, VALUE=?, CURRENCY=? WHERE EMPID=?</sql-update>
- <sql-delete>DELETE FROM EMPLOYMENT WHERE EMPID=?</sql-delete>
- </class>
-
- <resultset name="org-emp-regionCode">
- <return-scalar column="regionCode" type="string"/>
- <return alias="org" class="Organization"/>
- <return-join alias="emp" property="org.employments"/>
- </resultset>
-
- <resultset name="org-emp-person">
- <return alias="org" class="Organization"/>
- <return-join alias="emp" property="org.employments"/>
- <return-join alias="pers" property="emp.employee"/>
- </resultset>
-
- <sql-query name="person">
- <return alias="p" class="Person" lock-mode="upgrade"/>
- SELECT NAME AS {p.name}, PERID AS {p.id} FROM PERSON WHERE PERID=? /*FOR UPDATE*/
- </sql-query>
-
- <sql-query name="organization">
- <return alias="org" class="Organization"/>
- <return-join alias="emp" property="org.employments"/>
- SELECT {org.*}, {emp.*}
- FROM ORGANIZATION org
- LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER
- WHERE org.ORGID=?
- </sql-query>
-
-
-
- <!--sql-query name="organization">
- <return alias="org" class="Organization"/>
- SELECT NAME AS {org.name}, ORGID AS {org.id} FROM ORGANIZATION
- WHERE ORGID=?
- </sql-query-->
-
- <sql-query name="allOrganizationsWithEmployees" flush-mode="never">
- <return alias="org" class="Organization"/>
- SELECT DISTINCT org.NAME AS {org.name}, org.ORGID AS {org.id}
- FROM ORGANIZATION org
- INNER JOIN EMPLOYMENT e ON e.EMPLOYER = org.ORGID
- </sql-query>
-
- <sql-query name="employment">
- <return alias="emp" class="Employment"/>
- SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer},
- STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate},
- REGIONCODE as {emp.regionCode}, EMPID AS {emp.id}
- FROM EMPLOYMENT
- WHERE EMPID = ?
- </sql-query>
-
-
- <sql-query name="organizationEmployments">
- <load-collection alias="empcol" role="Organization.employments"/>
- SELECT {empcol.*}
- FROM EMPLOYMENT empcol
- WHERE EMPLOYER = :id
- ORDER BY STARTDATE ASC, EMPLOYEE ASC
- </sql-query>
-
-
- <sql-query name="organizationCurrentEmployments">
- <return alias="emp" class="Employment">
- <return-property name="salary">
- <!-- as multi column properties are not supported via the
- {}-syntax, we need to provide an explicit column list for salary via <return-property> -->
- <return-column name="VALUE"/>
- <return-column name="CURRENCY"/>
- </return-property>
- <!-- Here we are remapping endDate. Notice that we can still use {emp.endDate} in the SQL. -->
- <return-property name="endDate" column="myEndDate"/>
- </return>
- <synchronize table="EMPLOYMENT"/>
- SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer},
- STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate},
- REGIONCODE as {emp.regionCode}, EMPID AS {emp.id}, VALUE, CURRENCY
- FROM EMPLOYMENT
- WHERE EMPLOYER = :id AND ENDDATE IS NULL
- ORDER BY STARTDATE ASC
- </sql-query>
-
- <sql-query name="simpleScalar" callable="true">
- <return-scalar column="name" type="string"/>
- <return-scalar column="value" type="long"/>
- { call simpleScalar(:number) }
- </sql-query>
-
- <sql-query name="paramhandling" callable="true">
- <return-scalar column="value" type="long"/>
- <return-scalar column="value2" type="long"/>
- { call paramHandling(?,?) }
- </sql-query>
-
- <sql-query name="paramhandling_mixed" callable="true">
- <return-scalar column="value" type="long" />
- <return-scalar column="value2" type="long" />
- { call paramHandling(?,:second) }
- </sql-query>
-
- <sql-query name="selectAllEmployments" callable="true">
- <return alias="" class="Employment">
- <return-property name="employee" column="EMPLOYEE"/>
- <return-property name="employer" column="EMPLOYER"/>
- <return-property name="startDate" column="STARTDATE"/>
- <return-property name="endDate" column="ENDDATE"/>
- <return-property name="regionCode" column="REGIONCODE"/>
- <return-property name="id" column="EMPID"/>
- <return-property name="salary">
- <!-- as multi column properties are not supported via the
- {}-syntax, we need to provide an explicit column list for salary via <return-property> -->
- <return-column name="VALUE"/>
- <return-column name="CURRENCY"/>
- </return-property>
- </return>
- { call selectAllEmployments() }
- </sql-query>
-
- <database-object>
- <create>
- CREATE PROCEDURE selectAllEmployments ()
- SELECT EMPLOYEE, EMPLOYER, STARTDATE, ENDDATE,
- REGIONCODE, EMPID, VALUE, CURRENCY
- FROM EMPLOYMENT
- </create>
- <drop>
- DROP PROCEDURE selectAllEmployments
- </drop>
- </database-object>
-
- <database-object>
- <create>
- CREATE PROCEDURE paramHandling (j int, i int)
- SELECT j AS value, i AS value2
- </create>
- <drop>
- DROP PROCEDURE paramHandling
- </drop>
- </database-object>
-
- <database-object>
- <create>
- CREATE PROCEDURE simpleScalar (number int)
- SELECT number AS value, 'getAll' AS name
- </create>
- <drop>
- DROP PROCEDURE simpleScalar
- </drop>
- </database-object>
-
-</hibernate-mapping>
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MySQLTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MySQLTest.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/MySQLTest.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,31 +0,0 @@
-//$Id$
-package org.hibernate.test.sql;
-
-import junit.framework.Test;
-
-import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.MySQLDialect;
-import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
-
-/**
- * @author Gavin King
- */
-public class MySQLTest extends HandSQLTest {
-
- public MySQLTest(String str) {
- super(str);
- }
-
- public String[] getMappings() {
- return new String[] { "sql/MySQLEmployment.hbm.xml" };
- }
-
- public static Test suite() {
- return new FunctionalTestClassTestSuite( MySQLTest.class );
- }
-
- public boolean appliesTo(Dialect dialect) {
- return ( dialect instanceof MySQLDialect );
- }
-}
-
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/NativeSqlSupportSuite.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/NativeSqlSupportSuite.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/NativeSqlSupportSuite.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -2,23 +2,32 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.hibernate.test.sql.check.OracleCheckStyleTest;
+import org.hibernate.test.sql.check.CheckSuite;
+import org.hibernate.test.sql.hand.custom.datadirect.oracle.DataDirectOracleCustomSQLTest;
+import org.hibernate.test.sql.hand.custom.db2.DB2CustomSQLTest;
+import org.hibernate.test.sql.hand.custom.mysql.MySQLCustomSQLTest;
+import org.hibernate.test.sql.hand.custom.oracle.OracleCustomSQLTest;
+import org.hibernate.test.sql.hand.custom.sybase.SybaseCustomSQLTest;
+import org.hibernate.test.sql.hand.query.NativeSQLQueriesTest;
+import org.hibernate.test.sql.hand.identity.CustomInsertSQLWithIdentityColumnTest;
+
/**
- * todo: describe NativeSqlSupportSuite
+ * Suite for testing aspects of native SQL support.
*
* @author Steve Ebersole
*/
public class NativeSqlSupportSuite {
public static Test suite() {
TestSuite suite = new TestSuite( "Native SQL support tests" );
- suite.addTest( Db2SQLTest.suite() );
- suite.addTest( DataDirectOracleSQLTest.suite() );
- suite.addTest( OracleSQLTest.suite() );
- suite.addTest( MSSQLTest.suite() );
- suite.addTest( MySQLTest.suite() );
- suite.addTest( GeneralTest.suite() );
- suite.addTest( OracleCheckStyleTest.suite() );
+ suite.addTest( DB2CustomSQLTest.suite() );
+ suite.addTest( DataDirectOracleCustomSQLTest.suite() );
+ suite.addTest( OracleCustomSQLTest.suite() );
+ suite.addTest( SybaseCustomSQLTest.suite() );
+ suite.addTest( MySQLCustomSQLTest.suite() );
+ suite.addTest( NativeSQLQueriesTest.suite() );
+ suite.addTest( CheckSuite.suite() );
+ suite.addTest( CustomInsertSQLWithIdentityColumnTest.suite() );
return suite;
}
}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/OracleDataDirectDriverStoredProcedures.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/OracleDataDirectDriverStoredProcedures.hbm.xml 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/OracleDataDirectDriverStoredProcedures.hbm.xml 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,48 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<!--
-
- This version is for DataDirect drivers jdbc standard handling of stored procedures/functions.
-
--->
-<hibernate-mapping
- package="org.hibernate.test.sql"
- default-access="field">
-
- <sql-query name="simpleScalar" callable="true">
- <return-scalar column="name" type="string"/>
- <return-scalar column="value" type="long"/>
- { call simpleScalar(:number) }
- </sql-query>
- <sql-query name="paramhandling" callable="true">
- <return-scalar column="value" type="long" />
- <return-scalar column="value2" type="long" />
- { call testParamHandling(?,?) }
- </sql-query>
-
- <sql-query name="paramhandling_mixed" callable="true">
- <return-scalar column="value" type="long" />
- <return-scalar column="value2" type="long" />
- { call testParamHandling(?,:second) }
- </sql-query>
-
- <sql-query name="selectAllEmployments" callable="true">
- <return alias="emp" class="Employment">
- <return-property name="employee" column="EMPLOYEE"/>
- <return-property name="employer" column="EMPLOYER"/>
- <return-property name="startDate" column="STARTDATE"/>
- <return-property name="endDate" column="ENDDATE"/>
- <return-property name="regionCode" column="REGIONCODE"/>
- <return-property name="employmentId" column="EMPID"/>
- <return-property name="salary">
- <return-column name="VALUE"/>
- <return-column name="CURRENCY"/>
- </return-property>
- </return>
- { call allEmployments() }
- </sql-query>
-
-</hibernate-mapping>
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/OracleDriverStoredProcedures.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/OracleDriverStoredProcedures.hbm.xml 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/OracleDriverStoredProcedures.hbm.xml 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,47 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<!--
-
- This version is for Oracle drivers proprietary handling of stored procedures/functions.
-
--->
-<hibernate-mapping package="org.hibernate.test.sql" default-access="field">
-
- <sql-query name="simpleScalar" callable="true">
- <return-scalar column="name" type="string"/>
- <return-scalar column="value" type="long"/>
- { ? = call simpleScalar(:number) }
- </sql-query>
-
- <sql-query name="paramhandling" callable="true">
- <return-scalar column="value" type="long"/>
- <return-scalar column="value2" type="long"/>
- { ? = call testParamHandling(?,?) }
- </sql-query>
-
- <sql-query name="paramhandling_mixed" callable="true">
- <return-scalar column="value" type="long"/>
- <return-scalar column="value2" type="long"/>
- { ? = call testParamHandling(?,:second) }
- </sql-query>
-
- <sql-query name="selectAllEmployments" callable="true">
- <return alias="emp" class="Employment">
- <return-property name="employee" column="EMPLOYEE"/>
- <return-property name="employer" column="EMPLOYER"/>
- <return-property name="startDate" column="STARTDATE"/>
- <return-property name="endDate" column="ENDDATE"/>
- <return-property name="regionCode" column="REGIONCODE"/>
- <return-property name="employmentId" column="EMPID"/>
- <return-property name="salary">
- <return-column name="VALUE"/>
- <return-column name="CURRENCY"/>
- </return-property>
- </return>
- { ? = call allEmployments() }
- </sql-query>
-
-</hibernate-mapping>
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/OracleEmployment.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/OracleEmployment.hbm.xml 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/OracleEmployment.hbm.xml 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,214 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
-
-<!--
-
- This mapping demonstrates the use of Hibernate with
- all-handwritten SQL!
-
- This version is for Oracle
-
--->
-<hibernate-mapping
- package="org.hibernate.test.sql"
- default-access="field">
-
- <class name="Organization">
- <id name="id" unsaved-value="0" column="orgid">
- <generator class="increment"/>
- </id>
- <property name="name" not-null="true"/>
- <set name="employments"
- inverse="true"
- order-by="DUMMY">
- <key column="employer"/>
- <!-- only needed for DDL generation -->
- <one-to-many class="Employment"/>
- <loader query-ref="organizationEmployments"/>
- </set>
- <!-- query-list name="currentEmployments"
- query-ref="organizationCurrentEmployments"-->
- <loader query-ref="organization"/>
- <sql-insert>INSERT INTO ORGANIZATION (NAME, ORGID) VALUES ( UPPER(?), ? )</sql-insert>
- <sql-update>UPDATE ORGANIZATION SET NAME=UPPER(?) WHERE ORGID=?</sql-update>
- <sql-delete>DELETE FROM ORGANIZATION WHERE ORGID=?</sql-delete>
- </class>
-
- <class name="Person">
- <id name="id" unsaved-value="0" column="perid">
- <generator class="increment"/>
- </id>
- <property name="name" not-null="true"/>
- <loader query-ref="person"/>
- <sql-insert callable="true" check="none">{call createPerson(?,?)}</sql-insert>
- <sql-update>UPDATE PERSON SET NAME=UPPER(?) WHERE PERID=?</sql-update>
- <sql-delete>DELETE FROM PERSON WHERE PERID=?</sql-delete>
- </class>
-
- <class name="Employment">
- <id name="employmentId" unsaved-value="0" column="empid">
- <generator class="increment"/>
- </id>
- <many-to-one name="employee" not-null="true" update="false"/>
- <many-to-one name="employer" not-null="true" update="false"/>
- <property name="startDate" not-null="true" update="false" insert="false"/>
- <property name="endDate" insert="false"/>
- <property name="regionCode" update="false"/>
- <property name="salary" type="org.hibernate.test.sql.MonetaryAmountUserType">
- <column name="VALUE" sql-type="float"/>
- <column name="CURRENCY"/>
- </property>
- <loader query-ref="employment"/>
- <sql-insert>
- INSERT INTO EMPLOYMENT
- (EMPLOYEE, EMPLOYER, STARTDATE, REGIONCODE, VALUE, CURRENCY, EMPID)
- VALUES (?, ?, CURRENT_DATE, UPPER(?), ?, ?, ?)
- </sql-insert>
- <sql-update>UPDATE EMPLOYMENT SET ENDDATE=?, VALUE=?, CURRENCY=? WHERE EMPID=?</sql-update>
- <sql-delete>DELETE FROM EMPLOYMENT WHERE EMPID=?</sql-delete>
- </class>
-
- <resultset name="org-emp-regionCode">
- <return-scalar column="regionCode" type="string"/>
- <return alias="org" class="Organization"/>
- <return-join alias="emp" property="org.employments"/>
- </resultset>
-
- <resultset name="org-emp-person">
- <return alias="org" class="Organization"/>
- <return-join alias="emp" property="org.employments"/>
- <return-join alias="pers" property="emp.employee"/>
- </resultset>
-
- <sql-query name="person">
- <return alias="p" class="Person" lock-mode="upgrade"/>
- SELECT NAME AS {p.name}, PERID AS {p.id} FROM PERSON WHERE PERID=? /*FOR UPDATE*/
- </sql-query>
-
- <sql-query name="organization">
- <return alias="org" class="Organization"/>
- <return-join alias="emp" property="org.employments"/>
- SELECT {org.*}, {emp.*}
- FROM ORGANIZATION org
- LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER
- WHERE org.ORGID=?
- </sql-query>
-
-
- <sql-query name="allOrganizationsWithEmployees" flush-mode="never">
- <return alias="org" class="Organization"/>
- SELECT DISTINCT org.NAME AS {org.name}, org.ORGID AS {org.id}
- FROM ORGANIZATION org
- INNER JOIN EMPLOYMENT e ON e.EMPLOYER = org.ORGID
- </sql-query>
-
-
- <sql-query name="employment">
- <return alias="emp" class="Employment"/>
- SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer},
- STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate},
- REGIONCODE as {emp.regionCode}, EMPID AS {emp.id}
- FROM EMPLOYMENT
- WHERE EMPID = ?
- </sql-query>
-
-
- <sql-query name="organizationEmployments">
- <load-collection alias="empcol" role="Organization.employments"/>
- SELECT {empcol.*}
- FROM EMPLOYMENT empcol
- WHERE EMPLOYER = :id
- ORDER BY STARTDATE ASC, EMPLOYEE ASC
- </sql-query>
-
-
- <sql-query name="organizationCurrentEmployments">
- <return alias="emp" class="Employment">
- <return-property name="salary">
- <!-- as multi column properties are not supported via the
- {}-syntax, we need to provide an explicit column list for salary via <return-property> -->
- <return-column name="VALUE"/>
- <return-column name="CURRENCY"/>
- </return-property>
- <!-- Here we are remapping endDate. Notice that we can still use {emp.endDate} in the SQL. -->
- <return-property name="endDate" column="myEndDate"/>
- </return>
- <synchronize table="EMPLOYMENT"/>
- SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer},
- STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate},
- REGIONCODE as {emp.regionCode}, EMPID AS {emp.id}, VALUE, CURRENCY
- FROM EMPLOYMENT
- WHERE EMPLOYER = :id AND ENDDATE IS NULL
- ORDER BY STARTDATE ASC
- </sql-query>
-
- <database-object>
- <create>
- CREATE OR REPLACE FUNCTION testParamHandling (j number, i number)
- RETURN SYS_REFCURSOR AS st_cursor SYS_REFCURSOR;
- BEGIN
- OPEN st_cursor FOR
- SELECT j as value, i as value2 from dual;
- RETURN st_cursor;
- END;
- </create>
- <drop>
- DROP FUNCTION testParamHandling
- </drop>
- </database-object>
-
- <database-object>
- <create>
- CREATE OR REPLACE FUNCTION simpleScalar (j number)
- RETURN SYS_REFCURSOR AS st_cursor SYS_REFCURSOR;
- BEGIN
- OPEN st_cursor FOR
- SELECT j as value, 'getAll' as name from dual;
- RETURN st_cursor;
- END;
- </create>
- <drop>
- DROP FUNCTION simpleScalar
- </drop>
- </database-object>
-
- <database-object>
- <create>
- CREATE OR REPLACE FUNCTION allEmployments
- RETURN SYS_REFCURSOR AS st_cursor SYS_REFCURSOR;
- BEGIN
- OPEN st_cursor FOR
- SELECT EMPLOYEE, EMPLOYER, STARTDATE, ENDDATE,
- REGIONCODE, EMPID, VALUE, CURRENCY
- FROM EMPLOYMENT;
- RETURN st_cursor;
- END;
- </create>
- <drop>
- DROP FUNCTION allEmployments
- </drop>
- </database-object>
-
- <database-object>
- <create>
- CREATE OR REPLACE PROCEDURE createPerson(p_name PERSON.NAME%TYPE, p_id PERSON.PERID%TYPE)
- AS
- rowcount INTEGER;
- BEGIN
- INSERT INTO PERSON ( PERID, NAME ) VALUES ( p_id, UPPER( p_name ) );
- rowcount := SQL%ROWCOUNT;
- IF rowcount = 1 THEN
- NULL;
- ELSE
- RAISE_APPLICATION_ERROR( -20001, 'Unexpected rowcount [' || rowcount || ']' );
- END IF;
- END;
- </create>
- <drop>
- DROP PROCEDURE createPerson;
- </drop>
- </database-object>
-
-</hibernate-mapping>
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/OracleSQLTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/OracleSQLTest.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/OracleSQLTest.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,33 +0,0 @@
-//$Id$
-package org.hibernate.test.sql;
-
-import junit.framework.Test;
-
-import org.hibernate.dialect.DataDirectOracle9Dialect;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.Oracle9Dialect;
-import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
-
-/**
- * @author Gavin King
- */
-public class OracleSQLTest extends HandSQLTest {
-
- public OracleSQLTest(String str) {
- super(str);
- }
-
- public String[] getMappings() {
- return new String[] { "sql/OracleEmployment.hbm.xml", "sql/OracleDriverStoredProcedures.hbm.xml" };
- }
-
- public static Test suite() {
- return new FunctionalTestClassTestSuite( OracleSQLTest.class );
- }
-
- public boolean appliesTo(Dialect dialect) {
- return ( dialect instanceof Oracle9Dialect ) && !( dialect instanceof DataDirectOracle9Dialect );
- }
-
-}
-
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Order.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Order.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Order.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,55 +0,0 @@
-package org.hibernate.test.sql;
-
-import java.io.Serializable;
-
-public class Order {
-
- static public class OrderId implements Serializable {
- String orgid;
- String ordernumber;
- public String getOrdernumber() {
- return ordernumber;
- }
- public void setOrdernumber(String ordernumber) {
- this.ordernumber = ordernumber;
- }
- public String getOrgid() {
- return orgid;
- }
- public void setOrgid(String orgid) {
- this.orgid = orgid;
- }
-
-
- }
-
- OrderId orderId;
-
- Product product;
-
- Person person;
-
- public Person getPerson() {
- return person;
- }
-
- public void setPerson(Person person) {
- this.person = person;
- }
- public OrderId getOrderId() {
- return orderId;
- }
-
- public void setOrderId(OrderId orderId) {
- this.orderId = orderId;
- }
-
- public Product getProduct() {
- return product;
- }
-
- public void setProduct(Product product) {
- this.product = product;
- }
-
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Organization.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Organization.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Organization.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,59 +0,0 @@
-//$Id$
-package org.hibernate.test.sql;
-
-import java.util.Collection;
-import java.util.HashSet;
-
-/**
- * @author Gavin King
- */
-public class Organization {
- private long id;
- private String name;
- private Collection employments;
-
- public Organization(String name) {
- this.name = name;
- employments = new HashSet();
- }
-
- public Organization() {}
-
- /**
- * @return Returns the employments.
- */
- public Collection getEmployments() {
- return employments;
- }
- /**
- * @param employments The employments to set.
- */
- public void setEmployments(Collection employments) {
- this.employments = employments;
- }
- /**
- * @return Returns the id.
- */
- public long getId() {
- return id;
- }
- /**
- * @param id The id to set.
- */
- public void setId(long id) {
- this.id = id;
- }
- /**
- * @return Returns the name.
- */
- public String getName() {
- return name;
- }
- /**
- * @param name The name to set.
- */
- public void setName(String name) {
- this.name = name;
- }
-
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Person.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Person.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Person.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,41 +0,0 @@
-//$Id$
-package org.hibernate.test.sql;
-
-/**
- * @author Gavin King
- */
-public class Person {
- private long id;
- private String name;
-
- public Person(String name) {
- this.name = name;
- }
-
- public Person() {}
-
-/**
- * @return Returns the id.
- */
- public long getId() {
- return id;
- }
- /**
- * @param id The id to set.
- */
- public void setId(long id) {
- this.id = id;
- }
- /**
- * @return Returns the name.
- */
- public String getName() {
- return name;
- }
- /**
- * @param name The name to set.
- */
- public void setName(String name) {
- this.name = name;
- }
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Product.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Product.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Product.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,66 +0,0 @@
-package org.hibernate.test.sql;
-
-import java.io.Serializable;
-import java.util.HashSet;
-import java.util.Set;
-
-public class Product {
-
- static public class ProductId implements Serializable {
- String orgid;
- String productnumber;
- public String getProductnumber() {
- return productnumber;
- }
- public void setProductnumber(String ordernumber) {
- this.productnumber = ordernumber;
- }
- public String getOrgid() {
- return orgid;
- }
- public void setOrgid(String orgid) {
- this.orgid = orgid;
- }
-
-
- }
-
- ProductId productId;
-
- String name;
-
- Person person;
-
- Set orders = new HashSet();
-
- public Set getOrders() {
- return orders;
- }
-
- public void setOrders(Set orders) {
- this.orders = orders;
- }
- public Person getPerson() {
- return person;
- }
-
- public void setPerson(Person person) {
- this.person = person;
- }
- public ProductId getProductId() {
- return productId;
- }
-
- public void setProductId(ProductId orderId) {
- this.productId = orderId;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String product) {
- this.name = product;
- }
-
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/SpaceShip.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/SpaceShip.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/SpaceShip.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,53 +0,0 @@
-//$Id: $
-package org.hibernate.test.sql;
-
-/**
- * @author Emmanuel Bernard
- */
-public class SpaceShip {
- private Integer id;
- private String name;
- private String model;
- private double speed;
- private Dimension dimensions;
-
- public Dimension getDimensions() {
- return dimensions;
- }
-
- public void setDimensions(Dimension dimensions) {
- this.dimensions = dimensions;
- }
-
- public Integer getId() {
- return id;
- }
-
- public void setId(Integer id) {
- this.id = id;
- }
-
- public String getModel() {
- return model;
- }
-
- public void setModel(String model) {
- this.model = model;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public double getSpeed() {
- return speed;
- }
-
- public void setSpeed(double speed) {
- this.speed = speed;
- }
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Speech.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Speech.java 2007-05-08 21:36:50 UTC (rev 11484)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/Speech.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -1,35 +0,0 @@
-//$Id: $
-package org.hibernate.test.sql;
-
-/**
- * @author Emmanuel Bernard
- */
-public class Speech {
- private Integer id;
- private String name;
- private Double length;
-
- public Integer getId() {
- return id;
- }
-
- public void setId(Integer id) {
- this.id = id;
- }
-
- public Double getLength() {
- return length;
- }
-
- public void setLength(Double length) {
- this.length = length;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/CheckSuite.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/CheckSuite.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/check/CheckSuite.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,19 @@
+package org.hibernate.test.sql.check;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Suite for testing custom SQL result checking strategies.
+ * <p/>
+ * Yes, currently there is only one actual test...
+ *
+ * @author Steve Ebersole
+ */
+public class CheckSuite {
+ public static Test suite() {
+ TestSuite suite = new TestSuite( "native sql result checking" );
+ suite.addTest( OracleCheckStyleTest.suite() );
+ return suite;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Dimension.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Dimension.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Dimension.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,31 @@
+package org.hibernate.test.sql.hand;
+
+/**
+ * Used to mimic some tests from the JPA testsuite...
+ *
+ * @author Steve Ebersole
+ */
+public class Dimension {
+ private Long id;
+ private int length;
+ private int width;
+
+ public Dimension() {}
+
+ public Dimension(int length, int width) {
+ this.length = length;
+ this.width = width;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public int getLength() {
+ return length;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Employment.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Employment.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Employment.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,107 @@
+//$Id: Employment.java 6356 2005-04-06 16:43:11Z maxcsaucdk $
+package org.hibernate.test.sql.hand;
+
+import java.util.Date;
+
+/**
+ * @author Gavin King
+ */
+public class Employment {
+ private long employmentId;
+ private Person employee;
+ private Organization employer;
+ private Date startDate;
+ private Date endDate;
+ private String regionCode;
+ private MonetaryAmount salary;
+
+ public Employment() {}
+
+ public Employment(Person employee, Organization employer, String regionCode) {
+ this.employee = employee;
+ this.employer = employer;
+ this.startDate = new Date();
+ this.regionCode = regionCode;
+ employer.getEmployments().add(this);
+ }
+ /**
+ * @return Returns the employee.
+ */
+ public Person getEmployee() {
+ return employee;
+ }
+ /**
+ * @param employee The employee to set.
+ */
+ public void setEmployee(Person employee) {
+ this.employee = employee;
+ }
+ /**
+ * @return Returns the employer.
+ */
+ public Organization getEmployer() {
+ return employer;
+ }
+ /**
+ * @param employer The employer to set.
+ */
+ public void setEmployer(Organization employer) {
+ this.employer = employer;
+ }
+ /**
+ * @return Returns the endDate.
+ */
+ public Date getEndDate() {
+ return endDate;
+ }
+ /**
+ * @param endDate The endDate to set.
+ */
+ public void setEndDate(Date endDate) {
+ this.endDate = endDate;
+ }
+ /**
+ * @return Returns the id.
+ */
+ public long getEmploymentId() {
+ return employmentId;
+ }
+ /**
+ * @param id The id to set.
+ */
+ public void setEmploymentId(long id) {
+ this.employmentId = id;
+ }
+ /**
+ * @return Returns the startDate.
+ */
+ public Date getStartDate() {
+ return startDate;
+ }
+ /**
+ * @param startDate The startDate to set.
+ */
+ public void setStartDate(Date startDate) {
+ this.startDate = startDate;
+ }
+ /**
+ * @return Returns the regionCode.
+ */
+ public String getRegionCode() {
+ return regionCode;
+ }
+ /**
+ * @param regionCode The regionCode to set.
+ */
+ public void setRegionCode(String regionCode) {
+ this.regionCode = regionCode;
+ }
+
+ public MonetaryAmount getSalary() {
+ return salary;
+ }
+
+ public void setSalary(MonetaryAmount salary) {
+ this.salary = salary;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/MonetaryAmount.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/MonetaryAmount.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/MonetaryAmount.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,78 @@
+package org.hibernate.test.sql.hand;
+
+import java.math.BigDecimal;
+import java.util.Currency;
+import java.io.Serializable;
+
+/**
+ * Represents a monetary amount as value and currency.
+ *
+ * @author Gavin King <gavin at hibernate.org>
+ * @author Christian Bauer <christian at hibernate.org>
+ */
+public class MonetaryAmount implements Serializable {
+
+ private final BigDecimal value;
+ private final Currency currency;
+
+ public MonetaryAmount(BigDecimal value, Currency currency) {
+ this.value = value;
+ this.currency = currency;
+ }
+
+ public Currency getCurrency() {
+ return currency;
+ }
+
+ public BigDecimal getValue() {
+ return value;
+ }
+
+ // ********************** Common Methods ********************** //
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof MonetaryAmount)) return false;
+
+ final MonetaryAmount monetaryAmount = (MonetaryAmount) o;
+
+ if (!currency.equals(monetaryAmount.currency)) return false;
+ if (!value.equals(monetaryAmount.value)) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = value.hashCode();
+ result = 29 * result + currency.hashCode();
+ return result;
+ }
+
+ public String toString() {
+ return "Value: '" + getValue() + "', " +
+ "Currency: '" + getCurrency() + "'";
+ }
+
+ public int compareTo(Object o) {
+ if (o instanceof MonetaryAmount) {
+ // TODO: This would actually require some currency conversion magic
+ return this.getValue().compareTo(((MonetaryAmount) o).getValue());
+ }
+ return 0;
+ }
+
+ // ********************** Business Methods ********************** //
+
+ public static MonetaryAmount fromString(String amount, String currencyCode) {
+ return new MonetaryAmount(new BigDecimal(amount),
+ Currency.getInstance(currencyCode));
+ }
+
+ public static MonetaryAmount convert(MonetaryAmount amount,
+ Currency toConcurrency) {
+ // TODO: This requires some conversion magic and is therefore broken
+ return new MonetaryAmount(amount.getValue(), toConcurrency);
+ }
+
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/MonetaryAmountUserType.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/MonetaryAmountUserType.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/MonetaryAmountUserType.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,85 @@
+package org.hibernate.test.sql.hand;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.Currency;
+
+import org.hibernate.HibernateException;
+import org.hibernate.usertype.UserType;
+
+/**
+ * This is a simple Hibernate custom mapping type for MonetaryAmount value types.
+ * <p>
+ *
+ * @author Max & Christian
+ */
+public class MonetaryAmountUserType
+ implements UserType {
+
+ private static final int[] SQL_TYPES = {Types.NUMERIC, Types.VARCHAR };
+
+ public int[] sqlTypes() { return SQL_TYPES; }
+
+ public Class returnedClass() { return MonetaryAmount.class; }
+
+ public boolean isMutable() { return false; }
+
+ public Object deepCopy(Object value) {
+ return value; // MonetaryAmount is immutable
+ }
+
+ public boolean equals(Object x, Object y) {
+ if (x == y) return true;
+ if (x == null || y == null) return false;
+ return x.equals(y);
+ }
+
+ public Object nullSafeGet(ResultSet resultSet,
+ String[] names,
+ Object owner)
+ throws HibernateException, SQLException {
+
+ BigDecimal value = resultSet.getBigDecimal(names[0]);
+ if (resultSet.wasNull()) return null;
+ String cur = resultSet.getString(names[1]);
+ Currency userCurrency = Currency.getInstance(cur);
+
+ return new MonetaryAmount(value, userCurrency);
+ }
+
+ public void nullSafeSet(PreparedStatement statement,
+ Object value,
+ int index)
+ throws HibernateException, SQLException {
+
+ if (value == null) {
+ statement.setNull(index, Types.NUMERIC);
+ statement.setNull(index+1, Types.VARCHAR);
+ } else {
+ MonetaryAmount currency = (MonetaryAmount)value;
+ statement.setBigDecimal(index, currency.getValue());
+ statement.setString(index+1, currency.getCurrency().getCurrencyCode());
+ }
+ }
+
+ public Serializable disassemble(Object value) throws HibernateException {
+ return (Serializable) value;
+ }
+
+ public Object assemble(Serializable cached, Object owner) throws HibernateException {
+ return cached;
+ }
+
+ public Object replace(Object original, Object target, Object owner)
+ throws HibernateException {
+ return original;
+ }
+
+ public int hashCode(Object x) throws HibernateException {
+ return x.hashCode();
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Order.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Order.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Order.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,55 @@
+package org.hibernate.test.sql.hand;
+
+import java.io.Serializable;
+
+public class Order {
+
+ static public class OrderId implements Serializable {
+ String orgid;
+ String ordernumber;
+ public String getOrdernumber() {
+ return ordernumber;
+ }
+ public void setOrdernumber(String ordernumber) {
+ this.ordernumber = ordernumber;
+ }
+ public String getOrgid() {
+ return orgid;
+ }
+ public void setOrgid(String orgid) {
+ this.orgid = orgid;
+ }
+
+
+ }
+
+ OrderId orderId;
+
+ Product product;
+
+ Person person;
+
+ public Person getPerson() {
+ return person;
+ }
+
+ public void setPerson(Person person) {
+ this.person = person;
+ }
+ public OrderId getOrderId() {
+ return orderId;
+ }
+
+ public void setOrderId(OrderId orderId) {
+ this.orderId = orderId;
+ }
+
+ public Product getProduct() {
+ return product;
+ }
+
+ public void setProduct(Product product) {
+ this.product = product;
+ }
+
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Organization.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Organization.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Organization.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,59 @@
+//$Id: Organization.java 7547 2005-07-19 18:21:35Z oneovthafew $
+package org.hibernate.test.sql.hand;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+/**
+ * @author Gavin King
+ */
+public class Organization {
+ private long id;
+ private String name;
+ private Collection employments;
+
+ public Organization(String name) {
+ this.name = name;
+ employments = new HashSet();
+ }
+
+ public Organization() {}
+
+ /**
+ * @return Returns the employments.
+ */
+ public Collection getEmployments() {
+ return employments;
+ }
+ /**
+ * @param employments The employments to set.
+ */
+ public void setEmployments(Collection employments) {
+ this.employments = employments;
+ }
+ /**
+ * @return Returns the id.
+ */
+ public long getId() {
+ return id;
+ }
+ /**
+ * @param id The id to set.
+ */
+ public void setId(long id) {
+ this.id = id;
+ }
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @param name The name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Person.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Person.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Person.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,41 @@
+//$Id: Person.java 4316 2004-08-14 13:12:03Z oneovthafew $
+package org.hibernate.test.sql.hand;
+
+/**
+ * @author Gavin King
+ */
+public class Person {
+ private long id;
+ private String name;
+
+ public Person(String name) {
+ this.name = name;
+ }
+
+ public Person() {}
+
+/**
+ * @return Returns the id.
+ */
+ public long getId() {
+ return id;
+ }
+ /**
+ * @param id The id to set.
+ */
+ public void setId(long id) {
+ this.id = id;
+ }
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @param name The name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Product.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Product.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Product.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,66 @@
+package org.hibernate.test.sql.hand;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+
+public class Product {
+
+ static public class ProductId implements Serializable {
+ String orgid;
+ String productnumber;
+ public String getProductnumber() {
+ return productnumber;
+ }
+ public void setProductnumber(String ordernumber) {
+ this.productnumber = ordernumber;
+ }
+ public String getOrgid() {
+ return orgid;
+ }
+ public void setOrgid(String orgid) {
+ this.orgid = orgid;
+ }
+
+
+ }
+
+ ProductId productId;
+
+ String name;
+
+ Person person;
+
+ Set orders = new HashSet();
+
+ public Set getOrders() {
+ return orders;
+ }
+
+ public void setOrders(Set orders) {
+ this.orders = orders;
+ }
+ public Person getPerson() {
+ return person;
+ }
+
+ public void setPerson(Person person) {
+ this.person = person;
+ }
+ public ProductId getProductId() {
+ return productId;
+ }
+
+ public void setProductId(ProductId orderId) {
+ this.productId = orderId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String product) {
+ this.name = product;
+ }
+
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/SpaceShip.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/SpaceShip.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/SpaceShip.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,53 @@
+//$Id: $
+package org.hibernate.test.sql.hand;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class SpaceShip {
+ private Integer id;
+ private String name;
+ private String model;
+ private double speed;
+ private Dimension dimensions;
+
+ public Dimension getDimensions() {
+ return dimensions;
+ }
+
+ public void setDimensions(Dimension dimensions) {
+ this.dimensions = dimensions;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getModel() {
+ return model;
+ }
+
+ public void setModel(String model) {
+ this.model = model;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public double getSpeed() {
+ return speed;
+ }
+
+ public void setSpeed(double speed) {
+ this.speed = speed;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Speech.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Speech.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/Speech.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,35 @@
+//$Id: $
+package org.hibernate.test.sql.hand;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Speech {
+ private Integer id;
+ private String name;
+ private Double length;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Double getLength() {
+ return length;
+ }
+
+ public void setLength(Double length) {
+ this.length = length;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/CustomSQLTestSupport.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/CustomSQLTestSupport.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/CustomSQLTestSupport.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,94 @@
+package org.hibernate.test.sql.hand.custom;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.Iterator;
+
+import org.hibernate.LockMode;
+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;
+import org.hibernate.junit.functional.DatabaseSpecificFunctionalTestCase;
+
+/**
+ * Abstract test case defining tests for the support for user-supplied (aka
+ * custom) insert, update, delete SQL.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class CustomSQLTestSupport extends DatabaseSpecificFunctionalTestCase {
+
+ public CustomSQLTestSupport(String name) {
+ super( name );
+ }
+
+ public String getCacheConcurrencyStrategy() {
+ return null;
+ }
+
+ public void testHandSQL() {
+ 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" );
+ Serializable orgId = s.save( jboss );
+ s.save( ifa );
+ s.save( gavin );
+ s.save( emp );
+ t.commit();
+
+ t = s.beginTransaction();
+ Person christian = new Person( "Christian" );
+ s.save( christian );
+ Employment emp2 = new Employment( christian, jboss, "EU" );
+ s.save( emp2 );
+ t.commit();
+ s.close();
+
+ getSessions().evict( Organization.class );
+ getSessions().evict( Person.class );
+ getSessions().evict( Employment.class );
+
+ s = openSession();
+ t = s.beginTransaction();
+ jboss = ( Organization ) s.get( Organization.class, orgId );
+ assertEquals( jboss.getEmployments().size(), 2 );
+ assertEquals( jboss.getName(), "JBOSS" );
+ emp = ( Employment ) jboss.getEmployments().iterator().next();
+ gavin = emp.getEmployee();
+ assertEquals( gavin.getName(), "GAVIN" );
+ assertEquals( s.getCurrentLockMode( gavin ), LockMode.UPGRADE );
+ emp.setEndDate( new Date() );
+ Employment emp3 = new Employment( gavin, jboss, "US" );
+ s.save( emp3 );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Iterator iter = s.getNamedQuery( "allOrganizationsWithEmployees" ).list().iterator();
+ assertTrue( iter.hasNext() );
+ Organization o = ( Organization ) iter.next();
+ assertEquals( o.getEmployments().size(), 3 );
+ Iterator iter2 = o.getEmployments().iterator();
+ while ( iter2.hasNext() ) {
+ Employment e = ( Employment ) iter2.next();
+ s.delete( e );
+ }
+ iter2 = o.getEmployments().iterator();
+ while ( iter2.hasNext() ) {
+ Employment e = ( Employment ) iter2.next();
+ s.delete( e.getEmployee() );
+ }
+ s.delete( o );
+ assertFalse( iter.hasNext() );
+ s.delete( ifa );
+ t.commit();
+ s.close();
+ }
+
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/CustomStoredProcTestSupport.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/CustomStoredProcTestSupport.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/CustomStoredProcTestSupport.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -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();
+ }
+
+
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/datadirect/oracle/DataDirectOracleCustomSQLTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/datadirect/oracle/DataDirectOracleCustomSQLTest.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/datadirect/oracle/DataDirectOracleCustomSQLTest.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,35 @@
+//$Id$
+package org.hibernate.test.sql.hand.custom.datadirect.oracle;
+
+import junit.framework.Test;
+
+import org.hibernate.dialect.DataDirectOracle9Dialect;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.test.sql.hand.custom.CustomStoredProcTestSupport;
+
+/**
+ * Custom SQL tests for Oracle via the DataDirect drivers.
+ *
+ * @author Max Rydahl Andersen
+ */
+public class DataDirectOracleCustomSQLTest extends CustomStoredProcTestSupport {
+
+ public DataDirectOracleCustomSQLTest(String str) {
+ super(str);
+ }
+
+ public String[] getMappings() {
+ return new String[] { "sql/hand/custom/oracle/Mappings.hbm.xml", "sql/hand/custom/datadirect/oracle/StoredProcedures.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( DataDirectOracleCustomSQLTest.class );
+ }
+
+ public boolean appliesTo(Dialect dialect) {
+ return ( dialect instanceof DataDirectOracle9Dialect );
+ }
+
+}
+
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/datadirect/oracle/StoredProcedures.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/datadirect/oracle/StoredProcedures.hbm.xml (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/datadirect/oracle/StoredProcedures.hbm.xml 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,44 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+ This version is for DataDirect drivers jdbc standard handling of stored procedures/functions.
+-->
+<hibernate-mapping package="org.hibernate.test.sql.hand" default-access="field">
+
+ <sql-query name="simpleScalar" callable="true">
+ <return-scalar column="name" type="string"/>
+ <return-scalar column="value" type="long"/>
+ { call simpleScalar(:number) }
+ </sql-query>
+ <sql-query name="paramhandling" callable="true">
+ <return-scalar column="value" type="long" />
+ <return-scalar column="value2" type="long" />
+ { call testParamHandling(?,?) }
+ </sql-query>
+
+ <sql-query name="paramhandling_mixed" callable="true">
+ <return-scalar column="value" type="long" />
+ <return-scalar column="value2" type="long" />
+ { call testParamHandling(?,:second) }
+ </sql-query>
+
+ <sql-query name="selectAllEmployments" callable="true">
+ <return alias="emp" class="Employment">
+ <return-property name="employee" column="EMPLOYEE"/>
+ <return-property name="employer" column="EMPLOYER"/>
+ <return-property name="startDate" column="STARTDATE"/>
+ <return-property name="endDate" column="ENDDATE"/>
+ <return-property name="regionCode" column="REGIONCODE"/>
+ <return-property name="employmentId" column="EMPID"/>
+ <return-property name="salary">
+ <return-column name="VALUE"/>
+ <return-column name="CURRENCY"/>
+ </return-property>
+ </return>
+ { call allEmployments() }
+ </sql-query>
+
+</hibernate-mapping>
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/db2/DB2CustomSQLTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/db2/DB2CustomSQLTest.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/db2/DB2CustomSQLTest.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,35 @@
+//$Id$
+package org.hibernate.test.sql.hand.custom.db2;
+
+import junit.framework.Test;
+
+import org.hibernate.dialect.DB2Dialect;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.test.sql.hand.custom.CustomStoredProcTestSupport;
+
+/**
+ * Custom SQL tests for DB2
+ *
+ * @author Max Rydahl Andersen
+ */
+public class DB2CustomSQLTest extends CustomStoredProcTestSupport {
+
+ public DB2CustomSQLTest(String str) {
+ super(str);
+ }
+
+ public String[] getMappings() {
+ return new String[] { "sql/hand/custom/db2/Mappings.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( DB2CustomSQLTest.class );
+ }
+
+ public boolean appliesTo(Dialect dialect) {
+ return ( dialect instanceof DB2Dialect);
+ }
+
+}
+
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/db2/Mappings.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/db2/Mappings.hbm.xml (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/db2/Mappings.hbm.xml 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,236 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+ This mapping demonstrates the use of Hibernate with all-handwritten SQL!
+
+ NOTE : this version is for DB2 & variants
+-->
+<hibernate-mapping package="org.hibernate.test.sql.hand" default-access="field">
+
+ <class name="Organization" table="ORGANIZATION">
+ <id name="id" unsaved-value="0" column="ORGID">
+ <generator class="increment"/>
+ </id>
+ <property name="name" not-null="true" column="NAME"/>
+ <set name="employments"
+ inverse="true"
+ order-by="DUMMY">
+ <key column="EMPLOYER"/> <!-- only needed for DDL generation -->
+ <one-to-many class="Employment"/>
+ <loader query-ref="organizationEmployments"/>
+ </set>
+ <!-- query-list name="currentEmployments"
+ query-ref="organizationCurrentEmployments"-->
+ <loader query-ref="organization"/>
+ <sql-insert>INSERT INTO ORGANIZATION (NAME, ORGID) VALUES ( UPPER(? || ''), ? )</sql-insert>
+ <sql-update>UPDATE ORGANIZATION SET NAME=UPPER(? || '') WHERE ORGID=?</sql-update>
+ <sql-delete>DELETE FROM ORGANIZATION WHERE ORGID=?</sql-delete>
+ </class>
+
+ <class name="Person" table="PERSON">
+ <id name="id" unsaved-value="0" column="PERID">
+ <generator class="increment"/>
+ </id>
+ <property name="name" not-null="true" column="NAME"/>
+ <loader query-ref="person"/>
+ <sql-insert>INSERT INTO PERSON (NAME, PERID) VALUES ( UPPER(? || ''), ? )</sql-insert>
+ <sql-update>UPDATE PERSON SET NAME=UPPER(? || '') WHERE PERID=?</sql-update>
+ <sql-delete>DELETE FROM PERSON WHERE PERID=?</sql-delete>
+ </class>
+
+ <class name="Employment" table="EMPLOYMENT">
+ <id name="employmentId" unsaved-value="0" column="EMPID">
+ <generator class="increment"/>
+ </id>
+ <many-to-one name="employee" column="EMPLOYEE" not-null="true" update="false"/>
+ <many-to-one name="employer" column="EMPLOYER" not-null="true" update="false"/>
+ <property name="startDate" column="STARTDATE" not-null="true" update="false" insert="false"/>
+ <property name="endDate" column="ENDDATE" insert="false"/>
+ <property name="regionCode" column="REGIONCODE" update="false"/>
+ <property name="salary" type="org.hibernate.test.sql.hand.MonetaryAmountUserType">
+ <column name="VALUE" sql-type="float"/>
+ <column name="CURRENCY"/>
+ </property>
+ <loader query-ref="employment"/>
+ <sql-insert>
+ INSERT INTO EMPLOYMENT
+ (EMPLOYEE, EMPLOYER, STARTDATE, REGIONCODE, VALUE, CURRENCY, EMPID)
+ <!-- inserting raw specific timestamp since using current date or current timestamp for some reason does not work with a timestamp column! -->
+ VALUES (?, ?, TIMESTAMP ('2006-02-28 11:39:00'), UPPER(? || ''), ?, ?, ?)
+ </sql-insert>
+ <sql-update>UPDATE EMPLOYMENT SET ENDDATE=?, VALUE=?, CURRENCY=? WHERE EMPID=?</sql-update>
+ <sql-delete>DELETE FROM EMPLOYMENT WHERE EMPID=?</sql-delete>
+ </class>
+
+ <resultset name="org-emp-regionCode">
+ <return-scalar column="regionCode" type="string"/>
+ <return alias="org" class="Organization"/>
+ <return-join alias="emp" property="org.employments"/>
+ </resultset>
+
+ <resultset name="org-emp-person">
+ <return alias="org" class="Organization"/>
+ <return-join alias="emp" property="org.employments"/>
+ <return-join alias="pers" property="emp.employee"/>
+ </resultset>
+
+ <sql-query name="person">
+ <return alias="p" class="Person" lock-mode="upgrade"/>
+ SELECT NAME AS {p.name}, PERID AS {p.id} FROM PERSON WHERE PERID=? /*FOR UPDATE*/
+ </sql-query>
+
+ <sql-query name="organization">
+ <return alias="org" class="Organization"/>
+ <return-join alias="emp" property="org.employments"/>
+ SELECT {org.*}, {emp.*}
+ FROM ORGANIZATION org
+ LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER
+ WHERE org.ORGID=?
+ </sql-query>
+
+
+ <!--sql-query name="organization">
+ <return alias="org" class="Organization"/>
+ SELECT NAME AS {org.name}, ORGID AS {org.id} FROM ORGANIZATION
+ WHERE ORGID=?
+ </sql-query-->
+
+ <sql-query name="allOrganizationsWithEmployees" flush-mode="never">
+ <return alias="org" class="Organization"/>
+ SELECT DISTINCT org.NAME AS {org.name}, org.ORGID AS {org.id}
+ FROM ORGANIZATION org
+ INNER JOIN EMPLOYMENT e ON e.EMPLOYER = org.ORGID
+ </sql-query>
+
+
+
+
+
+ <sql-query name="employment">
+ <return alias="emp" class="Employment"/>
+ SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer},
+ STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate},
+ REGIONCODE as {emp.regionCode}, EMPID AS {emp.id}
+ FROM EMPLOYMENT
+ WHERE EMPID = ?
+ </sql-query>
+
+ <sql-query name="organizationEmployments">
+ <load-collection alias="empcol" role="Organization.employments"/>
+ SELECT {empcol.*}
+ FROM EMPLOYMENT empcol
+ WHERE EMPLOYER = :id
+ ORDER BY STARTDATE ASC, EMPLOYEE ASC
+ </sql-query>
+
+
+ <sql-query name="organizationCurrentEmployments">
+ <return alias="emp" class="Employment">
+ <return-property name="salary">
+ <!-- as multi column properties are not supported via the
+ {}-syntax, we need to provide an explicit column list for salary via <return-property> -->
+ <return-column name="VALUE"/>
+ <return-column name="CURRENCY"/>
+ </return-property>
+ <!-- Here we are remapping endDate. Notice that we can still use {emp.endDate} in the SQL. -->
+ <return-property name="endDate" column="myEndDate"/>
+ </return>
+ <synchronize table="EMPLOYMENT"/>
+ SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer},
+ STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate},
+ REGIONCODE as {emp.regionCode}, EMPID AS {emp.id}, VALUE, CURRENCY
+ FROM EMPLOYMENT
+ WHERE EMPLOYER = :id AND ENDDATE IS NULL
+ ORDER BY STARTDATE ASC
+ </sql-query>
+
+ <sql-query name="simpleScalar" callable="true">
+ <return-scalar column="name" type="string"/>
+ <return-scalar column="value" type="long"/>
+ { call HIBDB2TST.simpleScalar(:number) }
+ </sql-query>
+
+ <sql-query name="paramhandling" callable="true">
+ <return-scalar column="value" type="long"/>
+ <return-scalar column="value2" type="long"/>
+ { call HIBDB2TST.paramHandling(?,?) }
+ </sql-query>
+
+ <sql-query name="paramhandling_mixed" callable="true">
+ <return-scalar column="value" type="long" />
+ <return-scalar column="value2" type="long" />
+ { call HIBDB2TST.paramHandling(?,:second) }
+ </sql-query>
+
+ <sql-query name="selectAllEmployments" callable="true">
+ <return alias="" class="Employment">
+ <return-property name="employee" column="EMPLOYEE"/>
+ <return-property name="employer" column="EMPLOYER"/>
+ <return-property name="startDate" column="STARTDATE"/>
+ <return-property name="endDate" column="ENDDATE"/>
+ <return-property name="regionCode" column="REGIONCODE"/>
+ <return-property name="id" column="EMPID"/>
+ <return-property name="salary">
+ <!-- as multi column properties are not supported via the
+ {}-syntax, we need to provide an explicit column list for salary via <return-property> -->
+ <return-column name="VALUE"/>
+ <return-column name="CURRENCY"/>
+ </return-property>
+ </return>
+ { call HIBDB2TST.selectAllEmployments() }
+ </sql-query>
+
+ <!-- DB2 seem to *require* users to specify explicit schema/location when executing a stored procedure *stupid* -->
+ <database-object>
+ <create>CREATE SCHEMA HIBDB2TST</create>
+ <drop>DROP SCHEMA HIBDB2TST RESTRICT</drop>
+ </database-object>
+
+ <database-object>
+ <create>
+ CREATE PROCEDURE HIBDB2TST.selectAllEmployments ()
+ P1: BEGIN
+ DECLARE C1 CURSOR WITH RETURN FOR
+ SELECT EMPLOYEE, EMPLOYER, STARTDATE, ENDDATE,
+ REGIONCODE, EMPID, VALUE, CURRENCY
+ FROM EMPLOYMENT;
+ OPEN C1;
+ END P1
+ </create>
+ <drop>
+ DROP PROCEDURE HIBDB2TST.selectAllEmployments
+ </drop>
+ </database-object>
+
+
+ <database-object>
+ <create>
+ CREATE PROCEDURE HIBDB2TST.paramHandling (IN j SMALLINT, IN i SMALLINT)
+ P1: BEGIN
+ DECLARE C1 CURSOR WITH RETURN FOR
+ SELECT j as value, i as value2 from sysibm.sysdummy1;
+ OPEN C1;
+ END P1
+ </create>
+ <drop>
+ DROP PROCEDURE HIBDB2TST.paramHandling
+ </drop>
+ </database-object>
+
+ <database-object>
+ <create>
+ CREATE PROCEDURE HIBDB2TST.simpleScalar (IN j SMALLINT)
+ P1: BEGIN
+ DECLARE C1 CURSOR WITH RETURN FOR
+ SELECT j as value, 'getAll' as name from sysibm.sysdummy1;
+ OPEN C1;
+ END P1
+ </create>
+ <drop>
+ DROP PROCEDURE HIBDB2TST.simpleScalar
+ </drop>
+ </database-object>
+</hibernate-mapping>
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/mysql/Mappings.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/mysql/Mappings.hbm.xml (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/mysql/Mappings.hbm.xml 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,216 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+ This mapping demonstrates the use of Hibernate with all-handwritten SQL!
+
+ This version is for MySQL
+-->
+
+<hibernate-mapping package="org.hibernate.test.sql.hand" default-access="field">
+
+ <class name="Organization">
+ <id name="id" unsaved-value="0" column="orgid">
+ <generator class="increment"/>
+ </id>
+ <property name="name" not-null="true"/>
+ <set name="employments"
+ inverse="true"
+ order-by="DUMMY">
+ <key column="employer"/> <!-- only needed for DDL generation -->
+ <one-to-many class="Employment"/>
+ <loader query-ref="organizationEmployments"/>
+ </set>
+ <!-- query-list name="currentEmployments"
+ query-ref="organizationCurrentEmployments"-->
+ <loader query-ref="organization"/>
+ <sql-insert>INSERT INTO ORGANIZATION (NAME, ORGID) VALUES ( UPPER(?), ? )</sql-insert>
+ <sql-update>UPDATE ORGANIZATION SET NAME=UPPER(?) WHERE ORGID=?</sql-update>
+ <sql-delete>DELETE FROM ORGANIZATION WHERE ORGID=?</sql-delete>
+ </class>
+
+ <class name="Person">
+ <id name="id" unsaved-value="0" column="perid">
+ <generator class="increment"/>
+ </id>
+ <property name="name" not-null="true"/>
+ <loader query-ref="person"/>
+ <sql-insert>INSERT INTO PERSON (NAME, PERID) VALUES ( UPPER(?), ? )</sql-insert>
+ <sql-update>UPDATE PERSON SET NAME=UPPER(?) WHERE PERID=?</sql-update>
+ <sql-delete>DELETE FROM PERSON WHERE PERID=?</sql-delete>
+ </class>
+
+ <class name="Employment">
+ <id name="employmentId" unsaved-value="0" column="empid">
+ <generator class="increment"/>
+ </id>
+ <many-to-one name="employee" not-null="true" update="false"/>
+ <many-to-one name="employer" not-null="true" update="false"/>
+ <property name="startDate" not-null="true" update="false" insert="false"/>
+ <property name="endDate" insert="false"/>
+ <property name="regionCode" update="false"/>
+ <property name="salary" type="org.hibernate.test.sql.hand.MonetaryAmountUserType">
+ <column name="VALUE" sql-type="float"/>
+ <column name="CURRENCY"/>
+ </property>
+ <loader query-ref="employment"/>
+ <sql-insert>
+ INSERT INTO EMPLOYMENT
+ (EMPLOYEE, EMPLOYER, STARTDATE, REGIONCODE, VALUE, CURRENCY, EMPID)
+ VALUES (?, ?, now(), UPPER(?), ?, ?, ?)
+ </sql-insert>
+ <sql-update>UPDATE EMPLOYMENT SET ENDDATE=?, VALUE=?, CURRENCY=? WHERE EMPID=?</sql-update>
+ <sql-delete>DELETE FROM EMPLOYMENT WHERE EMPID=?</sql-delete>
+ </class>
+
+ <resultset name="org-emp-regionCode">
+ <return-scalar column="regionCode" type="string"/>
+ <return alias="org" class="Organization"/>
+ <return-join alias="emp" property="org.employments"/>
+ </resultset>
+
+ <resultset name="org-emp-person">
+ <return alias="org" class="Organization"/>
+ <return-join alias="emp" property="org.employments"/>
+ <return-join alias="pers" property="emp.employee"/>
+ </resultset>
+
+ <sql-query name="person">
+ <return alias="p" class="Person" lock-mode="upgrade"/>
+ SELECT NAME AS {p.name}, PERID AS {p.id} FROM PERSON WHERE PERID=? /*FOR UPDATE*/
+ </sql-query>
+
+ <sql-query name="organization">
+ <return alias="org" class="Organization"/>
+ <return-join alias="emp" property="org.employments"/>
+ SELECT {org.*}, {emp.*}
+ FROM ORGANIZATION org
+ LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER
+ WHERE org.ORGID=?
+ </sql-query>
+
+
+
+ <!--sql-query name="organization">
+ <return alias="org" class="Organization"/>
+ SELECT NAME AS {org.name}, ORGID AS {org.id} FROM ORGANIZATION
+ WHERE ORGID=?
+ </sql-query-->
+
+ <sql-query name="allOrganizationsWithEmployees" flush-mode="never">
+ <return alias="org" class="Organization"/>
+ SELECT DISTINCT org.NAME AS {org.name}, org.ORGID AS {org.id}
+ FROM ORGANIZATION org
+ INNER JOIN EMPLOYMENT e ON e.EMPLOYER = org.ORGID
+ </sql-query>
+
+ <sql-query name="employment">
+ <return alias="emp" class="Employment"/>
+ SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer},
+ STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate},
+ REGIONCODE as {emp.regionCode}, EMPID AS {emp.id}
+ FROM EMPLOYMENT
+ WHERE EMPID = ?
+ </sql-query>
+
+
+ <sql-query name="organizationEmployments">
+ <load-collection alias="empcol" role="Organization.employments"/>
+ SELECT {empcol.*}
+ FROM EMPLOYMENT empcol
+ WHERE EMPLOYER = :id
+ ORDER BY STARTDATE ASC, EMPLOYEE ASC
+ </sql-query>
+
+
+ <sql-query name="organizationCurrentEmployments">
+ <return alias="emp" class="Employment">
+ <return-property name="salary">
+ <!-- as multi column properties are not supported via the
+ {}-syntax, we need to provide an explicit column list for salary via <return-property> -->
+ <return-column name="VALUE"/>
+ <return-column name="CURRENCY"/>
+ </return-property>
+ <!-- Here we are remapping endDate. Notice that we can still use {emp.endDate} in the SQL. -->
+ <return-property name="endDate" column="myEndDate"/>
+ </return>
+ <synchronize table="EMPLOYMENT"/>
+ SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer},
+ STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate},
+ REGIONCODE as {emp.regionCode}, EMPID AS {emp.id}, VALUE, CURRENCY
+ FROM EMPLOYMENT
+ WHERE EMPLOYER = :id AND ENDDATE IS NULL
+ ORDER BY STARTDATE ASC
+ </sql-query>
+
+ <sql-query name="simpleScalar" callable="true">
+ <return-scalar column="name" type="string"/>
+ <return-scalar column="value" type="long"/>
+ { call simpleScalar(:number) }
+ </sql-query>
+
+ <sql-query name="paramhandling" callable="true">
+ <return-scalar column="value" type="long"/>
+ <return-scalar column="value2" type="long"/>
+ { call paramHandling(?,?) }
+ </sql-query>
+
+ <sql-query name="paramhandling_mixed" callable="true">
+ <return-scalar column="value" type="long" />
+ <return-scalar column="value2" type="long" />
+ { call paramHandling(?,:second) }
+ </sql-query>
+
+ <sql-query name="selectAllEmployments" callable="true">
+ <return alias="" class="Employment">
+ <return-property name="employee" column="EMPLOYEE"/>
+ <return-property name="employer" column="EMPLOYER"/>
+ <return-property name="startDate" column="STARTDATE"/>
+ <return-property name="endDate" column="ENDDATE"/>
+ <return-property name="regionCode" column="REGIONCODE"/>
+ <return-property name="id" column="EMPID"/>
+ <return-property name="salary">
+ <!-- as multi column properties are not supported via the
+ {}-syntax, we need to provide an explicit column list for salary via <return-property> -->
+ <return-column name="VALUE"/>
+ <return-column name="CURRENCY"/>
+ </return-property>
+ </return>
+ { call selectAllEmployments() }
+ </sql-query>
+
+ <database-object>
+ <create>
+ CREATE PROCEDURE selectAllEmployments ()
+ SELECT EMPLOYEE, EMPLOYER, STARTDATE, ENDDATE,
+ REGIONCODE, EMPID, VALUE, CURRENCY
+ FROM EMPLOYMENT
+ </create>
+ <drop>
+ DROP PROCEDURE selectAllEmployments
+ </drop>
+ </database-object>
+
+ <database-object>
+ <create>
+ CREATE PROCEDURE paramHandling (j int, i int)
+ SELECT j AS value, i AS value2
+ </create>
+ <drop>
+ DROP PROCEDURE paramHandling
+ </drop>
+ </database-object>
+
+ <database-object>
+ <create>
+ CREATE PROCEDURE simpleScalar (number int)
+ SELECT number AS value, 'getAll' AS name
+ </create>
+ <drop>
+ DROP PROCEDURE simpleScalar
+ </drop>
+ </database-object>
+
+</hibernate-mapping>
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/mysql/MySQLCustomSQLTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/mysql/MySQLCustomSQLTest.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/mysql/MySQLCustomSQLTest.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,34 @@
+//$Id: MySQLCustomSQLTest.java 10977 2006-12-12 17:28:04 -0600 (Tue, 12 Dec 2006) steve.ebersole at jboss.com $
+package org.hibernate.test.sql.hand.custom.mysql;
+
+import junit.framework.Test;
+
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.MySQLDialect;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.test.sql.hand.custom.CustomStoredProcTestSupport;
+
+/**
+ * Custom SQL tests for MySQL
+ *
+ * @author Gavin King
+ */
+public class MySQLCustomSQLTest extends CustomStoredProcTestSupport {
+
+ public MySQLCustomSQLTest(String str) {
+ super(str);
+ }
+
+ public String[] getMappings() {
+ return new String[] { "sql/hand/custom/mysql/Mappings.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( MySQLCustomSQLTest.class );
+ }
+
+ public boolean appliesTo(Dialect dialect) {
+ return ( dialect instanceof MySQLDialect );
+ }
+}
+
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/oracle/Mappings.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/oracle/Mappings.hbm.xml (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/oracle/Mappings.hbm.xml 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,209 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+ This mapping demonstrates the use of Hibernate with all-handwritten SQL!
+
+ Note: this version is for Oracle
+-->
+<hibernate-mapping package="org.hibernate.test.sql.hand" default-access="field">
+
+ <class name="Organization">
+ <id name="id" unsaved-value="0" column="orgid">
+ <generator class="increment"/>
+ </id>
+ <property name="name" not-null="true"/>
+ <set name="employments"
+ inverse="true"
+ order-by="DUMMY">
+ <key column="employer"/>
+ <!-- only needed for DDL generation -->
+ <one-to-many class="Employment"/>
+ <loader query-ref="organizationEmployments"/>
+ </set>
+ <!-- query-list name="currentEmployments"
+ query-ref="organizationCurrentEmployments"-->
+ <loader query-ref="organization"/>
+ <sql-insert>INSERT INTO ORGANIZATION (NAME, ORGID) VALUES ( UPPER(?), ? )</sql-insert>
+ <sql-update>UPDATE ORGANIZATION SET NAME=UPPER(?) WHERE ORGID=?</sql-update>
+ <sql-delete>DELETE FROM ORGANIZATION WHERE ORGID=?</sql-delete>
+ </class>
+
+ <class name="Person">
+ <id name="id" unsaved-value="0" column="perid">
+ <generator class="increment"/>
+ </id>
+ <property name="name" not-null="true"/>
+ <loader query-ref="person"/>
+ <sql-insert callable="true" check="none">{call createPerson(?,?)}</sql-insert>
+ <sql-update>UPDATE PERSON SET NAME=UPPER(?) WHERE PERID=?</sql-update>
+ <sql-delete>DELETE FROM PERSON WHERE PERID=?</sql-delete>
+ </class>
+
+ <class name="Employment">
+ <id name="employmentId" unsaved-value="0" column="empid">
+ <generator class="increment"/>
+ </id>
+ <many-to-one name="employee" not-null="true" update="false"/>
+ <many-to-one name="employer" not-null="true" update="false"/>
+ <property name="startDate" not-null="true" update="false" insert="false"/>
+ <property name="endDate" insert="false"/>
+ <property name="regionCode" update="false"/>
+ <property name="salary" type="org.hibernate.test.sql.hand.MonetaryAmountUserType">
+ <column name="VALUE" sql-type="float"/>
+ <column name="CURRENCY"/>
+ </property>
+ <loader query-ref="employment"/>
+ <sql-insert>
+ INSERT INTO EMPLOYMENT
+ (EMPLOYEE, EMPLOYER, STARTDATE, REGIONCODE, VALUE, CURRENCY, EMPID)
+ VALUES (?, ?, CURRENT_DATE, UPPER(?), ?, ?, ?)
+ </sql-insert>
+ <sql-update>UPDATE EMPLOYMENT SET ENDDATE=?, VALUE=?, CURRENCY=? WHERE EMPID=?</sql-update>
+ <sql-delete>DELETE FROM EMPLOYMENT WHERE EMPID=?</sql-delete>
+ </class>
+
+ <resultset name="org-emp-regionCode">
+ <return-scalar column="regionCode" type="string"/>
+ <return alias="org" class="Organization"/>
+ <return-join alias="emp" property="org.employments"/>
+ </resultset>
+
+ <resultset name="org-emp-person">
+ <return alias="org" class="Organization"/>
+ <return-join alias="emp" property="org.employments"/>
+ <return-join alias="pers" property="emp.employee"/>
+ </resultset>
+
+ <sql-query name="person">
+ <return alias="p" class="Person" lock-mode="upgrade"/>
+ SELECT NAME AS {p.name}, PERID AS {p.id} FROM PERSON WHERE PERID=? /*FOR UPDATE*/
+ </sql-query>
+
+ <sql-query name="organization">
+ <return alias="org" class="Organization"/>
+ <return-join alias="emp" property="org.employments"/>
+ SELECT {org.*}, {emp.*}
+ FROM ORGANIZATION org
+ LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER
+ WHERE org.ORGID=?
+ </sql-query>
+
+
+ <sql-query name="allOrganizationsWithEmployees" flush-mode="never">
+ <return alias="org" class="Organization"/>
+ SELECT DISTINCT org.NAME AS {org.name}, org.ORGID AS {org.id}
+ FROM ORGANIZATION org
+ INNER JOIN EMPLOYMENT e ON e.EMPLOYER = org.ORGID
+ </sql-query>
+
+
+ <sql-query name="employment">
+ <return alias="emp" class="Employment"/>
+ SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer},
+ STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate},
+ REGIONCODE as {emp.regionCode}, EMPID AS {emp.id}
+ FROM EMPLOYMENT
+ WHERE EMPID = ?
+ </sql-query>
+
+
+ <sql-query name="organizationEmployments">
+ <load-collection alias="empcol" role="Organization.employments"/>
+ SELECT {empcol.*}
+ FROM EMPLOYMENT empcol
+ WHERE EMPLOYER = :id
+ ORDER BY STARTDATE ASC, EMPLOYEE ASC
+ </sql-query>
+
+
+ <sql-query name="organizationCurrentEmployments">
+ <return alias="emp" class="Employment">
+ <return-property name="salary">
+ <!-- as multi column properties are not supported via the
+ {}-syntax, we need to provide an explicit column list for salary via <return-property> -->
+ <return-column name="VALUE"/>
+ <return-column name="CURRENCY"/>
+ </return-property>
+ <!-- Here we are remapping endDate. Notice that we can still use {emp.endDate} in the SQL. -->
+ <return-property name="endDate" column="myEndDate"/>
+ </return>
+ <synchronize table="EMPLOYMENT"/>
+ SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer},
+ STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate},
+ REGIONCODE as {emp.regionCode}, EMPID AS {emp.id}, VALUE, CURRENCY
+ FROM EMPLOYMENT
+ WHERE EMPLOYER = :id AND ENDDATE IS NULL
+ ORDER BY STARTDATE ASC
+ </sql-query>
+
+ <database-object>
+ <create>
+ CREATE OR REPLACE FUNCTION testParamHandling (j number, i number)
+ RETURN SYS_REFCURSOR AS st_cursor SYS_REFCURSOR;
+ BEGIN
+ OPEN st_cursor FOR
+ SELECT j as value, i as value2 from dual;
+ RETURN st_cursor;
+ END;
+ </create>
+ <drop>
+ DROP FUNCTION testParamHandling
+ </drop>
+ </database-object>
+
+ <database-object>
+ <create>
+ CREATE OR REPLACE FUNCTION simpleScalar (j number)
+ RETURN SYS_REFCURSOR AS st_cursor SYS_REFCURSOR;
+ BEGIN
+ OPEN st_cursor FOR
+ SELECT j as value, 'getAll' as name from dual;
+ RETURN st_cursor;
+ END;
+ </create>
+ <drop>
+ DROP FUNCTION simpleScalar
+ </drop>
+ </database-object>
+
+ <database-object>
+ <create>
+ CREATE OR REPLACE FUNCTION allEmployments
+ RETURN SYS_REFCURSOR AS st_cursor SYS_REFCURSOR;
+ BEGIN
+ OPEN st_cursor FOR
+ SELECT EMPLOYEE, EMPLOYER, STARTDATE, ENDDATE,
+ REGIONCODE, EMPID, VALUE, CURRENCY
+ FROM EMPLOYMENT;
+ RETURN st_cursor;
+ END;
+ </create>
+ <drop>
+ DROP FUNCTION allEmployments
+ </drop>
+ </database-object>
+
+ <database-object>
+ <create>
+ CREATE OR REPLACE PROCEDURE createPerson(p_name PERSON.NAME%TYPE, p_id PERSON.PERID%TYPE)
+ AS
+ rowcount INTEGER;
+ BEGIN
+ INSERT INTO PERSON ( PERID, NAME ) VALUES ( p_id, UPPER( p_name ) );
+ rowcount := SQL%ROWCOUNT;
+ IF rowcount = 1 THEN
+ NULL;
+ ELSE
+ RAISE_APPLICATION_ERROR( -20001, 'Unexpected rowcount [' || rowcount || ']' );
+ END IF;
+ END;
+ </create>
+ <drop>
+ DROP PROCEDURE createPerson;
+ </drop>
+ </database-object>
+
+</hibernate-mapping>
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/oracle/OracleCustomSQLTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/oracle/OracleCustomSQLTest.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/oracle/OracleCustomSQLTest.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,36 @@
+//$Id$
+package org.hibernate.test.sql.hand.custom.oracle;
+
+import junit.framework.Test;
+
+import org.hibernate.dialect.DataDirectOracle9Dialect;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.Oracle9Dialect;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.test.sql.hand.custom.CustomStoredProcTestSupport;
+
+/**
+ * Custom SQL tests for Oracle
+ *
+ * @author Gavin King
+ */
+public class OracleCustomSQLTest extends CustomStoredProcTestSupport {
+
+ public OracleCustomSQLTest(String str) {
+ super(str);
+ }
+
+ public String[] getMappings() {
+ return new String[] { "sql/hand/custom/oracle/Mappings.hbm.xml", "sql/hand/custom/oracle/StoredProcedures.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( OracleCustomSQLTest.class );
+ }
+
+ public boolean appliesTo(Dialect dialect) {
+ return ( dialect instanceof Oracle9Dialect ) && !( dialect instanceof DataDirectOracle9Dialect );
+ }
+
+}
+
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/oracle/StoredProcedures.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/oracle/StoredProcedures.hbm.xml (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/oracle/StoredProcedures.hbm.xml 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+ This version is for Oracle drivers proprietary handling of stored procedures/functions.
+-->
+<hibernate-mapping package="org.hibernate.test.sql.hand" default-access="field">
+
+ <sql-query name="simpleScalar" callable="true">
+ <return-scalar column="name" type="string"/>
+ <return-scalar column="value" type="long"/>
+ { ? = call simpleScalar(:number) }
+ </sql-query>
+
+ <sql-query name="paramhandling" callable="true">
+ <return-scalar column="value" type="long"/>
+ <return-scalar column="value2" type="long"/>
+ { ? = call testParamHandling(?,?) }
+ </sql-query>
+
+ <sql-query name="paramhandling_mixed" callable="true">
+ <return-scalar column="value" type="long"/>
+ <return-scalar column="value2" type="long"/>
+ { ? = call testParamHandling(?,:second) }
+ </sql-query>
+
+ <sql-query name="selectAllEmployments" callable="true">
+ <return alias="emp" class="Employment">
+ <return-property name="employee" column="EMPLOYEE"/>
+ <return-property name="employer" column="EMPLOYER"/>
+ <return-property name="startDate" column="STARTDATE"/>
+ <return-property name="endDate" column="ENDDATE"/>
+ <return-property name="regionCode" column="REGIONCODE"/>
+ <return-property name="employmentId" column="EMPID"/>
+ <return-property name="salary">
+ <return-column name="VALUE"/>
+ <return-column name="CURRENCY"/>
+ </return-property>
+ </return>
+ { ? = call allEmployments() }
+ </sql-query>
+
+</hibernate-mapping>
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/sybase/Mappings.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/sybase/Mappings.hbm.xml (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/sybase/Mappings.hbm.xml 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,217 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+ This mapping demonstrates the use of Hibernate with all-handwritten SQL!
+
+ NOTE: this version is for Sybase/SQLServer
+-->
+<hibernate-mapping package="org.hibernate.test.sql.hand" default-access="field">
+
+ <class name="Organization" table="ORGANIZATION">
+ <id name="id" unsaved-value="0" column="ORGID">
+ <generator class="increment"/>
+ </id>
+ <property name="name" not-null="true" column="NAME"/>
+ <set name="employments"
+ inverse="true"
+ order-by="DUMMY">
+ <key column="EMPLOYER"/> <!-- only needed for DDL generation -->
+ <one-to-many class="Employment"/>
+ <loader query-ref="organizationEmployments"/>
+ </set>
+ <!-- query-list name="currentEmployments"
+ query-ref="organizationCurrentEmployments"-->
+ <loader query-ref="organization"/>
+ <sql-insert>INSERT INTO ORGANIZATION (NAME, ORGID) VALUES ( UPPER(?), ? )</sql-insert>
+ <sql-update>UPDATE ORGANIZATION SET NAME=UPPER(?) WHERE ORGID=?</sql-update>
+ <sql-delete>DELETE FROM ORGANIZATION WHERE ORGID=?</sql-delete>
+ </class>
+
+ <class name="Person" table="PERSON">
+ <id name="id" unsaved-value="0" column="PERID">
+ <generator class="increment"/>
+ </id>
+ <property name="name" not-null="true" column="NAME"/>
+ <loader query-ref="person"/>
+ <sql-insert>INSERT INTO PERSON (NAME, PERID) VALUES ( UPPER(?), ? )</sql-insert>
+ <sql-update>UPDATE PERSON SET NAME=UPPER(?) WHERE PERID=?</sql-update>
+ <sql-delete>DELETE FROM PERSON WHERE PERID=?</sql-delete>
+ </class>
+
+ <class name="Employment" table="EMPLOYMENT">
+ <id name="employmentId" unsaved-value="0" column="EMPID">
+ <generator class="increment"/>
+ </id>
+ <many-to-one name="employee" column="EMPLOYEE" not-null="true" update="false"/>
+ <many-to-one name="employer" column="EMPLOYER" not-null="true" update="false"/>
+ <property name="startDate" column="STARTDATE" not-null="true" update="false" insert="false"/>
+ <property name="endDate" column="ENDDATE" insert="false"/>
+ <property name="regionCode" column="REGIONCODE" update="false"/>
+ <property name="salary" type="org.hibernate.test.sql.hand.MonetaryAmountUserType">
+ <column name="VALUE" sql-type="float"/>
+ <column name="CURRENCY"/>
+ </property>
+ <loader query-ref="employment"/>
+ <sql-insert>
+ INSERT INTO EMPLOYMENT
+ (EMPLOYEE, EMPLOYER, STARTDATE, REGIONCODE, VALUE, CURRENCY, EMPID)
+ VALUES (?, ?, getdate(), UPPER(?), ?, ?, ?)
+ </sql-insert>
+ <sql-update>UPDATE EMPLOYMENT SET ENDDATE=?, VALUE=?, CURRENCY=? WHERE EMPID=?</sql-update>
+ <sql-delete>DELETE FROM EMPLOYMENT WHERE EMPID=?</sql-delete>
+ </class>
+
+ <resultset name="org-emp-regionCode">
+ <return-scalar column="regionCode" type="string"/>
+ <return alias="org" class="Organization"/>
+ <return-join alias="emp" property="org.employments"/>
+ </resultset>
+
+ <resultset name="org-emp-person">
+ <return alias="org" class="Organization"/>
+ <return-join alias="emp" property="org.employments"/>
+ <return-join alias="pers" property="emp.employee"/>
+ </resultset>
+
+ <sql-query name="person">
+ <return alias="p" class="Person" lock-mode="upgrade"/>
+ SELECT NAME AS {p.name}, PERID AS {p.id} FROM PERSON WHERE PERID=? /*FOR UPDATE*/
+ </sql-query>
+
+ <sql-query name="organization">
+ <return alias="org" class="Organization"/>
+ <return-join alias="emp" property="org.employments"/>
+ SELECT {org.*}, {emp.*}
+ FROM ORGANIZATION org
+ LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER
+ WHERE org.ORGID=?
+ </sql-query>
+
+
+ <!--sql-query name="organization">
+ <return alias="org" class="Organization"/>
+ SELECT NAME AS {org.name}, ORGID AS {org.id} FROM ORGANIZATION
+ WHERE ORGID=?
+ </sql-query-->
+
+ <sql-query name="allOrganizationsWithEmployees" flush-mode="never">
+ <return alias="org" class="Organization"/>
+ SELECT DISTINCT org.NAME AS {org.name}, org.ORGID AS {org.id}
+ FROM ORGANIZATION org
+ INNER JOIN EMPLOYMENT e ON e.EMPLOYER = org.ORGID
+ </sql-query>
+
+
+
+
+
+ <sql-query name="employment">
+ <return alias="emp" class="Employment"/>
+ SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer},
+ STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate},
+ REGIONCODE as {emp.regionCode}, EMPID AS {emp.id}
+ FROM EMPLOYMENT
+ WHERE EMPID = ?
+ </sql-query>
+
+ <sql-query name="organizationEmployments">
+ <load-collection alias="empcol" role="Organization.employments"/>
+ SELECT {empcol.*}
+ FROM EMPLOYMENT empcol
+ WHERE EMPLOYER = :id
+ ORDER BY STARTDATE ASC, EMPLOYEE ASC
+ </sql-query>
+
+
+ <sql-query name="organizationCurrentEmployments">
+ <return alias="emp" class="Employment">
+ <return-property name="salary">
+ <!-- as multi column properties are not supported via the
+ {}-syntax, we need to provide an explicit column list for salary via <return-property> -->
+ <return-column name="VALUE"/>
+ <return-column name="CURRENCY"/>
+ </return-property>
+ <!-- Here we are remapping endDate. Notice that we can still use {emp.endDate} in the SQL. -->
+ <return-property name="endDate" column="myEndDate"/>
+ </return>
+ <synchronize table="EMPLOYMENT"/>
+ SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer},
+ STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate},
+ REGIONCODE as {emp.regionCode}, EMPID AS {emp.id}, VALUE, CURRENCY
+ FROM EMPLOYMENT
+ WHERE EMPLOYER = :id AND ENDDATE IS NULL
+ ORDER BY STARTDATE ASC
+ </sql-query>
+
+ <sql-query name="simpleScalar" callable="true">
+ <return-scalar column="name" type="string"/>
+ <return-scalar column="value" type="long"/>
+ { call simpleScalar(:number) }
+ </sql-query>
+
+ <sql-query name="paramhandling" callable="true">
+ <return-scalar column="value" type="long"/>
+ <return-scalar column="value2" type="long"/>
+ { call paramHandling(?,?) }
+ </sql-query>
+
+ <sql-query name="paramhandling_mixed" callable="true">
+ <return-scalar column="value" type="long" />
+ <return-scalar column="value2" type="long" />
+ { call paramHandling(?,:second) }
+ </sql-query>
+
+ <sql-query name="selectAllEmployments" callable="true">
+ <return alias="" class="Employment">
+ <return-property name="employee" column="EMPLOYEE"/>
+ <return-property name="employer" column="EMPLOYER"/>
+ <return-property name="startDate" column="STARTDATE"/>
+ <return-property name="endDate" column="ENDDATE"/>
+ <return-property name="regionCode" column="REGIONCODE"/>
+ <return-property name="id" column="EMPID"/>
+ <return-property name="salary">
+ <!-- as multi column properties are not supported via the
+ {}-syntax, we need to provide an explicit column list for salary via <return-property> -->
+ <return-column name="VALUE"/>
+ <return-column name="CURRENCY"/>
+ </return-property>
+ </return>
+ { call selectAllEmployments() }
+ </sql-query>
+
+ <database-object>
+ <create>
+ CREATE PROCEDURE selectAllEmployments AS
+ SELECT EMPLOYEE, EMPLOYER, STARTDATE, ENDDATE,
+ REGIONCODE, EMPID, VALUE, CURRENCY
+ FROM EMPLOYMENT
+ </create>
+ <drop>
+ DROP PROCEDURE selectAllEmployments
+ </drop>
+ </database-object>
+
+ <database-object>
+ <create>
+ CREATE PROCEDURE paramHandling @j int, @i int AS
+ SELECT @j as value, @i as value2
+ </create>
+ <drop>
+ DROP PROCEDURE paramHandling
+ </drop>
+ </database-object>
+
+ <database-object>
+ <create>
+ CREATE PROCEDURE simpleScalar @number int AS
+ SELECT @number as value, 'getAll' as name
+ </create>
+ <drop>
+ DROP PROCEDURE simpleScalar
+ </drop>
+ </database-object>
+
+</hibernate-mapping>
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/sybase/SybaseCustomSQLTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/sybase/SybaseCustomSQLTest.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/custom/sybase/SybaseCustomSQLTest.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,34 @@
+//$Id$
+package org.hibernate.test.sql.hand.custom.sybase;
+
+import junit.framework.Test;
+
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.SybaseDialect;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.test.sql.hand.custom.CustomStoredProcTestSupport;
+
+/**
+ * Custom SQL tests for Sybase/SQLServer (Transact-SQL)
+ *
+ * @author Gavin King
+ */
+public class SybaseCustomSQLTest extends CustomStoredProcTestSupport {
+
+ public SybaseCustomSQLTest(String str) {
+ super( str );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "sql/hand/custom/sybase/Mappings.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( SybaseCustomSQLTest.class );
+ }
+
+ public boolean appliesTo(Dialect dialect) {
+ return ( dialect instanceof SybaseDialect );
+ }
+}
+
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/identity/CustomInsertSQLWithIdentityColumnTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/identity/CustomInsertSQLWithIdentityColumnTest.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/identity/CustomInsertSQLWithIdentityColumnTest.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,50 @@
+package org.hibernate.test.sql.hand.identity;
+
+import junit.framework.Test;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.junit.functional.DatabaseSpecificFunctionalTestCase;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.Session;
+import org.hibernate.JDBCException;
+import org.hibernate.test.sql.hand.Organization;
+
+/**
+ * Custom SQL tests for combined usage of custom insert SQL and identity columns
+ *
+ * @author Gail Badner
+ */
+public class CustomInsertSQLWithIdentityColumnTest extends DatabaseSpecificFunctionalTestCase {
+
+ public CustomInsertSQLWithIdentityColumnTest(String str) {
+ super( str );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( CustomInsertSQLWithIdentityColumnTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] {"sql/hand/identity/Mappings.hbm.xml"};
+ }
+
+ public boolean appliesTo(Dialect dialect) {
+ return dialect.supportsIdentityColumns();
+ }
+
+ public void testBadInsertionFails() {
+ Session session = openSession();
+ session.beginTransaction();
+ Organization org = new Organization( "hola!" );
+ try {
+ session.save( org );
+ session.delete( org );
+ fail( "expecting bad custom insert statement to fail" );
+ }
+ catch( JDBCException e ) {
+ // expected failure
+ }
+
+ session.getTransaction().rollback();
+ session.close();
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/identity/Mappings.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/identity/Mappings.hbm.xml (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/identity/Mappings.hbm.xml 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+ This mapping demonstrates the combined use of IDENTITY PK columns and
+ custom supplied SQL statements.
+
+ @author : Gail Badner
+-->
+
+<hibernate-mapping package="org.hibernate.test.sql.hand" default-access="field">
+
+ <class name="Organization" table="ORGANIZATION">
+ <id name="id" column="ORG_ID">
+ <generator class="identity"/>
+ </id>
+ <property name="name" not-null="true"/>
+ <!-- Intentionally bad SQL statement!!! -->
+ <sql-insert>INSERT INTO PERSON WHERE x=y</sql-insert>
+ </class>
+
+</hibernate-mapping>
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,262 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+
+ This mapping demonstrates the use of Hibernate with
+ all-handwritten SQL!
+-->
+
+<hibernate-mapping package="org.hibernate.test.sql.hand" default-access="field">
+
+ <class name="Organization" table="ORGANIZATION">
+ <id name="id" unsaved-value="0" column="ORGID">
+ <generator class="increment"/>
+ </id>
+ <property name="name" column="NAME" not-null="true"/>
+ <set lazy="true" name="employments"
+ inverse="true">
+ <key column="EMPLOYER"/> <!-- only needed for DDL generation -->
+ <one-to-many class="Employment"/>
+ </set>
+ </class>
+
+ <class name="Person" table="PERSON">
+ <id name="id" unsaved-value="0" column="PERID">
+ <generator class="increment"/>
+ </id>
+ <property name="name" column="NAME" not-null="true"/>
+
+ </class>
+
+ <class name="Employment" table="EMPLOYMENT">
+ <id name="employmentId" unsaved-value="0" column="EMPID">
+ <generator class="increment"/>
+ </id>
+ <many-to-one name="employee" column="EMPLOYEE" not-null="true" update="false"/>
+ <many-to-one name="employer" column="EMPLOYER" not-null="true" update="false"/>
+ <property name="startDate" column="STARTDATE" not-null="false"/>
+ <property name="endDate" column="ENDDATE" insert="false"/>
+ <property name="regionCode" column="REGIONCODE" update="false"/>
+ <property name="salary" type="org.hibernate.test.sql.hand.MonetaryAmountUserType">
+ <column name="VALUE" sql-type="float"/>
+ <column name="CURRENCY"/>
+ </property>
+ </class>
+
+ <class name="Order" table="TBL_ORDER">
+ <composite-id name="orderId" class="Order$OrderId">
+ <key-property name="orgid"/>
+ <key-property name="ordernumber"/>
+ </composite-id>
+
+ <many-to-one name="product">
+ <column name="PROD_ORGID"/>
+ <column name="PROD_NO"/>
+ </many-to-one>
+ <many-to-one name="person"/>
+ </class>
+
+ <class name="Product">
+ <composite-id name="productId" class="Product$ProductId">
+ <key-property name="orgid"/>
+ <key-property name="productnumber"/>
+ </composite-id>
+
+ <property name="name"/>
+
+ <set name="orders" inverse="true">
+ <key>
+ <column name="PROD_ORGID"/>
+ <column name="PROD_NO"/>
+ </key>
+ <one-to-many class="Order"/>
+ </set>
+ </class>
+
+ <class name="Dimension">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="length" column="d_len"/>
+ <property name="width" column="d_width"/>
+ </class>
+
+ <class name="SpaceShip">
+ <id name="id" type="integer">
+ <generator class="increment"/>
+ </id>
+ <property name="name" column="fld_name"/>
+ <property name="model" column="fld_model"/>
+ <property name="speed" column="fld_speed"/>
+ <component name="dimensions">
+ <property name="length" column="fld_length"/>
+ <property name="width" column="fld_width"/>
+ </component>
+ </class>
+
+ <class name="Speech">
+ <id name="id" type="integer">
+ <generator class="increment"/>
+ </id>
+ <property name="name" column="name"/>
+ <property name="length" column="flength"/>
+ </class>
+
+ <resultset name="org-emp-regionCode">
+ <return-scalar column="regionCode" type="string"/>
+ <return alias="org" class="Organization"/>
+ <return-join alias="emp" property="org.employments"/>
+ </resultset>
+
+ <resultset name="org-emp-person">
+ <return alias="org" class="Organization"/>
+ <return-join alias="emp" property="org.employments"/>
+ <return-join alias="pers" property="emp.employee"/>
+ </resultset>
+
+
+ <resultset name="org-description">
+ <return alias="org" class="Organization"/>
+ <return-join alias="emp" property="org.employments"/>
+ </resultset>
+
+ <resultset name="spaceship-vol">
+ <return alias="sps" class="SpaceShip">
+ <return-property name="id" column="id"/>
+ <return-property name="name" column="name"/>
+ <return-property name="model" column="model"/>
+ <return-property name="speed" column="speed"/>
+ <return-property name="dimensions.length" column="length"/>
+ <return-property name="dimensions.width" column="width"/>
+ </return>
+ <return-scalar column="surface"/>
+ <return-scalar column="volume"/>
+ </resultset>
+
+ <resultset name="speech">
+ <return alias="sp" class="Speech">
+ <return-property name="id" column="id"/>
+ <return-property name="name" column="name"/>
+ <return-property name="length" column="flength"/>
+ </return>
+ <return-scalar column="scalarName"/>
+ </resultset>
+
+ <sql-query name="spaceship" resultset-ref="spaceship-vol">
+ select id as id,
+ fld_name as name,
+ fld_model as model,
+ fld_speed as speed,
+ fld_length as length,
+ fld_width as width,
+ fld_length * fld_width as surface,
+ fld_length * fld_width *10 as volume
+ from SpaceShip
+ </sql-query>
+
+ <sql-query name="orgNamesOnly">
+ <return-scalar column="NAME" type="string"/>
+ SELECT org.NAME FROM ORGANIZATION org
+ </sql-query>
+
+ <sql-query name="orgNamesAndOrgs">
+ <return-scalar column="thename" type="string"/>
+ <return alias="org" class="Organization"/>
+ SELECT org.NAME AS thename, org.NAME AS {org.name}, org.ORGID AS {org.id}
+ FROM ORGANIZATION org
+ ORDER BY thename
+ </sql-query>
+
+ <sql-query name="orgsAndOrgNames">
+ <return alias="org" class="Organization"/>
+ <return-scalar column="thename" type="string"/>
+ SELECT org.NAME AS thename, org.NAME AS {org.name}, org.ORGID AS {org.id}
+ FROM ORGANIZATION org
+ ORDER BY thename
+ </sql-query>
+
+ <sql-query name="orgIdsAndOrgNames">
+ <return-scalar column="orgid" type="long"/>
+ <return-scalar column="thename" type="string"/>
+ SELECT NAME AS thename, ORGID AS orgid
+ FROM ORGANIZATION
+ ORDER BY thename
+ </sql-query>
+
+ <sql-query name="AllEmploymentAsMapped">
+ <return class="Employment"/>
+ SELECT * FROM EMPLOYMENT
+ </sql-query>
+
+ <sql-query name="EmploymentAndPerson">
+ <return class="Employment"/>
+ <return class="Person"/>
+ SELECT * FROM EMPLOYMENT, PERSON
+ </sql-query>
+
+ <sql-query name="organizationEmploymentsExplicitAliases">
+ <load-collection alias="empcol" role="Organization.employments"/>
+ SELECT empcol.EMPLOYER as {empcol.key}, empcol.EMPID as {empcol.element}, {empcol.element.*}
+ FROM EMPLOYMENT empcol
+ WHERE EMPLOYER = :id
+ ORDER BY STARTDATE ASC, EMPLOYEE ASC
+ </sql-query>
+
+ <sql-query name="organizationreturnproperty">
+ <return alias="org" class="Organization">
+ <return-property name="id" column="ORGID"/>
+ <return-property name="name" column="NAME"/>
+ </return>
+ <return-join alias="emp" property="org.employments">
+ <return-property name="key" column="EMPLOYER"/>
+ <return-property name="element" column="EMPID"/>
+ <return-property name="element.employee" column="EMPLOYEE"/>
+ <return-property name="element.employer" column="EMPLOYER"/>
+ <return-property name="element.startDate" column="XSTARTDATE"/>
+ <return-property name="element.endDate" column="ENDDATE"/>
+ <return-property name="element.regionCode" column="REGIONCODE"/>
+ <return-property name="element.employmentId" column="EMPID"/>
+ <return-property name="element.salary">
+ <return-column name="VALUE"/>
+ <return-column name="CURRENCY"/>
+ </return-property>
+ </return-join>
+ SELECT org.ORGID as orgid,
+ org.NAME as name,
+ emp.EMPLOYER as employer,
+ emp.EMPID as empid,
+ emp.EMPLOYEE as employee,
+ emp.EMPLOYER as employer,
+ emp.STARTDATE as xstartDate,
+ emp.ENDDATE as endDate,
+ emp.REGIONCODE as regionCode,
+ emp.VALUE as VALUE,
+ emp.CURRENCY as CURRENCY
+ FROM ORGANIZATION org
+ LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER
+ </sql-query>
+
+
+ <sql-query name="organizationautodetect" resultset-ref="org-description">
+ <!-- equal to "organizationpropertyreturn" but since no {} nor return-property are used hibernate will fallback to use the columns directly from the mapping -->
+ <return alias="org" class="Organization"/>
+ <return-join alias="emp" property="org.employments"/>
+ SELECT org.ORGID as orgid,
+ org.NAME as name,
+ emp.EMPLOYER as employer,
+ emp.EMPID as empid,
+ emp.EMPLOYEE as employee,
+ emp.EMPLOYER as employer,
+ emp.STARTDATE as startDate,
+ emp.ENDDATE as endDate,
+ emp.REGIONCODE as regionCode,
+ emp.VALUE as VALUE,
+ emp.CURRENCY as CURRENCY
+ FROM ORGANIZATION org
+ LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER
+ </sql-query>
+
+</hibernate-mapping>
\ No newline at end of file
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/sql/hand/query/NativeSQLQueriesTest.java 2007-05-08 21:56:00 UTC (rev 11485)
@@ -0,0 +1,618 @@
+package org.hibernate.test.sql.hand.query;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Test;
+
+import org.hibernate.Hibernate;
+import org.hibernate.HibernateException;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.test.sql.hand.Organization;
+import org.hibernate.test.sql.hand.Person;
+import org.hibernate.test.sql.hand.Employment;
+import org.hibernate.test.sql.hand.Product;
+import org.hibernate.test.sql.hand.Order;
+import org.hibernate.test.sql.hand.Dimension;
+import org.hibernate.test.sql.hand.SpaceShip;
+import org.hibernate.test.sql.hand.Speech;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.transform.DistinctRootEntityResultTransformer;
+import org.hibernate.transform.Transformers;
+import org.hibernate.transform.AliasToEntityMapResultTransformer;
+
+/**
+ * Tests of various features of native SQL queries.
+ *
+ * @author Steve Ebersole
+ */
+public class NativeSQLQueriesTest extends FunctionalTestCase {
+
+ public NativeSQLQueriesTest(String x) {
+ super( x );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "sql/hand/query/NativeSQLQueries.hbm.xml" };
+ }
+
+ public void configure(Configuration cfg) {
+ super.configure( cfg );
+ cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( NativeSQLQueriesTest.class );
+ }
+
+ protected String getOrganizationFetchJoinEmploymentSQL() {
+ return "SELECT org.ORGID as {org.id}, " +
+ " org.NAME as {org.name}, " +
+ " emp.EMPLOYER as {emp.key}, " +
+ " emp.EMPID as {emp.element}, " +
+ " {emp.element.*} " +
+ "FROM ORGANIZATION org " +
+ " LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER";
+ }
+
+ protected String getOrganizationJoinEmploymentSQL() {
+ return "SELECT org.ORGID as {org.id}, " +
+ " org.NAME as {org.name}, " +
+ " {emp.*} " +
+ "FROM ORGANIZATION org " +
+ " LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER";
+ }
+
+ protected String getEmploymentSQL() {
+ return "SELECT * FROM EMPLOYMENT";
+ }
+
+ protected String getEmploymentSQLMixedScalarEntity() {
+ return "SELECT e.*, e.employer as employerid FROM EMPLOYMENT e" ;
+ }
+
+ protected String getOrgEmpRegionSQL() {
+ return "select {org.*}, {emp.*}, emp.REGIONCODE " +
+ "from ORGANIZATION org " +
+ " left outer join EMPLOYMENT emp on org.ORGID = emp.EMPLOYER";
+ }
+
+ protected String getOrgEmpPersonSQL() {
+ return "select {org.*}, {emp.*}, {pers.*} " +
+ "from ORGANIZATION org " +
+ " join EMPLOYMENT emp on org.ORGID = emp.EMPLOYER " +
+ " join PERSON pers on pers.PERID = emp.EMPLOYEE ";
+ }
+
+ public void testFailOnNoAddEntityOrScalar() {
+ // Note: this passes, but for the wrong reason.
+ // there is actually an exception thrown, but it is the database
+ // throwing a sql exception because the SQL gets passed
+ // "un-processed"...
+ Session s = openSession();
+ try {
+ String sql = "select {org.*} " +
+ "from organization org";
+ s.createSQLQuery( sql ).list();
+ fail( "Should throw an exception since no addEntity nor addScalar has been performed." );
+ }
+ catch( HibernateException he) {
+ // expected behavior
+ }
+ finally {
+ s.close();
+ }
+ }
+
+ public void testManualSynchronization() {
+ Session s = openSession();
+ s.beginTransaction();
+
+ sfi().getStatistics().clear();
+
+ // create an Organization...
+ Organization jboss = new Organization( "JBoss" );
+ s.persist( jboss );
+
+ // now query on Employment, this should not cause an auto-flush
+ s.createSQLQuery( getEmploymentSQL() ).list();
+ assertEquals( 0, sfi().getStatistics().getEntityInsertCount() );
+
+ // now try to query on Employment but this time add Organization as a synchronized query space...
+ s.createSQLQuery( getEmploymentSQL() ).addSynchronizedEntityClass( Organization.class ).list();
+ assertEquals( 1, sfi().getStatistics().getEntityInsertCount() );
+
+ // clean up
+ s.delete( jboss );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testSQLQueryInterface() {
+ 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);
+
+ List l = s.createSQLQuery( getOrgEmpRegionSQL() )
+ .addEntity("org", Organization.class)
+ .addJoin("emp", "org.employments")
+ .addScalar("regionCode", Hibernate.STRING)
+ .list();
+ assertEquals( 2, l.size() );
+
+ l = s.createSQLQuery( getOrgEmpPersonSQL() )
+ .addEntity("org", Organization.class)
+ .addJoin("emp", "org.employments")
+ .addJoin("pers", "emp.employee")
+ .list();
+ assertEquals( l.size(), 1 );
+
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+
+ l = s.createSQLQuery( "select {org.*}, {emp.*} " +
+ "from ORGANIZATION org " +
+ " left outer join EMPLOYMENT emp on org.ORGID = emp.EMPLOYER, ORGANIZATION org2" )
+ .addEntity("org", Organization.class)
+ .addJoin("emp", "org.employments")
+ .setResultTransformer(new DistinctRootEntityResultTransformer())
+ .list();
+ assertEquals( l.size(), 2 );
+
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+
+ s.delete(emp);
+ s.delete(gavin);
+ s.delete(ifa);
+ s.delete(jboss);
+
+ t.commit();
+ s.close();
+ }
+
+ public void testResultSetMappingDefinition() {
+ 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);
+
+ List l = s.createSQLQuery( getOrgEmpRegionSQL() )
+ .setResultSetMapping( "org-emp-regionCode" )
+ .list();
+ assertEquals( l.size(), 2 );
+
+ l = s.createSQLQuery( getOrgEmpPersonSQL() )
+ .setResultSetMapping( "org-emp-person" )
+ .list();
+ assertEquals( l.size(), 1 );
+
+ s.delete(emp);
+ s.delete(gavin);
+ s.delete(ifa);
+ s.delete(jboss);
+
+ t.commit();
+ s.close();
+ }
+
+ public void testScalarValues() throws Exception {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+
+ Organization ifa = new Organization( "IFA" );
+ Organization jboss = new Organization( "JBoss" );
+
+ Serializable idIfa = s.save( ifa );
+ Serializable idJBoss = s.save( jboss );
+
+ s.flush();
+
+ List result = s.getNamedQuery( "orgNamesOnly" ).list();
+ assertTrue( result.contains( "IFA" ) );
+ assertTrue( result.contains( "JBoss" ) );
+
+ result = s.getNamedQuery( "orgNamesOnly" ).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
+ Map m = (Map) result.get(0);
+ assertEquals( 2, result.size() );
+ assertEquals( 1, m.size() );
+ assertTrue( m.containsKey("NAME") );
+
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+
+ Iterator iter = s.getNamedQuery( "orgNamesAndOrgs" ).list().iterator();
+ Object[] o = ( Object[] ) iter.next();
+ assertEquals( o[0], "IFA" );
+ assertEquals( ( ( Organization ) o[1] ).getName(), "IFA" );
+ o = ( Object[] ) iter.next();
+ assertEquals( o[0], "JBoss" );
+ assertEquals( ( ( Organization ) o[1] ).getName(), "JBoss" );
+
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+
+ // test that the ordering of the results is truly based on the order in which they were defined
+ iter = s.getNamedQuery( "orgsAndOrgNames" ).list().iterator();
+ Object[] row = ( Object[] ) iter.next();
+ assertEquals( "expecting non-scalar result first", Organization.class, row[0].getClass() );
+ assertEquals( "expecting scalar result second", String.class, row[1].getClass() );
+ assertEquals( ( ( Organization ) row[0] ).getName(), "IFA" );
+ assertEquals( row[1], "IFA" );
+ row = ( Object[] ) iter.next();
+ assertEquals( "expecting non-scalar result first", Organization.class, row[0].getClass() );
+ assertEquals( "expecting scalar result second", String.class, row[1].getClass() );
+ assertEquals( ( ( Organization ) row[0] ).getName(), "JBoss" );
+ assertEquals( row[1], "JBoss" );
+ assertFalse( iter.hasNext() );
+
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+
+ iter = s.getNamedQuery( "orgIdsAndOrgNames" ).list().iterator();
+ o = ( Object[] ) iter.next();
+ assertEquals( o[1], "IFA" );
+ assertEquals( o[0], idIfa );
+ o = ( Object[] ) iter.next();
+ assertEquals( o[1], "JBoss" );
+ assertEquals( o[0], idJBoss );
+
+ s.delete( ifa );
+ s.delete( jboss );
+ t.commit();
+ s.close();
+ }
+
+ public void testMappedAliasStrategy() {
+ 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");
+ Serializable orgId = s.save(jboss);
+ Serializable orgId2 = s.save(ifa);
+ s.save(gavin);
+ s.save(emp);
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Query namedQuery = s.getNamedQuery("AllEmploymentAsMapped");
+ List list = namedQuery.list();
+ assertEquals(1,list.size());
+ Employment emp2 = (Employment) list.get(0);
+ assertEquals(emp2.getEmploymentId(), emp.getEmploymentId() );
+ assertEquals(emp2.getStartDate().getDate(), emp.getStartDate().getDate() );
+ assertEquals(emp2.getEndDate(), emp.getEndDate() );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Query sqlQuery = s.getNamedQuery("EmploymentAndPerson");
+ sqlQuery.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
+ list = sqlQuery.list();
+ assertEquals(1,list.size() );
+ Object res = list.get(0);
+ assertClassAssignability(res.getClass(),Map.class);
+ Map m = (Map) res;
+ assertEquals(2,m.size());
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ sqlQuery = s.getNamedQuery("organizationreturnproperty");
+ sqlQuery.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
+ list = sqlQuery.list();
+ assertEquals(2,list.size() );
+ m = (Map) list.get(0);
+ assertTrue(m.containsKey("org"));
+ assertClassAssignability(m.get("org").getClass(), Organization.class);
+ assertTrue(m.containsKey("emp"));
+ assertClassAssignability(m.get("emp").getClass(), Employment.class);
+ assertEquals(2, m.size());
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ namedQuery = s.getNamedQuery("EmploymentAndPerson");
+ list = namedQuery.list();
+ assertEquals(1,list.size() );
+ Object[] objs = (Object[]) list.get(0);
+ assertEquals(2, objs.length);
+ emp2 = (Employment) objs[0];
+ gavin = (Person) objs[1];
+ s.delete(emp2);
+ s.delete(jboss);
+ s.delete(gavin);
+ s.delete(ifa);
+ t.commit();
+ s.close();
+ }
+
+ /* test for native sql composite id joins which has never been implemented */
+ public void testCompositeIdJoinsFailureExpected() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Person person = new Person();
+ person.setName( "Noob" );
+
+ Product product = new Product();
+ product.setProductId( new Product.ProductId() );
+ product.getProductId().setOrgid( "x" );
+ product.getProductId().setProductnumber( "1234" );
+ product.setName( "Hibernate 3" );
+
+ Order order = new Order();
+ order.setOrderId( new Order.OrderId() );
+ order.getOrderId().setOrdernumber( "1" );
+ order.getOrderId().setOrgid( "y" );
+
+ product.getOrders().add( order );
+ order.setProduct( product );
+ order.setPerson( person );
+
+ s.save( product );
+ s.save( order);
+ s.save( person );
+
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Product p = (Product) s.createQuery( "from Product p join fetch p.orders" ).list().get(0);
+ assertTrue(Hibernate.isInitialized( p.getOrders()));
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Object[] o = (Object[]) s.createSQLQuery( "select\r\n" +
+ " product.orgid as {product.id.orgid}," +
+ " product.productnumber as {product.id.productnumber}," +
+ " {prod_orders}.orgid as orgid3_1_,\r\n" +
+ " {prod_orders}.ordernumber as ordernum2_3_1_,\r\n" +
+ " product.name as {product.name}," +
+ " {prod_orders.element.*}" +
+ /*" orders.PROD_NO as PROD4_3_1_,\r\n" +
+ " orders.person as person3_1_,\r\n" +
+ " orders.PROD_ORGID as PROD3_0__,\r\n" +
+ " orders.PROD_NO as PROD4_0__,\r\n" +
+ " orders.orgid as orgid0__,\r\n" +
+ " orders.ordernumber as ordernum2_0__ \r\n" +*/
+ " from\r\n" +
+ " Product product \r\n" +
+ " inner join\r\n" +
+ " TBL_ORDER {prod_orders} \r\n" +
+ " on product.orgid={prod_orders}.PROD_ORGID \r\n" +
+ " and product.productnumber={prod_orders}.PROD_NO" )
+ .addEntity( "product", Product.class )
+ .addJoin( "prod_orders", "product.orders" )
+ .list().get(0);
+
+ p = (Product) o[0];
+ assertTrue(Hibernate.isInitialized( p.getOrders() ));
+ assertNotNull(p.getOrders().iterator().next());
+ t.commit();
+ s.close();
+ }
+
+ public void testAutoDetectAliasing() {
+ 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");
+ Serializable orgId = s.save(jboss);
+ Serializable orgId2 = s.save(ifa);
+ s.save(gavin);
+ s.save(emp);
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ List list = s.createSQLQuery( getEmploymentSQL() )
+ .addEntity( Employment.class.getName() )
+ .list();
+ assertEquals( 1,list.size() );
+
+ Employment emp2 = (Employment) list.get(0);
+ assertEquals(emp2.getEmploymentId(), emp.getEmploymentId() );
+ assertEquals(emp2.getStartDate().getDate(), emp.getStartDate().getDate() );
+ assertEquals(emp2.getEndDate(), emp.getEndDate() );
+
+ s.clear();
+
+ list = s.createSQLQuery( getEmploymentSQL() )
+ .addEntity( Employment.class.getName() )
+ .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
+ .list();
+ assertEquals( 1,list.size() );
+ Map m = (Map) list.get(0);
+ assertTrue(m.containsKey("Employment"));
+ assertEquals(1,m.size());
+
+ list = s.createSQLQuery(getEmploymentSQL()).list();
+ assertEquals(1, list.size());
+ Object[] o = (Object[]) list.get(0);
+ assertEquals(8, o.length);
+
+ list = s.createSQLQuery( getEmploymentSQL() ).setResultTransformer( new UpperCasedAliasToEntityMapResultTransformer() ).list();
+ assertEquals(1, list.size());
+ m = (Map) list.get(0);
+ assertTrue(m.containsKey("EMPID"));
+ assertTrue(m.containsKey("VALUE"));
+ assertTrue(m.containsKey("ENDDATE"));
+ assertEquals(8, m.size());
+
+ list = s.createSQLQuery( getEmploymentSQLMixedScalarEntity() ).addScalar( "employerid" ).addEntity( Employment.class ).list();
+ assertEquals(1, list.size());
+ o = (Object[]) list.get(0);
+ assertEquals(2, o.length);
+ assertClassAssignability( o[0].getClass(), Number.class);
+ assertClassAssignability( o[1].getClass(), Employment.class);
+
+
+
+ Query queryWithCollection = s.getNamedQuery("organizationEmploymentsExplicitAliases");
+ queryWithCollection.setLong("id", jboss.getId() );
+ list = queryWithCollection.list();
+ assertEquals(list.size(),1);
+
+ s.clear();
+
+ list = s.createSQLQuery( getOrganizationJoinEmploymentSQL() )
+ .addEntity( "org", Organization.class )
+ .addJoin( "emp", "org.employments" )
+ .list();
+ assertEquals( 2,list.size() );
+
+ s.clear();
+
+ list = s.createSQLQuery( getOrganizationFetchJoinEmploymentSQL() )
+ .addEntity( "org", Organization.class )
+ .addJoin( "emp", "org.employments" )
+ .list();
+ assertEquals( 2,list.size() );
+
+ s.clear();
+
+ // TODO : why twice?
+ s.getNamedQuery( "organizationreturnproperty" ).list();
+ list = s.getNamedQuery( "organizationreturnproperty" ).list();
+ assertEquals( 2,list.size() );
+
+ s.clear();
+
+ list = s.getNamedQuery( "organizationautodetect" ).list();
+ assertEquals( 2,list.size() );
+
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ s.delete(emp2);
+
+ s.delete(jboss);
+ s.delete(gavin);
+ s.delete(ifa);
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Dimension dim = new Dimension( 3, Integer.MAX_VALUE );
+ s.save( dim );
+ list = s.createSQLQuery( "select d_len * d_width as surface, d_len * d_width * 10 as volume from Dimension" ).list();
+ s.delete( dim );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ SpaceShip enterprise = new SpaceShip();
+ enterprise.setModel( "USS" );
+ enterprise.setName( "Entreprise" );
+ enterprise.setSpeed( 50d );
+ Dimension d = new Dimension(45, 10);
+ enterprise.setDimensions( d );
+ s.save( enterprise );
+ Object[] result = (Object[]) s.getNamedQuery( "spaceship" ).uniqueResult();
+ enterprise = ( SpaceShip ) result[0];
+ assertTrue(50d == enterprise.getSpeed() );
+ assertTrue( 450d == extractDoubleValue( result[1] ) );
+ assertTrue( 4500d == extractDoubleValue( result[2] ) );
+ s.delete( enterprise );
+ t.commit();
+ s.close();
+
+ }
+
+ public void testMixAndMatchEntityScalar() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Speech speech = new Speech();
+ speech.setLength( new Double( 23d ) );
+ speech.setName( "Mine" );
+ s.persist( speech );
+ s.flush();
+ s.clear();
+
+ List l = s.createSQLQuery( "select name, id, flength, name as scalarName from Speech" )
+ .setResultSetMapping( "speech" )
+ .list();
+ assertEquals( l.size(), 1 );
+
+ t.rollback();
+ s.close();
+ }
+
+ private double extractDoubleValue(Object value) {
+ if ( value instanceof BigInteger ) {
+ return ( ( BigInteger ) value ).doubleValue();
+ }
+ else if ( value instanceof BigDecimal ) {
+ return ( ( BigDecimal ) value ).doubleValue();
+ }
+ else {
+ return Double.valueOf( value.toString() ).doubleValue();
+ }
+ }
+
+ private static class UpperCasedAliasToEntityMapResultTransformer extends AliasToEntityMapResultTransformer {
+ public Object transformTuple(Object[] tuple, String[] aliases) {
+ String[] ucAliases = new String[aliases.length];
+ for ( int i = 0; i < aliases.length; i++ ) {
+ ucAliases[i] = aliases[i].toUpperCase();
+ }
+ return super.transformTuple( tuple, ucAliases );
+ }
+ }
+}
More information about the hibernate-commits
mailing list