Search in sources :

Example 6 with Email

use of com.github.drinkjava2.functionstest.entitynet.entities.Email 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 Email

use of com.github.drinkjava2.functionstest.entitynet.entities.Email 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 Email

use of com.github.drinkjava2.functionstest.entitynet.entities.Email 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 Email

use of com.github.drinkjava2.functionstest.entitynet.entities.Email in project jDialects by drinkjava2.

the class DDLTest method singleXxxMethodTest.

@Test
public void singleXxxMethodTest() {
    // Test singleXxx methods
    TableModel t1 = new TableModel("customers");
    t1.column("name").STRING(20).singleUnique();
    t1.column("email").VARCHAR(50).defaultValue("'Beijing'").comment("address comment").singleIndex("IDX1");
    TableModel t2 = new TableModel("orders");
    t2.column("item").STRING(20).singleUnique("A");
    t2.column("name").STRING(20).singleFKey("customers", "name");
    String[] dropAndCreateDDL = Dialect.H2Dialect.toDropAndCreateDDL(t1, t2);
    for (String ddl : dropAndCreateDDL) System.out.println(ddl);
    testOnCurrentRealDatabase(t1, t2);
}
Also used : TableModel(com.github.drinkjava2.jdialects.model.TableModel) Test(org.junit.Test)

Example 10 with Email

use of com.github.drinkjava2.functionstest.entitynet.entities.Email in project jSqlBox by drinkjava2.

the class EntityNetDemoTest method testAutoPath2.

@Test
public void testAutoPath2() {
    insertDemoData();
    EntityNet net = ctx.netLoad(new Email(), new User(), new Role(), Privilege.class, UserRole.class, RolePrivilege.class);
    Set<Privilege> privileges = net.findEntitySet(Privilege.class, new Path(Email.class).setValidator(new EmailValidator()).autoPath(Privilege.class));
    for (Privilege privilege : privileges) System.out.println(privilege.getId());
    Assert.assertEquals(1, 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) Email(com.github.drinkjava2.functionstest.entitynet.entities.Email) 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)

Aggregations

Test (org.junit.Test)13 Email (com.github.drinkjava2.functionstest.entitynet.entities.Email)11 User (com.github.drinkjava2.functionstest.entitynet.entities.User)11 EntityNet (com.github.drinkjava2.jsqlbox.entitynet.EntityNet)10 Path (com.github.drinkjava2.jsqlbox.entitynet.Path)8 Set (java.util.Set)4 Privilege (com.github.drinkjava2.functionstest.entitynet.entities.Privilege)3 Role (com.github.drinkjava2.functionstest.entitynet.entities.Role)3 RolePrivilege (com.github.drinkjava2.functionstest.entitynet.entities.RolePrivilege)3 UserRole (com.github.drinkjava2.functionstest.entitynet.entities.UserRole)3 TableModel (com.github.drinkjava2.jdialects.model.TableModel)3 Address (com.github.drinkjava2.functionstest.entitynet.entities.Address)2 EntitySqlMapListHandler (com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler)2 Map (java.util.Map)2 ColumnModel (com.github.drinkjava2.jdialects.model.ColumnModel)1 Node (com.github.drinkjava2.jsqlbox.entitynet.Node)1 EntityNetHandler (com.github.drinkjava2.jsqlbox.handler.EntityNetHandler)1