⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 foobartest.java

📁 人力资源管理系统主要包括:人员管理、招聘管理、培训管理、奖惩管理和薪金管理五大管理模块。
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		assertTrue( "returned object", list.get(0)==foo.getFoo() );		list = s.find("from foo in class Foo where foo.component.subcomponent.name='bar'");		assertTrue( "components of components", list.size()==2 );		list = s.find("select foo.foo from foo in class Foo where foo.foo.id=?", foo.getFoo().getKey(), Hibernate.STRING);		assertTrue( "by id query", list.size()==1 );		assertTrue( "by id returned object", list.get(0)==foo.getFoo() );				s.find( "from foo in class Foo where foo.foo = ?", foo.getFoo(), Hibernate.entity(Foo.class) );				assertTrue( !s.iterate("from bar in class Bar where bar.string='a string' or bar.string='a string'").hasNext() );				iter = s.iterate(			"select foo.component.name, foo.component.importantDates.elements from foo in class Foo where foo.foo.id=?",			foo.getFoo().getKey(),			Hibernate.STRING		);		int i=0;		while ( iter.hasNext() ) {			i++;			Object[] row = (Object[]) iter.next();			assertTrue( row[0] instanceof String && ( row[1]==null || row[1] instanceof Date ) );		}		assertTrue(i==3); //WAS: 4		iter = s.iterate(			"select max(foo.component.importantDates.elements) from foo in class Foo group by foo.id"		);		assertTrue( iter.next() instanceof Date );				list = s.find(			"select foo.foo.foo.foo from foo in class Foo, foo2 in class Foo where"			+ " foo = foo2.foo and not not ( not foo.string='fizard' )"			+ " and foo2.string between 'a' and (foo.foo.string)"			+ ( ( getDialect() instanceof HSQLDialect || getDialect() instanceof InterbaseDialect )?				" and ( foo2.string in ( 'fiz', 'blah') or 1=1 )"				:				" and ( foo2.string in ( 'fiz', 'blah', foo.foo.string, foo.string, foo2.string ) )"			)		);		assertTrue( "complex query", list.size()==1 );		assertTrue( "returned object", list.get(0)==foo );		foo.setString("from BoogieDown  -tinsel town  =!@#$^&*())");		list = s.find("from foo in class Foo where foo.string='from BoogieDown  -tinsel town  =!@#$^&*())'");		assertTrue( "single quotes", list.size()==1 );		list = s.find("from foo in class Foo where not foo.string='foo''bar'");		assertTrue( "single quotes", list.size()==2 );		list = s.find("from foo in class Foo where foo.component.glarch.next is null");		assertTrue( "query association in component", list.size()==2 );		Bar bar = new Bar();		Baz baz = new Baz();		baz.setDefaults();		bar.setBaz(baz);		baz.setManyToAny( new ArrayList() );		baz.getManyToAny().add(bar);		baz.getManyToAny().add(foo);		s.save(bar);		s.save(baz);		list = s.find(" from bar in class Bar where bar.baz.count=667 and bar.baz.count!=123 and not bar.baz.name='1-E-1'");		assertTrue( "query many-to-one", list.size()==1 );		list = s.find(" from i in class Bar where i.baz.name='Bazza'");		assertTrue( "query many-to-one", list.size()==1 );				Iterator rs = s.iterate("select count(distinct foo.foo) from foo in class Foo");		assertTrue( "count", ( (Integer) rs.next() ).intValue()==2 );		assertTrue( !rs.hasNext() );		rs = s.iterate("select count(foo.foo.boolean) from foo in class Foo");		assertTrue( "count", ( (Integer) rs.next() ).intValue()==2 );		assertTrue( !rs.hasNext() );		rs = s.iterate("select count(*), foo.int from foo in class Foo group by foo.int");		assertTrue( "count(*) group by", ( (Object[]) rs.next() )[0].equals( new Integer(3) ) );		assertTrue( !rs.hasNext() );		rs = s.iterate("select sum(foo.foo.int) from foo in class Foo");		assertTrue( "sum", ( (Integer) rs.next() ).intValue()==4 );		assertTrue( !rs.hasNext() );		rs = s.iterate("select count(foo) from foo in class Foo where foo.id=?", foo.getKey(), Hibernate.STRING);		assertTrue( "id query count", ( (Integer) rs.next() ).intValue()==1 );		assertTrue( !rs.hasNext() );				list = s.find( "from foo in class Foo where foo.boolean = ?", new Boolean(true), Hibernate.BOOLEAN );				list = s.find("select new Foo(fo.x) from Fo fo");		list = s.find("select new Foo(fo.integer) from Foo fo");				list = s.createQuery("select new Foo(fo.x) from Foo fo")			.setCacheable(true)			.list();		assertTrue(list.size()==3);		list = s.createQuery("select new Foo(fo.x) from Foo fo")			.setCacheable(true)			.list();		assertTrue(list.size()==3);				list = s.find("select foo.long, foo.component.name, foo, foo.foo from foo in class Foo");		rs = list.iterator();		int count=0;		while ( rs.hasNext() ) {			count++;			Object[] row = (Object[]) rs.next();			assertTrue( row[0] instanceof Long );			assertTrue( row[1] instanceof String );			assertTrue( row[2] instanceof Foo );			assertTrue( row[3] instanceof Foo );		}		assertTrue(count!=0);		list = s.find("select avg(foo.float), max(foo.component.name), count(distinct foo.id) from foo in class Foo");		rs = list.iterator();		count=0;		while ( rs.hasNext() ) {			count++;			Object[] row = (Object[]) rs.next();			assertTrue( row[0] instanceof Float );			assertTrue( row[1] instanceof String );			assertTrue( row[2] instanceof Integer );		}		assertTrue(count!=0);		list = s.find("select foo.long, foo.component, foo, foo.foo from foo in class Foo");		rs = list.iterator();		count=0;		while ( rs.hasNext() ) {			count++;			Object[] row = (Object[]) rs.next();			assertTrue( row[0] instanceof Long );			assertTrue( row[1] instanceof FooComponent );			assertTrue( row[2] instanceof Foo );			assertTrue( row[3] instanceof Foo );		}		assertTrue(count!=0);				s.save( new Holder("ice T") );		s.save( new Holder("ice cube") );				assertTrue( s.find("from o in class java.lang.Object").size()==15 );		System.out.println( s.find("from n in class Named") );		assertTrue( s.find("from n in class Named").size()==7 );		assertTrue( s.find("from n in class Named where n.name is not null").size()==4 );		iter = s.iterate("from n in class Named");		while ( iter.hasNext() ) {			assertTrue( iter.next() instanceof Named );		}				s.save( new Holder("bar") );		iter = s.iterate("from n0 in class Named, n1 in class Named where n0.name = n1.name");		int cnt = 0;		while ( iter.hasNext() ) {			Object[] row = (Object[]) iter.next();			if ( row[0]!=row[1] ) cnt++;		}		if ( !(getDialect() instanceof HSQLDialect) ) {			assertTrue(cnt==2);			assertTrue( s.find("from n0 in class Named, n1 in class Named where n0.name = n1.name").size()==7 );		}				Query qu = s.createQuery("from n in class Named where n.name = :name");		qu.getReturnTypes();		qu.getNamedParameters();				iter = s.iterate("from o in class java.lang.Object");		int c = 0;		while ( iter.hasNext() ) {			iter.next();			c++;		}		assertTrue(c==16);						s.iterate("select baz.code, min(baz.count) from baz in class Baz group by baz.code");				iter = s.iterate("selecT baz from baz in class Baz where baz.stringDateMap['foo'] is not null or baz.stringDateMap['bar'] = ?", new Date(), Hibernate.DATE);		assertFalse( iter.hasNext() );		list = s.find("select baz from baz in class Baz where baz.stringDateMap['now'] is not null");		assertTrue( list.size()==1 );		list = s.find("select baz from baz in class Baz where baz.stringDateMap['now'] is not null and baz.stringDateMap['big bang'] < baz.stringDateMap['now']");		assertTrue( list.size()==1 );		list = s.find("select index(date) from Baz baz join baz.stringDateMap date");		System.out.println(list);		assertTrue( list.size()==2 );				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");				s.find("from Baz baz inner join baz.collectionComponent.nested.foos foo where foo.string is null");		if ( !(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof SAPDBDialect) && !(getDialect() instanceof PointbaseDialect) /*&& !(dialect instanceof Oracle9Dialect)*/ )  {			s.find("from Baz baz inner join baz.fooSet where '1' in (from baz.fooSet foo where foo.string is not null)");			s.find("from Baz baz where 'a' in elements(baz.collectionComponent.nested.foos) and 1.0 in elements(baz.collectionComponent.nested.floats)");			s.find("from Baz baz where 'b' in baz.collectionComponent.nested.foos.elements and 1.0 in baz.collectionComponent.nested.floats.elements");		}				s.find("from Foo foo join foo.foo where foo.foo in ('1','2','3')");		if ( !(getDialect() instanceof HSQLDialect) ) s.find("from Foo foo left join foo.foo where foo.foo in ('1','2','3')");		s.find("select foo.foo from Foo foo where foo.foo in ('1','2','3')");		s.find("select foo.foo.string from Foo foo where foo.foo in ('1','2','3')");		s.find("select foo.foo.string from Foo foo where foo.foo.string in ('1','2','3')");		s.find("select foo.foo.long from Foo foo where foo.foo.string in ('1','2','3')");		s.find("select count(*) from Foo foo where foo.foo.string in ('1','2','3') or foo.foo.long in (1,2,3)");		s.find("select count(*) from Foo foo where foo.foo.string in ('1','2','3') group by foo.foo.long");				s.find("from Foo foo1 left join foo1.foo foo2 left join foo2.foo where foo1.string is not null");		s.find("from Foo foo1 left join foo1.foo.foo where foo1.string is not null");		s.find("from Foo foo1 left join foo1.foo foo2 left join foo1.foo.foo foo3 where foo1.string is not null");				s.find("select foo.formula from Foo foo where foo.formula > 0");		int len = s.find("from Foo as foo join foo.foo as foo2 where foo2.id >'a' or foo2.id <'a'").size();		assertTrue(len==2);				s.delete("from Holder");		s.flush();		s.connection().commit();		s.close();				s = openSession();		baz = (Baz) s.createQuery("from Baz baz left outer join fetch baz.manyToAny").uniqueResult();		assertTrue( Hibernate.isInitialized( baz.getManyToAny() ) );		assertTrue( baz.getManyToAny().size()==2 );		BarProxy barp = (BarProxy) baz.getManyToAny().get(0);		s.find("from Baz baz join baz.manyToAny");		assertTrue( s.find("select baz from Baz baz join baz.manyToAny a where index(a) = 0").size()==1 );				FooProxy foop = (FooProxy) s.get( Foo.class, foo.getKey() );		assertTrue( foop == baz.getManyToAny().get(1) );				barp.setBaz(baz);		assertTrue( s.find("select bar from Bar bar where bar.baz.stringDateMap['now'] is not null").size()==1 );		assertTrue( s.find("select bar from Bar bar join bar.baz b where b.stringDateMap['big bang'] < b.stringDateMap['now'] and b.stringDateMap['now'] is not null").size()==1 );		assertTrue( s.find("select bar from Bar bar where bar.baz.stringDateMap['big bang'] < bar.baz.stringDateMap['now'] and bar.baz.stringDateMap['now'] is not null").size()==1 );				list = s.find("select foo.string, foo.component, foo.id from Bar foo");		assertTrue ( ( (FooComponent) ( (Object[]) list.get(0) )[1] ).getName().equals("foo") );		list = s.find("select elements(baz.components) from Baz baz");		assertTrue( list.size()==2 );		list = s.find("select bc.name from Baz baz join baz.components bc");		assertTrue( list.size()==2 );		//list = s.find("select bc from Baz baz join baz.components bc");				s.createQuery("from Foo foo where foo.integer < 10 order by foo.string").setMaxResults(12).list();				s.delete(barp);		s.delete(baz);		s.delete( foop.getFoo() );		s.delete(foop);		s.flush();		s.connection().commit();		s.close();	}	public void testCascadeDeleteDetached() throws Exception {		Session s = openSession();		Baz baz = new Baz();		List list = new ArrayList();		list.add( new Fee() );		baz.setFees(list);		s.save(baz);		s.flush();		s.connection().commit();		s.close();				s = openSession();		baz = (Baz) s.get( Baz.class, baz.getCode() );		s.connection().commit();		s.close();				assertFalse( Hibernate.isInitialized( baz.getFees() ) );				s = openSession();		s.delete(baz);		s.flush();		assertFalse( s.iterate("from Fee").hasNext() );		s.connection().commit();		s.close();				s = openSession();		baz = new Baz();		list = new ArrayList();		list.add( new Fee() );		list.add( new Fee() );		baz.setFees(list);		s.save(baz);		s.flush();		s.connection().commit();		s.close();		s = openSession();		baz = (Baz) s.get( Baz.class, baz.getCode() );		Hibernate.initialize( baz.getFees() );		s.connection().commit();		s.close();				assertTrue( baz.getFees().size()==2 );		s = openSession();		s.delete(baz);		s.flush();		assertFalse( s.iterate("from Fee").hasNext() );		s.connection().commit();		s.close();		}		public void testForeignKeys() throws Exception {		Session s = openSession();		Baz baz = new Baz();		Foo foo = new Foo();		List bag = new ArrayList();		bag.add(foo);		baz.setIdFooBag(bag);		baz.setFoo(foo);		s.save(baz);		s.flush();		s.connection().commit();		s.close();				s = openSession();		baz = (Baz) s.load( Baz.class, baz.getCode() );		s.delete(baz);		s.flush();		s.connection().commit();		s.close();	}		public void testDatabinder() throws Exception {		Session s = openSession();		BarProxy bar = new Bar();		s.save(bar);		FooProxy foo = new Foo();		s.save(foo);		FooProxy foo2 = new Foo();		s.save(foo2);		foo2.setFoo(foo);		Baz baz = new Baz();		s.save(baz);		baz.setDefaults();		baz.setFooArray( new FooProxy[] { foo, foo2, bar, null } );		bar.setFoo(foo);		s.flush();		s.connection().commit();		s.close();		s = openSession();		bar = (BarProxy) s.load( Foo.class, bar.getKey() );		foo = (FooProxy) s.load( Foo.class, foo.getKey() );		foo2 = (FooProxy) s.load( Foo.class, foo2.getKey() );		baz = (Baz) s.load( Baz.class, baz.getCode() );				Databinder binder = getSessions().openDatabinder();		binder.setInitializeLazy(true);		binder.bind(foo2).bind(baz).bind(foo).bind(bar);		System.out.println( binder.toGenericXML() );		binder.bind(foo2).bind(baz);		System.out.println( binder.toXML() );		assertTrue( "dom", binder.toDOM()!=null );		assertTrue( "generic dom", binder.toGenericDOM()!=null );							s.delete(foo);		s.delete(baz);		s.delete(bar);		s.delete(foo2);				s.flush();		s.connection().commit();		s.close();	}		public void testNonlazyCollection() throws Exception {		Session s = openSession();		Baz baz = new Baz();		s.save(baz);		s.flush();		s.connection().commit();		s.close();				s = openSession();		baz = (Baz) s.createCriteria(Baz.class)			.setFetchMode("stringDateMap", FetchMode.EAGER)			.uniqueResult();		assertTrue( Hibernate.isInitialized( baz.getFooToGlarch() ) );		assertTrue( Hibernate.isInitialized( baz.getFooComponentToFoo() ) );		assertTrue( !Hibernate.isInitialized( baz.getStringSet() ) );		assertTrue( Hibernate.isInitialized( baz.getStringDateMap() ) );		s.delete(baz);		s.flush();		s.connection().commit();		s.close();			}		public void testReuseDeletedCollection() throws Exception {		Session s = openSession();		Baz baz = new Baz();		baz.setDefaults();		s.save(baz);		s.flush();		s.delete(baz);		Baz baz2 = new Baz();		baz2.setStringArray( new String[] {"x-y-z"} );		s.save(baz2);		s.flush();		s.connection().commit();		s.close();				baz2.setStringSet( baz.getStringSet() );		baz2.setStringArray( baz.getStringArray() );		baz2.setFooArray( baz.getFooArray() );				s = openSession();		s.update(baz2);		s.flush();		s.connection().commit();		s.close();		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -