#716 - Remove createNamedQuery() and createQuery(Class<T> beanType, String query) ... use criteria API, query beans and RawSql

This commit is contained in:
Robin Bygrave
2016-05-20 22:13:58 +12:00
parent a20822a9e1
commit 11d623cb69
58 changed files with 56 additions and 3578 deletions
@@ -63,63 +63,5 @@ public class TestQueryConversationRowCount extends BaseTestCase {
Assert.assertTrue(countSql.contains("select count(*) from ( select distinct t0.id c0 from c_conversation t0 left outer join c_participation u1 on u1.conversation_id = t0.id where t0.group_id = ? and ((t0.isopen = ? and u1.user_id = ? ) or t0.isopen = ? )"));
}
@Test
public void testUsingQueryLanguage() {
//"find conversation where club = :clubId and ( ( isPublic = :false and participants.user.id = :userId ) or isPublic = :true ) order by createdAt desc ";
String qry = "find conversation where group.id = :groupId and ( ( open = :false and participants.user.id = :userId ) or open = :true ) order by whenCreated desc ";
Long groupId = 1L;
Long userId = 1L;
Query<Conversation> query = Ebean.createQuery(Conversation.class, qry);
query.setParameter("groupId", groupId);
query.setParameter("userId", userId);
query.setParameter("false", false);
query.setParameter("true", true);
query.findList();
String generatedSql = query.getGeneratedSql();
// ACTUAL:
// select distinct t0.id c0, t0.title c1, t0.open c2, t0.version c3, t0.when_created c4, t0.when_updated c5, t0.group_id c6, t0.when_created
// from c_conversation t0
// join c_participation t1 on t1.conversation_id = t0.id
// where t0.group_id = ? and ( ( t0.open = ? and t1.user_id = ? ) or t0.open = ? )
// order by t0.when_created desc; --bind(1, false, 1, true, )
// SHOULD BE:
// select distinct t0.id c0, t0.title c1, t0.open c2, t0.version c3, t0.when_created c4, t0.when_updated c5, t0.group_id c6, t0.when_created
// from c_conversation t0
// left outer join c_participation u1 on u1.conversation_id = t0.id
// where t0.group_id = ? and ((t0.open = ? and u1.user_id = ? ) or t0.open = ? )
// order by t0.when_created desc;
Assert.assertTrue(generatedSql.contains("select distinct t0.id c0, t0.title c1, t0.isopen"));
// THE NEXT ASSERT CURRENTLY FAILS:
// Assert.assertTrue(generatedSql.contains("left outer join c_participation u1 on u1.conversation_id = t0.id"));
// Assert.assertTrue(generatedSql.contains("where t0.group_id = ? and ((t0.open = ? and u1.user_id = ? ) or t0.open = ? )"));
//
//
// LoggedSqlCollector.start();
// query.findRowCount();
//
// // select count(*) from (
// // select distinct t0.id c0
// // from c_conversation t0
// // left outer join c_participation u1 on u1.conversation_id = t0.id
// // where t0.group_id = ? and ((t0.open = ? and u1.user_id = ? ) or t0.open = ? )
// // ); --bind(1,true,1,true)
//
// List<String> loggedSql = LoggedSqlCollector.stop();
// Assert.assertEquals(1, loggedSql.size());
//
// String countSql = loggedSql.get(0);
//
// Assert.assertTrue(countSql.contains("select count(*) from ( select distinct t0.id c0 from c_conversation t0 left outer join c_participation u1 on u1.conversation_id = t0.id where t0.group_id = ? and ((t0.open = ? and u1.user_id = ? ) or t0.open = ? )"));
}
}