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

2014-11-24 10:53:15 · 作者: · 浏览: 2
")");
// Collect Columns from the 'ALL' data dicitonary table.
// A decode is used to map the type name to the JDBC Type ID
Statement stmt = this.getConnection().createStatement();


query.append("select t.column_name as COLUMN_NAME, t.owner as TABLE_SCHEM, decode(t.nullable,'N',0,1) as NULLABLE, ");
query.append("decode(t.data_type, 'FLOAT',decode(t.data_precision,null, t.data_length, t.data_precision), 'NUMBER', decode(t.data_precision,null, t.data_length, t.data_precision), t.data_length) as COLUMN_SIZE, ");
query.append("decode(t.data_type,'CHAR',1, 'DATE',91, 'FLOAT',6, 'LONG',-1, 'NUMBER',2, 'VARCHAR2',12, 'BFILE',-13, ");
query.append("'BLOB',2004, 'CLOB',2005, 'MLSLABEL',1111, 'NCHAR',1, 'NCLOB',2005, 'NVARCHAR2',12, ");
query.append("'RAW',-3, 'ROWID',1111, 'UROWID',1111, 'LONG RAW', -4, 'TIMESTAMP', 93, 'XMLTYPE',2005, 1111) as DATA_TYPE, ");
query.append("t.table_name as TABLE_NAME, t.data_type as TYPE_NAME, decode(t.data_scale, null, 0 ,data_scale) as DECIMAL_DIGITS ");
query.append(",tc.COMMENTS as REMARKS ");
query.append("from all_tab_columns t");
query.append(", USER_COL_COMMENTS tc");

query.append(" where 1=1 and t.TABLE_NAME=tc.TABLE_NAME and t.COLUMN_NAME=tc.COLUMN_NAME ");
if (schema != null || table != null || column != null)

if (schema != null) {
query.append(" and t.owner='" + schema + "' ");
}
if (table != null) {
if (schema != null)
query.append("and ");
query.append(" t.table_name = '" + table + "' ");
}
if (column != null) {
if (schema != null || table != null)
query.append("and ");
query.append(" t.column_name = '" + column + "' ");
}
query.append("order by t.column_id ");
if (log.isDebugEnabled())
log.debug("getIndexInfo Query:" + query.toString());

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

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

Map element = new HashMap();
protected Object convertRow(ResultSet rs) throws SQLException {
element.clear();
element.put("COLUMN_NAME", rs.getString(1));
element.put("TABLE_SCHEM", rs.getString(2));
element.put("NULLABLE", new Integer(rs.getInt(3)));
element.put("COLUMN_SIZE", new Integer(rs.getInt(4)));
element.put("DATA_TYPE", new Integer(rs.getInt(5)));
element.put("TABLE_NAME", rs.getString(6));
element.put("TYPE_NAME", rs.getString(7));
element.put("DECIMAL_DIGITS", new Integer(rs.getInt(8)));
element.put("TABLE_CAT", null);
element.put("REMARKS", rs.getString("REMARKS"));

return element;
}
protected Throwable handleSQLException(SQLException e) {
throw getSQLExceptionConverter().convert(e, "Error while reading column meta data for " +