Search in sources :

Example 21 with EntityNet

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

the class EntityNetQueryTest method testFindSelf.

@Test
public void testFindSelf() {
    System.out.println("==============testFindSelf================ ");
    int sampleSize = 500;
    int queyrTimes = 200;
    for (int i = 1; i <= sampleSize; i++) {
        new User().put("id", "u" + i).put("userName", "user" + i).insert();
    }
    EntityNet net = ctx.netLoad(new User(), Email.class);
    Set<User> users2 = net.findEntitySet(User.class, new Path("S-", User.class));
    Assert.assertEquals(0, users2.size());
    long start = System.currentTimeMillis();
    for (int i = 0; i < queyrTimes; i++) {
        Set<User> users = net.findEntitySet(User.class, new Path("S+", User.class).setCacheable(false));
        Assert.assertTrue(users.size() > 0);
    }
    printTimeUsed(start, "Find self No Cache");
    start = System.currentTimeMillis();
    for (int i = 0; i < queyrTimes; i++) {
        Set<User> users = net.findEntitySet(User.class, new Path("S+", User.class).setCacheable(true));
        Assert.assertTrue(users.size() > 0);
    }
    printTimeUsed(start, "Find self With Cache");
}
Also used : Path(com.github.drinkjava2.jsqlbox.entitynet.Path) User(com.github.drinkjava2.functionstest.entitynet.entities.User) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) Test(org.junit.Test)

Example 22 with EntityNet

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

the class EntityNetQueryTest method testFindChild2.

@Test
public void testFindChild2() {
    // This unit test will put on user manual
    int sampleSize = 30;
    int queyrTimes = 30;
    for (int i = 0; i < sampleSize; i++) {
        new User().put("id", "usr" + i).put("userName", "user" + i).insert();
        for (int j = 0; j < sampleSize; j++) new Email().put("id", "email" + i + "_" + j, "userId", "usr" + i).insert();
    }
    EntityNet net = ctx.netLoad(new User(), Email.class);
    net.setAllowQueryCache(true);
    Map<Class<?>, Set<Node>> result = null;
    long start = System.currentTimeMillis();
    for (int i = 0; i < queyrTimes; i++) {
        result = net.findNodeMapByEntities(new Path("S+", User.class).nextPath("C+", Email.class, "userId"));
    }
    printTimeUsed(start, "Find Childs with Cache");
    System.out.println("user selected2:" + result.get(User.class).size());
    System.out.println("email selected2:" + 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 23 with EntityNet

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

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

the class EntityNetTreeTest method testSearchTreeParent.

@Test
public void testSearchTreeParent() {
    EntityNet net = ctx.netLoad(TreeNode.class);
    Set<TreeNode> TreeNodes = net.findEntitySet(TreeNode.class, new Path("S-", TreeNode.class).where("id='F' or id='K'").nextPath("P*", TreeNode.class, "pid"));
    for (TreeNode node : TreeNodes) System.out.print(node.getId() + " ");
    Assert.assertEquals(4, 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 25 with EntityNet

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

the class EntityNetTreeTest method testSearchTreeChild2.

@Test
public void testSearchTreeChild2() {
    EntityNet net = ctx.netLoad(TreeNode.class);
    Set<TreeNode> TreeNodes = net.findEntitySet(TreeNode.class, new Path("C*", TreeNode.class, "pid"), new TreeNode("B"), new TreeNode("D"));
    for (TreeNode node : TreeNodes) System.out.print(node.getId() + " ");
    Assert.assertEquals(7, 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)

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