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

📄 hqlparsertest.java

📁 介绍了hibernate的入门有一些基本常用的事例
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		parse( "from eg.Cat as fatcat where fatcat.weight > (\n"				+ "select avg(cat.weight) from eg.DomesticCat cat)" );		parse( "from eg.DomesticCat as cat where cat.name = some (\n"				+ "select name.nickName from eg.Name as name)\n" );		parse( "from eg.Cat as cat where not exists (\n"				+ "from eg.Cat as mate where mate.mate = cat)" );		parse( "from eg.DomesticCat as cat where cat.name not in (\n"				+ "select name.nickName from eg.Name as name)" );	}	public void testDocoExamples912() throws Exception {		parse( "select ord.id, sum(price.amount), count(item)\n"				+ "from Order as ord join ord.lineItems as item\n"				+ "join item.product as product, Catalog as catalog\n"				+ "join catalog.prices as price\n"				+ "where ord.paid = false\n"				+ "and ord.customer = :customer\n"				+ "and price.product = product\n"				+ "and catalog.effectiveDate < sysdate\n"				+ "and catalog.effectiveDate >= all (\n"				+ "select cat.effectiveDate from Catalog as cat where cat.effectiveDate < sysdate)\n"				+ "group by ord\n"				+ "having sum(price.amount) > :minAmount\n"				+ "order by sum(price.amount) desc" );		parse( "select ord.id, sum(price.amount), count(item)\n"				+ "from Order as ord join ord.lineItems as item join item.product as product,\n"				+ "Catalog as catalog join catalog.prices as price\n"				+ "where ord.paid = false and ord.customer = :customer\n"				+ "and price.product = product and catalog = :currentCatalog\n"				+ "group by ord having sum(price.amount) > :minAmount\n"				+ "order by sum(price.amount) desc" );		parse( "select count(payment), status.name \n"				+ "from Payment as payment \n"				+ "    join payment.currentStatus as status\n"				+ "    join payment.statusChanges as statusChange\n"				+ "where payment.status.name <> PaymentStatus.AWAITING_APPROVAL\n"				+ "    or (\n"				+ "        statusChange.timeStamp = ( \n"				+ "            select max(change.timeStamp) \n"				+ "            from PaymentStatusChange change \n"				+ "            where change.payment = payment\n"				+ "        )\n"				+ "        and statusChange.user <> :currentUser\n"				+ "    )\n"				+ "group by status.name, status.sortOrder\n"				+ "order by status.sortOrder" );		parse( "select count(payment), status.name \n"				+ "from Payment as payment\n"				+ "    join payment.currentStatus as status\n"				+ "where payment.status.name <> PaymentStatus.AWAITING_APPROVAL\n"				+ "    or payment.statusChanges[ maxIndex(payment.statusChanges) ].user <> :currentUser\n"				+ "group by status.name, status.sortOrder\n"				+ "order by status.sortOrder" );		parse( "select account, payment\n"				+ "from Account as account\n"				+ "    left outer join account.payments as payment\n"				+ "where :currentUser in elements(account.holder.users)\n"				+ "    and PaymentStatus.UNPAID = isNull(payment.currentStatus.name, PaymentStatus.UNPAID)\n"				+ "order by account.type.sortOrder, account.accountNumber, payment.dueDate" );		parse( "select account, payment\n"				+ "from Account as account\n"				+ "    join account.holder.users as user\n"				+ "    left outer join account.payments as payment\n"				+ "where :currentUser = user\n"				+ "    and PaymentStatus.UNPAID = isNull(payment.currentStatus.name, PaymentStatus.UNPAID)\n"				+ "order by account.type.sortOrder, account.accountNumber, payment.dueDate" );	}	public void testExamples1() throws Exception {		parse( "select new org.hibernate.test.S(s.count, s.address)\n"				+ "from s in class Simple" );		parse( "select s.name, sysdate, trunc(s.pay), round(s.pay) from s in class Simple" );		parse( "select round(s.pay, 2) from s" );		parse( "select abs(round(s.pay)) from s in class Simple" );		parse( "select trunc(round(sysdate)) from s in class Simple" );	}	public void testArrayExpr() throws Exception {		parse( "from Order ord where ord.items[0].id = 1234" );	}	public void testMultipleActualParameters() throws Exception {		parse( "select round(s.pay, 2) from s" );	}	public void testMultipleFromClasses() throws Exception {		parse( "FROM eg.mypackage.Cat qat, com.toadstool.Foo f" );		parse( "FROM eg.mypackage.Cat qat, org.jabberwocky.Dipstick" );	}	public void testFromWithJoin() throws Exception {		parse( "FROM eg.mypackage.Cat qat, com.toadstool.Foo f join net.sf.blurb.Blurb" );		parse( "FROM eg.mypackage.Cat qat  left join com.multijoin.JoinORama , com.toadstool.Foo f join net.sf.blurb.Blurb" );	}	public void testSelect() throws Exception {		parse( "SELECT f FROM eg.mypackage.Cat qat, com.toadstool.Foo f join net.sf.blurb.Blurb" );		parse( "SELECT DISTINCT bar FROM eg.mypackage.Cat qat  left join com.multijoin.JoinORama as bar, com.toadstool.Foo f join net.sf.blurb.Blurb" );		parse( "SELECT count(*) FROM eg.mypackage.Cat qat" );		parse( "SELECT avg(qat.weight) FROM eg.mypackage.Cat qat" );	}	public void testWhere() throws Exception {		parse( "FROM eg.mypackage.Cat qat where qat.name like '%fluffy%' or qat.toes > 5" );		parse( "FROM eg.mypackage.Cat qat where not qat.name like '%fluffy%' or qat.toes > 5" );		parse( "FROM eg.mypackage.Cat qat where not qat.name not like '%fluffy%'" );		parse( "FROM eg.mypackage.Cat qat where qat.name in ('crater','bean','fluffy')" );		parse( "FROM eg.mypackage.Cat qat where qat.name not in ('crater','bean','fluffy')" );		parse( "from Animal an where sqrt(an.bodyWeight)/2 > 10" );		parse( "from Animal an where (an.bodyWeight > 10 and an.bodyWeight < 100) or an.bodyWeight is null" );	}	public void testGroupBy() throws Exception {		parse( "FROM eg.mypackage.Cat qat group by qat.breed" );		parse( "FROM eg.mypackage.Cat qat group by qat.breed, qat.eyecolor" );	}	public void testOrderBy() throws Exception {		parse( "FROM eg.mypackage.Cat qat order by avg(qat.toes)" );		parse( "from Animal an order by sqrt(an.bodyWeight)/2" );	}	public void testDoubleLiteral() throws Exception {		parse( "from eg.Cat as tinycat where fatcat.weight < 3.1415" );		parse( "from eg.Cat as enormouscat where fatcat.weight > 3.1415e3" );	}	public void testComplexConstructor() throws Exception {		parse( "select new Foo(count(bar)) from bar" );		parse( "select new Foo(count(bar),(select count(*) from doofus d where d.gob = 'fat' )) from bar" );	}	public void testInNotIn() throws Exception {		parse( "from foo where foo.bar in ('a' , 'b', 'c')" );		parse( "from foo where foo.bar not in ('a' , 'b', 'c')" );	}	public void testOperatorPrecedence() throws Exception {		parse( "from foo where foo.bar = 123 + foo.baz * foo.not" );		parse( "from foo where foo.bar like 'testzzz' || foo.baz or foo.bar in ('duh', 'gob')" );	}	/**	 * Tests HQL generated by the other unit tests.	 *	 * @throws Exception if the HQL could not be parsed.	 */	public void testUnitTestHql() throws Exception {		parse( "select foo from foo in class org.hibernate.test.Foo, fee in class org.hibernate.test.Fee where foo.dependent = fee order by foo.string desc, foo.component.count asc, fee.id" );		parse( "select foo.foo, foo.dependent from foo in class org.hibernate.test.Foo order by foo.foo.string desc, foo.component.count asc, foo.dependent.id" );		parse( "select foo from foo in class org.hibernate.test.Foo order by foo.dependent.id, foo.dependent.fi" );		parse( "SELECT one FROM one IN CLASS org.hibernate.test.One ORDER BY one.value ASC" );		parse( "SELECT many.one FROM many IN CLASS org.hibernate.test.Many ORDER BY many.one.value ASC, many.one.id" );		parse( "select foo.id from org.hibernate.test.Foo foo where foo.joinedProp = 'foo'" );		parse( "from org.hibernate.test.Foo foo inner join fetch foo.foo" );		parse( "from org.hibernate.test.Baz baz left outer join fetch baz.fooToGlarch" );		parse( "select foo.foo.foo.string from foo in class org.hibernate.test.Foo where foo.foo = 'bar'" );		parse( "select foo.foo.foo.foo.string from foo in class org.hibernate.test.Foo where foo.foo.foo = 'bar'" );		parse( "select foo.foo.foo.string from foo in class org.hibernate.test.Foo where foo.foo.foo.foo.string = 'bar'" );		parse( "select foo.string from foo in class org.hibernate.test.Foo where foo.foo.foo = 'bar' and foo.foo.foo.foo = 'baz'" );		parse( "select foo.string from foo in class org.hibernate.test.Foo where foo.foo.foo.foo.string = 'a' and foo.foo.string = 'b'" );		parse( "from org.hibernate.test.Foo as foo where foo.component.glarch.name is not null" );		parse( "from org.hibernate.test.Foo as foo left outer join foo.component.glarch as glarch where glarch.name = 'foo'" );		parse( "from org.hibernate.test.Foo" );		parse( "from org.hibernate.test.Foo foo left outer join foo.foo" );		parse( "from org.hibernate.test.Foo, org.hibernate.test.Bar" );		parse( "from org.hibernate.test.Baz baz left join baz.fooToGlarch, org.hibernate.test.Bar bar join bar.foo" );		parse( "from org.hibernate.test.Baz baz left join baz.fooToGlarch join baz.fooSet" );		parse( "from org.hibernate.test.Baz baz left join baz.fooToGlarch join fetch baz.fooSet foo left join fetch foo.foo" );		parse( "from foo in class org.hibernate.test.Foo where foo.string='osama bin laden' and foo.boolean = true order by foo.string asc, foo.component.count desc" );		parse( "from foo in class org.hibernate.test.Foo where foo.string='osama bin laden' order by foo.string asc, foo.component.count desc" );		parse( "select foo.foo from foo in class org.hibernate.test.Foo" );		parse( "from foo in class org.hibernate.test.Foo where foo.component.count is null order by foo.component.count" );		parse( "from foo in class org.hibernate.test.Foo where foo.component.name='foo'" );		parse( "select distinct foo.component.name, foo.component.name from foo in class org.hibernate.test.Foo where foo.component.name='foo'" );		parse( "select distinct foo.component.name, foo.id from foo in class org.hibernate.test.Foo where foo.component.name='foo'" );		parse( "from foo in class org.hibernate.test.Foo where foo.id=?" );		parse( "from foo in class org.hibernate.test.Foo where foo.key=?" );		parse( "select foo.foo from foo in class org.hibernate.test.Foo where foo.string='fizard'" );		parse( "from foo in class org.hibernate.test.Foo where foo.component.subcomponent.name='bar'" );		parse( "select foo.foo from foo in class org.hibernate.test.Foo where foo.foo.id=?" );		parse( "from foo in class org.hibernate.test.Foo where foo.foo = ?" );		parse( "from bar in class org.hibernate.test.Bar where bar.string='a string' or bar.string='a string'" );		parse( "select foo.component.name, elements(foo.component.importantDates) from foo in class org.hibernate.test.Foo where foo.foo.id=?" );		parse( "select max(elements(foo.component.importantDates)) from foo in class org.hibernate.test.Foo group by foo.id" );		parse( "select foo.foo.foo.foo from foo in class org.hibernate.test.Foo, foo2 in class org.hibernate.test.Foo where foo = foo2.foo and not not ( not foo.string='fizard' ) and foo2.string between 'a' and (foo.foo.string) and ( foo2.string in ( 'fiz', 'blah') or 1=1 )" );		parse( "from foo in class org.hibernate.test.Foo where foo.string='from BoogieDown  -tinsel town  =!@#$^&*())'" );		parse( "from foo in class org.hibernate.test.Foo where not foo.string='foo''bar'" ); // Added quote quote is an escape		parse( "from foo in class org.hibernate.test.Foo where foo.component.glarch.next is null" );		parse( " from bar in class org.hibernate.test.Bar where bar.baz.count=667 and bar.baz.count!=123 and not bar.baz.name='1-E-1'" );		parse( " from i in class org.hibernate.test.Bar where i.baz.name='Bazza'" );		parse( "select count(distinct foo.foo) from foo in class org.hibernate.test.Foo" );		parse( "select count(foo.foo.boolean) from foo in class org.hibernate.test.Foo" );		parse( "select count(*), foo.int from foo in class org.hibernate.test.Foo group by foo.int" );		parse( "select sum(foo.foo.int) from foo in class org.hibernate.test.Foo" );		parse( "select count(foo) from foo in class org.hibernate.test.Foo where foo.id=?" );		parse( "from foo in class org.hibernate.test.Foo where foo.boolean = ?" );		parse( "select new Foo(fo.x) from org.hibernate.test.Fo fo" );		parse( "select new Foo(fo.integer) from org.hibernate.test.Foo fo" );		parse( "select new Foo(fo.x) from org.hibernate.test.Foo fo" );

⌨️ 快捷键说明

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