增加 DatabaseTableOracleDAOImpl 实现
parent
3950c58c18
commit
6b68aa95fe
|
@ -25,6 +25,11 @@ public class DatabaseColumnDO {
|
||||||
/**
|
/**
|
||||||
* 字段类型
|
* 字段类型
|
||||||
*/
|
*/
|
||||||
|
private String dataType;
|
||||||
|
/**
|
||||||
|
* 字段类型
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
private String columnType;
|
private String columnType;
|
||||||
/**
|
/**
|
||||||
* 字段描述
|
* 字段描述
|
||||||
|
|
|
@ -41,11 +41,10 @@ public class DatabaseTableMySQLDAOImpl implements DatabaseTableDAO {
|
||||||
@Override
|
@Override
|
||||||
public List<DatabaseColumnDO> selectColumnList(Connection connection, String tableName) {
|
public List<DatabaseColumnDO> selectColumnList(Connection connection, String tableName) {
|
||||||
// 拼接 SQL
|
// 拼接 SQL
|
||||||
String sql = "SELECT table_name, column_name, column_type, column_comment, " +
|
String sql = "SELECT table_name, column_name, column_type, column_comment, ordinal_position" +
|
||||||
" (CASE WHEN is_nullable = 'yes' THEN '1' ELSE '0' END) AS nullable," +
|
" (CASE WHEN is_nullable = 'yes' THEN '1' ELSE '0' END) AS nullable," +
|
||||||
" (CASE WHEN column_key = 'PRI' THEN '1' ELSE '0' END) AS primary_key," +
|
" (CASE WHEN column_key = 'PRI' THEN '1' ELSE '0' END) AS primary_key," +
|
||||||
" (CASE WHEN extra = 'auto_increment' THEN '1' ELSE '0' END) AS auto_increment," +
|
" (CASE WHEN extra = 'auto_increment' THEN '1' ELSE '0' END) AS auto_increment," +
|
||||||
" ordinal_position" +
|
|
||||||
" FROM information_schema.COLUMNS" +
|
" FROM information_schema.COLUMNS" +
|
||||||
" WHERE table_schema = (SELECT DATABASE())" +
|
" WHERE table_schema = (SELECT DATABASE())" +
|
||||||
String.format(" AND table_name = '%s'", tableName);
|
String.format(" AND table_name = '%s'", tableName);
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
package cn.iocoder.yudao.module.infra.dal.mysql.db;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils;
|
||||||
|
import cn.iocoder.yudao.module.infra.dal.dataobject.db.DatabaseColumnDO;
|
||||||
|
import cn.iocoder.yudao.module.infra.dal.dataobject.db.DatabaseTableDO;
|
||||||
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link DatabaseTableDAO} 的 Oracle 实现类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public class DatabaseTableOracleDAOImpl implements DatabaseTableDAO {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DatabaseTableDO> selectTableList(Connection connection, String tableNameLike, String tableCommentLike) {
|
||||||
|
// 拼接 SQL
|
||||||
|
String sql = "SELECT tbl.table_name, col.comments, obj.created" +
|
||||||
|
" FROM user_tables tbl, user_tab_comments col, user_objects obj" +
|
||||||
|
" WHERE tbl.table_name = col.table_name" +
|
||||||
|
" AND tbl.table_name = obj.object_name" +
|
||||||
|
" AND obj.object_type = 'TABLE'";
|
||||||
|
if (StrUtil.isNotEmpty(tableNameLike)) {
|
||||||
|
sql += StrUtil.format(" AND tbl.table_name LIKE '%{}%'", tableNameLike);
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotEmpty(tableCommentLike)) {
|
||||||
|
sql += StrUtil.format(" AND col.comments LIKE '%{}%'", tableCommentLike);
|
||||||
|
}
|
||||||
|
// 执行并返回结果
|
||||||
|
return JdbcUtils.query(connection, sql, (rs, rowNum) -> DatabaseTableDO.builder()
|
||||||
|
.tableName(rs.getString("table_name"))
|
||||||
|
.tableComment(rs.getString("comments"))
|
||||||
|
.createTime(rs.getDate("created"))
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DatabaseColumnDO> selectColumnList(Connection connection, String tableName) {
|
||||||
|
// 拼接 SQL
|
||||||
|
String sql = String.format("SELECT table_name, column_name, data_type, comments, column_id," +
|
||||||
|
" (CASE WHEN nullable = 'Y' THEN '1' ELSE '0' END) AS nullable," +
|
||||||
|
" (CASE WHEN constraint_type = 'P' THEN '1' ELSE '0' END) AS primary_key" +
|
||||||
|
" FROM" +
|
||||||
|
" (" +
|
||||||
|
" SELECT col.*, comments, constraint_type," +
|
||||||
|
" row_number ( ) over ( partition BY col.column_name ORDER BY constraint_type DESC ) AS row_flag" +
|
||||||
|
" FROM user_tab_columns col" +
|
||||||
|
" LEFT JOIN user_col_comments ON user_col_comments.table_name = col.table_name" +
|
||||||
|
" AND user_col_comments.column_name = col.column_name" +
|
||||||
|
" LEFT JOIN user_cons_columns ON user_cons_columns.table_name = col.table_name" +
|
||||||
|
" AND user_cons_columns.column_name = col.column_name" +
|
||||||
|
" LEFT JOIN user_constraints ON user_constraints.constraint_name = user_cons_columns.constraint_name" +
|
||||||
|
" WHERE col.table_name = '%s'" +
|
||||||
|
" )" +
|
||||||
|
"WHERE row_flag = 1", tableName);
|
||||||
|
// 执行并返回结果
|
||||||
|
return JdbcUtils.query(connection, sql, (rs, rowNum) -> DatabaseColumnDO.builder()
|
||||||
|
.tableName(rs.getString("table_name"))
|
||||||
|
.columnName(rs.getString("column_name"))
|
||||||
|
.dataType(rs.getString("data_type"))
|
||||||
|
.columnComment(rs.getString("comments"))
|
||||||
|
.nullable(rs.getBoolean("nullable"))
|
||||||
|
.primaryKey(rs.getBoolean("primary_key"))
|
||||||
|
.autoIncrement(false) // TODO 芋艿:oracle???
|
||||||
|
.ordinalPosition(rs.getInt("column_id"))
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DbType getType() {
|
||||||
|
return DbType.ORACLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -101,8 +101,8 @@ public class CodegenServiceImpl implements CodegenService {
|
||||||
@Override
|
@Override
|
||||||
public Long createCodegen(Long userId, String tableName) {
|
public Long createCodegen(Long userId, String tableName) {
|
||||||
// 从数据库中,获得数据库表结构
|
// 从数据库中,获得数据库表结构
|
||||||
DatabaseTableDO schemaTable = databaseTableService.getTable(0L, tableName);
|
DatabaseTableDO schemaTable = databaseTableService.getTable(9L, tableName);
|
||||||
List<DatabaseColumnDO> schemaColumns = databaseTableService.getColumnList(0L, tableName);
|
List<DatabaseColumnDO> schemaColumns = databaseTableService.getColumnList(9L, tableName);
|
||||||
// 导入
|
// 导入
|
||||||
return this.createCodegen0(userId, CodegenImportTypeEnum.DB, schemaTable, schemaColumns);
|
return this.createCodegen0(userId, CodegenImportTypeEnum.DB, schemaTable, schemaColumns);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@ -85,7 +84,10 @@ public class DataSourceConfigServiceImpl implements DataSourceConfigService {
|
||||||
}
|
}
|
||||||
// 从 DB 中读取
|
// 从 DB 中读取
|
||||||
DataSourceConfigDO dataSourceConfig = dataSourceConfigMapper.selectById(id);
|
DataSourceConfigDO dataSourceConfig = dataSourceConfigMapper.selectById(id);
|
||||||
|
try {
|
||||||
dataSourceConfig.setPassword(stringEncryptor.decrypt(dataSourceConfig.getPassword()));
|
dataSourceConfig.setPassword(stringEncryptor.decrypt(dataSourceConfig.getPassword()));
|
||||||
|
} catch (Exception ignore) { // 解码失败,则不解码
|
||||||
|
}
|
||||||
return dataSourceConfig;
|
return dataSourceConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue