mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
fix: codegen can not get oracle comments
This commit is contained in:
parent
a6f5d09acd
commit
ed32e8c569
@ -107,7 +107,7 @@ public class Generator {
|
|||||||
|
|
||||||
buildPrimaryKey(table);
|
buildPrimaryKey(table);
|
||||||
|
|
||||||
dialect.buildTableColumns(table, globalConfig, dbMeta, conn);
|
dialect.buildTableColumns(schemaName,table, globalConfig, dbMeta, conn);
|
||||||
|
|
||||||
tables.add(table);
|
tables.add(table);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,6 +62,11 @@ public interface IDialect {
|
|||||||
public ResultSet getTablesResultSet(DatabaseMetaData dbMeta, Connection conn, String schema, String[] types) throws SQLException {
|
public ResultSet getTablesResultSet(DatabaseMetaData dbMeta, Connection conn, String schema, String[] types) throws SQLException {
|
||||||
return dbMeta.getTables(conn.getCatalog(), StringUtil.isNotBlank(schema) ? schema : dbMeta.getUserName(), null, types);
|
return dbMeta.getTables(conn.getCatalog(), StringUtil.isNotBlank(schema) ? schema : dbMeta.getUserName(), null, types);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ResultSet forRemarks(String schema, Table table, DatabaseMetaData dbMeta, Connection conn) throws SQLException {
|
||||||
|
return dbMeta.getColumns(conn.getCatalog(), StringUtil.isNotBlank(schema) ? schema : dbMeta.getUserName(), table.getName(), null);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,13 +77,14 @@ public interface IDialect {
|
|||||||
/**
|
/**
|
||||||
* 构建表和列的信息。
|
* 构建表和列的信息。
|
||||||
*
|
*
|
||||||
|
* @param schemaName
|
||||||
* @param table 存入的表对象
|
* @param table 存入的表对象
|
||||||
* @param globalConfig 全局配置
|
* @param globalConfig 全局配置
|
||||||
* @param dbMeta 数据库元数据
|
* @param dbMeta 数据库元数据
|
||||||
* @param conn 连接
|
* @param conn 连接
|
||||||
* @throws SQLException 发生 SQL 异常时抛出
|
* @throws SQLException 发生 SQL 异常时抛出
|
||||||
*/
|
*/
|
||||||
void buildTableColumns(Table table, GlobalConfig globalConfig, DatabaseMetaData dbMeta, Connection conn) throws SQLException;
|
void buildTableColumns(String schemaName, Table table, GlobalConfig globalConfig, DatabaseMetaData dbMeta, Connection conn) throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取表的描述信息。
|
* 获取表的描述信息。
|
||||||
|
|||||||
@ -29,8 +29,8 @@ import java.util.Map;
|
|||||||
public abstract class JdbcDialect implements IDialect {
|
public abstract class JdbcDialect implements IDialect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void buildTableColumns(Table table, GlobalConfig globalConfig, DatabaseMetaData dbMeta, Connection conn) throws SQLException {
|
public void buildTableColumns(String schemaName, Table table, GlobalConfig globalConfig, DatabaseMetaData dbMeta, Connection conn) throws SQLException {
|
||||||
Map<String, String> columnRemarks = buildColumnRemarks(table, dbMeta, conn);
|
Map<String, String> columnRemarks = buildColumnRemarks(schemaName,table, dbMeta, conn);
|
||||||
|
|
||||||
String sql = forBuildColumnsSql(table.getSchema(), table.getName());
|
String sql = forBuildColumnsSql(table.getSchema(), table.getName());
|
||||||
try (Statement stm = conn.createStatement(); ResultSet rs = stm.executeQuery(sql)) {
|
try (Statement stm = conn.createStatement(); ResultSet rs = stm.executeQuery(sql)) {
|
||||||
@ -55,9 +55,9 @@ public abstract class JdbcDialect implements IDialect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> buildColumnRemarks(Table table, DatabaseMetaData dbMeta, Connection conn) {
|
private Map<String, String> buildColumnRemarks(String schemaName, Table table, DatabaseMetaData dbMeta, Connection conn) {
|
||||||
Map<String, String> columnRemarks = new HashMap<>();
|
Map<String, String> columnRemarks = new HashMap<>();
|
||||||
try (ResultSet colRs = dbMeta.getColumns(conn.getCatalog(), null, table.getName(), null)) {
|
try (ResultSet colRs = forRemarks(schemaName,table, dbMeta, conn)) {
|
||||||
while (colRs.next()) {
|
while (colRs.next()) {
|
||||||
columnRemarks.put(colRs.getString("COLUMN_NAME"), colRs.getString("REMARKS"));
|
columnRemarks.put(colRs.getString("COLUMN_NAME"), colRs.getString("REMARKS"));
|
||||||
}
|
}
|
||||||
@ -67,6 +67,7 @@ public abstract class JdbcDialect implements IDialect {
|
|||||||
return columnRemarks;
|
return columnRemarks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSet getTablesResultSet(DatabaseMetaData dbMeta, Connection conn, String schema, String[] types) throws SQLException {
|
public ResultSet getTablesResultSet(DatabaseMetaData dbMeta, Connection conn, String schema, String[] types) throws SQLException {
|
||||||
return dbMeta.getTables(conn.getCatalog(), schema, null, types);
|
return dbMeta.getTables(conn.getCatalog(), schema, null, types);
|
||||||
@ -81,4 +82,23 @@ public abstract class JdbcDialect implements IDialect {
|
|||||||
*/
|
*/
|
||||||
abstract String forBuildColumnsSql(String schema, String tableName);
|
abstract String forBuildColumnsSql(String schema, String tableName);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建 remarks 的 ResultSet
|
||||||
|
*
|
||||||
|
* @param schemaName
|
||||||
|
* @param table
|
||||||
|
* @param dbMeta
|
||||||
|
* @param conn
|
||||||
|
* @return
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
protected ResultSet forRemarks(String schemaName, Table table, DatabaseMetaData dbMeta, Connection conn) throws SQLException {
|
||||||
|
return dbMeta.getColumns(conn.getCatalog(), null, table.getName(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,7 +29,7 @@ import java.sql.*;
|
|||||||
public class SqliteDialect implements IDialect {
|
public class SqliteDialect implements IDialect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void buildTableColumns(Table table, GlobalConfig globalConfig, DatabaseMetaData dbMeta, Connection conn) throws SQLException {
|
public void buildTableColumns(String schemaName, Table table, GlobalConfig globalConfig, DatabaseMetaData dbMeta, Connection conn) throws SQLException {
|
||||||
Statement statement = conn.createStatement();
|
Statement statement = conn.createStatement();
|
||||||
ResultSet rs = statement.executeQuery("pragma table_info(" + table.getName() + ")");
|
ResultSet rs = statement.executeQuery("pragma table_info(" + table.getName() + ")");
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user