【update】注释方法

This commit is contained in:
mzc5649
2021-04-02 10:21:28 +08:00
parent 9af33335f2
commit 5761557a6f
2 changed files with 39 additions and 11 deletions
@@ -150,7 +150,9 @@ public class DbReadTableUtil {
log.debug("--------------sql-------------" + sqlStr);
ResultSet resultSet = statement.executeQuery(sqlStr);
// 游标指向结果集末尾
resultSet.last();
// 返回结果是当前数据集的行号,而不是结果的行数
row = resultSet.getRow();
if (row <= 0) {
throw new Exception("该表不存在或者表中没有字段");
@@ -177,7 +179,7 @@ public class DbReadTableUtil {
if (com.jero.codegenerate.properties.CodeConfigProperties.pageFilterFields != null) {
pageFilterFieldsStrings = com.jero.codegenerate.properties.CodeConfigProperties.pageFilterFields.toLowerCase().split(",");
}
// 字段名不等与表id名&&查询字段不包括数据库名
if (!com.jero.codegenerate.properties.CodeConfigProperties.dbTableId.equals(columnVo.getFieldName()) && !CodeStringUtils.isPageFilterFieldsContainDbName(columnVo.getFieldDbName().toLowerCase(), pageFilterFieldsStrings)) {
list.add(columnVo);
}
@@ -239,7 +241,12 @@ public class DbReadTableUtil {
return result;
}
/**
* 获取该表下原本所有列(字段)信息的集合
* @date 2021/4/2 10:02
* @param tableName
* @return java.util.List<com.jero.codegenerate.generate.pojo.ColumnVo>
*/
public static List<ColumnVo> listOriginalColumns(String tableName) throws Exception {
ResultSet resultSet = null;
String sqlStr = null;
@@ -274,7 +281,9 @@ public class DbReadTableUtil {
}
resultSet = statement.executeQuery(sqlStr);
// 游标指向结果集末尾
resultSet.last();
// 返回结果是当前数据集的行号,而不是结果的行数
row = resultSet.getRow();
if (row <= 0) {
throw new Exception("该表不存在或者表中没有字段");
@@ -356,7 +365,7 @@ public class DbReadTableUtil {
return result;
}
/**
* 该方法暂未用到
* 查询是否该表不存在或没有字段
* @date 2021/4/2 9:18
* @param tableName
* @return boolean
@@ -376,21 +385,23 @@ public class DbReadTableUtil {
// mysql获取表的列信息sql
sqlStr = "select column_name,data_type,column_comment,0,0 from information_schema.columns where table_name = '" + tableName + "' and table_schema = '" + catalog + "'";
}
// oracle获取表的列信息sql
if (com.jero.codegenerate.properties.CodeConfigProperties.databaseType.equals(DbConvertDef.ORACLE)) {
sqlStr = "select colstable.column_name column_name, colstable.data_type data_type, commentstable.comments column_comment from user_tab_cols colstable inner join user_col_comments commentstable on colstable.column_name = commentstable.column_name where colstable.table_name = commentstable.table_name and colstable.table_name = '" + tableName.toUpperCase() + "'";
}
// postgresql获取表的列信息sql
if (com.jero.codegenerate.properties.CodeConfigProperties.databaseType.equals(DbConvertDef.POSTGRESQL)) {
sqlStr = MessageFormat.format("select icm.column_name as field,icm.udt_name as type,fieldtxt.descript as comment, icm.numeric_precision_radix as column_precision ,icm.numeric_scale as column_scale ,icm.character_maximum_length as Char_Length,icm.is_nullable as attnotnull from information_schema.columns icm, (SELECT A.attnum,( SELECT description FROM pg_catalog.pg_description WHERE objoid = A.attrelid AND objsubid = A.attnum ) AS descript,A.attname FROM\tpg_catalog.pg_attribute A WHERE A.attrelid = ( SELECT oid FROM pg_class WHERE relname = {0} ) AND A.attnum > 0 AND NOT A.attisdropped ORDER BY\tA.attnum ) fieldtxt where icm.table_name={1} and fieldtxt.attname = icm.column_name", TableConvert.c(tableName), TableConvert.c(tableName));
sqlStr = MessageFormat.format(DbConvertDef.POSTGRESQL_ALLCOLUMNS_SQL, TableConvert.c(tableName), TableConvert.c(tableName));
}
// sqlserver获取表的列信息sql
if (com.jero.codegenerate.properties.CodeConfigProperties.databaseType.equals(DbConvertDef.SQLSERVER)) {
sqlStr = MessageFormat.format("select distinct cast(a.name as varchar(50)) column_name, cast(b.name as varchar(50)) data_type, cast(e.value as NVARCHAR(200)) comment, cast(ColumnProperty(a.object_id,a.Name,'''Precision''') as int) num_precision, cast(ColumnProperty(a.object_id,a.Name,'''Scale''') as int) num_scale, a.max_length, (case when a.is_nullable=1 then '''y''' else '''n''' end) nullable,column_id from sys.columns a left join sys.types b on a.user_type_id=b.user_type_id left join (select top 1 * from sys.objects where type = '''U''' and name ={0} order by name) c on a.object_id=c.object_id left join sys.extended_properties e on e.major_id=c.object_id and e.minor_id=a.column_id and e.class=1 where c.name={0} order by a.column_id", TableConvert.c(tableName));
sqlStr = MessageFormat.format(DbConvertDef.SQLSERVER_ALLCOLUMNS_SQL, TableConvert.c(tableName));
}
ResultSet resultSet = statement.executeQuery(sqlStr);
// 游标指向结果集末尾
resultSet.last();
// 返回结果是当前数据集的行号,而不是结果的行数
int row = resultSet.getRow();
return row > 0;
} catch (Exception e) {
@@ -398,7 +409,12 @@ public class DbReadTableUtil {
return false;
}
}
/**
* 转换字段名破折号间隔命名为驼峰命名
* @date 2021/4/2 9:35
* @param fieldName 字段名
* @return java.lang.String
*/
private static String convertFieldNameToCamelCase(String fieldName) {
String[] fieldNameArray = fieldName.split("_");
fieldName = "";
@@ -36,7 +36,13 @@ public class CodeStringUtils {
public static Integer checkIntegerAndGet(Integer var0) {
return var0 == null ? 0 : var0;
}
/**
* 是否查询字段数组包含数据库名
* @date 2021/4/2 9:48
* @param dbName 数据库名
* @param pageFilterFieldsStrings 查询字段数组
* @return boolean
*/
public static boolean isPageFilterFieldsContainDbName(String dbName, String[] pageFilterFieldsStrings) {
if (pageFilterFieldsStrings != null && pageFilterFieldsStrings.length != 0) {
for(int i = 0; i < pageFilterFieldsStrings.length; ++i) {
@@ -51,7 +57,13 @@ public class CodeStringUtils {
return false;
}
}
/**
* 字符串集合是否包含目标字符串
* @date 2021/4/2 10:18
* @param target
* @param stringList
* @return boolean
*/
public static boolean isListContainString(String target, List<String> stringList) {
String[] stringArray = new String[0];
if (stringList != null) {