Search in sources :

Example 11 with EntityNet

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

the class EntityNetQueryTest method testAddEntity.

@Test
public void testAddEntity() {
    System.out.println("==============testAddEntity================ ");
    new User().put("id", "u1").put("userName", "user1").insert();
    EntityNet net = ctx.netLoad(User.class);
    Assert.assertEquals(1, net.size());
    User u2 = new User();
    u2.setId("u2");
    u2.setUserName("user2");
    u2.insert();
    ctx.netAddEntity(net, u2);
    Assert.assertEquals(2, net.size());
    User u = net.getOneEntity(User.class, "u2");
    Assert.assertEquals("user2", u.getUserName());
}
Also used : User(com.github.drinkjava2.functionstest.entitynet.entities.User) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) Test(org.junit.Test)

Example 12 with EntityNet

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

the class EntityNetTreeTest method testSearchTreeChild.

@Test
public void testSearchTreeChild() {
    EntityNet net = ctx.netLoad(TreeNode.class);
    Set<TreeNode> TreeNodes = net.findEntitySet(TreeNode.class, new Path("S+", TreeNode.class).where("id=? or id=?", "B", "D").nextPath("C*", TreeNode.class, "pid"));
    for (TreeNode node : TreeNodes) System.out.print(node.getId() + " ");
    Assert.assertEquals(9, TreeNodes.size());
}
Also used : Path(com.github.drinkjava2.jsqlbox.entitynet.Path) TreeNode(com.github.drinkjava2.functionstest.entitynet.entities.TreeNode) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) Test(org.junit.Test)

Example 13 with EntityNet

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

the class EntityListHandler method handleResult.

@Override
public Object handleResult(QueryRunner query, Object result) {
    List<Map<String, Object>> list = (List) sqlMapListHandler.handleResult(query, result);
    EntityNet net = ((SqlBoxContext) query).netCreate(list);
    return net.getAllEntityList(targetClass);
}
Also used : EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) List(java.util.List) SqlBoxContext(com.github.drinkjava2.jsqlbox.SqlBoxContext) Map(java.util.Map)

Example 14 with EntityNet

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

the class EntityNetDemoTest method testAutoPath2.

@Test
public void testAutoPath2() {
    insertDemoData();
    EntityNet net = ctx.netLoad(new Email(), new User(), new Role(), Privilege.class, UserRole.class, RolePrivilege.class);
    Set<Privilege> privileges = net.findEntitySet(Privilege.class, new Path(Email.class).setValidator(new EmailValidator()).autoPath(Privilege.class));
    for (Privilege privilege : privileges) System.out.println(privilege.getId());
    Assert.assertEquals(1, 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) Email(com.github.drinkjava2.functionstest.entitynet.entities.Email) 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 15 with EntityNet

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

the class EntityNetDemoTest method testNetLoadSketch.

@Test
public void testNetLoadSketch() {
    insertDemoData();
    EntityNet net = ctx.netLoadSketch(new User(), Email.class, Address.class, new Role(), Privilege.class, UserRole.class, RolePrivilege.class);
    Assert.assertEquals(37, net.size());
    System.out.println(net.size());
    List<User> users = net.getAllEntityList(User.class);
    Assert.assertEquals(5, users.size());
    Assert.assertEquals(null, users.get(0).getUserName());
}
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) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) 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