From: <one...@us...> - 2003-04-03 12:34:36
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test In directory sc8-pr-cvs1:/tmp/cvs-serv28961/hibernate/test Modified Files: FooBarTest.java XY.hbm.xml Y.java Log Message: * improved foreign id-generator * fixed a bug with long path expressions ending in elements or indices in where clause Index: FooBarTest.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/FooBarTest.java,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** FooBarTest.java 29 Mar 2003 04:08:49 -0000 1.45 --- FooBarTest.java 3 Apr 2003 12:34:29 -0000 1.46 *************** *** 80,83 **** --- 80,126 ---- } + public void testOneToOneGenerator() throws Exception { + Session s = sessions.openSession(); + X x = new X(); + Y y = new Y(); + x.setY(y); + y.setTheX(x); + Serializable id = s.save(y); + assertEquals( id, s.save(x) ); + s.flush(); + assertTrue( s.contains(y) && s.contains(x) ); + s.connection().commit(); + s.close(); + assertEquals( new Long(x.getId()), y.getId() ); + + s = sessions.openSession(); + x = new X(); + y = new Y(); + x.setY(y); + y.setTheX(x); + s.save(y); + s.flush(); + assertTrue( s.contains(y) && s.contains(x) ); + s.connection().commit(); + s.close(); + assertEquals( new Long(x.getId()), y.getId() ); + + s = sessions.openSession(); + x = new X(); + y = new Y(); + x.setY(y); + y.setTheX(x); + id = s.save(x); + assertEquals( id, y.getId() ); + assertEquals( id, new Long( x.getId() ) ); + s.flush(); + assertTrue( s.contains(y) && s.contains(x) ); + s.delete("from X x"); + s.flush(); + s.connection().commit(); + s.close(); + + } + public void testNamedParams() throws Exception { Bar bar = new Bar(); *************** *** 412,415 **** --- 455,468 ---- assertTrue( list.size()==2 && ( list.get(0) instanceof Result ) && ( list.get(1) instanceof Result ) ); + s.find("select max( elements(bar.baz.fooArray) ) from Bar as bar"); + s.find("select count(*) from Baz as baz where 1 in indices(baz.fooArray)"); + s.find("select count(*) from Bar as bar where 'abc' in elements(bar.baz.fooArray)"); + s.find("select count(*) from Bar as bar where 1 in indices(bar.baz.fooArray)"); + s.find("select count(*) from Bar as bar, bar.component.glarch.proxyArray as g where g.id in indices(bar.baz.fooArray)"); + s.find("select max( elements(bar.baz.fooArray) ) from Bar as bar, bar.component.glarch.proxyArray as g where g.id in indices(bar.baz.fooArray)"); + + s.find("select count(*) from Bar as bar where 1 in (from g in bar.component.glarch.proxyArray where g.name='foo')"); + s.find("select count(*) from Bar as bar left outer join bar.component.glarch.proxyArray as pg where 1 in (from g in bar.component.glarch.proxyArray)"); + s.find("select baz.name from Bar bar inner join bar.baz baz inner join baz.fooSet foo where baz.name = bar.string"); s.find("SELECT baz.name FROM Bar AS bar INNER JOIN bar.baz AS baz INNER JOIN baz.fooSet AS foo WHERE baz.name = bar.string"); *************** *** 2773,2788 **** } ! public void testOneToOneGenerator() throws Exception { ! Session s = sessions.openSession(); ! X x = new X(); ! Y y = new Y(); ! x.setY(y); ! s.save(y); ! s.save(x); ! s.flush(); ! s.connection().commit(); ! s.close(); ! } ! public void testAny() throws Exception { Session s = sessions.openSession(); --- 2826,2830 ---- } ! public void testAny() throws Exception { Session s = sessions.openSession(); Index: XY.hbm.xml =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/XY.hbm.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** XY.hbm.xml 29 Mar 2003 04:20:19 -0000 1.1 --- XY.hbm.xml 3 Apr 2003 12:34:30 -0000 1.2 *************** *** 5,14 **** <hibernate-mapping> <class name="net.sf.hibernate.test.X"> ! <id name="id"> <generator class="foreign"> <param name="property">y</param> </generator> </id> ! <one-to-one name="y" constrained="true"/> </class> <class name="net.sf.hibernate.test.Y"> --- 5,14 ---- <hibernate-mapping> <class name="net.sf.hibernate.test.X"> ! <id name="id" unsaved-value="0"> <generator class="foreign"> <param name="property">y</param> </generator> </id> ! <one-to-one name="y" constrained="true" cascade="all"/> </class> <class name="net.sf.hibernate.test.Y"> *************** *** 17,20 **** --- 17,21 ---- </id> <property name="x"/> + <one-to-one name="theX" cascade="save-update"/> </class> </hibernate-mapping> Index: Y.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/Y.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Y.java 29 Mar 2003 04:20:19 -0000 1.1 --- Y.java 3 Apr 2003 12:34:30 -0000 1.2 *************** *** 6,9 **** --- 6,10 ---- private Long id; private String x; + private X theX; /** * Returns the id. *************** *** 36,39 **** --- 37,54 ---- public void setX(String x) { this.x = x; + } + + /** + * @return + */ + public X getTheX() { + return theX; + } + + /** + * @param x + */ + public void setTheX(X x) { + theX = x; } |