Search in sources :

Example 1 with EntitySqlMapListHandler

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);
}
Also used : PaginHandler(com.github.drinkjava2.jsqlbox.handler.PaginHandler) Wrap(com.github.drinkjava2.jdbpro.handler.Wrap) EntityListHandler(com.github.drinkjava2.jsqlbox.handler.EntityListHandler) Map(java.util.Map) EntitySqlMapListHandler(com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler) Test(org.junit.Test)

Example 2 with EntitySqlMapListHandler

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());
}
Also used : UserRole(com.github.drinkjava2.functionstest.entitynet.entities.UserRole) Role(com.github.drinkjava2.functionstest.entitynet.entities.Role) User(com.github.drinkjava2.functionstest.entitynet.entities.User) Email(com.github.drinkjava2.functionstest.entitynet.entities.Email) Address(com.github.drinkjava2.functionstest.entitynet.entities.Address) UserRole(com.github.drinkjava2.functionstest.entitynet.entities.UserRole) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) RolePrivilege(com.github.drinkjava2.functionstest.entitynet.entities.RolePrivilege) RolePrivilege(com.github.drinkjava2.functionstest.entitynet.entities.RolePrivilege) Privilege(com.github.drinkjava2.functionstest.entitynet.entities.Privilege) Map(java.util.Map) EntitySqlMapListHandler(com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler) Test(org.junit.Test)

Example 3 with EntitySqlMapListHandler

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());
}
Also used : User(com.github.drinkjava2.functionstest.entitynet.entities.User) Email(com.github.drinkjava2.functionstest.entitynet.entities.Email) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) Node(com.github.drinkjava2.jsqlbox.entitynet.Node) Map(java.util.Map) EntitySqlMapListHandler(com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler) Test(org.junit.Test)

Example 4 with EntitySqlMapListHandler

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());
}
Also used : User(com.github.drinkjava2.functionstest.entitynet.entities.User) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) Map(java.util.Map) EntitySqlMapListHandler(com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler) Test(org.junit.Test)

Example 5 with EntitySqlMapListHandler

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);
}
Also used : Map(java.util.Map) EntitySqlMapListHandler(com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler) Test(org.junit.Test)

Aggregations

EntitySqlMapListHandler (com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler)6 Map (java.util.Map)6 Test (org.junit.Test)5 User (com.github.drinkjava2.functionstest.entitynet.entities.User)3 EntityNet (com.github.drinkjava2.jsqlbox.entitynet.EntityNet)3 Email (com.github.drinkjava2.functionstest.entitynet.entities.Email)2 Address (com.github.drinkjava2.functionstest.entitynet.entities.Address)1 Privilege (com.github.drinkjava2.functionstest.entitynet.entities.Privilege)1 Role (com.github.drinkjava2.functionstest.entitynet.entities.Role)1 RolePrivilege (com.github.drinkjava2.functionstest.entitynet.entities.RolePrivilege)1 UserRole (com.github.drinkjava2.functionstest.entitynet.entities.UserRole)1 Wrap (com.github.drinkjava2.jdbpro.handler.Wrap)1 TableModel (com.github.drinkjava2.jdialects.model.TableModel)1 Node (com.github.drinkjava2.jsqlbox.entitynet.Node)1 EntityListHandler (com.github.drinkjava2.jsqlbox.handler.EntityListHandler)1 PaginHandler (com.github.drinkjava2.jsqlbox.handler.PaginHandler)1