Search in sources :

Example 16 with EntityNet

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

the class EntityNetDemoTest method testEntityNetQuery.

@Test
public void testEntityNetQuery() {
    insertDemoData();
    EntityNet net = ctx.nQuery(new EntityNetHandler(User.class, Email.class), "select u.**, e.** from usertb u, emailtb e where u.id=e.userId");
    Assert.assertEquals(8, net.size());
    Set<Email> emails = net.findEntitySet(Email.class, new Path(User.class).where("id='u1' or id='u2'").autoPath(Email.class));
    Assert.assertEquals(4, emails.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) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) EntityNetHandler(com.github.drinkjava2.jsqlbox.handler.EntityNetHandler) Test(org.junit.Test)

Example 17 with EntityNet

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

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

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

the class EntityNetDemoTest method testloadEntityNet.

@Test
public void testloadEntityNet() {
    insertDemoData();
    EntityNet net = ctx.netLoad(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("user1", users.get(0).getUserName());
    System.out.println(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)

Example 20 with EntityNet

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

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