📄 hqltest.java
字号:
assertTranslation( "select an.mother.mother.bodyWeight from Animal an" ); assertTranslation( "select an.mother.zoo.id from Animal an" ); assertTranslation( "select user.human.zoo.id from User user" ); assertTranslation( "select u.userName, u.human.name.first from User u" ); assertTranslation( "select u.human.name.last, u.human.name.first from User u" ); assertTranslation( "select bar.baz.name from Bar bar" ); assertTranslation( "select bar.baz.name, bar.baz.count from Bar bar" ); DotNode.useThetaStyleImplicitJoins = false; } public void testSelectStandardFunctionsNoParens() throws Exception { assertTranslation( "select current_date, current_time, current_timestamp from Animal" ); } public void testMapIndex() throws Exception { assertTranslation( "from User u where u.permissions['hibernate']='read'" ); } /*public void testCollectionFunctionsInSelect() { //sql is correct, just different order in select clause assertTranslation("select baz, size(baz.stringSet), count( distinct elements(baz.stringSet) ), max( elements(baz.stringSet) ) from Baz baz group by baz"); } public void testSelectElements() throws Exception { assertTranslation( "select elements(fum1.friends) from org.hibernate.test.legacy.Fum fum1" ); assertTranslation( "select elements(one.manies) from org.hibernate.test.legacy.One one" ); }*/ public void testNamedParameters() throws Exception { assertTranslation( "from Animal an where an.mother.bodyWeight > :weight" ); } // Second set of examples.... public void testClassProperty() throws Exception { // This test causes failures on theta-join dialects because the SQL is different. // The queries are semantically the same however. if ( getDialect() instanceof Oracle9Dialect ) return; if ( getDialect() instanceof Oracle8iDialect ) return; assertTranslation( "from Animal a where a.mother.class = Reptile" ); } public void testComponent() throws Exception { assertTranslation( "from Human h where h.name.first = 'Gavin'" ); } public void testSelectEntity() throws Exception { assertTranslation( "select an from Animal an inner join an.mother mo where an.bodyWeight < mo.bodyWeight" ); assertTranslation( "select mo, an from Animal an inner join an.mother mo where an.bodyWeight < mo.bodyWeight" ); } public void testValueAggregate() { assertTranslation( "select max(p), min(p) from User u join u.permissions p" ); } public void testAggregation() throws Exception { assertTranslation( "select count(an) from Animal an" ); assertTranslation( "select count(*) from Animal an" ); assertTranslation( "select count(distinct an) from Animal an" ); assertTranslation( "select count(distinct an.id) from Animal an" ); assertTranslation( "select count(all an.id) from Animal an" ); } public void testSelectProperty() throws Exception { assertTranslation( "select an.bodyWeight, mo.bodyWeight from Animal an inner join an.mother mo where an.bodyWeight < mo.bodyWeight" ); } public void testSelectEntityProperty() throws Exception { DotNode.useThetaStyleImplicitJoins = true; assertTranslation( "select an.mother from Animal an" ); assertTranslation( "select an, an.mother from Animal an" ); DotNode.useThetaStyleImplicitJoins = false; } public void testSelectDistinctAll() throws Exception { assertTranslation( "select distinct an.description, an.bodyWeight from Animal an" ); assertTranslation( "select all an from Animal an" ); } public void testSelectAssociatedEntityId() throws Exception { assertTranslation( "select an.mother.id from Animal an" ); } public void testGroupBy() throws Exception { assertTranslation( "select an.mother.id, max(an.bodyWeight) from Animal an group by an.mother.id" ); assertTranslation( "select an.mother.id, max(an.bodyWeight) from Animal an group by an.mother.id having max(an.bodyWeight)>1.0" ); } public void testGroupByMultiple() throws Exception { assertTranslation( "select s.id, s.count, count(t), max(t.date) from org.hibernate.test.legacy.Simple s, org.hibernate.test.legacy.Simple t where s.count = t.count group by s.id, s.count order by s.count" ); } public void testManyToMany() throws Exception { assertTranslation( "from Human h join h.friends f where f.nickName = 'Gavin'" ); assertTranslation( "from Human h join h.friends f where f.bodyWeight > 100" ); } public void testManyToManyElementFunctionInWhere() throws Exception { assertTranslation( "from Human human where human in elements(human.friends)" ); assertTranslation( "from Human human where human = some elements(human.friends)" ); } public void testManyToManyElementFunctionInWhere2() throws Exception { assertTranslation( "from Human h1, Human h2 where h2 in elements(h1.family)" ); assertTranslation( "from Human h1, Human h2 where 'father' in indices(h1.family)" ); } public void testManyToManyFetch() throws Exception { assertTranslation( "from Human h left join fetch h.friends" ); } public void testManyToManyIndexAccessor() throws Exception { // From ParentChildTest.testCollectionQuery() assertTranslation( "select c from ContainerX c, Simple s where c.manyToMany[2] = s" ); assertTranslation( "select s from ContainerX c, Simple s where c.manyToMany[2] = s" ); assertTranslation( "from ContainerX c, Simple s where c.manyToMany[2] = s" ); //would be nice to have: //assertTranslation( "select c.manyToMany[2] from ContainerX c" ); } public void testSelectNew() throws Exception { assertTranslation( "select new Animal(an.description, an.bodyWeight) from Animal an" ); assertTranslation( "select new org.hibernate.test.hql.Animal(an.description, an.bodyWeight) from Animal an" ); } public void testSimpleCorrelatedSubselect() throws Exception { assertTranslation( "from Animal a where a.bodyWeight = (select o.bodyWeight from a.offspring o)" ); assertTranslation( "from Animal a where a = (from a.offspring o)" ); } public void testSimpleUncorrelatedSubselect() throws Exception { assertTranslation( "from Animal a where a.bodyWeight = (select an.bodyWeight from Animal an)" ); assertTranslation( "from Animal a where a = (from Animal an)" ); } public void testSimpleCorrelatedSubselect2() throws Exception { assertTranslation( "from Animal a where a = (select o from a.offspring o)" ); assertTranslation( "from Animal a where a in (select o from a.offspring o)" ); } public void testSimpleUncorrelatedSubselect2() throws Exception { assertTranslation( "from Animal a where a = (select an from Animal an)" ); assertTranslation( "from Animal a where a in (select an from Animal an)" ); } public void testUncorrelatedSubselect2() throws Exception { assertTranslation( "from Animal a where a.bodyWeight = (select max(an.bodyWeight) from Animal an)" ); } public void testCorrelatedSubselect2() throws Exception { assertTranslation( "from Animal a where a.bodyWeight > (select max(o.bodyWeight) from a.offspring o)" ); } public void testManyToManyJoinInSubselect() throws Exception { DotNode.useThetaStyleImplicitJoins = true; assertTranslation( "select foo from Foo foo where foo in (select elt from Baz baz join baz.fooArray elt)" ); DotNode.useThetaStyleImplicitJoins = false; } public void testImplicitJoinInSubselect() throws Exception { assertTranslation( "from Animal a where a = (select an.mother from Animal an)" ); assertTranslation( "from Animal a where a.id = (select an.mother.id from Animal an)" ); } public void testManyToOneSubselect() { //TODO: the join in the subselect also shows up in the outer query! assertTranslation( "from Animal a where 'foo' in (select m.description from a.mother m)" ); } public void testPositionalParameters() throws Exception { assertTranslation( "from Animal an where an.bodyWeight > ?" ); } public void testKeywordPropertyName() throws Exception { assertTranslation( "from Glarch g order by g.order asc" ); assertTranslation( "select g.order from Glarch g where g.order = 3" ); } public void testJavaConstant() throws Exception { assertTranslation( "from org.hibernate.test.legacy.Category c where c.name = org.hibernate.test.legacy.Category.ROOT_CATEGORY" ); assertTranslation( "from org.hibernate.test.legacy.Category c where c.id = org.hibernate.test.legacy.Category.ROOT_ID" ); // todo : additional desired functionality //assertTranslation( "from Category c where c.name = Category.ROOT_CATEGORY" ); //assertTranslation( "select c.name, Category.ROOT_ID from Category as c"); } public void testClassName() throws Exception { // The Zoo reference is OK; Zoo is discriminator-based; // the old parser could handle these correctly // // However, the Animal one ares not; Animal is joined subclassing; // the old parser does not handle thee correctly. The new parser // previously did not handle them correctly in that same way. So they // used to pass regression even though the output was bogus SQL... // // I have moved the Animal ones (plus duplicating the Zoo one) // to ASTParserLoadingTest for syntax checking. assertTranslation( "from Zoo zoo where zoo.class = PettingZoo" );// assertTranslation( "from DomesticAnimal an where an.class = Dog" );// assertTranslation( "from Animal an where an.class = Dog" ); } public void testSelectDialectFunction() throws Exception { // From SQLFunctionsTest.testDialectSQLFunctions... if ( getDialect() instanceof HSQLDialect ) { assertTranslation( "select mod(s.count, 2) from org.hibernate.test.legacy.Simple as s where s.id = 10" ); //assertTranslation( "from org.hibernate.test.legacy.Simple as s where mod(s.count, 2) = 0" ); } assertTranslation( "select upper(human.name.first) from Human human" ); assertTranslation( "from Human human where lower(human.name.first) like 'gav%'" ); assertTranslation( "select upper(a.description) from Animal a" ); assertTranslation( "select max(a.bodyWeight) from Animal a" ); } public void testTwoJoins() throws Exception { assertTranslation( "from Human human join human.friends, Human h join h.mother" ); assertTranslation( "from Human human join human.friends f, Animal an join an.mother m where f=m" ); assertTranslation( "from Baz baz left join baz.fooToGlarch, Bar bar join bar.foo" ); } public void testToOneToManyManyJoinSequence() throws Exception { assertTranslation( "from Dog d join d.owner h join h.friends f where f.name.first like 'joe%'" ); } public void testToOneToManyJoinSequence() throws Exception { assertTranslation( "from Animal a join a.mother m join m.offspring" ); assertTranslation( "from Dog d join d.owner m join m.offspring" ); assertTranslation( "from Animal a join a.mother m join m.offspring o where o.bodyWeight > a.bodyWeight" ); } public void testSubclassExplicitJoin() throws Exception { assertTranslation( "from DomesticAnimal da join da.owner o where o.nickName = 'gavin'" ); assertTranslation( "from DomesticAnimal da join da.owner o where o.bodyWeight > 0" ); } public void testMultipleExplicitCollectionJoins() throws Exception { assertTranslation( "from Animal an inner join an.offspring os join os.offspring gc" ); assertTranslation( "from Animal an left outer join an.offspring os left outer join os.offspring gc" ); } public void testSelectDistinctComposite() throws Exception { // This is from CompositeElementTest.testHandSQL. assertTranslation( "select distinct p from org.hibernate.test.compositeelement.Parent p join p.children c where c.name like 'Child%'" ); } public void testDotComponent() throws Exception { // from FumTest.testListIdentifiers() assertTranslation( "select fum.id from org.hibernate.test.legacy.Fum as fum where not fum.fum='FRIEND'" ); } public void testOrderByCount() throws Exception { assertTranslation( "from Animal an group by an.zoo.id order by an.zoo.id, count(*)" ); } public void testHavingCount() throws Exception { assertTranslation( "from Animal an group by an.zoo.id having count(an.zoo.id) > 1" ); } public void selectWhereElements() throws Exception { assertTranslation( "select foo from Foo foo, Baz baz where foo in elements(baz.fooArray)" ); } public void testCollectionOfComponents() throws Exception { assertTranslation( "from Baz baz inner join baz.components comp where comp.name='foo'" ); } public void testNestedComponentIsNull() { // From MapTest... assertTranslation( "from Commento c where c.marelo.commento.mcompr is null" ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -