use of com.github.drinkjava2.functionstest.entitynet.entities.Email in project jSqlBox by drinkjava2.
the class EntityNetDemoTest method insertDemoData.
protected void insertDemoData() {
// @formatter:off
// Batch insert enabled
ctx.nBatchBegin();
new User().put("id", "u1").put("userName", "user1").insert();
new User().put("id", "u2").put("userName", "user2").insert();
new User().put("id", "u3").put("userName", "user3").insert();
new User().put("id", "u4").put("userName", "user4").insert();
new User().put("id", "u5").put("userName", "user5").insert();
new Address().put("id", "a1", "addressName", "address1", "userId", "u1").insert();
new Address().put("id", "a2", "addressName", "address2", "userId", "u2").insert();
new Address().put("id", "a3", "addressName", "address3", "userId", "u3").insert();
new Address().put("id", "a4", "addressName", "address4", "userId", "u4").insert();
new Address().put("id", "a5", "addressName", "address5", "userId", "u5").insert();
new Email().putFields("id", "emailName", "userId");
new Email().putValues("e1", "email1", "u1").insert();
new Email().putValues("e2", "email2", "u1").insert();
new Email().putValues("e3", "email3", "u2").insert();
new Email().putValues("e4", "email4", "u2").insert();
new Email().putValues("e5", "email5", "u3").insert();
Role r = new Role();
r.setId("r1");
r.setRoleName("role1");
r.insert();
r.setId("r2");
r.setRoleName("role2");
r.insert();
r.setId("r3");
r.setRoleName("role3");
r.insert();
r.setId("r4");
r.setRoleName("role4");
r.insert();
r.setId("r5");
r.setRoleName("role5");
r.insert();
Privilege p = new Privilege();
p.setId("p1");
p.setPrivilegeName("privilege1");
p.insert();
p.setId("p2");
p.setPrivilegeName("privilege2");
p.insert();
p.setId("p3");
p.setPrivilegeName("privilege3");
p.insert();
p.setId("p4");
p.setPrivilegeName("privilege4");
p.insert();
p.setId("p5");
p.setPrivilegeName("privilege5");
p.insert();
UserRole ur = new UserRole();
ur.setUserId("u1");
ur.setRid("r1");
ur.insert();
ur.setUserId("u2");
ur.setRid("r1");
ur.insert();
ur.setUserId("u2");
ur.setRid("r2");
ur.insert();
ur.setUserId("u2");
ur.setRid("r3");
ur.insert();
ur.setUserId("u3");
ur.setRid("r4");
ur.insert();
ur.setUserId("u4");
ur.setRid("r1");
ur.insert();
new RolePrivilege().putFields("rid", "pid");
new RolePrivilege().putValues("r1", "p1").insert();
new RolePrivilege().putValues("r2", "p1").insert();
new RolePrivilege().putValues("r2", "p2").insert();
new RolePrivilege().putValues("r2", "p3").insert();
new RolePrivilege().putValues("r3", "p3").insert();
new RolePrivilege().putValues("r4", "p1").insert();
// Batch insert end
ctx.nBatchEnd();
// @formatter:on
}
use of com.github.drinkjava2.functionstest.entitynet.entities.Email in project jSqlBox by drinkjava2.
the class EntityNetDemoTest method testEntityNetQuery.
@Test
public void testEntityNetQuery() {
insertDemoData();
EntityNet net = ctx.nQuery(new EntityNetHandler(User.class, Email.class), "select u.**, e.** from usertb u, emailtb e where u.id=e.userId");
Assert.assertEquals(8, net.size());
Set<Email> emails = net.findEntitySet(Email.class, new Path(User.class).where("id='u1' or id='u2'").autoPath(Email.class));
Assert.assertEquals(4, emails.size());
}
use of com.github.drinkjava2.functionstest.entitynet.entities.Email 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.functionstest.entitynet.entities.Email 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