|
From: <one...@us...> - 2003-01-20 12:48:48
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test
In directory sc8-pr-cvs1:/tmp/cvs-serv2323/sf/hibernate/test
Modified Files:
FooBarTest.java MultiTableTest.java
Log Message:
major refactoring to create SQL Generation layer
more efficient queries against normalized mappings
Index: FooBarTest.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/FooBarTest.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** FooBarTest.java 19 Jan 2003 11:47:08 -0000 1.11
--- FooBarTest.java 20 Jan 2003 12:48:14 -0000 1.12
***************
*** 972,976 ****
s.iterate("select baz.code, min(baz.count) from baz in class Baz group by baz.code");
! s.iterate("Select baz from baz in class Baz where baz.stringDateMap['foo'] is not null or baz.stringDateMap['bar'] = ?", new Date(), Hibernate.DATE);
s.find("from foo in class Foo where foo.integer not between 1 and 5 and foo.string not in ('cde', 'abc') and foo.string is not null and foo.integer<=3");
--- 972,976 ----
s.iterate("select baz.code, min(baz.count) from baz in class Baz group by baz.code");
! s.iterate("selecT baz from baz in class Baz where baz.stringDateMap['foo'] is not null or baz.stringDateMap['bar'] = ?", new Date(), Hibernate.DATE);
s.find("from foo in class Foo where foo.integer not between 1 and 5 and foo.string not in ('cde', 'abc') and foo.string is not null and foo.integer<=3");
Index: MultiTableTest.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/MultiTableTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** MultiTableTest.java 5 Jan 2003 02:11:23 -0000 1.3
--- MultiTableTest.java 20 Jan 2003 12:48:14 -0000 1.4
***************
*** 9,16 ****
import java.util.Set;
- import net.sf.hibernate.*;
-
import junit.framework.Test;
import junit.framework.TestSuite;
public class MultiTableTest extends TestCase {
--- 9,18 ----
import java.util.Set;
import junit.framework.Test;
import junit.framework.TestSuite;
+ import net.sf.hibernate.LockMode;
+ import net.sf.hibernate.Session;
+ import net.sf.hibernate.Transaction;
+ import net.sf.hibernate.dialect.SybaseDialect;
public class MultiTableTest extends TestCase {
***************
*** 20,24 ****
--- 22,42 ----
}
+ public void testQueries() throws Exception {
+ Session s = sessions.openSession();
+ s.find("select s.count from s in class Simple");
+ s.find("from s in class LessSimple where s.another.name='name'");
+ s.find("from s in class LessSimple where s.yetanother.name='name'");
+ s.find("from s in class LessSimple where s.yetanother.name='name' and s.yetanother.foo is null");
+ s.find("from s in class Simple where s.count=1");
+ s.find("select s.count from s in class Simple, ls in class LessSimple where ls.another=s");
+ s.iterate("from s in class LessSimple");
+ s.iterate("from s in class Simple");
+ s.close();
+ }
+
public void testConstraints() throws Exception {
+
+ if ( dialect instanceof SybaseDialect ) return;
+
Session s = sessions.openSession();
Transaction t = s.beginTransaction();
***************
*** 36,39 ****
--- 54,60 ----
public void testMultiTable() throws Exception {
+
+ if ( dialect instanceof SybaseDialect ) return;
+
Session s = sessions.openSession();
Transaction t = s.beginTransaction();
***************
*** 152,156 ****
--- 173,298 ----
}
+ public void testMultiTableGeneratedId() throws Exception {
+
+ Session s = sessions.openSession();
+ Transaction t = s.beginTransaction();
+ Multi multi = new Multi();
+ multi.setExtraProp("extra");
+ //multi.setCount(666);
+ multi.setName("name");
+ Simple simp = new Simple();
+ simp.setDate( new Date() );
+ simp.setName("simp");
+ //simp.setCount(132);
+ Serializable multiId = s.save( multi );
+ Serializable simpId = s.save( simp );
+ SubMulti sm = new SubMulti();
+ sm.setAmount(66.5f);
+ Serializable smId = s.save( sm );
+ t.commit();
+ s.close();
+
+ s = sessions.openSession();
+ t = s.beginTransaction();
+ multi.setExtraProp( multi.getExtraProp() + "2" );
+ //multi.setCount( multi.getCount() + 1 );
+ multi.setName("new name");
+ s.update( multi, multiId );
+ simp.setName("new name");
+ s.update( simp, simpId );
+ sm.setAmount(456.7f);
+ s.update( sm, smId );
+ t.commit();
+ s.close();
+
+ s = sessions.openSession();
+ t = s.beginTransaction();
+ multi = (Multi) s.load( Multi.class, multiId );
+ assertTrue( multi.getExtraProp().equals("extra2") );
+ multi.setExtraProp( multi.getExtraProp() + "3" );
+ //multi.setCount( multi.getCount() + 1 );
+ 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);
+ t.commit();
+ s.close();
+
+ s = sessions.openSession();
+ t = s.beginTransaction();
+ multi = (Multi) s.load( Simple.class, multiId );
+ simp = (Simple) s.load( Simple.class, simpId );
+ assertTrue( ! (simp instanceof Multi) );
+ assertTrue( multi instanceof Multi );
+ assertTrue( multi.getExtraProp().equals("extra23") );
+ //multi.setCount( multi.getCount() + 1 );
+ assertTrue( multi.getName().equals("newer name") );
+ t.commit();
+ s.close();
+
+ s = sessions.openSession();
+ t = s.beginTransaction();
+ Iterator iter = s.iterate("select\n\ns from s in class Simple where s.count>0");
+ boolean foundSimp = false;
+ boolean foundMulti = false;
+ boolean foundSubMulti = false;
+ while ( iter.hasNext() ) {
+ Object o = iter.next();
+ if ( ( o instanceof Simple ) && !( o instanceof Multi) ) foundSimp = true;
+ if ( o instanceof Multi && !(o instanceof SubMulti) ) foundMulti = true;
+ if ( o instanceof SubMulti ) foundSubMulti = true;
+ }
+ assertTrue( foundSimp&&foundMulti&&foundSubMulti );
+ s.find("from m in class Multi where m.count>0 and m.extraProp is not null");
+ s.find("from m in class Simple where m.count>0 and m.name is not null");
+ s.find("from m in class LessSimple where m.other is not null");
+ s.find("from m in class Multi where m.other.id = 1");
+ s.find("from m in class SubMulti where m.amount > 0.0");
+
+ assertTrue(
+ s.find("from m in class Multi").size()==2
+ );
+ /*assertTrue(
+ s.find("from m in class Multi where m.class = Multi").size()==1
+ );*/
+ assertTrue(
+ s.find("from s in class Simple").size()==3
+ );
+ assertTrue(
+ s.find("from ls in class LessSimple").size()==0
+ );
+ assertTrue(
+ s.find("from sm in class SubMulti").size()==1
+ );
+
+ s.find("from ls in class LessSimple, s in ls.bag.elements where s.id is not null");
+ s.find("from sm in class SubMulti where exists sm.children.elements");
+
+ t.commit();
+ s.close();
+
+ s = sessions.openSession();
+ t = s.beginTransaction();
+ multi = (Multi) s.load( Simple.class, multiId, LockMode.UPGRADE );
+ simp = (Simple) s.load( Simple.class, simpId );
+ s.lock(simp, LockMode.UPGRADE_NOWAIT);
+ t.commit();
+ s.close();
+
+ s = sessions.openSession();
+ t = s.beginTransaction();
+ s.update( multi, multiId );
+ s.delete(multi);
+ assertTrue( s.delete("from s in class Simple")==2);
+ t.commit();
+ s.close();
+
+ }
+
public void testMultiTableCollections() throws Exception {
+
+ if ( dialect instanceof SybaseDialect ) return;
+
Session s = sessions.openSession();
Transaction t = s.beginTransaction();
|