Search in sources :

Example 11 with Path

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

the class EntityNetDemoTest method testAutoPath.

@Test
public void testAutoPath() {
    insertDemoData();
    EntityNet net = ctx.netLoad(new User(), new Role(), Privilege.class, UserRole.class, RolePrivilege.class);
    Set<Privilege> privileges = net.findEntitySet(Privilege.class, new Path(User.class).where("id='u1' or id='u2'").autoPath(Privilege.class));
    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 12 with Path

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

the class EntityNetDemoTest method testAutoPathAndBind.

@Test
public void testAutoPathAndBind() {
    insertDemoData();
    EntityNet net = ctx.netLoad(new User(), new Role(), Privilege.class, UserRole.class, RolePrivilege.class);
    Set<Privilege> privileges = net.findEntitySet(Privilege.class, new Path(User.class).where("id='u1' or id='u2'").autoPath(Privilege.class));
    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 13 with Path

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

the class EntityNetQueryTest method testFindChild.

@Test
public void testFindChild() {
    System.out.println("==============testFindChild================ ");
    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);
    Map<Class<?>, Set<Node>> result = null;
    long start = System.currentTimeMillis();
    start = System.currentTimeMillis();
    for (int i = 0; i < queyrTimes; i++) {
        result = net.findNodeMapByEntities(new Path("S+", User.class).setCacheable(false).nextPath("C+", Email.class, "userId").setCacheable(false));
    }
    printTimeUsed(start, "Find Childs no Cache");
    System.out.println("user selected2:" + result.get(User.class).size());
    System.out.println("email selected2:" + result.get(Email.class).size());
    net.setAllowQueryCache(true);
    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 14 with Path

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

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

Aggregations

EntityNet (com.github.drinkjava2.jsqlbox.entitynet.EntityNet)15 Path (com.github.drinkjava2.jsqlbox.entitynet.Path)15 Test (org.junit.Test)15 User (com.github.drinkjava2.functionstest.entitynet.entities.User)12 Email (com.github.drinkjava2.functionstest.entitynet.entities.Email)8 Set (java.util.Set)6 Privilege (com.github.drinkjava2.functionstest.entitynet.entities.Privilege)4 Role (com.github.drinkjava2.functionstest.entitynet.entities.Role)4 RolePrivilege (com.github.drinkjava2.functionstest.entitynet.entities.RolePrivilege)4 UserRole (com.github.drinkjava2.functionstest.entitynet.entities.UserRole)4 TableModel (com.github.drinkjava2.jdialects.model.TableModel)4 TreeNode (com.github.drinkjava2.functionstest.entitynet.entities.TreeNode)3 FKeyModel (com.github.drinkjava2.jdialects.model.FKeyModel)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 ColumnModel (com.github.drinkjava2.jdialects.model.ColumnModel)1 SqlBoxException (com.github.drinkjava2.jsqlbox.SqlBoxException)1 EntityNetHandler (com.github.drinkjava2.jsqlbox.handler.EntityNetHandler)1 IOException (java.io.IOException)1