Search in sources :

Example 16 with Path

use of com.github.drinkjava2.jsqlbox.entitynet.Path 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 17 with Path

use of com.github.drinkjava2.jsqlbox.entitynet.Path 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 18 with Path

use of com.github.drinkjava2.jsqlbox.entitynet.Path in project jSqlBox by drinkjava2.

the class PathUtils method getRelationShip.

/**
 * The the relationship between from and to
 */
static Object[] getRelationShip(EntityNet net, Class<?> from, Class<?> to) {
    TableModel fromModel = net.getConfigModels().get(from);
    String fromTable = fromModel.getTableName();
    TableModel toModel = net.getConfigModels().get(to);
    String toTable = toModel.getTableName();
    Object[] result = null;
    // assume from is child, like from is RoleUser, to is UserPOJO
    for (FKeyModel fKeyModel : fromModel.getFkeyConstraints()) {
        String parentTableName = fKeyModel.getRefTableAndColumns()[0];
        if (toTable.equalsIgnoreCase(parentTableName)) {
            if (result != null)
                throw new EntityNetException("Auto path can not determined, multiple relationships found between class " + from + " and " + to);
            result = new Object[3];
            result[0] = "P-";
            result[1] = to;
            String[] refs = fKeyModel.getColumnNames().toArray(new String[fKeyModel.getColumnNames().size()]);
            result[2] = refs;
        }
    }
    // assume to is child, like from is UserPOJO, to is UserRole
    for (FKeyModel fKeyModel : toModel.getFkeyConstraints()) {
        String parentTableName = fKeyModel.getRefTableAndColumns()[0];
        if (fromTable.equalsIgnoreCase(parentTableName)) {
            if (result != null)
                throw new EntityNetException("Auto path can not determined, multiple relationships found between class " + from + " and " + to);
            result = new Object[3];
            result[0] = "C-";
            result[1] = to;
            String[] refs = fKeyModel.getColumnNames().toArray(new String[fKeyModel.getColumnNames().size()]);
            result[2] = refs;
        }
    }
    if (result != null)
        return result;
    throw new EntityNetException("Auto path can not determined, no relationship found between class " + from + " and " + to);
}
Also used : TableModel(com.github.drinkjava2.jdialects.model.TableModel) FKeyModel(com.github.drinkjava2.jdialects.model.FKeyModel)

Example 19 with Path

use of com.github.drinkjava2.jsqlbox.entitynet.Path 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)

Example 20 with Path

use of com.github.drinkjava2.jsqlbox.entitynet.Path in project jSqlBox by drinkjava2.

the class DynamicCompileEngine method buildClassPath.

/**
 * Only tested in Maven, Tomcat, Weblogic
 */
private void buildClassPath() {
    // Build classPath for weblogic
    this.classpath = null;
    String weblogicClazzPass = null;
    ClassLoader weblogicClassloader = this.getClass().getClassLoader();
    try {
        Method methods = weblogicClassloader.getClass().getDeclaredMethod("getClassPath", null);
        if (methods != null)
            weblogicClazzPass = (String) methods.invoke(weblogicClassloader, null);
    } catch (Exception e) {
    // Eat exception
    }
    if (!StrUtils.isEmpty(weblogicClazzPass)) {
        this.parentClassLoader = weblogicClassloader;
        this.classpath = weblogicClazzPass;
        return;
    }
    // buildClassPath for Tomcat
    this.parentClassLoader = (URLClassLoader) this.getClass().getClassLoader();
    StringBuilder sb = new StringBuilder();
    for (URL url : ((URLClassLoader) this.parentClassLoader).getURLs()) {
        String p = url.getFile();
        sb.append(p).append(File.pathSeparator);
    }
    this.classpath = sb.toString();
    // buildClassPath for Maven unit test by run "mvn test" command
    if (classpath.indexOf("surefire/surefirebooter") > 0) {
        String path = StrUtils.substringAfter(classpath, "/");
        path = StrUtils.substringBeforeLast(path, ";");
        String mavenJarPath = readFileToString(path);
        mavenJarPath = StrUtils.substringBetween(mavenJarPath, "Class-Path: ", "Main-Class: ");
        mavenJarPath = StrUtils.replace(mavenJarPath, "\r\n ", "").trim();
        mavenJarPath = StrUtils.replace(mavenJarPath, " ", ";");
        classpath = StrUtils.replace(mavenJarPath, "file:/", "");
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) Method(java.lang.reflect.Method) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SqlBoxException(com.github.drinkjava2.jsqlbox.SqlBoxException) URL(java.net.URL)

Aggregations

EntityNet (com.github.drinkjava2.jsqlbox.entitynet.EntityNet)15 Path (com.github.drinkjava2.jsqlbox.entitynet.Path)15 Test (org.junit.Test)15 User (com.github.drinkjava2.functionstest.entitynet.entities.User)12 Email (com.github.drinkjava2.functionstest.entitynet.entities.Email)8 Set (java.util.Set)6 Privilege (com.github.drinkjava2.functionstest.entitynet.entities.Privilege)4 Role (com.github.drinkjava2.functionstest.entitynet.entities.Role)4 RolePrivilege (com.github.drinkjava2.functionstest.entitynet.entities.RolePrivilege)4 UserRole (com.github.drinkjava2.functionstest.entitynet.entities.UserRole)4 TableModel (com.github.drinkjava2.jdialects.model.TableModel)4 TreeNode (com.github.drinkjava2.functionstest.entitynet.entities.TreeNode)3 FKeyModel (com.github.drinkjava2.jdialects.model.FKeyModel)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 ColumnModel (com.github.drinkjava2.jdialects.model.ColumnModel)1 SqlBoxException (com.github.drinkjava2.jsqlbox.SqlBoxException)1 EntityNetHandler (com.github.drinkjava2.jsqlbox.handler.EntityNetHandler)1 IOException (java.io.IOException)1