use of com.github.drinkjava2.jsqlbox.entitynet.EntityNet 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.EntityNet 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());
}
use of com.github.drinkjava2.jsqlbox.entitynet.EntityNet in project jSqlBox by drinkjava2.
the class EntityNetQueryTest method testJoinFields.
@Test
public void testJoinFields() {
System.out.println("==============testJoinFields================ ");
new User().put("id", "u1").put("userName", "user1").insert();
new User().put("id", "u2").put("userName", "user2").insert();
EntityNet net = ctx.netLoadSketch(User.class);
Assert.assertEquals(2, net.size());
List<User> users = net.getAllEntityList(User.class);
Assert.assertNull(users.get(0).getUserName());
User u = new User();
u.tableModel().setAlias("u");
List<Map<String, Object>> listMap = ctx.nQuery(new EntitySqlMapListHandler(u), "select u.id as u_id, u.userName as u_userName from usertb as u");
// not userName be joined
ctx.netJoinList(net, listMap);
Assert.assertEquals(2, net.size());
users = net.getAllEntityList(User.class);
Assert.assertNotNull(users.get(0).getUserName());
}
use of com.github.drinkjava2.jsqlbox.entitynet.EntityNet in project jSqlBox by drinkjava2.
the class EntityNetTreeTest method testSearchTreeParent.
@Test
public void testSearchTreeParent() {
EntityNet net = ctx.netLoad(TreeNode.class);
Set<TreeNode> TreeNodes = net.findEntitySet(TreeNode.class, new Path("S-", TreeNode.class).where("id='F' or id='K'").nextPath("P*", TreeNode.class, "pid"));
for (TreeNode node : TreeNodes) System.out.print(node.getId() + " ");
Assert.assertEquals(4, TreeNodes.size());
}
use of com.github.drinkjava2.jsqlbox.entitynet.EntityNet in project jSqlBox by drinkjava2.
the class EntityNetTreeTest method testSearchTreeChild2.
@Test
public void testSearchTreeChild2() {
EntityNet net = ctx.netLoad(TreeNode.class);
Set<TreeNode> TreeNodes = net.findEntitySet(TreeNode.class, new Path("C*", TreeNode.class, "pid"), new TreeNode("B"), new TreeNode("D"));
for (TreeNode node : TreeNodes) System.out.print(node.getId() + " ");
Assert.assertEquals(7, TreeNodes.size());
}
Aggregations