Search in sources :

Example 6 with Node

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());
}
Also used : Path(com.github.drinkjava2.jsqlbox.entitynet.Path) User(com.github.drinkjava2.functionstest.entitynet.entities.User) Email(com.github.drinkjava2.functionstest.entitynet.entities.Email) Set(java.util.Set) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) Test(org.junit.Test)

Example 7 with Node

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());
}
Also used : Path(com.github.drinkjava2.jsqlbox.entitynet.Path) User(com.github.drinkjava2.functionstest.entitynet.entities.User) Email(com.github.drinkjava2.functionstest.entitynet.entities.Email) Set(java.util.Set) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) Test(org.junit.Test)

Example 8 with Node

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());
}
Also used : Path(com.github.drinkjava2.jsqlbox.entitynet.Path) TreeNode(com.github.drinkjava2.functionstest.entitynet.entities.TreeNode) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) Test(org.junit.Test)

Example 9 with Node

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());
}
Also used : Path(com.github.drinkjava2.jsqlbox.entitynet.Path) TreeNode(com.github.drinkjava2.functionstest.entitynet.entities.TreeNode) EntityNet(com.github.drinkjava2.jsqlbox.entitynet.EntityNet) Test(org.junit.Test)

Example 10 with Node

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");
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) TableModel(com.github.drinkjava2.jdialects.model.TableModel) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) FKeyModel(com.github.drinkjava2.jdialects.model.FKeyModel)

Aggregations

EntityNet (com.github.drinkjava2.jsqlbox.entitynet.EntityNet)7 Test (org.junit.Test)7 Path (com.github.drinkjava2.jsqlbox.entitynet.Path)6 Set (java.util.Set)5 Email (com.github.drinkjava2.functionstest.entitynet.entities.Email)4 User (com.github.drinkjava2.functionstest.entitynet.entities.User)4 TreeNode (com.github.drinkjava2.functionstest.entitynet.entities.TreeNode)3 TableModel (com.github.drinkjava2.jdialects.model.TableModel)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 ColumnModel (com.github.drinkjava2.jdialects.model.ColumnModel)1 FKeyModel (com.github.drinkjava2.jdialects.model.FKeyModel)1 Node (com.github.drinkjava2.jsqlbox.entitynet.Node)1 EntitySqlMapListHandler (com.github.drinkjava2.jsqlbox.handler.EntitySqlMapListHandler)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Entry (java.util.Map.Entry)1