[hibernate-commits] Hibernate SVN: r11346 - in branches/Branch_3_2/Hibernate3: test/org/hibernate/test and 5 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Mon Mar 26 13:24:58 EDT 2007
Author: steve.ebersole at jboss.com
Date: 2007-03-26 13:24:58 -0400 (Mon, 26 Mar 2007)
New Revision: 11346
Added:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/ComponentSuite.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/ComponentTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/Employee.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/Person.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/User.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/User.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/CascadeToComponentCollectionTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/Definition.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/LocalizedStrings.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/Mappings.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/Value.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/Address.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/CascadeToComponentAssociationTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/Document.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/Mappings.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/PersonalInfo.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/User.java
Removed:
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/A.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/ABC.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/B.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/C.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/ComponentTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/DynamicComponentTest.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/Employee.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/Person.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/User.hbm.xml
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/User.java
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/type/TypeFactory.java
branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
Log:
HHH-2521 : component cascading
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/type/TypeFactory.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/type/TypeFactory.java 2007-03-26 17:24:20 UTC (rev 11345)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/type/TypeFactory.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -19,7 +19,6 @@
import java.util.TimeZone;
import org.hibernate.Hibernate;
-import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.classic.Lifecycle;
import org.hibernate.engine.SessionImplementor;
@@ -501,6 +500,9 @@
/**
* Apply the {@link Type#replace} operation across a series of values, as
* long as the corresponding {@link Type} is an association.
+ * <p/>
+ * If the corresponding type is a component type, then apply {@link #replaceAssociations}
+ * accross the component subtypes but do not replace the component value itself.
*
* @param original The source of the state
* @param target The target into which to replace the source values.
@@ -522,10 +524,21 @@
Object[] copied = new Object[original.length];
for ( int i = 0; i < types.length; i++ ) {
if ( original[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
- || original[i] == BackrefPropertyAccessor.UNKNOWN
- || !types[i].isAssociationType() ) {
+ || original[i] == BackrefPropertyAccessor.UNKNOWN ) {
copied[i] = target[i];
}
+ else if ( types[i].isComponentType() ) {
+ // need to extract the component values and check for subtype replacements...
+ AbstractComponentType componentType = ( AbstractComponentType ) types[i];
+ Type[] subtypes = componentType.getSubtypes();
+ Object[] origComponentValues = original[i] == null ? new Object[subtypes.length] : componentType.getPropertyValues( original[i], session );
+ Object[] targetComponentValues = componentType.getPropertyValues( target[i], session );
+ replaceAssociations( origComponentValues, targetComponentValues, subtypes, session, null, copyCache, foreignKeyDirection );
+ copied[i] = target[i];
+ }
+ else if ( !types[i].isAssociationType() ) {
+ copied[i] = target[i];
+ }
else {
copied[i] = types[i].replace( original[i], target[i], session, owner, copyCache, foreignKeyDirection );
}
Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2007-03-26 17:24:20 UTC (rev 11345)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/AllTests.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -23,7 +23,7 @@
import org.hibernate.test.cascade.RefreshTest;
import org.hibernate.test.cid.CompositeIdTest;
import org.hibernate.test.collection.CollectionSuite;
-import org.hibernate.test.component.ComponentTest;
+import org.hibernate.test.component.ComponentSuite;
import org.hibernate.test.compositeelement.CompositeElementTest;
import org.hibernate.test.connections.ConnectionsSuite;
import org.hibernate.test.criteria.CriteriaQueryTest;
@@ -171,7 +171,7 @@
TestSuite suite = new TestSuite("New tests suite");
suite.addTest( OpsSuite.suite() );
suite.addTest( NaturalIdTest.suite() );
- suite.addTest( ComponentTest.suite() );
+ suite.addTest( ComponentSuite.suite() );
suite.addTest( ProxyTest.suite() );
suite.addTest( VersionTest.suite() );
suite.addTest( TimestampTest.suite() );
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/A.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/A.java 2007-03-26 17:24:20 UTC (rev 11345)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/A.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -1,42 +0,0 @@
-package org.hibernate.test.component;
-
-import java.util.Map;
-
-public class A {
-
- public int id;
- public Map dynComp;
-
- public A() {
- this(-1);
- }
-
- public A(int id) {
- this.id = id;
- }
-
- public Map getDynComp() {
- return dynComp;
- }
-
- public void setDynComp(Map dynComp) {
- this.dynComp = dynComp;
- }
-
- public int getId() {
- return id;
- }
-
- public void setId(int id) {
- this.id = id;
- }
-
- public boolean equals(Object obj) {
- if ( !( obj instanceof A ) ) return false;
- return id == ( (A) obj ).id;
- }
-
- public int hashCode() {
- return id == -1 ? super.hashCode() : id;
- }
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/ABC.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/ABC.hbm.xml 2007-03-26 17:24:20 UTC (rev 11345)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/ABC.hbm.xml 2007-03-26 17:24:58 UTC (rev 11346)
@@ -1,30 +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">
-
-<hibernate-mapping package="org.hibernate.test.component">
-
- <class name="A" table="aa">
- <id name="id"/>
- <dynamic-component name="dynComp">
- <property name="a" type="string"/>
- </dynamic-component>
- </class>
-
- <joined-subclass name="B" extends="A" table="bb">
- <key column="A"/>
- <dynamic-component name="dynComp">
- <property name="b" type="string"/>
- </dynamic-component>
- </joined-subclass>
-
- <joined-subclass name="C" extends="B" table="cc">
- <key column="B"/>
- <dynamic-component name="dynComp">
- <property name="c" type="string"/>
- </dynamic-component>
- </joined-subclass>
-
-
-</hibernate-mapping>
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/B.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/B.java 2007-03-26 17:24:20 UTC (rev 11345)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/B.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -1,13 +0,0 @@
-package org.hibernate.test.component;
-
-
-public class B extends A {
-
- public B() {
- super(-1);
- }
-
- public B(int id) {
- super(id);
- }
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/C.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/C.java 2007-03-26 17:24:20 UTC (rev 11345)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/C.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -1,13 +0,0 @@
-package org.hibernate.test.component;
-
-
-public class C extends B {
-
- public C() {
- super(-1);
- }
-
- public C(int id) {
- super(id);
- }
-}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/ComponentSuite.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/ComponentSuite.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/ComponentSuite.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -0,0 +1,23 @@
+package org.hibernate.test.component;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.hibernate.test.component.basic.ComponentTest;
+import org.hibernate.test.component.cascading.collection.CascadeToComponentCollectionTest;
+import org.hibernate.test.component.cascading.toone.CascadeToComponentAssociationTest;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class ComponentSuite {
+ public static Test suite() {
+ TestSuite suite = new TestSuite( "component test suite" );
+ suite.addTest( ComponentTest.suite() );
+ suite.addTest( CascadeToComponentCollectionTest.suite() );
+ suite.addTest( CascadeToComponentAssociationTest.suite() );
+ return suite;
+ }
+}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/ComponentTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/ComponentTest.java 2007-03-26 17:24:20 UTC (rev 11345)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/ComponentTest.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -1,195 +0,0 @@
-//$Id$
-package org.hibernate.test.component;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import junit.framework.Test;
-
-import org.hibernate.Session;
-import org.hibernate.Transaction;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
-import org.hibernate.cfg.Mappings;
-import org.hibernate.criterion.Property;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.HSQLDialect;
-import org.hibernate.dialect.function.SQLFunction;
-import org.hibernate.junit.functional.FunctionalTestCase;
-import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
-import org.hibernate.mapping.Component;
-import org.hibernate.mapping.Formula;
-import org.hibernate.mapping.PersistentClass;
-
-/**
- * @author Gavin King
- */
-public class ComponentTest extends FunctionalTestCase {
-
- public ComponentTest(String str) {
- super(str);
- }
-
- public String[] getMappings() {
- return new String[] { "component/User.hbm.xml" };
- }
-
- public void configure(Configuration cfg) {
- cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
- }
-
- public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
- super.afterConfigurationBuilt( mappings, dialect );
- // Oracle and Postgres do not have year() functions, so we need to
- // redefine the 'User.person.yob' formula
- //
- // consider temporary until we add the capability to define
- // mapping foprmulas which can use dialect-registered functions...
- PersistentClass user = mappings.getClass( User.class.getName() );
- org.hibernate.mapping.Property personProperty = user.getProperty( "person" );
- Component component = ( Component ) personProperty.getValue();
- Formula f = ( Formula ) component.getProperty( "yob" ).getValue().getColumnIterator().next();
-
- SQLFunction yearFunction = ( SQLFunction ) dialect.getFunctions().get( "year" );
- if ( yearFunction == null ) {
- // the dialect not know to support a year() function, so rely on the
- // ANSI SQL extract function
- f.setFormula( "extract( year from dob )");
- }
- else {
- List args = new ArrayList();
- args.add( "dob" );
- f.setFormula( yearFunction.render( args, null ) );
- }
- }
-
- public static Test suite() {
- return new FunctionalTestClassTestSuite(ComponentTest.class);
- }
-
- public void testUpdateFalse() {
- getSessions().getStatistics().clear();
-
- Session s = openSession();
- Transaction t = s.beginTransaction();
- User u = new User( "gavin", "secret", new Person("Gavin King", new Date(), "Karbarook Ave") );
- s.persist(u);
- s.flush();
- u.getPerson().setName("XXXXYYYYY");
- t.commit();
- s.close();
-
- assertEquals( 1, getSessions().getStatistics().getEntityInsertCount() );
- assertEquals( 0, getSessions().getStatistics().getEntityUpdateCount() );
-
- s = openSession();
- t = s.beginTransaction();
- u = (User) s.get(User.class, "gavin");
- assertEquals( u.getPerson().getName(), "Gavin King" );
- s.delete(u);
- t.commit();
- s.close();
-
- assertEquals( 1, getSessions().getStatistics().getEntityDeleteCount() );
- }
-
- public void testComponent() {
- Session s = openSession();
- Transaction t = s.beginTransaction();
- User u = new User( "gavin", "secret", new Person("Gavin King", new Date(), "Karbarook Ave") );
- s.persist(u);
- s.flush();
- u.getPerson().changeAddress("Phipps Place");
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- u = (User) s.get(User.class, "gavin");
- assertEquals( u.getPerson().getAddress(), "Phipps Place" );
- assertEquals( u.getPerson().getPreviousAddress(), "Karbarook Ave" );
- assertEquals( u.getPerson().getYob(), u.getPerson().getDob().getYear()+1900 );
- u.setPassword("$ecret");
- t.commit();
- s.close();
-
- s = openSession();
- t = s.beginTransaction();
- u = (User) s.get(User.class, "gavin");
- assertEquals( u.getPerson().getAddress(), "Phipps Place" );
- assertEquals( u.getPerson().getPreviousAddress(), "Karbarook Ave" );
- assertEquals( u.getPassword(), "$ecret" );
- s.delete(u);
- t.commit();
- s.close();
- }
-
- public void testComponentStateChangeAndDirtiness() {
- // test for HHH-2366
- Session s = openSession();
- s.beginTransaction();
- User u = new User( "steve", "hibernater", new Person( "Steve Ebersole", new Date(), "Main St") );
- s.persist( u );
- s.flush();
- long intialUpdateCount = sfi().getStatistics().getEntityUpdateCount();
- u.getPerson().setAddress( "Austin" );
- s.flush();
- assertEquals( intialUpdateCount + 1, sfi().getStatistics().getEntityUpdateCount() );
- intialUpdateCount = sfi().getStatistics().getEntityUpdateCount();
- u.getPerson().setAddress( "Cedar Park" );
- s.flush();
- assertEquals( intialUpdateCount + 1, sfi().getStatistics().getEntityUpdateCount() );
- s.delete( u );
- s.getTransaction().commit();
- s.close();
- }
-
- public void testComponentQueries() {
- Session s = openSession();
- Transaction t = s.beginTransaction();
- Employee emp = new Employee();
- emp.setHireDate( new Date() );
- emp.setPerson( new Person() );
- emp.getPerson().setName( "steve" );
- emp.getPerson().setDob( new Date() );
- s.save( emp );
-
- s.createQuery( "from Employee e where e.person = :p and 1 = 1 and 2=2" ).setParameter( "p", emp.getPerson() ).list();
- s.createQuery( "from Employee e where :p = e.person" ).setParameter( "p", emp.getPerson() ).list();
- s.createQuery( "from Employee e where e.person = ('steve', current_timestamp)" ).list();
-
- s.delete( emp );
- t.commit();
- s.close();
- }
-
- public void testComponentFormulaQuery() {
- Session s = openSession();
- Transaction t = s.beginTransaction();
- s.createQuery("from User u where u.person.yob = 1999").list();
- s.createCriteria(User.class)
- .add( Property.forName("person.yob").between( new Integer(1999), new Integer(2002) ) )
- .list();
- if ( getDialect().supportsRowValueConstructorSyntax() ) {
- s.createQuery("from User u where u.person = ('gavin', :dob, 'Peachtree Rd', 'Karbarook Ave', 1974, 'Peachtree Rd')")
- .setDate("dob", new Date("March 25, 1974")).list();
- s.createQuery("from User where person = ('gavin', :dob, 'Peachtree Rd', 'Karbarook Ave', 1974, 'Peachtree Rd')")
- .setDate("dob", new Date("March 25, 1974")).list();
- }
- t.commit();
- s.close();
- }
-
- public void testNamedQuery() {
- Session s = openSession();
- Transaction t = s.beginTransaction();
- s.getNamedQuery("userNameIn")
- .setParameterList( "nameList", new Object[] {"1ovthafew", "turin", "xam"} )
- .list();
- t.commit();
- s.close();
- }
-
-}
-
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/DynamicComponentTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/DynamicComponentTest.java 2007-03-26 17:24:20 UTC (rev 11345)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/DynamicComponentTest.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -1,84 +0,0 @@
-package org.hibernate.test.component;
-
-import java.util.HashMap;
-import java.util.List;
-
-import org.hibernate.classic.Session;
-import org.hibernate.test.TestCase;
-
-public class DynamicComponentTest extends TestCase {
-
- public DynamicComponentTest(String x) {
- super(x);
- }
-
- public void testQuery() throws Exception {
- Session session = openSession();
-
- A a = new A(1);
- a.setDynComp(new HashMap());
- a.getDynComp().put("a", "a-a");
- session.save(a);
-
- B b = new B(2);
- b.setDynComp(new HashMap());
- b.getDynComp().put("a", "b-a");
- b.getDynComp().put("b", "b-b");
- session.save(b);
-
- C c = new C(3);
- c.setDynComp(new HashMap());
- c.getDynComp().put("a", "c-a");
- c.getDynComp().put("b", "c-b");
- c.getDynComp().put("c", "c-c");
- session.save(c);
-
- session.flush();
-
- List list = session.createQuery("from A a where a.dynComp.a = ?")
- .setParameter(0, "a-a")
- .list();
-
- assertEquals(1, list.size());
- assertTrue(a.equals(list.get(0)));
-
- list = session.createQuery("from B b where b.dynComp.b = ?")
- .setParameter(0, "b-b")
- .list();
-
- assertEquals(1, list.size());
- assertTrue(b.equals(list.get(0)));
-
- list = session.createQuery("from B b where b.dynComp.a = ?")
- .setParameter(0, "b-a")
- .list();
-
- assertEquals(1, list.size());
- assertTrue(b.equals(list.get(0)));
-
- list = session.createQuery("from C c where c.dynComp.c = ?")
- .setParameter(0, "c-c")
- .list();
-
- list = session.createQuery("from C c where c.dynComp.b = ?")
- .setParameter(0, "c-b")
- .list();
-
- list = session.createQuery("from C c where c.dynComp.a = ?")
- .setParameter(0, "c-a")
- .list();
-
- assertEquals(1, list.size());
- assertTrue(c.equals(list.get(0)));
-
- session.delete(c);
- session.delete(b);
- session.delete(a);
- session.close();
- }
-
- protected String[] getMappings() {
- return new String[] { "component/ABC.hbm.xml" };
- }
-
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/Employee.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/Employee.java 2007-03-26 17:24:20 UTC (rev 11345)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/Employee.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -1,38 +0,0 @@
-package org.hibernate.test.component;
-
-import java.util.Date;
-
-/**
- * todo: describe Employee
- *
- * @author Steve Ebersole
- */
-public class Employee {
- private Long id;
- private Person person;
- private Date hireDate;
-
- public Long getId() {
- return id;
- }
-
- public void setId(Long id) {
- this.id = id;
- }
-
- public Person getPerson() {
- return person;
- }
-
- public void setPerson(Person person) {
- this.person = person;
- }
-
- public Date getHireDate() {
- return hireDate;
- }
-
- public void setHireDate(Date hireDate) {
- this.hireDate = hireDate;
- }
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/Person.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/Person.java 2007-03-26 17:24:20 UTC (rev 11345)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/Person.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -1,63 +0,0 @@
-//$Id$
-package org.hibernate.test.component;
-
-import java.util.Date;
-
-/**
- * @author Gavin King
- */
-public class Person {
- private String name;
- private Date dob;
- private String address;
- private String currentAddress;
- private String previousAddress;
- private int yob;
- Person() {}
- public Person(String name, Date dob, String address) {
- this.name = name;
- this.dob = dob;
- this.address = address;
- this.currentAddress = address;
- }
- public int getYob() {
- return yob;
- }
- public void setYob(int age) {
- this.yob = age;
- }
- public String getAddress() {
- return address;
- }
- public void setAddress(String address) {
- this.address = address;
- }
- public Date getDob() {
- return dob;
- }
- public void setDob(Date dob) {
- this.dob = dob;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getPreviousAddress() {
- return previousAddress;
- }
- public void setPreviousAddress(String previousAddress) {
- this.previousAddress = previousAddress;
- }
- public void changeAddress(String add) {
- setPreviousAddress( getAddress() );
- setAddress(add);
- }
- public String getCurrentAddress() {
- return currentAddress;
- }
- public void setCurrentAddress(String currentAddress) {
- this.currentAddress = currentAddress;
- }
-}
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/User.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/User.hbm.xml 2007-03-26 17:24:20 UTC (rev 11345)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/User.hbm.xml 2007-03-26 17:24:58 UTC (rev 11346)
@@ -1,42 +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">
-
-<!--
-
--->
-
-<hibernate-mapping package="org.hibernate.test.component">
-
- <class name="User" table="T_USER">
- <id name="userName"/>
- <timestamp name="lastModified"/>
- <property name="password" not-null="true" optimistic-lock="false"/>
- <component name="person">
- <property name="name" update="false" not-null="true"/>
- <property name="dob" update="false" not-null="true"/>
- <property name="address"/>
- <property name="previousAddress" insert="false"/>
- <property name="yob" formula="year(dob)"/>
- <property name="currentAddress"
- column="address"
- insert="false"
- update="false"/>
- </component>
- </class>
-
- <class name="Employee" table="T_EMP">
- <id name="id" type="long" column="ID">
- <generator class="increment"/>
- </id>
- <property name="hireDate" type="date" column="HIRE_DATE"/>
- <component name="person">
- <property name="name" update="false" not-null="true"/>
- <property name="dob" update="false" not-null="true"/>
- </component>
- </class>
-
- <query name="userNameIn"><![CDATA[from User where person.name in (:nameList) or userName in (:nameList)]]></query>
-
-</hibernate-mapping>
Deleted: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/User.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/User.java 2007-03-26 17:24:20 UTC (rev 11345)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/User.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -1,44 +0,0 @@
-//$Id$
-package org.hibernate.test.component;
-
-import java.util.Date;
-
-/**
- * @author Gavin King
- */
-public class User {
- private String userName;
- private String password;
- private Person person;
- private Date lastModified;
- User() {}
- public User(String id, String pw, Person person) {
- this.userName = id;
- this.password = pw;
- this.person = person;
- }
- public Date getLastModified() {
- return lastModified;
- }
- public void setLastModified(Date lastModified) {
- this.lastModified = lastModified;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public Person getPerson() {
- return person;
- }
- public void setPerson(Person person) {
- this.person = person;
- }
- public String getUserName() {
- return userName;
- }
- public void setUserName(String userName) {
- this.userName = userName;
- }
-}
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/ComponentTest.java (from rev 11089, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/ComponentTest.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/ComponentTest.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/ComponentTest.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -0,0 +1,194 @@
+//$Id$
+package org.hibernate.test.component.basic;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.cfg.Mappings;
+import org.hibernate.criterion.Property;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.function.SQLFunction;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.Formula;
+import org.hibernate.mapping.PersistentClass;
+
+/**
+ * @author Gavin King
+ */
+public class ComponentTest extends FunctionalTestCase {
+
+ public ComponentTest(String str) {
+ super(str);
+ }
+
+ public String[] getMappings() {
+ return new String[] { "component/basic/User.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( ComponentTest.class );
+ }
+
+ public void configure(Configuration cfg) {
+ cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
+ }
+
+ public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
+ super.afterConfigurationBuilt( mappings, dialect );
+ // Oracle and Postgres do not have year() functions, so we need to
+ // redefine the 'User.person.yob' formula
+ //
+ // consider temporary until we add the capability to define
+ // mapping foprmulas which can use dialect-registered functions...
+ PersistentClass user = mappings.getClass( User.class.getName() );
+ org.hibernate.mapping.Property personProperty = user.getProperty( "person" );
+ Component component = ( Component ) personProperty.getValue();
+ Formula f = ( Formula ) component.getProperty( "yob" ).getValue().getColumnIterator().next();
+
+ SQLFunction yearFunction = ( SQLFunction ) dialect.getFunctions().get( "year" );
+ if ( yearFunction == null ) {
+ // the dialect not know to support a year() function, so rely on the
+ // ANSI SQL extract function
+ f.setFormula( "extract( year from dob )");
+ }
+ else {
+ List args = new ArrayList();
+ args.add( "dob" );
+ f.setFormula( yearFunction.render( args, null ) );
+ }
+ }
+
+ public void testUpdateFalse() {
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ User u = new User( "gavin", "secret", new Person("Gavin King", new Date(), "Karbarook Ave") );
+ s.persist(u);
+ s.flush();
+ u.getPerson().setName("XXXXYYYYY");
+ t.commit();
+ s.close();
+
+ assertEquals( 1, getSessions().getStatistics().getEntityInsertCount() );
+ assertEquals( 0, getSessions().getStatistics().getEntityUpdateCount() );
+
+ s = openSession();
+ t = s.beginTransaction();
+ u = (User) s.get(User.class, "gavin");
+ assertEquals( u.getPerson().getName(), "Gavin King" );
+ s.delete(u);
+ t.commit();
+ s.close();
+
+ assertEquals( 1, getSessions().getStatistics().getEntityDeleteCount() );
+ }
+
+ public void testComponent() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ User u = new User( "gavin", "secret", new Person("Gavin King", new Date(), "Karbarook Ave") );
+ s.persist(u);
+ s.flush();
+ u.getPerson().changeAddress("Phipps Place");
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ u = (User) s.get(User.class, "gavin");
+ assertEquals( u.getPerson().getAddress(), "Phipps Place" );
+ assertEquals( u.getPerson().getPreviousAddress(), "Karbarook Ave" );
+ assertEquals( u.getPerson().getYob(), u.getPerson().getDob().getYear()+1900 );
+ u.setPassword("$ecret");
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ u = (User) s.get(User.class, "gavin");
+ assertEquals( u.getPerson().getAddress(), "Phipps Place" );
+ assertEquals( u.getPerson().getPreviousAddress(), "Karbarook Ave" );
+ assertEquals( u.getPassword(), "$ecret" );
+ s.delete(u);
+ t.commit();
+ s.close();
+ }
+
+ public void testComponentStateChangeAndDirtiness() {
+ // test for HHH-2366
+ Session s = openSession();
+ s.beginTransaction();
+ User u = new User( "steve", "hibernater", new Person( "Steve Ebersole", new Date(), "Main St") );
+ s.persist( u );
+ s.flush();
+ long intialUpdateCount = sfi().getStatistics().getEntityUpdateCount();
+ u.getPerson().setAddress( "Austin" );
+ s.flush();
+ assertEquals( intialUpdateCount + 1, sfi().getStatistics().getEntityUpdateCount() );
+ intialUpdateCount = sfi().getStatistics().getEntityUpdateCount();
+ u.getPerson().setAddress( "Cedar Park" );
+ s.flush();
+ assertEquals( intialUpdateCount + 1, sfi().getStatistics().getEntityUpdateCount() );
+ s.delete( u );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testComponentQueries() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Employee emp = new Employee();
+ emp.setHireDate( new Date() );
+ emp.setPerson( new Person() );
+ emp.getPerson().setName( "steve" );
+ emp.getPerson().setDob( new Date() );
+ s.save( emp );
+
+ s.createQuery( "from Employee e where e.person = :p and 1 = 1 and 2=2" ).setParameter( "p", emp.getPerson() ).list();
+ s.createQuery( "from Employee e where :p = e.person" ).setParameter( "p", emp.getPerson() ).list();
+ s.createQuery( "from Employee e where e.person = ('steve', current_timestamp)" ).list();
+
+ s.delete( emp );
+ t.commit();
+ s.close();
+ }
+
+ public void testComponentFormulaQuery() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ s.createQuery("from User u where u.person.yob = 1999").list();
+ s.createCriteria(User.class)
+ .add( Property.forName("person.yob").between( new Integer(1999), new Integer(2002) ) )
+ .list();
+ if ( getDialect().supportsRowValueConstructorSyntax() ) {
+ s.createQuery("from User u where u.person = ('gavin', :dob, 'Peachtree Rd', 'Karbarook Ave', 1974, 'Peachtree Rd')")
+ .setDate("dob", new Date("March 25, 1974")).list();
+ s.createQuery("from User where person = ('gavin', :dob, 'Peachtree Rd', 'Karbarook Ave', 1974, 'Peachtree Rd')")
+ .setDate("dob", new Date("March 25, 1974")).list();
+ }
+ t.commit();
+ s.close();
+ }
+
+ public void testNamedQuery() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ s.getNamedQuery("userNameIn")
+ .setParameterList( "nameList", new Object[] {"1ovthafew", "turin", "xam"} )
+ .list();
+ t.commit();
+ s.close();
+ }
+
+}
+
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/ComponentTest.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/Employee.java (from rev 11089, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/Employee.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/Employee.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/Employee.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -0,0 +1,38 @@
+package org.hibernate.test.component.basic;
+
+import java.util.Date;
+
+/**
+ * todo: describe Employee
+ *
+ * @author Steve Ebersole
+ */
+public class Employee {
+ private Long id;
+ private Person person;
+ private Date hireDate;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Person getPerson() {
+ return person;
+ }
+
+ public void setPerson(Person person) {
+ this.person = person;
+ }
+
+ public Date getHireDate() {
+ return hireDate;
+ }
+
+ public void setHireDate(Date hireDate) {
+ this.hireDate = hireDate;
+ }
+}
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/Person.java (from rev 11089, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/Person.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/Person.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/Person.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -0,0 +1,63 @@
+//$Id$
+package org.hibernate.test.component.basic;
+
+import java.util.Date;
+
+/**
+ * @author Gavin King
+ */
+public class Person {
+ private String name;
+ private Date dob;
+ private String address;
+ private String currentAddress;
+ private String previousAddress;
+ private int yob;
+ Person() {}
+ public Person(String name, Date dob, String address) {
+ this.name = name;
+ this.dob = dob;
+ this.address = address;
+ this.currentAddress = address;
+ }
+ public int getYob() {
+ return yob;
+ }
+ public void setYob(int age) {
+ this.yob = age;
+ }
+ public String getAddress() {
+ return address;
+ }
+ public void setAddress(String address) {
+ this.address = address;
+ }
+ public Date getDob() {
+ return dob;
+ }
+ public void setDob(Date dob) {
+ this.dob = dob;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public String getPreviousAddress() {
+ return previousAddress;
+ }
+ public void setPreviousAddress(String previousAddress) {
+ this.previousAddress = previousAddress;
+ }
+ public void changeAddress(String add) {
+ setPreviousAddress( getAddress() );
+ setAddress(add);
+ }
+ public String getCurrentAddress() {
+ return currentAddress;
+ }
+ public void setCurrentAddress(String currentAddress) {
+ this.currentAddress = currentAddress;
+ }
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/Person.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/User.hbm.xml (from rev 11089, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/User.hbm.xml)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/User.hbm.xml (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/User.hbm.xml 2007-03-26 17:24:58 UTC (rev 11346)
@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+
+-->
+
+<hibernate-mapping package="org.hibernate.test.component.basic">
+
+ <class name="User" table="T_USER">
+ <id name="userName"/>
+ <timestamp name="lastModified"/>
+ <property name="password" not-null="true" optimistic-lock="false"/>
+ <component name="person">
+ <property name="name" update="false" not-null="true"/>
+ <property name="dob" update="false" not-null="true"/>
+ <property name="address"/>
+ <property name="previousAddress" insert="false"/>
+ <property name="yob" formula="year(dob)"/>
+ <property name="currentAddress"
+ column="address"
+ insert="false"
+ update="false"/>
+ </component>
+ </class>
+
+ <class name="Employee" table="T_EMP">
+ <id name="id" type="long" column="ID">
+ <generator class="increment"/>
+ </id>
+ <property name="hireDate" type="date" column="HIRE_DATE"/>
+ <component name="person">
+ <property name="name" update="false" not-null="true"/>
+ <property name="dob" update="false" not-null="true"/>
+ </component>
+ </class>
+
+ <query name="userNameIn"><![CDATA[from User where person.name in (:nameList) or userName in (:nameList)]]></query>
+
+</hibernate-mapping>
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/User.hbm.xml
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/User.java (from rev 11089, branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/User.java)
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/User.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/User.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -0,0 +1,44 @@
+//$Id$
+package org.hibernate.test.component.basic;
+
+import java.util.Date;
+
+/**
+ * @author Gavin King
+ */
+public class User {
+ private String userName;
+ private String password;
+ private Person person;
+ private Date lastModified;
+ User() {}
+ public User(String id, String pw, Person person) {
+ this.userName = id;
+ this.password = pw;
+ this.person = person;
+ }
+ public Date getLastModified() {
+ return lastModified;
+ }
+ public void setLastModified(Date lastModified) {
+ this.lastModified = lastModified;
+ }
+ public String getPassword() {
+ return password;
+ }
+ public void setPassword(String password) {
+ this.password = password;
+ }
+ public Person getPerson() {
+ return person;
+ }
+ public void setPerson(Person person) {
+ this.person = person;
+ }
+ public String getUserName() {
+ return userName;
+ }
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+}
Property changes on: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/basic/User.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/CascadeToComponentCollectionTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/CascadeToComponentCollectionTest.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/CascadeToComponentCollectionTest.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -0,0 +1,116 @@
+package org.hibernate.test.component.cascading.collection;
+
+import java.util.Iterator;
+import java.util.Locale;
+
+import junit.framework.Test;
+
+import org.hibernate.Session;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class CascadeToComponentCollectionTest extends FunctionalTestCase {
+
+ public CascadeToComponentCollectionTest(String string) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "component/cascading/collection/Mappings.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( CascadeToComponentCollectionTest.class );
+ }
+
+ public void testMerging() {
+ // step1, we create a definition with one value
+ Session session = openSession();
+ session.beginTransaction();
+ Definition definition = new Definition();
+ Value value1 = new Value( definition );
+ value1.getLocalizedStrings().addString( new Locale( "en_US" ), "hello" );
+ session.persist( definition );
+ session.getTransaction().commit();
+ session.close();
+
+ // step2, we verify that the definition has one value; then we detach it
+ session = openSession();
+ session.beginTransaction();
+ definition = ( Definition ) session.get( Definition.class, definition.getId() );
+ assertEquals( 1, definition.getValues().size() );
+ session.getTransaction().commit();
+ session.close();
+
+ // step3, we add a new value during detachment
+ Value value2 = new Value( definition );
+ value2.getLocalizedStrings().addString( new Locale( "es" ), "hola" );
+
+ // step4 we merge the definition
+ session = openSession();
+ session.beginTransaction();
+ session.merge( definition );
+ session.getTransaction().commit();
+ session.close();
+
+ // step5, final test
+ session = openSession();
+ session.beginTransaction();
+ definition = ( Definition ) session.get( Definition.class, definition.getId() );
+ assertEquals( 2, definition.getValues().size() );
+ Iterator values = definition.getValues().iterator();
+ while ( values.hasNext() ) {
+ assertEquals( 1, ( ( Value ) values.next() ).getLocalizedStrings().getStringsCopy().size() );
+ }
+ session.getTransaction().commit();
+ session.close();
+ }
+
+ public void testMergingOriginallyNullComponent() {
+ // step1, we create a definition with one value, but with a null component
+ Session session = openSession();
+ session.beginTransaction();
+ Definition definition = new Definition();
+ Value value1 = new Value( definition );
+ session.persist( definition );
+ session.getTransaction().commit();
+ session.close();
+
+ // step2, we verify that the definition has one value; then we detach it
+ session = openSession();
+ session.beginTransaction();
+ definition = ( Definition ) session.get( Definition.class, definition.getId() );
+ assertEquals( 1, definition.getValues().size() );
+ session.getTransaction().commit();
+ session.close();
+
+ // step3, we add a new value during detachment
+ ( ( Value ) definition.getValues().iterator().next() ).getLocalizedStrings().addString( new Locale( "en_US" ), "hello" );
+ Value value2 = new Value( definition );
+ value2.getLocalizedStrings().addString( new Locale( "es" ), "hola" );
+
+ // step4 we merge the definition
+ session = openSession();
+ session.beginTransaction();
+ session.merge( definition );
+ session.getTransaction().commit();
+ session.close();
+
+ // step5, final test
+ session = openSession();
+ session.beginTransaction();
+ definition = ( Definition ) session.get( Definition.class, definition.getId() );
+ assertEquals( 2, definition.getValues().size() );
+ Iterator values = definition.getValues().iterator();
+ while ( values.hasNext() ) {
+ assertEquals( 1, ( ( Value ) values.next() ).getLocalizedStrings().getStringsCopy().size() );
+ }
+ session.getTransaction().commit();
+ session.close();
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/Definition.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/Definition.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/Definition.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -0,0 +1,30 @@
+package org.hibernate.test.component.cascading.collection;
+
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class Definition {
+ private Long id;
+ private Set values = new HashSet();
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Set getValues() {
+ return values;
+ }
+
+ public void setValues(Set values) {
+ this.values = values;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/LocalizedStrings.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/LocalizedStrings.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/LocalizedStrings.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -0,0 +1,26 @@
+package org.hibernate.test.component.cascading.collection;
+
+import java.util.Locale;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class LocalizedStrings {
+ private Map strings = new HashMap();
+
+ public void addString(Locale locale, String value) {
+ strings.put( locale, value );
+ }
+
+ public String getString(Locale locale) {
+ return ( String ) strings.get( locale );
+ }
+
+ public Map getStringsCopy() {
+ return java.util.Collections.unmodifiableMap( strings );
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/Mappings.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/Mappings.hbm.xml (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/Mappings.hbm.xml 2007-03-26 17:24:58 UTC (rev 11346)
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.component.cascading.collection">
+
+ <class name="Definition" >
+ <id name="id" type="long" column="ID">
+ <generator class="increment"/>
+ </id>
+ <set name="values" cascade="all-delete-orphan,merge" lazy="false" inverse="true">
+ <key column="DEF_ID" />
+ <one-to-many class="Value"/>
+ </set>
+ </class>
+
+ <class name="Value" >
+ <id name="id" type="long" column="ID">
+ <generator class="increment"/>
+ </id>
+
+ <many-to-one name="definition" class="Definition" column="DEF_ID"/>
+
+ <component name="localizedStrings" class="LocalizedStrings">
+ <map name="strings" access="field" cascade="persist,merge" lazy="false">
+ <key column="VAL_ID" />
+ <map-key type="locale" column="LOC" />
+ <element type="string" column="STR_VAL" />
+ </map>
+ </component>
+
+ </class>
+
+</hibernate-mapping>
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/Value.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/Value.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/collection/Value.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -0,0 +1,45 @@
+package org.hibernate.test.component.cascading.collection;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class Value {
+ private Long id;
+ private Definition definition;
+ private LocalizedStrings localizedStrings = new LocalizedStrings();
+
+ private Value() {
+ }
+
+ public Value(Definition definition) {
+ this();
+ this.definition = definition;
+ definition.getValues().add( this );
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Definition getDefinition() {
+ return definition;
+ }
+
+ public void setDefinition(Definition definition) {
+ this.definition = definition;
+ }
+
+ public LocalizedStrings getLocalizedStrings() {
+ return localizedStrings;
+ }
+
+ public void setLocalizedStrings(LocalizedStrings localizedStrings) {
+ this.localizedStrings = localizedStrings;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/Address.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/Address.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/Address.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -0,0 +1,63 @@
+package org.hibernate.test.component.cascading.toone;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class Address {
+ private Long id;
+ private String street1;
+ private String street2;
+ private String city;
+ private String state;
+ private String zipCode;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getStreet1() {
+ return street1;
+ }
+
+ public void setStreet1(String street1) {
+ this.street1 = street1;
+ }
+
+ public String getStreet2() {
+ return street2;
+ }
+
+ public void setStreet2(String street2) {
+ this.street2 = street2;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public String getZipCode() {
+ return zipCode;
+ }
+
+ public void setZipCode(String zipCode) {
+ this.zipCode = zipCode;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/CascadeToComponentAssociationTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/CascadeToComponentAssociationTest.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/CascadeToComponentAssociationTest.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -0,0 +1,71 @@
+package org.hibernate.test.component.cascading.toone;
+
+import junit.framework.Test;
+
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.Session;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class CascadeToComponentAssociationTest extends FunctionalTestCase {
+ public CascadeToComponentAssociationTest(String string) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "component/cascading/toone/Mappings.hbm.xml" };
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( CascadeToComponentAssociationTest.class );
+ }
+
+ public void testMerging() {
+ // step1, we create a document with owner
+ Session session = openSession();
+ session.beginTransaction();
+ User user = new User();
+ Document document = new Document();
+ document.setOwner( user );
+ session.persist( document );
+ session.getTransaction().commit();
+ session.close();
+
+ // step2, we verify that the document has owner and that owner has no personal-info; then we detach
+ session = openSession();
+ session.beginTransaction();
+ document = ( Document ) session.get( Document.class, document.getId() );
+ assertNotNull( document.getOwner() );
+ assertNull( document.getOwner().getPersonalInfo() );
+ session.getTransaction().commit();
+ session.close();
+
+ // step3, try to specify the personal-info during detachment
+ Address addr = new Address();
+ addr.setStreet1( "123 6th St" );
+ addr.setCity( "Austin" );
+ addr.setState( "TX" );
+ document.getOwner().setPersonalInfo( new PersonalInfo( addr ) );
+
+ // step4 we merge the document
+ session = openSession();
+ session.beginTransaction();
+ session.merge( document );
+ session.getTransaction().commit();
+ session.close();
+
+ // step5, final test
+ session = openSession();
+ session.beginTransaction();
+ document = ( Document ) session.get( Document.class, document.getId() );
+ assertNotNull( document.getOwner() );
+ assertNotNull( document.getOwner().getPersonalInfo() );
+ assertNotNull( document.getOwner().getPersonalInfo().getHomeAddress() );
+ session.getTransaction().commit();
+ session.close();
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/Document.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/Document.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/Document.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -0,0 +1,36 @@
+package org.hibernate.test.component.cascading.toone;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class Document {
+ private Long id;
+ private String location;
+ private User owner;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public User getOwner() {
+ return owner;
+ }
+
+ public void setOwner(User owner) {
+ this.owner = owner;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/Mappings.hbm.xml
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/Mappings.hbm.xml (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/Mappings.hbm.xml 2007-03-26 17:24:58 UTC (rev 11346)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.component.cascading.toone">
+
+ <class name="Document" >
+ <id name="id" type="long" column="ID">
+ <generator class="increment"/>
+ </id>
+ <many-to-one name="owner" class="User" cascade="persist,merge,delete"/>
+ </class>
+
+ <class name="User" >
+ <id name="id" type="long" column="ID">
+ <generator class="increment"/>
+ </id>
+ <component name="personalInfo" class="PersonalInfo">
+ <many-to-one name="homeAddress" class="Address" cascade="persist,merge,delete"/>
+ </component>
+ </class>
+
+ <class name="Address">
+ <id name="id" type="long" column="ID">
+ <generator class="increment"/>
+ </id>
+ <property name="street1" type="string" column="STREET1" />
+ <property name="street2" type="string" column="STREET2" />
+ <property name="city" type="string" column="CITY" />
+ <property name="state" type="string" column="STATE" />
+ <property name="zipCode" type="string" column="ZIP_CODE" />
+ </class>
+</hibernate-mapping>
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/PersonalInfo.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/PersonalInfo.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/PersonalInfo.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -0,0 +1,25 @@
+package org.hibernate.test.component.cascading.toone;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class PersonalInfo {
+ private Address homeAddress = new Address();
+
+ public PersonalInfo() {
+ }
+
+ public PersonalInfo(Address homeAddress) {
+ this.homeAddress = homeAddress;
+ }
+
+ public Address getHomeAddress() {
+ return homeAddress;
+ }
+
+ public void setHomeAddress(Address homeAddress) {
+ this.homeAddress = homeAddress;
+ }
+}
Added: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/User.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/User.java (rev 0)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/component/cascading/toone/User.java 2007-03-26 17:24:58 UTC (rev 11346)
@@ -0,0 +1,27 @@
+package org.hibernate.test.component.cascading.toone;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class User {
+ private Long id;
+ private PersonalInfo personalInfo;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public PersonalInfo getPersonalInfo() {
+ return personalInfo;
+ }
+
+ public void setPersonalInfo(PersonalInfo personalInfo) {
+ this.personalInfo = personalInfo;
+ }
+}
More information about the hibernate-commits
mailing list