use of com.github.drinkjava2.jsqlbox.entitynet.Path in project jSqlBox by drinkjava2.
the class EntityNetDemoTest method testAutoPath.
@Test
public void testAutoPath() {
insertDemoData();
EntityNet net = ctx.netLoad(new User(), new Role(), Privilege.class, UserRole.class, RolePrivilege.class);
Set<Privilege> privileges = net.findEntitySet(Privilege.class, new Path(User.class).where("id='u1' or id='u2'").autoPath(Privilege.class));
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 testAutoPathAndBind.
@Test
public void testAutoPathAndBind() {
insertDemoData();
EntityNet net = ctx.netLoad(new User(), new Role(), Privilege.class, UserRole.class, RolePrivilege.class);
Set<Privilege> privileges = net.findEntitySet(Privilege.class, new Path(User.class).where("id='u1' or id='u2'").autoPath(Privilege.class));
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 EntityNetQueryTest method testFindChild.
@Test
public void testFindChild() {
System.out.println("==============testFindChild================ ");
int sampleSize = 30;
int queyrTimes = 30;
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+", User.class).setCacheable(false).nextPath("C+", Email.class, "userId").setCacheable(false));
}
printTimeUsed(start, "Find Childs no Cache");
System.out.println("user selected2:" + result.get(User.class).size());
System.out.println("email selected2:" + result.get(Email.class).size());
net.setAllowQueryCache(true);
start = System.currentTimeMillis();
for (int i = 0; i < queyrTimes; i++) {
result = net.findNodeMapByEntities(new Path("S+", User.class).nextPath("C+", Email.class, "userId"));
}
printTimeUsed(start, "Find Childs with 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.jsqlbox.entitynet.Path in project jSqlBox by drinkjava2.
the class EntityNetQueryTest method testFindSelf.
@Test
public void testFindSelf() {
System.out.println("==============testFindSelf================ ");
int sampleSize = 500;
int queyrTimes = 200;
for (int i = 1; i <= sampleSize; i++) {
new User().put("id", "u" + i).put("userName", "user" + i).insert();
}
EntityNet net = ctx.netLoad(new User(), Email.class);
Set<User> users2 = net.findEntitySet(User.class, new Path("S-", User.class));
Assert.assertEquals(0, users2.size());
long start = System.currentTimeMillis();
for (int i = 0; i < queyrTimes; i++) {
Set<User> users = net.findEntitySet(User.class, new Path("S+", User.class).setCacheable(false));
Assert.assertTrue(users.size() > 0);
}
printTimeUsed(start, "Find self No Cache");
start = System.currentTimeMillis();
for (int i = 0; i < queyrTimes; i++) {
Set<User> users = net.findEntitySet(User.class, new Path("S+", User.class).setCacheable(true));
Assert.assertTrue(users.size() > 0);
}
printTimeUsed(start, "Find self With Cache");
}
use of com.github.drinkjava2.jsqlbox.entitynet.Path in project jSqlBox by drinkjava2.
the class EntityNetQueryTest method testFindChild2.
@Test
public void testFindChild2() {
// This unit test will put on user manual
int sampleSize = 30;
int queyrTimes = 30;
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);
net.setAllowQueryCache(true);
Map<Class<?>, Set<Node>> result = null;
long start = System.currentTimeMillis();
for (int i = 0; i < queyrTimes; i++) {
result = net.findNodeMapByEntities(new Path("S+", User.class).nextPath("C+", Email.class, "userId"));
}
printTimeUsed(start, "Find Childs with Cache");
System.out.println("user selected2:" + result.get(User.class).size());
System.out.println("email selected2:" + result.get(Email.class).size());
}
Aggregations