use of com.github.drinkjava2.jsqlbox.entitynet.Node 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.Node 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.Node 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.Node 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());
}
use of com.github.drinkjava2.jsqlbox.entitynet.Node in project jSqlBox by drinkjava2.
the class PathUtils method searchNodePath.
/**
* Search Node path from from to to
*/
@SuppressWarnings("all")
static Set<Class<?>> searchNodePath(Map<Class<?>, TableModel> models, Class<?> from, Class<?> to) {
Set<Class<?>> checked = new HashSet<Class<?>>();
checked.add(from);
Set<Class<?>> result = new LinkedHashSet<Class<?>>();
result.add(from);
List<Set<Class<?>>> paths = new ArrayList<Set<Class<?>>>();
paths.add(result);
int i = 0;
LinkedHashSet<Class<?>> newPath = null;
do {
i++;
Class<?> foundClass;
do {
foundClass = null;
for (Set<Class<?>> subSet : paths) {
if (subSet.size() == i) {
Class<?> last = getLastElement(subSet);
for (Entry<Class<?>, TableModel> entry : models.entrySet()) {
Class<?> c = entry.getKey();
List<FKeyModel> fkeyList = entry.getValue().getFkeyConstraints();
for (FKeyModel fKeyModel : fkeyList) {
String parentTableName = fKeyModel.getRefTableAndColumns()[0];
Class<?> p = findClassByTableName(models, parentTableName);
if (!checked.contains(c) && p != null && p.equals(last)) {
foundClass = c;
break;
} else if (!checked.contains(p) && c.equals(last)) {
foundClass = p;
break;
}
if (foundClass != null)
break;
}
if (foundClass != null)
break;
}
}
if (foundClass != null) {
newPath = new LinkedHashSet<Class<?>>(subSet);
newPath.add(foundClass);
if (foundClass.equals(to))
return newPath;
checked.add(foundClass);
break;
}
}
if (newPath != null)
paths.add(newPath);
} while (foundClass != null);
} while (i < 200);
throw new EntityNetException("Not found availible auto path");
}
Aggregations