use of com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler in project jSqlBox by drinkjava2.
the class HandlersTest method testPaginHandler.
@Test
public void testPaginHandler() {
List<Map<String, Object>> result = ctx.nQuery(new Wrap(new EntitySqlMapListHandler(DemoUser.class), new PaginHandler(2, 5)), "select u.** from DemoUser u where u.age>?", 0);
Assert.assertTrue(result.size() == 5);
List<DemoUser> users = ctx.nQuery(new Wrap(new EntityListHandler(DemoUser.class), new PaginHandler(2, 5)), "select u.** from DemoUser u where u.age>?", 0);
Assert.assertTrue(users.size() == 5);
}
use of com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler in project jSqlBox by drinkjava2.
the class EntityNetDemoTest method testManualLoadAndJoin.
@Test
public void testManualLoadAndJoin() {
insertDemoData();
List<Map<String, Object>> mapList1 = ctx.nQuery(new EntitySqlMapListHandler(User.class, Address.class), "select u.**, a.** from usertb u, addresstb a where a.userId=u.id");
EntityNet net = ctx.netCreate(mapList1);
Assert.assertEquals(10, net.size());
Email e = new Email();
e.alias("e");
List<Map<String, Object>> mapList2 = ctx.nQuery(new EntitySqlMapListHandler(e), "select e.id as e_id from emailtb as e");
ctx.netJoinList(net, mapList2);
Assert.assertEquals(15, net.size());
List<Map<String, Object>> mapList3 = ctx.nQuery(new EntitySqlMapListHandler(Role.class, UserRole.class, RolePrivilege.class, Privilege.class), "select r.**, ur.**, rp.**, p.** from roletb r, userroletb ur, RolePrivilegetb rp, privilegetb p");
Assert.assertEquals(900, mapList3.size());
ctx.netJoinList(net, mapList3);
Assert.assertEquals(37, net.size());
}
use of com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler in project jSqlBox by drinkjava2.
the class EntityNetQueryTest method testJoinParents.
@Test
public void testJoinParents() {
System.out.println("==============testJoinParents================ ");
new User().put("id", "u1").put("userName", "user1").insert();
new User().put("id", "u2").put("userName", "user2").insert();
new Email().putFields("id", "emailName", "userId");
new Email().putValues("e1", "email1", "u1").insert();
new Email().putValues("e2", "email2", "u1").insert();
List<Map<String, Object>> listMap = ctx.nQuery(new EntitySqlMapListHandler(new Email().alias("e")), "select e.id as e_id from emailtb e");
EntityNet net = (EntityNet) ctx.netCreate(listMap);
Assert.assertEquals(2, net.size());
Node emailNode = net.getOneNode(Email.class, "e1");
// e1 have no userId
Assert.assertNull(emailNode.getParentRelations());
// field
List<Map<String, Object>> listMap2 = ctx.nQuery(new EntitySqlMapListHandler(Email.class), "select e.** from emailtb e");
ctx.netJoinList(net, listMap2);
Assert.assertEquals(2, net.size());
emailNode = net.getOneNode(Email.class, "e1");
Assert.assertNotNull(emailNode.getParentRelations());
}
use of com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler in project jSqlBox by drinkjava2.
the class EntityNetQueryTest method testJoinFields.
@Test
public void testJoinFields() {
System.out.println("==============testJoinFields================ ");
new User().put("id", "u1").put("userName", "user1").insert();
new User().put("id", "u2").put("userName", "user2").insert();
EntityNet net = ctx.netLoadSketch(User.class);
Assert.assertEquals(2, net.size());
List<User> users = net.getAllEntityList(User.class);
Assert.assertNull(users.get(0).getUserName());
User u = new User();
u.tableModel().setAlias("u");
List<Map<String, Object>> listMap = ctx.nQuery(new EntitySqlMapListHandler(u), "select u.id as u_id, u.userName as u_userName from usertb as u");
// not userName be joined
ctx.netJoinList(net, listMap);
Assert.assertEquals(2, net.size());
users = net.getAllEntityList(User.class);
Assert.assertNotNull(users.get(0).getUserName());
}
use of com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler in project jSqlBox by drinkjava2.
the class HandlersTest method testEntityMapListHandler.
@Test
public void testEntityMapListHandler() {
List<Map<String, Object>> result = ctx.nQuery(new EntitySqlMapListHandler(DemoUser.class), "select u.** from DemoUser u where u.age>?", 0);
Assert.assertTrue(result.size() == 99);
}
Aggregations