use of org.sagacity.sqltoy.model.TableMeta in project sagacity-sqltoy by chenrenfei.
the class SqlServerDialectUtils method getTables.
@SuppressWarnings("unchecked")
public static List<TableMeta> getTables(String catalog, String schema, String tableName, Connection conn, Integer dbType, String dialect) throws Exception {
String sql = "select d.name TABLE_NAME, cast(isnull(f.value,'') as varchar(1000)) COMMENTS,d.xtype TABLE_TYPE" + " from syscolumns a " + " inner join sysobjects d on a.id=d.id and d.xtype in ('U','V') and d.name<>'dtproperties' " + " left join sys.extended_properties f on d.id=f.major_id and f.minor_id=0 " + " where a.colorder=1 ";
if (StringUtil.isNotBlank(tableName)) {
sql = sql.concat(" and d.name like ?");
}
PreparedStatement pst = conn.prepareStatement(sql);
ResultSet rs = null;
// 通过preparedStatementProcess反调,第二个参数是pst
return (List<TableMeta>) SqlUtil.preparedStatementProcess(null, pst, rs, new PreparedStatementResultHandler() {
@Override
public void execute(Object rowData, PreparedStatement pst, ResultSet rs) throws Exception {
if (StringUtil.isNotBlank(tableName)) {
if (tableName.contains("%")) {
pst.setString(1, tableName);
} else {
pst.setString(1, "%" + tableName + "%");
}
}
rs = pst.executeQuery();
List<TableMeta> tables = new ArrayList<TableMeta>();
while (rs.next()) {
TableMeta tableMeta = new TableMeta();
tableMeta.setTableName(rs.getString("TABLE_NAME"));
tableMeta.setType(rs.getString("TABLE_TYPE"));
if (tableMeta.getType().equals("V")) {
tableMeta.setType("VIEW");
} else {
tableMeta.setType("TABLE");
}
tableMeta.setRemarks(rs.getString("COMMENTS"));
tables.add(tableMeta);
}
this.setResult(tables);
}
});
}
use of org.sagacity.sqltoy.model.TableMeta in project sagacity-sqltoy by chenrenfei.
the class DefaultDialectUtils method getTables.
@SuppressWarnings("unchecked")
public static List<TableMeta> getTables(String catalog, String schema, String tableName, Connection conn, Integer dbType, String dialect) throws Exception {
// 可自定义 PreparedStatement pst=conn.xxx;
ResultSet rs = conn.getMetaData().getTables(catalog, schema, tableName, new String[] { "TABLE", "VIEW" });
// 通过preparedStatementProcess反调,第二个参数是pst
return (List<TableMeta>) SqlUtil.preparedStatementProcess(null, null, rs, new PreparedStatementResultHandler() {
@Override
public void execute(Object rowData, PreparedStatement pst, ResultSet rs) throws Exception {
List<TableMeta> tables = new ArrayList<TableMeta>();
while (rs.next()) {
TableMeta tableMeta = new TableMeta();
tableMeta.setTableName(rs.getString("TABLE_NAME"));
tableMeta.setSchema(rs.getString("TABLE_SCHEM"));
tableMeta.setType(rs.getString("TABLE_TYPE"));
tableMeta.setRemarks(rs.getString("REMARKS"));
tables.add(tableMeta);
}
this.setResult(tables);
}
});
}
use of org.sagacity.sqltoy.model.TableMeta in project sagacity-sqltoy by chenrenfei.
the class OracleDialectUtils method getTables.
@SuppressWarnings("unchecked")
public static List<TableMeta> getTables(String catalog, String schema, String tableName, Connection conn, Integer dbType, String dialect) throws Exception {
String sql = "select * from user_tab_comments";
if (StringUtil.isNotBlank(tableName)) {
sql = sql.concat(" where TABLE_NAME like ?");
}
PreparedStatement pst = conn.prepareStatement(sql);
ResultSet rs = null;
// 通过preparedStatementProcess反调,第二个参数是pst
return (List<TableMeta>) SqlUtil.preparedStatementProcess(null, pst, rs, new PreparedStatementResultHandler() {
@Override
public void execute(Object rowData, PreparedStatement pst, ResultSet rs) throws Exception {
if (StringUtil.isNotBlank(tableName)) {
if (tableName.contains("%")) {
pst.setString(1, tableName);
} else {
pst.setString(1, "%" + tableName + "%");
}
}
rs = pst.executeQuery();
List<TableMeta> tables = new ArrayList<TableMeta>();
while (rs.next()) {
TableMeta tableMeta = new TableMeta();
tableMeta.setTableName(rs.getString("TABLE_NAME"));
tableMeta.setType(rs.getString("TABLE_TYPE"));
tableMeta.setRemarks(rs.getString("COMMENTS"));
tables.add(tableMeta);
}
this.setResult(tables);
}
});
}
Aggregations