Search in sources :

Example 6 with EntityNet

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

the class EntityNetQueryTest method testValidateByBeanValidator.

@Test
public void testValidateByBeanValidator() {
    // no cache
    System.out.println("==============testValidateByBeanValidator================ ");
    int sampleSize = 30;
    int queyrTimes = 60;
    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(User.class, Email.class);
    long start = System.currentTimeMillis();
    Set<Email> emails = null;
    // Set validator instance will not cache query result
    Path p = new Path("S-", User.class).nextPath("C+", Email.class, "userId").setValidator(new MyBeanValidator());
    for (int i = 0; i < queyrTimes; i++) {
        emails = net.findEntitySet(Email.class, p);
    }
    printTimeUsed(start, "Bean Validator instance (No Cache)");
    Assert.assertEquals(sampleSize * sampleSize, emails.size());
    // Set validator class will cache query result
    net.setAllowQueryCache(true);
    start = System.currentTimeMillis();
    p = new Path("S-", User.class).nextPath("C+", Email.class, "userId").setValidator(MyBeanValidator.class);
    for (int i = 0; i < queyrTimes; i++) {
        emails = net.findEntitySet(Email.class, p);
    }
    printTimeUsed(start, "Bean Validator instance (Has Cache)");
    Assert.assertEquals(sampleSize * sampleSize, 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) Test(org.junit.Test)

Example 7 with EntityNet

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

the class EntityNetQueryTest method testValidateByExpression.

@Test
public void testValidateByExpression() {
    System.out.println("==============testValidateByExpression================ ");
    // no cache
    int sampleSize = 20;
    int queyrTimes = 20;
    for (int i = 0; i < sampleSize; i++) {
        new User().put("id", "usr" + i).put("userName", "user" + i).put("age", i).insert();
        for (int j = 0; j < sampleSize; j++) new Email().put("id", "email" + i + "_" + j, "userId", "usr" + i).insert();
    }
    EntityNet net = ctx.netLoad(User.class, Email.class);
    long start = System.currentTimeMillis();
    Set<Email> emails = null;
    // Set expression query parameters will not cache query result
    Path p = new Path("S-", User.class).where("age>?", 10).nextPath("C+", Email.class, "userId").where("id startwith ? or emailName=?", "email1", "Bar");
    for (int i = 0; i < queyrTimes; i++) {
        emails = net.findEntitySet(Email.class, p);
    }
    printTimeUsed(start, "Validate by expression with parameters");
    Assert.assertEquals(180, emails.size());
    // Do not have query parameters will cause query result be cached
    start = System.currentTimeMillis();
    p = new Path("S-", User.class).where("age>10").nextPath("C+", Email.class, "userId").where("id startwith 'email1' or emailName='Bar'");
    for (int i = 0; i < queyrTimes; i++) {
        emails = net.findEntitySet(Email.class, p);
    }
    printTimeUsed(start, "Validate by expression no parameters");
    Assert.assertEquals(180, 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) Test(org.junit.Test)

Example 8 with EntityNet

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

the class EntityNetQueryTest method testFindParent.

@Test
public void testFindParent() {
    System.out.println("==============testFindParent================ ");
    int sampleSize = 20;
    int queyrTimes = 10;
    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+", Email.class).nextPath("P+", User.class, "userId"));
    }
    printTimeUsed(start, "Find parent (no 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 9 with EntityNet

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

the class EntityNetQueryTest method testUpdateEntity.

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

Example 10 with EntityNet

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

the class EntityNetQueryTest method testRemoveEntity.

@Test
public void testRemoveEntity() {
    System.out.println("==============testRemoveEntity================ ");
    new User().put("id", "u1").put("userName", "user1").insert();
    new User().put("id", "u2").put("userName", "user2").insert();
    EntityNet net = ctx.netLoad(User.class);
    Assert.assertEquals(2, net.size());
    User u2 = net.getOneEntity(User.class, "u2");
    ctx.netRemoveEntity(net, u2);
    Assert.assertEquals(1, net.size());
}
Also used : 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