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