完美解决hibernatetool oracle注释问题 (二)

2014-11-24 10:53:15 · 作者: · 浏览: 1
exception
String databaseStructure = getDatabaseStructure(catalog,schema);
throw getSQLExceptionConverter().convert(e, "Could not get list of tables from database. Probably a JDBC driver problem. "+query.toString() + databaseStructure, null);
}
}

public Iterator getTables(final String catalog, final String schema, String table) {
final StringBuffer query = new StringBuffer();
try {
log.debug("getTables(" + catalog + "." + schema + "." + table + ")");
// Collect both Tables and Views from the 'ALL' data dicitonary tables.
// Note: This will potentally collect more tables that the jdbc meta data
Statement stmt = this.getConnection().createStatement();
query.append("select t.*,tc.comments as REMARKS from ( ");
query.append("select table_name, owner, 'TABLE' from all_tables ");
if (schema != null || table != null)
query.append("where ");
if (schema != null) {
query.append("owner='" + schema + "' ");
}
if (table != null) {
if (schema != null)
query.append("and ");
query.append("table_name = '" + table + "' ");
}
query.append("union all ");
query.append("select view_name, owner, 'VIEW' from all_views ");
if (schema != null || table != null)
query.append("where ");
if (schema != null) {
query.append("owner='" + schema + "' ");
}
if (table != null) {
if (schema != null)
query.append("and ");
query.append("view_name = '" + table + "' ");
}
query.append(" )t ");
query.append(" ,USER_TAB_COMMENTS tc where t.table_name=tc.table_name ");

if (log.isDebugEnabled())
log.debug("getTables Query:" + query.toString());

ResultSet tableRs = stmt.executeQuery(query.toString());

return new ResultSetIterator(stmt, tableRs, getSQLExceptionConverter()) {

Map element = new HashMap();
protected Object convertRow(ResultSet tableRs) throws SQLException {
element.clear();
element.put("TABLE_NAME", tableRs.getString(1));
element.put("TABLE_SCHEM", tableRs.getString(2));
element.put("TABLE_CAT", null);
element.put("TABLE_TYPE", tableRs.getString(3));
element.put("REMARKS", tableRs.getString("REMARKS"));
return element;
}
protected Throwable handleSQLException(SQLException e) {
// schemaRs and catalogRs are only used for error reporting if
// we get an exception
String databaseStructure = getDatabaseStructure( catalog, schema );
throw getSQLExceptionConverter().convert( e,
"Could not get list of tables from database. Probably a JDBC driver problem. "+query.toString()
+ databaseStructure, null );
}
};
} catch (SQLException e) {
// schemaRs and catalogRs are only used for error reporting if we get an exception
String databaseStructure = getDatabaseStructure(catalog,schema);
throw getSQLExceptionConverter().convert(e, "Could not get list of tables from database. Probably a JDBC driver problem. "+query.toString() + databaseStructure, null);
}
}
[java]
public Iterator getColumns(final String catalog, final String schema, final String table, String column) {
final StringBuffer query = new StringBuffer();
try {
log.debug("getColumns(" + catalog + "." + schema + "." + table + "." + column +