Search in sources :

Example 1 with EntityNet

use of com.github.drinkjava2.jsqlbox.entitynet.EntityNet in project jSqlBox by drinkjava2.

the class HandlersTest method testEntityNetHandler.

@Test
public void testEntityNetHandler() {
    EntityNet net = ctx.nQuery(new EntityNetHandler(DemoUser.class), "select u.** from DemoUser u where u.age>?", 0);
    List<DemoUser> result = net.getAllEntityList(DemoUser.class);
    Assert.assertTrue(result.size() == 99);
}
Also used : EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) EntityNetHandler(com.github.drinkjava2.jsqlbox.handler.EntityNetHandler) Test(org.junit.Test)

Example 2 with EntityNet

use of com.github.drinkjava2.jsqlbox.entitynet.EntityNet in project jSqlBox by drinkjava2.

the class EntityNetDemoTest method testPathFind.

@Test
public void testPathFind() {
    insertDemoData();
    EntityNet net = ctx.netLoad(new User(), new Role(), Privilege.class, UserRole.class, RolePrivilege.class);
    Set<Privilege> privileges = net.findEntitySet(Privilege.class, new Path("S-", User.class).where("id='u1' or id='u2'").nextPath("C-", UserRole.class, "userId").nextPath("P-", Role.class, "rid").nextPath("C-", RolePrivilege.class, "rid").nextPath("P+", Privilege.class, "pid"));
    for (Privilege privilege : privileges) System.out.print(privilege.getId() + " ");
    Assert.assertEquals(3, privileges.size());
}
Also used : UserRole(com.github.drinkjava2.functionstest.entitynet.entities.UserRole) Role(com.github.drinkjava2.functionstest.entitynet.entities.Role) Path(com.github.drinkjava2.jsqlbox.entitynet.Path) User(com.github.drinkjava2.functionstest.entitynet.entities.User) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) RolePrivilege(com.github.drinkjava2.functionstest.entitynet.entities.RolePrivilege) Privilege(com.github.drinkjava2.functionstest.entitynet.entities.Privilege) Test(org.junit.Test)

Example 3 with EntityNet

use of com.github.drinkjava2.jsqlbox.entitynet.EntityNet in project jSqlBox by drinkjava2.

the class EntityNetDemoTest method testReturnDifferentType.

@Test
public void testReturnDifferentType() {
    insertDemoData();
    EntityNet net = ctx.netLoad(new User(), new Email());
    Map<Class<?>, Set<Object>> result = net.findEntityMap(new Path("S+", Email.class).nextPath("P+", User.class, "userId"));
    System.out.println("user selected:" + result.get(User.class).size());
    System.out.println("email selected:" + result.get(Email.class).size());
}
Also used : Path(com.github.drinkjava2.jsqlbox.entitynet.Path) User(com.github.drinkjava2.functionstest.entitynet.entities.User) Email(com.github.drinkjava2.functionstest.entitynet.entities.Email) Set(java.util.Set) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) Test(org.junit.Test)

Example 4 with EntityNet

use of com.github.drinkjava2.jsqlbox.entitynet.EntityNet 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 5 with EntityNet

use of com.github.drinkjava2.jsqlbox.entitynet.EntityNet 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)

Aggregations

EntityNet (com.github.drinkjava2.jsqlbox.entitynet.EntityNet)25 Test (org.junit.Test)24 User (com.github.drinkjava2.functionstest.entitynet.entities.User)20 Path (com.github.drinkjava2.jsqlbox.entitynet.Path)15 Email (com.github.drinkjava2.functionstest.entitynet.entities.Email)10 Role (com.github.drinkjava2.functionstest.entitynet.entities.Role)7 UserRole (com.github.drinkjava2.functionstest.entitynet.entities.UserRole)7 Privilege (com.github.drinkjava2.functionstest.entitynet.entities.Privilege)5 RolePrivilege (com.github.drinkjava2.functionstest.entitynet.entities.RolePrivilege)5 Map (java.util.Map)5 EntitySqlMapListHandler (com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler)4 Set (java.util.Set)4 TreeNode (com.github.drinkjava2.functionstest.entitynet.entities.TreeNode)3 TableModel (com.github.drinkjava2.jdialects.model.TableModel)2 EntityNetHandler (com.github.drinkjava2.jsqlbox.handler.EntityNetHandler)2 Address (com.github.drinkjava2.functionstest.entitynet.entities.Address)1 FKeyModel (com.github.drinkjava2.jdialects.model.FKeyModel)1 SqlBoxContext (com.github.drinkjava2.jsqlbox.SqlBoxContext)1 Node (com.github.drinkjava2.jsqlbox.entitynet.Node)1 List (java.util.List)1