Search in sources :

Example 1 with Path

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

the class EntityNetDemoTest method testPathFind.

@Test
public void testPathFind() {
    insertDemoData();
    EntityNet net = ctx.netLoad(new User(), new Role(), Privilege.class, UserRole.class, RolePrivilege.class);
    Set<Privilege> privileges = net.findEntitySet(Privilege.class, new Path("S-", User.class).where("id='u1' or id='u2'").nextPath("C-", UserRole.class, "userId").nextPath("P-", Role.class, "rid").nextPath("C-", RolePrivilege.class, "rid").nextPath("P+", Privilege.class, "pid"));
    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 2 with Path

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

the class EntityNetDemoTest method testReturnDifferentType.

@Test
public void testReturnDifferentType() {
    insertDemoData();
    EntityNet net = ctx.netLoad(new User(), new Email());
    Map<Class<?>, Set<Object>> result = net.findEntityMap(new Path("S+", Email.class).nextPath("P+", User.class, "userId"));
    System.out.println("user selected:" + result.get(User.class).size());
    System.out.println("email selected:" + 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 3 with Path

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

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

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

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