Skip to content

Commit

Permalink
更新1.1.1,修复oracle等部分数据库无法查询表的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfantasy committed Jun 22, 2020
1 parent fd93183 commit e56b49c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class GeberatorUIServer {
.userName("root")
.password("root")
.driverClassName("com.mysql.cj.jdbc.Driver")
//数据库schema,POSTGRE_SQL,ORACLE,DB2类型的数据库需要指定
.schemaName("myBusiness")
.basePackage("com.github.davidfantasy.mybatisplustools.example")
.port(8068)
.build();
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.github.davidfantasy</groupId>
<artifactId>mybatis-plus-generator-ui</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<modelVersion>4.0.0</modelVersion>

<name>mybatis-plus-generator-ui</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public DataSourceConfig dataSourceConfig(GeneratorConfig config) {
dataSourceConfig.setDriverName(config.getDriverClassName());
dataSourceConfig.setUsername(config.getUserName());
dataSourceConfig.setPassword(config.getPassword());
dataSourceConfig.setSchemaName(config.getSchemaName());
return dataSourceConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public class GeneratorConfig {
*/
private String jdbcUrl;

/**
* 数据库schema,POSTGRE_SQL,ORACLE,DB2类型的数据库需要指定
*/
private String schemaName;

/**
* 数据库用户名
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.github.davidfantasy.mybatisplus.generatorui.service;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.IDbQuery;
import com.github.davidfantasy.mybatisplus.generatorui.dto.TableInfo;
import com.google.common.collect.Lists;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
Expand All @@ -23,7 +25,7 @@ public class DatabaseService {

public List<TableInfo> getTablesFromDb() {
IDbQuery dbQuery = dataSourceConfig.getDbQuery();
List<Map<String, Object>> results = jdbcTemplate.queryForList(dbQuery.tablesSql());
List<Map<String, Object>> results = jdbcTemplate.queryForList(getTableSql());
List<TableInfo> tableInfos = Lists.newArrayList();
for (Map<String, Object> table : results) {
TableInfo tableInfo = new TableInfo();
Expand All @@ -34,4 +36,44 @@ public List<TableInfo> getTablesFromDb() {
return tableInfos;
}

public String getTableSql() {
String tablesSql = dataSourceConfig.getDbQuery().tablesSql();
if (DbType.POSTGRE_SQL == dataSourceConfig.getDbType()) {
String schema = dataSourceConfig.getSchemaName();
if (schema == null) {
//pg 默认 schema=public
schema = "public";
dataSourceConfig.setSchemaName(schema);
}
tablesSql = String.format(tablesSql, schema);
} else if (DbType.KINGBASE_ES == dataSourceConfig.getDbType()) {
String schema = dataSourceConfig.getSchemaName();
if (schema == null) {
//kingbase 默认 schema=PUBLIC
schema = "PUBLIC";
dataSourceConfig.setSchemaName(schema);
}
tablesSql = String.format(tablesSql, schema);
} else if (DbType.DB2 == dataSourceConfig.getDbType()) {
String schema = dataSourceConfig.getSchemaName();
if (schema == null) {
//db2 默认 schema=current schema
schema = "current schema";
dataSourceConfig.setSchemaName(schema);
}
tablesSql = String.format(tablesSql, schema);
}
//oracle数据库表太多,出现最大游标错误
else if (DbType.ORACLE == dataSourceConfig.getDbType()) {
String schema = dataSourceConfig.getSchemaName();
//oracle 默认 schema=username
if (schema == null) {
schema = dataSourceConfig.getUsername().toUpperCase();
dataSourceConfig.setSchemaName(schema);
}
tablesSql = String.format(tablesSql, schema);
}
return tablesSql;
}

}

0 comments on commit e56b49c

Please sign in to comment.