use of org.h2.bnf.context.DbTableOrView in project h2database by h2database.
the class WebApp method addTablesAndViews.
private int addTablesAndViews(DbSchema schema, boolean mainSchema, StringBuilder buff, int treeIndex) throws SQLException {
if (schema == null) {
return treeIndex;
}
Connection conn = session.getConnection();
DatabaseMetaData meta = session.getMetaData();
int level = mainSchema ? 0 : 1;
boolean showColumns = mainSchema || !schema.isSystem;
String indentation = ", " + level + ", " + (showColumns ? "1" : "2") + ", ";
String indentNode = ", " + (level + 1) + ", 2, ";
DbTableOrView[] tables = schema.getTables();
if (tables == null) {
return treeIndex;
}
boolean isOracle = schema.getContents().isOracle();
boolean notManyTables = tables.length < SysProperties.CONSOLE_MAX_TABLES_LIST_INDEXES;
for (DbTableOrView table : tables) {
if (table.isView()) {
continue;
}
int tableId = treeIndex;
String tab = table.getQuotedName();
if (!mainSchema) {
tab = schema.quotedName + "." + tab;
}
tab = escapeIdentifier(tab);
buff.append("setNode(").append(treeIndex).append(indentation).append(" 'table', '").append(PageParser.escapeJavaScript(table.getName())).append("', 'javascript:ins(\\'").append(tab).append("\\',true)');\n");
treeIndex++;
if (mainSchema || showColumns) {
StringBuilder columnsBuffer = new StringBuilder();
treeIndex = addColumns(mainSchema, table, buff, treeIndex, notManyTables, columnsBuffer);
if (!isOracle && notManyTables) {
treeIndex = addIndexes(mainSchema, meta, table.getName(), schema.name, buff, treeIndex);
}
buff.append("addTable('").append(PageParser.escapeJavaScript(table.getName())).append("', '").append(PageParser.escapeJavaScript(columnsBuffer.toString())).append("', ").append(tableId).append(");\n");
}
}
tables = schema.getTables();
for (DbTableOrView view : tables) {
if (!view.isView()) {
continue;
}
int tableId = treeIndex;
String tab = view.getQuotedName();
if (!mainSchema) {
tab = view.getSchema().quotedName + "." + tab;
}
tab = escapeIdentifier(tab);
buff.append("setNode(").append(treeIndex).append(indentation).append(" 'view', '").append(PageParser.escapeJavaScript(view.getName())).append("', 'javascript:ins(\\'").append(tab).append("\\',true)');\n");
treeIndex++;
if (mainSchema) {
StringBuilder columnsBuffer = new StringBuilder();
treeIndex = addColumns(mainSchema, view, buff, treeIndex, notManyTables, columnsBuffer);
if (schema.getContents().isH2()) {
try (PreparedStatement prep = conn.prepareStatement("SELECT * FROM " + "INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME=?")) {
prep.setString(1, view.getName());
ResultSet rs = prep.executeQuery();
if (rs.next()) {
String sql = rs.getString("SQL");
buff.append("setNode(").append(treeIndex).append(indentNode).append(" 'type', '").append(PageParser.escapeJavaScript(sql)).append("', null);\n");
treeIndex++;
}
rs.close();
}
}
buff.append("addTable('").append(PageParser.escapeJavaScript(view.getName())).append("', '").append(PageParser.escapeJavaScript(columnsBuffer.toString())).append("', ").append(tableId).append(");\n");
}
}
return treeIndex;
}
use of org.h2.bnf.context.DbTableOrView in project h2database by h2database.
the class WebApp method addColumns.
private static int addColumns(boolean mainSchema, DbTableOrView table, StringBuilder buff, int treeIndex, boolean showColumnTypes, StringBuilder columnsBuffer) {
DbColumn[] columns = table.getColumns();
for (int i = 0; columns != null && i < columns.length; i++) {
DbColumn column = columns[i];
if (columnsBuffer.length() > 0) {
columnsBuffer.append(' ');
}
columnsBuffer.append(column.getName());
String col = escapeIdentifier(column.getName());
String level = mainSchema ? ", 1, 1" : ", 2, 2";
buff.append("setNode(").append(treeIndex).append(level).append(", 'column', '").append(PageParser.escapeJavaScript(column.getName())).append("', 'javascript:ins(\\'").append(col).append("\\')');\n");
treeIndex++;
if (mainSchema && showColumnTypes) {
buff.append("setNode(").append(treeIndex).append(", 2, 2, 'type', '").append(PageParser.escapeJavaScript(column.getDataType())).append("', null);\n");
treeIndex++;
}
}
return treeIndex;
}
Aggregations