Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test In directory sc8-pr-cvs1:/tmp/cvs-serv32602/sf/hibernate/test Modified Files: Baz.hbm.xml Baz.java FooBarTest.java MultiTableTest.java SQLFunctionsTest.java Added Files: Blobber.hbm.xml Blobber.java Log Message: fixed a bug wrapping sorted collections don't ever update mutable=false objects added where attribute to collection mappings --- NEW FILE: Blobber.hbm.xml --- <?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.Blobber" dynamic-update="true"> <id name="id"> <generator class="hilo"/> </id> <property name="blob" column="blob_"/> <property name="clob" column="clob_"/> </class> </hibernate-mapping> --- NEW FILE: Blobber.java --- package net.sf.hibernate.test; import java.sql.Blob; import java.sql.Clob; /** * @author Administrator * * To change this generated comment edit the template variable "typecomment": * Window>Preferences>Java>Templates. * To enable and disable the creation of type comments go to * Window>Preferences>Java>Code Generation. */ public class Blobber { private int id; private Blob blob; private Clob clob; /** * Returns the blob. * @return Blob */ public Blob getBlob() { return blob; } /** * Returns the clob. * @return Clob */ public Clob getClob() { return clob; } /** * Returns the id. * @return int */ public int getId() { return id; } /** * Sets the blob. * @param blob The blob to set */ public void setBlob(Blob blob) { this.blob = blob; } /** * Sets the clob. * @param clob The clob to set */ public void setClob(Clob clob) { this.clob = clob; } /** * Sets the id. * @param id The id to set */ public void setId(int id) { this.id = id; } } Index: Baz.hbm.xml =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/Baz.hbm.xml,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Baz.hbm.xml 9 Feb 2003 06:28:16 -0000 1.10 --- Baz.hbm.xml 15 Feb 2003 01:00:55 -0000 1.11 *************** *** 177,180 **** --- 177,186 ---- </composite-element> </map> + + <map name="stringGlarchMap" where="baz_map_index > 'a' and tha_key is not null" cascade="all"> + <key column="baz_map_id"/> + <index column="baz_map_index" type="string"/> + <one-to-many class="net.sf.hibernate.test.Glarch"/> + </map> </class> Index: Baz.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/Baz.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Baz.java 9 Feb 2003 06:28:16 -0000 1.6 --- Baz.java 15 Feb 2003 01:00:56 -0000 1.7 *************** *** 31,34 **** --- 31,35 ---- private Set cached; private Map cachedMap; + private Map stringGlarchMap; Baz() {} *************** *** 296,299 **** --- 297,316 ---- public int compareTo(Object o) { return ( (Baz) o ).code.compareTo(code); + } + + /** + * Returns the stringGlarchMap. + * @return Map + */ + public Map getStringGlarchMap() { + return stringGlarchMap; + } + + /** + * Sets the stringGlarchMap. + * @param stringGlarchMap The stringGlarchMap to set + */ + public void setStringGlarchMap(Map stringGlarchMap) { + this.stringGlarchMap = stringGlarchMap; } Index: FooBarTest.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/FooBarTest.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** FooBarTest.java 9 Feb 2003 06:28:16 -0000 1.20 --- FooBarTest.java 15 Feb 2003 01:00:57 -0000 1.21 *************** *** 10,17 **** import java.util.HashSet; import java.util.Iterator; - import java.util.LinkedList; import java.util.List; import java.util.Locale; - import java.util.Properties; import java.util.Set; import java.util.TimeZone; --- 10,15 ---- *************** *** 46,52 **** import net.sf.hibernate.dialect.SybaseDialect; import net.sf.hibernate.proxy.HibernateProxy; - import net.sf.hibernate.type.DateType; - import net.sf.hibernate.type.EntityType; - import net.sf.hibernate.type.StringType; import net.sf.hibernate.type.Type; --- 44,47 ---- *************** *** 371,374 **** --- 366,373 ---- bars.add( new Bar() ); baz.setCascadingBars(bars); + HashMap sgm = new HashMap(); + sgm.put( "a", new Glarch() ); + sgm.put( "b", new Glarch() ); + baz.setStringGlarchMap(sgm); //System.out.println( s.print(baz) ); s.flush(); *************** *** 393,396 **** --- 392,397 ---- //System.out.println(time); + assertTrue( baz.getStringGlarchMap().size()==1 ); + //The following test is disabled databases with no subselects if ( !(dialect instanceof MySQLDialect) && !(dialect instanceof HSQLDialect) && !(dialect instanceof PointbaseDialect) ) { *************** *** 499,502 **** --- 500,505 ---- s.load( Qux.class, new Long(666) ); //nonexistent + assertTrue( s.delete("from g in class Glarch")==1 ); + s.flush(); s.connection().commit(); *************** *** 849,853 **** s.save(foo2); foo.setFoo(foo2); ! if ( dialect instanceof DB2Dialect) { s.find("from foo in class Foo where lower( foo.foo.string ) = 'foo'"); --- 852,856 ---- s.save(foo2); foo.setFoo(foo2); ! if ( dialect instanceof DB2Dialect) { s.find("from foo in class Foo where lower( foo.foo.string ) = 'foo'"); *************** *** 890,893 **** --- 893,898 ---- assertTrue( list.size()==2, "component query" ); s.find("from foo in class Foo where not exists (from bar in class Bar where bar.id = foo.id)"); + + s.iterate("select foo.string, foo.date, foo.foo.string, foo.id from foo in class Foo, baz in class Baz where foo in baz.fooArray.elements and foo.string like 'foo'"); } list = s.find("from foo in class net.sf.hibernate.test.Foo where foo.component.count is null order by foo.component.count"); *************** *** 1097,1101 **** - //TODO: reenable public void testReachability() throws Exception { //first for unkeyed collections --- 1102,1105 ---- *************** *** 1539,1719 **** s.close(); } - - - private FumCompositeID fumKey(String str) { - - return fumKey(str,false); - } - - private FumCompositeID fumKey(String str, boolean aCompositeQueryTest) { - FumCompositeID id = new FumCompositeID(); - if( dialect instanceof MckoiDialect ) { - java.util.GregorianCalendar now = new java.util.GregorianCalendar(); - java.util.GregorianCalendar cal - = new java.util.GregorianCalendar( now.get(java.util.Calendar.YEAR), - now.get(java.util.Calendar.MONTH), - now.get(java.util.Calendar.DATE) ); - id.setDate( cal.getTime() ); - } - else - id.setDate( new Date() ); - id.setString( new String(str) ); - - if (aCompositeQueryTest) - id.setShort( fumKeyShort++ ); - else - id.setShort((short)12); - - return id; - } - - public void testCompositeID() throws Exception { - Session s = sessions.openSession(); - Fum fum = new Fum( fumKey("fum") ); - fum.setFum("fee fi fo"); - s.save(fum); - assertTrue( fum==s.load( Fum.class, fumKey("fum") ), "load by composite key" ); - s.flush(); - s.connection().commit(); - s.close(); - - s = sessions.openSession(); - fum = (Fum) s.load( Fum.class, fumKey("fum"), LockMode.UPGRADE ); - assertTrue( fum!=null, "load by composite key" ); - - Fum fum2 = new Fum( fumKey("fi") ); - fum2.setFum("fee fo fi"); - fum.setFo(fum2); - s.save(fum2); - assertTrue( - s.find("from fum in class net.sf.hibernate.test.Fum where not fum.fum='FRIEND'").size()==2, - "find composite keyed objects" - ); - assertTrue( - s.find("select fum from fum in class net.sf.hibernate.test.Fum where fum.fum='fee fi fo'").get(0)==fum, - "find composite keyed object" - ); - fum.setFo(null); - s.flush(); - s.connection().commit(); - s.close(); - - s = sessions.openSession(); - Iterator iter = s.iterate("from fum in class net.sf.hibernate.test.Fum where not fum.fum='FRIEND'"); - int i = 0; - while ( iter.hasNext() ) { - fum = (Fum) iter.next(); - //iter.remove(); - s.delete(fum); - i++; - } - assertTrue( i==2, "iterate on composite key" ); - s.flush(); - s.connection().commit(); - s.close(); - } - - public void testCompositeIDOneToOne() throws Exception { - Session s = sessions.openSession(); - Fum fum = new Fum( fumKey("fum") ); - fum.setFum("fee fi fo"); - //s.save(fum); - Fumm fumm = new Fumm(); - fumm.setFum(fum); - s.save(fumm); - s.flush(); - s.connection().commit(); - s.close(); - s = sessions.openSession(); - fumm = (Fumm) s.load( Fumm.class, fumKey("fum") ); - //s.delete( fumm.getFum() ); - s.delete(fumm); - s.flush(); - s.connection().commit(); - s.close(); - } - - public void testCompositeIDQuery() throws Exception { - Session s = sessions.openSession(); - Fum fee = new Fum( fumKey("fee",true) ); - fee.setFum("fee"); - s.save(fee); - Fum fi = new Fum( fumKey("fi",true) ); - fi.setFum("fi"); - short fiShort = fi.getId().getShort(); - s.save(fi); - Fum fo = new Fum( fumKey("fo",true) ); - fo.setFum("fo"); - s.save(fo); - Fum fum = new Fum( fumKey("fum",true) ); - fum.setFum("fum"); - s.save(fum); - s.flush(); - s.connection().commit(); - s.close(); - - s = sessions.openSession(); - // Try to find the Fum object "fo" that we inserted searching by the string in the id - List vList = s.find("from fum in class net.sf.hibernate.test.Fum where fum.id.string='fo'" ); - assertTrue( vList.size() == 1, "find by composite key query (find fo object)" ); - fum = (Fum)vList.get(0); - assertTrue( fum.getId().getString().equals("fo"), "find by composite key query (check fo object)" ); - - // Try to find the Fum object "fi" that we inserted searching by the date in the id - vList = s.find("from fum in class net.sf.hibernate.test.Fum where fum.id.short = ?",new Short(fiShort),Hibernate.SHORT); - assertTrue( vList.size() == 1, "find by composite key query (find fi object)" ); - fi = (Fum)vList.get(0); - assertTrue( fi.getId().getString().equals("fi"), "find by composite key query (check fi object)" ); - - // Make sure we can return all of the objects by searching by the date id - assertTrue( - s.find("from fum in class net.sf.hibernate.test.Fum where fum.id.date <= ? and not fum.fum='FRIEND'",new Date(),Hibernate.DATE).size()==4, - "find by composite key query with arguments" - ); - s.flush(); - s.connection().commit(); - s.close(); - - s = sessions.openSession(); - assertTrue( - s.iterate("select fum.id.short, fum.id.date, fum.id.string from fum in class net.sf.hibernate.test.Fum").hasNext() - ); - assertTrue( - s.iterate("select fum.id from fum in class net.sf.hibernate.test.Fum").hasNext() - ); - Query qu = s.createQuery("select fum.fum, fum , fum.fum, fum.id.date from fum in class net.sf.hibernate.test.Fum"); - Type[] types = qu.getReturnTypes(); - assertTrue(types.length==4); - for ( int k=0; k<types.length; k++) { - assertTrue( types[k]!=null ); - } - assertTrue(types[0] instanceof StringType); - assertTrue(types[1] instanceof EntityType); - assertTrue(types[2] instanceof StringType); - assertTrue(types[3] instanceof DateType); - Iterator iter = qu.iterate(); - int j = 0; - while ( iter.hasNext() ) { - j++; - assertTrue( ( (Object[]) iter.next() )[1] instanceof Fum ); - } - assertTrue( j==8, "iterate on composite key" ); - iter = s.iterate("from fum in class net.sf.hibernate.test.Fum where not fum.fum='FRIEND'"); - int i = 0; - while ( iter.hasNext() ) { - fum = (Fum) iter.next(); - //iter.remove(); - s.delete(fum); - i++; - } - assertTrue( i==4, "iterate on composite key" ); - s.flush(); - - s.iterate("from fu in class Fum, fo in class Fum where fu.fo.id.string = fo.id.string and fo.fum is not null"); - s.connection().commit(); - s.close(); - } - public void testScrollableIterator() throws Exception { if ( dialect instanceof DB2Dialect || dialect instanceof OracleDialect || dialect instanceof SybaseDialect ) { --- 1543,1547 ---- *************** *** 1753,1793 **** } } ! ! public void testCompositeIDCollections() throws Exception { ! Session s = sessions.openSession(); ! Fum fum1 = new Fum( fumKey("fum1") ); ! Fum fum2 = new Fum( fumKey("fum2") ); ! fum1.setFum("fee fo fi"); ! fum2.setFum("fee fo fi"); ! s.save(fum1); ! s.save(fum2); ! Qux q = new Qux(); ! s.save(q); ! Set set = new HashSet(); ! List list = new ArrayList(); ! set.add(fum1); set.add(fum2); ! list.add(fum1); ! q.setFums(set); ! q.setMoreFums(list); ! fum1.setQuxArray( new Qux[] {q} ); ! s.flush(); ! s.connection().commit(); ! s.close(); ! s = sessions.openSession(); ! q = (Qux) s.load( Qux.class, q.getKey() ); ! assertTrue( q.getFums().size()==2, "collection of fums" ); ! assertTrue( q.getMoreFums().size()==1, "collection of fums" ); ! assertTrue( ( (Fum) q.getMoreFums().get(0) ).getQuxArray()[0]==q, "unkeyed composite id collection" ); ! Iterator iter = q.getFums().iterator(); ! iter.hasNext(); ! s.delete( (Fum) iter.next() ); ! iter.hasNext(); ! s.delete( (Fum) iter.next() ); ! s.delete(q); ! s.flush(); ! s.connection().commit(); ! s.close(); ! } ! public void testMultiColumnQueries() throws Exception { Session s = sessions.openSession(); --- 1581,1585 ---- } } ! public void testMultiColumnQueries() throws Exception { Session s = sessions.openSession(); *************** *** 2166,2213 **** } - public void testDeleteOwner() throws Exception { - Session s = sessions.openSession(); - Qux q = new Qux(); - s.save(q); - Fum f1 = new Fum( fumKey("f1") ); - Fum f2 = new Fum( fumKey("f2") ); - Set set = new HashSet(); - set.add(f1); - set.add(f2); - List list = new LinkedList(); - list.add(f1); - list.add(f2); - f1.setFum("f1"); - f2.setFum("f2"); - q.setFums(set); - q.setMoreFums(list); - s.save(f1); - s.save(f2); - s.flush(); - s.connection().commit(); - s.close(); - - s = sessions.openSession(); - q = (Qux) s.load( Qux.class, q.getKey(), LockMode.UPGRADE ); - s.lock( q, LockMode.UPGRADE ); - s.delete(q); - s.flush(); - s.connection().commit(); - s.close(); - - s = sessions.openSession(); - list = s.find("from fum in class net.sf.hibernate.test.Fum where not fum.fum='FRIEND'"); - assertTrue( list.size()==2, "deleted owner" ); - s.lock( list.get(0), LockMode.UPGRADE ); - s.lock( list.get(1), LockMode.UPGRADE ); - Iterator iter = list.iterator(); - while ( iter.hasNext() ) { - s.delete( iter.next() ); - } - s.flush(); - s.connection().commit(); - s.close(); - } - public void testNewSessionLifecycle() throws Exception { Session s = sessions.openSession(); --- 1958,1961 ---- *************** *** 2589,2616 **** } - public void testListIdentifiers() throws Exception { - Session s = sessions.openSession(); - Fum fum = new Fum( fumKey("fum") ); - fum.setFum("fo fee fi"); - s.save(fum); - fum = new Fum( fumKey("fi") ); - fum.setFum("fee fi fo"); - s.save(fum); - List list = s.find("select fum.id from fum in class net.sf.hibernate.test.Fum where not fum.fum='FRIEND'"); - assertTrue( list.size()==2, "list identifiers"); - Iterator iter = s.iterate("select fum.id from fum in class net.sf.hibernate.test.Fum where not fum.fum='FRIEND'"); - int i=0; - while ( iter.hasNext() ) { - assertTrue( iter.next() instanceof FumCompositeID, "iterate identifiers"); - i++; - } - assertTrue(i==2); - s.delete( s.load(Fum.class, (Serializable) list.get(0) ) ); - s.delete( s.load(Fum.class, (Serializable) list.get(1) ) ); - s.flush(); - s.connection().commit(); - s.close(); - } - public void testVeto() throws Exception { Session s = sessions.openSession(); --- 2337,2340 ---- *************** *** 2711,2760 **** } - - public void testCompositeIDs() throws Exception { - Session s = sessions.openSession(); - Fo fo = new Fo(); - Properties props = new Properties(); - props.setProperty("foo", "bar"); - props.setProperty("bar", "foo"); - fo.setSerial(props); - fo.setBuf( "abcdefghij1`23%$*^*$*\n\t".getBytes() ); - s.save( fo, fumKey("an instance of fo") ); - s.flush(); - props.setProperty("x", "y"); - s.flush(); - s.connection().commit(); - s.close(); - - s = sessions.openSession(); - fo = (Fo) s.load( Fo.class, fumKey("an instance of fo") ); - props = (Properties) fo.getSerial(); - assertTrue( props.getProperty("foo").equals("bar") ); - assertTrue( props.getProperty("x").equals("y") ); - assertTrue( fo.getBuf()[0]=='a' ); - fo.getBuf()[1]=(byte)126; - s.flush(); - s.connection().commit(); - s.close(); - s = sessions.openSession(); - fo = (Fo) s.load( Fo.class, fumKey("an instance of fo") ); - assertTrue( fo.getBuf()[1]==126 ); - assertTrue( - s.iterate("from fo in class net.sf.hibernate.test.Fo where fo.id.string like 'an instance of fo'").next()==fo - ); - s.delete(fo); - s.flush(); - try { - s.save( new Fo() ); - assertTrue(false); - } - catch (Exception e) { - //System.out.println( e.getMessage() ); - } - s.connection().commit(); - s.close(); - } - public void testUserProvidedConnection() throws Exception { ConnectionProvider dcp = new DriverManagerConnectionProvider(); --- 2435,2439 ---- *************** *** 2841,2845 **** assertTrue(err); Fo fo = new Fo(); ! id = fumKey("abc"); s.save(fo, id); s.flush(); --- 2520,2524 ---- assertTrue(err); Fo fo = new Fo(); ! id = FumTest.fumKey("abc"); //yuck!! s.save(fo, id); s.flush(); *************** *** 2960,2963 **** --- 2639,2643 ---- s.flush(); s.connection().commit(); + s.close(); s = sessions.openSession(); *************** *** 2975,2981 **** assertTrue( !(baz.getFooBag().iterator().next() instanceof HibernateProxy) ); //many-to-many outer-join="true" assertTrue( !(baz.getFooSet().iterator().next() instanceof HibernateProxy) ); //one-to-many ! s.delete("from o in class java.lang.Object"); s.flush(); s.connection().commit(); } --- 2655,2663 ---- assertTrue( !(baz.getFooBag().iterator().next() instanceof HibernateProxy) ); //many-to-many outer-join="true" assertTrue( !(baz.getFooSet().iterator().next() instanceof HibernateProxy) ); //one-to-many ! s.delete("from o in class Baz"); ! s.delete("from o in class Foo"); s.flush(); s.connection().commit(); + s.close(); } Index: MultiTableTest.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/MultiTableTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MultiTableTest.java 24 Jan 2003 13:07:17 -0000 1.5 --- MultiTableTest.java 15 Feb 2003 01:00:58 -0000 1.6 *************** *** 23,28 **** public void testQueries() throws Exception { Session s = sessions.openSession(); ! s.save( new TrivialClass(), new Long(1) ); s.flush(); s.connection().commit(); --- 23,36 ---- public void testQueries() throws Exception { + Session s = sessions.openSession(); ! ! if (dialect instanceof SybaseDialect) { ! s.save( new TrivialClass() ); ! } ! else{ ! s.save( new TrivialClass(), new Long(1) ); ! } ! s.flush(); s.connection().commit(); *************** *** 46,57 **** public void testConstraints() throws Exception { ! ! if ( dialect instanceof SybaseDialect ) return; ! Session s = sessions.openSession(); Transaction t = s.beginTransaction(); SubMulti sm = new SubMulti(); sm.setAmount(66.5f); ! s.save( sm, new Long(2) ); t.commit(); s.close(); --- 54,68 ---- public void testConstraints() throws Exception { ! Session s = sessions.openSession(); Transaction t = s.beginTransaction(); SubMulti sm = new SubMulti(); sm.setAmount(66.5f); ! if ( dialect instanceof SybaseDialect ) { ! s.save(sm); ! } ! else { ! s.save( sm, new Long(2) ); ! } t.commit(); s.close(); Index: SQLFunctionsTest.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/SQLFunctionsTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SQLFunctionsTest.java 5 Jan 2003 02:11:23 -0000 1.3 --- SQLFunctionsTest.java 15 Feb 2003 01:00:58 -0000 1.4 *************** *** 5,9 **** import java.util.Iterator; ! import net.sf.hibernate.*; import net.sf.hibernate.dialect.DB2Dialect; import net.sf.hibernate.dialect.InterbaseDialect; --- 5,13 ---- import java.util.Iterator; ! import junit.framework.Test; ! import junit.framework.TestSuite; ! import net.sf.hibernate.Query; ! import net.sf.hibernate.Session; ! import net.sf.hibernate.Transaction; import net.sf.hibernate.dialect.DB2Dialect; import net.sf.hibernate.dialect.InterbaseDialect; *************** *** 11,17 **** import net.sf.hibernate.dialect.SybaseDialect; - import junit.framework.Test; - import junit.framework.TestSuite; - public class SQLFunctionsTest extends TestCase { --- 15,18 ---- *************** *** 159,166 **** } public static Test suite() throws Exception { TestCase.exportSchema( ! new String[] { "Simple.hbm.xml" } ); return new TestSuite(SQLFunctionsTest.class); --- 160,198 ---- } + /*public void testBlobClob() throws Exception { + Session s = sessions.openSession(); + Blobber b = new Blobber(); + b.setBlob( Hibernate.createBlob( "foo/bar/baz".getBytes() ) ); + b.setClob( Hibernate.createClob("foo/bar/baz") ); + s.save(b); + //s.refresh(b); + //assertTrue( b.getClob() instanceof ClobImpl ); + s.flush(); + s.refresh(b); + //b.getBlob().setBytes( 2, "abc".getBytes() ); + b.getClob().getSubString(2, 3); + b.getClob().setString(2, "abc"); + s.flush(); + s.connection().commit(); + s.close(); + + s = sessions.openSession(); + b = (Blobber) s.load( Blobber.class, new Integer( b.getId() ) ); + Blobber b2 = new Blobber(); + s.save(b2); + b2.setBlob( b.getBlob() ); + b.setBlob(null); + assertTrue( b.getClob().getSubString(1, 3).equals("fab") ); + b.getClob().getSubString(1, 6); + b.getClob().setString(1, "qwerty"); + s.flush(); + s.connection().commit(); + s.close(); + }*/ + public static Test suite() throws Exception { TestCase.exportSchema( ! new String[] { "Simple.hbm.xml", "Blobber.hbm.xml" } ); return new TestSuite(SQLFunctionsTest.class); |