use of henplus.sqlmodel.Table in project henplus by neurolabs.
the class SQLMetaDataBuilder method getTable.
public Table getTable(final SQLSession session, final String tableName) {
Table table = null;
ResultSet rset = null;
try {
final String catalog = session.getConnection().getCatalog();
final DatabaseMetaData meta = session.getConnection().getMetaData();
rset = meta.getColumns(catalog, null, tableName, null);
table = buildTable(catalog, meta, tableName, rset);
} catch (final Exception e) {
if (VERBOSE) {
e.printStackTrace();
}
HenPlus.msg().println("Database problem reading meta data: " + e.getMessage().trim());
} finally {
if (rset != null) {
try {
rset.close();
} catch (final Exception e) {
}
}
}
return table;
}
use of henplus.sqlmodel.Table in project henplus by neurolabs.
the class DependencyResolver method resolveDep.
/**
* @return
*
*/
/*
* Martin: needed ? private Set restructureDeps() { Set deps = null; if (
* cyclicDependencies != null ) { deps = new HashSet(); Iterator iter =
* cyclicDependencies.iterator(); while ( iter.hasNext() ) deps.add(
* ((ListMap)iter.next()).valuesList() ); } return deps; }
*/
/**
* @param resolved
* @param unresolved
* @return A Map which contains all yet unresolved Tables mapped to their names.
*/
/*
* Martin: needed ? private Map cleanUnresolved( Map resolved, Map
* unresolved ) { Map result = null;
*
* if ( unresolved != null ) { Iterator iter =
* unresolved.keySet().iterator(); while ( iter.hasNext() ) { // type
* element = (type) iter.next();
*
* } }
*
* return null; }
*/
/**
* @param t
* @param cyclePath
* The path of tables which have cyclic dependencies
* @param resolved
* @param unresolved
*/
private void resolveDep(final Table t, List<Table> cyclePath, final Map<String, Table> resolved, final Map<String, Table> unresolved) {
Logger.debug("[resolveDep] >>> Starting for t: %s and cyclePath: %s", t, cyclePath);
// if the current table is no more in the unresolved collection
if (t == null || resolved.containsKey(t.getName())) {
return;
}
boolean nodep = false;
boolean firstrun = true;
final Set<ColumnFkInfo> fks = t.getForeignKeys();
final Iterator<ColumnFkInfo> iter = fks.iterator();
while (iter.hasNext()) {
final ColumnFkInfo fk = iter.next();
Logger.debug("[resolveDep] FK -> %s: %s", fk.getPkTable(), resolved.containsKey(fk.getPkTable()));
if (!resolved.containsKey(fk.getPkTable())) {
final Table inner = unresolved.get(fk.getPkTable());
// then proceed to the next FK and ignore this potential cycle
if (duplicateCycle(t, inner)) {
continue;
}
if (cyclePath != null && cyclePath.contains(inner)) {
cyclePath.add(t);
// create a new list for the detected cycle to add to the
// cyclicDeps, the former one (cyclePath) is used further on
final List<Table> cycle = new ArrayList<Table>(cyclePath);
cycle.add(inner);
if (_cyclicDependencies == null) {
_cyclicDependencies = new HashSet<List<Table>>();
}
Logger.debug("[resolveDep] +++ Putting cyclePath: %s", cycle);
_cyclicDependencies.add(cycle);
continue;
} else {
if (cyclePath == null) {
Logger.debug("[resolveDep] Starting cyclePath with: %s", t);
cyclePath = new ArrayList<Table>();
}
cyclePath.add(t);
}
resolveDep(inner, cyclePath, resolved, unresolved);
if (resolved.containsKey(fk.getPkTable())) {
nodep = (firstrun || nodep);
firstrun = false;
}
} else {
nodep = (firstrun || nodep);
firstrun = false;
}
}
if (nodep && !resolved.containsKey(t.getName())) {
Logger.debug("[resolveDep] put %s to resolved.", t);
resolved.put(t.getName(), t);
}
}
Aggregations