Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test In directory sc8-pr-cvs1:/tmp/cvs-serv26833/test Modified Files: DoubleStringType.java FooBarTest.java Glarch.hbm.xml Glarch.java MultiTableTest.java Qux.hbm.xml Log Message: * reworked CompositeUserType * improved some exception handling Index: DoubleStringType.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/DoubleStringType.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DoubleStringType.java 6 Apr 2003 02:28:58 -0000 1.4 --- DoubleStringType.java 6 Apr 2003 10:11:11 -0000 1.5 *************** *** 2,5 **** --- 2,6 ---- package net.sf.hibernate.test; + import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.ResultSet; *************** *** 10,13 **** --- 11,15 ---- import net.sf.hibernate.Hibernate; import net.sf.hibernate.HibernateException; + import net.sf.hibernate.engine.SessionImplementor; import net.sf.hibernate.type.Type; *************** *** 41,45 **** public boolean isMutable() { return true; } ! public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException { --- 43,47 ---- public boolean isMutable() { return true; } ! public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { *************** *** 50,54 **** } ! public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { --- 52,56 ---- } ! public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { *************** *** 77,80 **** --- 79,94 ---- ( (String[]) component )[property] = (String) value; + } + + public Object assemble( + Serializable cached, + SessionImplementor session, + Object owner) { + + return deepCopy(cached); + } + + public Serializable disassemble(Object value, SessionImplementor session) { + return (Serializable) deepCopy(value); } Index: FooBarTest.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/FooBarTest.java,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** FooBarTest.java 6 Apr 2003 02:28:58 -0000 1.49 --- FooBarTest.java 6 Apr 2003 10:11:11 -0000 1.50 *************** *** 123,126 **** --- 123,158 ---- } + public void testCustom() throws Exception { + Glarch g = new Glarch(); + Multiplicity m = new Multiplicity(); + m.count = 12; + m.glarch = g; + g.setMultiple(m); + Session s = sessions.openSession(); + Serializable gid = s.save(g); + s.flush(); + s.connection().commit(); + s.close(); + + s = sessions.openSession(); + g = (Glarch) s.find("from Glarch g where g.multiple.glarch=g and g.multiple.count=12").get(0); + assertTrue( g.getMultiple()!=null ); + assertEquals( g.getMultiple().count, 12 ); + assertSame(g.getMultiple().glarch, g); + s.flush(); + s.connection().commit(); + s.close(); + + s = sessions.openSession(); + g = (Glarch) s.load(Glarch.class, gid); + assertTrue( g.getMultiple()!=null ); + assertEquals( g.getMultiple().count, 12 ); + assertSame(g.getMultiple().glarch, g); + s.delete(g); + s.flush(); + s.connection().commit(); + s.close(); + } + public void testNamedParams() throws Exception { Bar bar = new Bar(); *************** *** 454,457 **** --- 486,495 ---- List list = s.find("select new Result(foo.string, foo.long, foo.integer) from foo in class Foo"); assertTrue( list.size()==2 && ( list.get(0) instanceof Result ) && ( list.get(1) instanceof Result ) ); + list = s.find("select new Result( baz.name, foo.long, count(elements(baz.fooArray)) ) from Baz baz join baz.fooArray foo group by baz.name, foo.long"); + assertTrue( list.size()==1 && ( list.get(0) instanceof Result ) ); + Result r = ((Result) list.get(0) ); + assertEquals( r.getName(), baz.getName() ); + assertEquals( r.getCount(), 1 ); + assertEquals( r.getAmount(), foos[1].getLong().longValue() ); s.find("select max( elements(bar.baz.fooArray) ) from Bar as bar"); Index: Glarch.hbm.xml =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/Glarch.hbm.xml,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Glarch.hbm.xml 2 Apr 2003 13:10:38 -0000 1.11 --- Glarch.hbm.xml 6 Apr 2003 10:11:11 -0000 1.12 *************** *** 54,57 **** --- 54,61 ---- <column name="any_class"/> </property> + <property name="multiple" type="net.sf.hibernate.test.MultiplicityType"> + <column name="count_"/> + <column name="glarch_"/> + </property> </class> Index: Glarch.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/Glarch.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Glarch.java 20 Mar 2003 13:59:10 -0000 1.8 --- Glarch.java 6 Apr 2003 10:11:11 -0000 1.9 *************** *** 34,37 **** --- 34,38 ---- private Object any; private int x; + private Multiplicity multiple; public int getX() { *************** *** 216,219 **** --- 217,234 ---- public void setAny(Object any) { this.any = any; + } + + /** + * @return + */ + public Multiplicity getMultiple() { + return multiple; + } + + /** + * @param multiplicity + */ + public void setMultiple(Multiplicity multiplicity) { + multiple = multiplicity; } Index: MultiTableTest.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/MultiTableTest.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** MultiTableTest.java 6 Apr 2003 02:28:58 -0000 1.12 --- MultiTableTest.java 6 Apr 2003 10:11:11 -0000 1.13 *************** *** 107,112 **** public void testMultiTable() throws Exception { - if ( dialect instanceof SybaseDialect ) return; - Session s = sessions.openSession(); Transaction t = s.beginTransaction(); --- 107,110 ---- *************** *** 119,127 **** simp.setName("simp"); //simp.setCount(132); ! s.save( multi, new Long(123) ); ! s.save( simp, new Long(1234) ); SubMulti sm = new SubMulti(); sm.setAmount(66.5f); ! s.save( sm, new Long(2) ); t.commit(); s.close(); --- 117,142 ---- simp.setName("simp"); //simp.setCount(132); ! Serializable mid; ! Serializable sid; ! if ( dialect instanceof SybaseDialect ) { ! mid = s.save(multi); ! sid = s.save(simp); ! } ! else { ! mid = new Long(123); ! s.save(multi, mid); ! sid = new Long(1234); ! s.save(simp, sid); ! } SubMulti sm = new SubMulti(); sm.setAmount(66.5f); ! Serializable smid; ! if (dialect instanceof SybaseDialect) { ! smid = s.save(sm); ! } ! else { ! smid = new Long(2); ! s.save(sm, smid); ! } t.commit(); s.close(); *************** *** 132,140 **** //multi.setCount( multi.getCount() + 1 ); multi.setName("new name"); ! s.update( multi, new Long(123) ); simp.setName("new name"); ! s.update( simp, new Long(1234) ); sm.setAmount(456.7f); ! s.update( sm, new Long(2) ); t.commit(); s.close(); --- 147,155 ---- //multi.setCount( multi.getCount() + 1 ); multi.setName("new name"); ! s.update(multi, mid); simp.setName("new name"); ! s.update(simp, sid); sm.setAmount(456.7f); ! s.update(sm, smid); t.commit(); s.close(); *************** *** 142,146 **** s = sessions.openSession(); t = s.beginTransaction(); ! multi = (Multi) s.load( Multi.class, new Long(123) ); assertTrue( multi.getExtraProp().equals("extra2") ); multi.setExtraProp( multi.getExtraProp() + "3" ); --- 157,161 ---- s = sessions.openSession(); t = s.beginTransaction(); ! multi = (Multi) s.load(Multi.class, mid); assertTrue( multi.getExtraProp().equals("extra2") ); multi.setExtraProp( multi.getExtraProp() + "3" ); *************** *** 148,152 **** assertTrue( multi.getName().equals("new name") ); multi.setName("newer name"); ! sm = (SubMulti) s.load( SubMulti.class, new Long(2) ); assertTrue( sm.getAmount()==456.7f ); sm.setAmount(23423f); --- 163,167 ---- assertTrue( multi.getName().equals("new name") ); multi.setName("newer name"); ! sm = (SubMulti) s.load(SubMulti.class, smid); assertTrue( sm.getAmount()==456.7f ); sm.setAmount(23423f); *************** *** 156,161 **** s = sessions.openSession(); t = s.beginTransaction(); ! multi = (Multi) s.load( Simple.class, new Long(123) ); ! simp = (Simple) s.load( Simple.class, new Long(1234) ); assertTrue( ! (simp instanceof Multi) ); assertTrue( multi instanceof Multi ); --- 171,176 ---- s = sessions.openSession(); t = s.beginTransaction(); ! multi = (Multi) s.load(Simple.class, mid); ! simp = (Simple) s.load(Simple.class, sid); assertTrue( ! (simp instanceof Multi) ); assertTrue( multi instanceof Multi ); *************** *** 192,196 **** ); assertTrue( ! s.find("from m in class Simple where m.class = Multi").size()==2 ); assertTrue( --- 207,211 ---- ); assertTrue( ! s.find("from m in class Simple where m.class = Multi").size()==1 ); assertTrue( *************** *** 213,218 **** s = sessions.openSession(); t = s.beginTransaction(); ! multi = (Multi) s.load( Simple.class, new Long(123), LockMode.UPGRADE ); ! simp = (Simple) s.load( Simple.class, new Long(1234) ); s.lock(simp, LockMode.UPGRADE_NOWAIT); t.commit(); --- 228,233 ---- s = sessions.openSession(); t = s.beginTransaction(); ! multi = (Multi) s.load(Simple.class, mid, LockMode.UPGRADE); ! simp = (Simple) s.load(Simple.class, sid); s.lock(simp, LockMode.UPGRADE_NOWAIT); t.commit(); *************** *** 221,225 **** s = sessions.openSession(); t = s.beginTransaction(); ! s.update( multi, new Long(123) ); s.delete(multi); assertTrue( s.delete("from s in class Simple")==2); --- 236,240 ---- s = sessions.openSession(); t = s.beginTransaction(); ! s.update(multi, mid); s.delete(multi); assertTrue( s.delete("from s in class Simple")==2); Index: Qux.hbm.xml =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/Qux.hbm.xml,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Qux.hbm.xml 6 Apr 2003 02:28:58 -0000 1.7 --- Qux.hbm.xml 6 Apr 2003 10:11:12 -0000 1.8 *************** *** 1,5 **** <?xml version="1.0"?> <!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > ! <hibernate-mapping schema="dbo"> <class name="net.sf.hibernate.test.Qux" table="quux" proxy="net.sf.hibernate.test.Qux"> <!----> --- 1,5 ---- <?xml version="1.0"?> <!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > ! <hibernate-mapping> <class name="net.sf.hibernate.test.Qux" table="quux" proxy="net.sf.hibernate.test.Qux"> <!----> |