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());
}
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());
}
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);
}
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");
}
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:/", "");
}
}
Aggregations