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());
}
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());
}
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());
}
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);
}
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());
}
Aggregations