diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/metadata/ColumnLength.java b/screw-core/src/main/java/cn/smallbun/screw/core/metadata/ColumnLength.java new file mode 100644 index 0000000..b598355 --- /dev/null +++ b/screw-core/src/main/java/cn/smallbun/screw/core/metadata/ColumnLength.java @@ -0,0 +1,32 @@ +package cn.smallbun.screw.core.metadata; + +import java.io.Serializable; + +/** + * 列长度 + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/8/25 10:53 + */ +public interface ColumnLength extends Serializable { + /** + * 表名 + * + * @return {@link String} + */ + String getTableName(); + + /** + * 列名 + * + * @return {@link String} + */ + String getColumnName(); + + /** + * 列长度 + * + * @return {@link String} + */ + String getColumnLength(); +} diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/metadata/model/ColumnModel.java b/screw-core/src/main/java/cn/smallbun/screw/core/metadata/model/ColumnModel.java index e5a73c9..fc23f1a 100644 --- a/screw-core/src/main/java/cn/smallbun/screw/core/metadata/model/ColumnModel.java +++ b/screw-core/src/main/java/cn/smallbun/screw/core/metadata/model/ColumnModel.java @@ -62,14 +62,9 @@ public class ColumnModel implements Serializable { */ private String typeName; /** - * 列表示给定列的指定列大小。 - * 对于数值数据,这是最大精度。 - * 对于字符数据,这是字符长度。 - * 对于日期时间数据类型,这是 String 表示形式的字符长度(假定允许的最大小数秒组件的精度)。 - * 对于二进制数据,这是字节长度。 - * 对于 ROWID 数据类型,这是字节长度。对于列大小不适用的数据类型,则返回 Null。 + * 列长度 */ - private String columnSize; + private String columnLength; /** * 小数位 */ diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/process/AbstractProcess.java b/screw-core/src/main/java/cn/smallbun/screw/core/process/AbstractProcess.java index cf78fe8..981b753 100644 --- a/screw-core/src/main/java/cn/smallbun/screw/core/process/AbstractProcess.java +++ b/screw-core/src/main/java/cn/smallbun/screw/core/process/AbstractProcess.java @@ -20,6 +20,7 @@ package cn.smallbun.screw.core.process; import cn.smallbun.screw.core.Configuration; import cn.smallbun.screw.core.engine.EngineFileType; import cn.smallbun.screw.core.metadata.Column; +import cn.smallbun.screw.core.metadata.ColumnLength; import cn.smallbun.screw.core.metadata.PrimaryKey; import cn.smallbun.screw.core.metadata.Table; import cn.smallbun.screw.core.metadata.model.ColumnModel; @@ -50,20 +51,24 @@ public abstract class AbstractProcess implements Process { /** * LOGGER */ - final Logger logger = LoggerFactory + final Logger logger = LoggerFactory .getLogger(this.getClass()); /** * 表信息缓存 */ - volatile Map> tablesCaching = new ConcurrentHashMap<>(); + volatile Map> tablesCaching = new ConcurrentHashMap<>(); /** * 列信息缓存 */ - volatile Map> columnsCaching = new ConcurrentHashMap<>(); + volatile Map> columnsCaching = new ConcurrentHashMap<>(); /** * 主键信息缓存 */ - volatile Map> primaryKeysCaching = new ConcurrentHashMap<>(); + volatile Map> primaryKeysCaching = new ConcurrentHashMap<>(); + /** + * 列长度信息缓存 + */ + volatile Map> columnLengthsCaching = new ConcurrentHashMap<>(); /** * Configuration diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/process/DataModelProcess.java b/screw-core/src/main/java/cn/smallbun/screw/core/process/DataModelProcess.java index 29d876e..4abc6b6 100644 --- a/screw-core/src/main/java/cn/smallbun/screw/core/process/DataModelProcess.java +++ b/screw-core/src/main/java/cn/smallbun/screw/core/process/DataModelProcess.java @@ -18,15 +18,13 @@ package cn.smallbun.screw.core.process; import cn.smallbun.screw.core.Configuration; -import cn.smallbun.screw.core.metadata.Column; -import cn.smallbun.screw.core.metadata.Database; -import cn.smallbun.screw.core.metadata.PrimaryKey; -import cn.smallbun.screw.core.metadata.Table; +import cn.smallbun.screw.core.metadata.*; import cn.smallbun.screw.core.metadata.model.ColumnModel; import cn.smallbun.screw.core.metadata.model.DataModel; import cn.smallbun.screw.core.metadata.model.TableModel; import cn.smallbun.screw.core.query.DatabaseQuery; import cn.smallbun.screw.core.query.DatabaseQueryFactory; +import cn.smallbun.screw.core.util.CollectionUtils; import cn.smallbun.screw.core.util.StringUtils; import java.util.ArrayList; @@ -87,8 +85,10 @@ public class DataModelProcess extends AbstractProcess { //获取全部列 start = System.currentTimeMillis(); List columns = query.getTableColumns(); + //获取列长度 + List lengths = query.getColumnLength(); logger.debug("query the column time consuming:{}ms", (System.currentTimeMillis() - start)); - //根据表名获取主键 + //获取主键 start = System.currentTimeMillis(); List primaryKeys = query.getPrimaryKeys(); logger.debug("query the primary key time consuming:{}ms", @@ -108,6 +108,10 @@ public class DataModelProcess extends AbstractProcess { primaryKeysCaching.put(table.getTableName(), primaryKeys.stream().filter(i -> i.getTableName().equals(table.getTableName())) .collect(Collectors.toList())); + //处理列长度 + columnLengthsCaching.put(table.getTableName(), + lengths.stream().filter(i -> i.getTableName().equals(table.getTableName())) + .collect(Collectors.toList())); } for (Table table : tables) { /*封装数据开始*/ @@ -120,11 +124,22 @@ public class DataModelProcess extends AbstractProcess { tableModels.add(tableModel); //处理列 List columnModels = new ArrayList<>(); - //处理主键 - List keyList = primaryKeysCaching.get(table.getTableName()).stream() + //获取主键 + List key = primaryKeysCaching.get(table.getTableName()).stream() .map(PrimaryKey::getColumnName).collect(Collectors.toList()); + //获取列长度 + List columnLengths = new ArrayList<>( + columnLengthsCaching.get(table.getTableName())); for (Column column : columnsCaching.get(table.getTableName())) { - packageColumn(columnModels, keyList, column); + //获取列长度 + List lengthList = columnLengths.stream() + .filter(i -> i.getColumnName().equals(column.getColumnName())) + .map(ColumnLength::getColumnLength).collect(Collectors.toList()); + String length = ""; + if (CollectionUtils.isNotEmpty(lengthList)) { + length = lengthList.get(0); + } + packageColumn(columnModels, key, length, column); } //放入列 tableModel.setColumns(columnModels); @@ -143,10 +158,11 @@ public class DataModelProcess extends AbstractProcess { * packageColumn * @param columnModels {@link List} * @param keyList {@link List} + * @param columnLength {@link String} 列长度 * @param column {@link Column} */ private void packageColumn(List columnModels, List keyList, - Column column) { + String columnLength, Column column) { ColumnModel columnModel = new ColumnModel(); //表中的列的索引(从 1 开始) columnModel.setOrdinalPosition(column.getOrdinalPosition()); @@ -155,7 +171,7 @@ public class DataModelProcess extends AbstractProcess { //类型 columnModel.setTypeName(column.getTypeName().toLowerCase()); //指定列大小 - columnModel.setColumnSize(column.getColumnSize()); + columnModel.setColumnLength(columnLength); //小数位 columnModel.setDecimalDigits( StringUtils.defaultString(column.getDecimalDigits(), ZERO_DECIMAL_DIGITS)); diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/query/AbstractDatabaseQuery.java b/screw-core/src/main/java/cn/smallbun/screw/core/query/AbstractDatabaseQuery.java index d51b189..fc1d128 100644 --- a/screw-core/src/main/java/cn/smallbun/screw/core/query/AbstractDatabaseQuery.java +++ b/screw-core/src/main/java/cn/smallbun/screw/core/query/AbstractDatabaseQuery.java @@ -18,6 +18,7 @@ package cn.smallbun.screw.core.query; import cn.smallbun.screw.core.exception.QueryException; +import cn.smallbun.screw.core.metadata.ColumnLength; import cn.smallbun.screw.core.metadata.PrimaryKey; import cn.smallbun.screw.core.util.Assert; import cn.smallbun.screw.core.util.ExceptionUtils; @@ -189,4 +190,15 @@ public abstract class AbstractDatabaseQuery implements DatabaseQuery { public List getPrimaryKeys() throws QueryException { throw ExceptionUtils.mpe(NOT_SUPPORTED); } + + /** + * 获取列长度 + * + * @return {@link List} + * @throws QueryException QueryException + */ + @Override + public List getColumnLength() throws QueryException { + throw ExceptionUtils.mpe(NOT_SUPPORTED); + } } diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/query/DatabaseQuery.java b/screw-core/src/main/java/cn/smallbun/screw/core/query/DatabaseQuery.java index e5e54c4..a4971f2 100644 --- a/screw-core/src/main/java/cn/smallbun/screw/core/query/DatabaseQuery.java +++ b/screw-core/src/main/java/cn/smallbun/screw/core/query/DatabaseQuery.java @@ -18,10 +18,7 @@ package cn.smallbun.screw.core.query; import cn.smallbun.screw.core.exception.QueryException; -import cn.smallbun.screw.core.metadata.Column; -import cn.smallbun.screw.core.metadata.Database; -import cn.smallbun.screw.core.metadata.PrimaryKey; -import cn.smallbun.screw.core.metadata.Table; +import cn.smallbun.screw.core.metadata.*; import java.io.Serializable; import java.util.List; @@ -77,10 +74,18 @@ public interface DatabaseQuery extends Serializable { List getPrimaryKeys(String table) throws QueryException; /** - * 根据表名获取主键 + * 获取主键 * * @return {@link List} * @throws QueryException QueryException */ List getPrimaryKeys() throws QueryException; + + /** + * 获取列长度 + * + * @return {@link List} + * @throws QueryException QueryException + */ + List getColumnLength() throws QueryException; } diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/query/cachedb/CacheDbDataBaseQuery.java b/screw-core/src/main/java/cn/smallbun/screw/core/query/cachedb/CacheDbDataBaseQuery.java index 0562fef..8f94a0f 100644 --- a/screw-core/src/main/java/cn/smallbun/screw/core/query/cachedb/CacheDbDataBaseQuery.java +++ b/screw-core/src/main/java/cn/smallbun/screw/core/query/cachedb/CacheDbDataBaseQuery.java @@ -24,10 +24,7 @@ import cn.smallbun.screw.core.metadata.Database; import cn.smallbun.screw.core.metadata.PrimaryKey; import cn.smallbun.screw.core.metadata.Table; import cn.smallbun.screw.core.query.AbstractDatabaseQuery; -import cn.smallbun.screw.core.query.cachedb.model.CacheDbColumnModel; -import cn.smallbun.screw.core.query.cachedb.model.CacheDbDatabaseModel; -import cn.smallbun.screw.core.query.cachedb.model.CacheDbPrimaryKeyModel; -import cn.smallbun.screw.core.query.cachedb.model.CacheDbTableModel; +import cn.smallbun.screw.core.query.cachedb.model.*; import cn.smallbun.screw.core.util.Assert; import cn.smallbun.screw.core.util.ExceptionUtils; import cn.smallbun.screw.core.util.JdbcUtils; @@ -35,6 +32,7 @@ import cn.smallbun.screw.core.util.JdbcUtils; import javax.sql.DataSource; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import static cn.smallbun.screw.core.constant.DefaultConstants.PERCENT_SIGN; @@ -171,4 +169,15 @@ public class CacheDbDataBaseQuery extends AbstractDatabaseQuery { JdbcUtils.close(resultSet); } } + + /** + * 获取列长度 + * + * @return {@link List} + * @throws QueryException QueryException + */ + @Override + public List getColumnLength() throws QueryException { + return new ArrayList<>(); + } } diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/query/cachedb/model/CacheDbColumnLengthModel.java b/screw-core/src/main/java/cn/smallbun/screw/core/query/cachedb/model/CacheDbColumnLengthModel.java new file mode 100644 index 0000000..9894ebe --- /dev/null +++ b/screw-core/src/main/java/cn/smallbun/screw/core/query/cachedb/model/CacheDbColumnLengthModel.java @@ -0,0 +1,28 @@ +package cn.smallbun.screw.core.query.cachedb.model; + +import cn.smallbun.screw.core.metadata.ColumnLength; +import lombok.Data; + +/** + * CacheDB 列长度 + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/8/25 11:01 + */ +@Data +public class CacheDbColumnLengthModel implements ColumnLength { + /** + * 表名 + */ + private String tableName; + + /** + * 列名 + */ + private String columnName; + + /** + * 列长度 + */ + private String columnLength; +} diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/query/mariadb/MariaDbDataBaseQuery.java b/screw-core/src/main/java/cn/smallbun/screw/core/query/mariadb/MariaDbDataBaseQuery.java index 70dcbae..069d5d7 100644 --- a/screw-core/src/main/java/cn/smallbun/screw/core/query/mariadb/MariaDbDataBaseQuery.java +++ b/screw-core/src/main/java/cn/smallbun/screw/core/query/mariadb/MariaDbDataBaseQuery.java @@ -23,10 +23,7 @@ import cn.smallbun.screw.core.metadata.Column; import cn.smallbun.screw.core.metadata.Database; import cn.smallbun.screw.core.metadata.PrimaryKey; import cn.smallbun.screw.core.query.AbstractDatabaseQuery; -import cn.smallbun.screw.core.query.mariadb.model.MariadbColumnModel; -import cn.smallbun.screw.core.query.mariadb.model.MariadbDatabaseModel; -import cn.smallbun.screw.core.query.mariadb.model.MariadbPrimaryKeyModel; -import cn.smallbun.screw.core.query.mariadb.model.MariadbTableModel; +import cn.smallbun.screw.core.query.mariadb.model.*; import cn.smallbun.screw.core.util.Assert; import cn.smallbun.screw.core.util.ExceptionUtils; import cn.smallbun.screw.core.util.JdbcUtils; @@ -34,6 +31,7 @@ import cn.smallbun.screw.core.util.JdbcUtils; import javax.sql.DataSource; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import static cn.smallbun.screw.core.constant.DefaultConstants.PERCENT_SIGN; @@ -167,4 +165,15 @@ public class MariaDbDataBaseQuery extends AbstractDatabaseQuery { JdbcUtils.close(resultSet); } } + + /** + * 获取列长度 + * + * @return {@link List} + * @throws QueryException QueryException + */ + @Override + public List getColumnLength() throws QueryException { + return new ArrayList<>(); + } } diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/query/mariadb/model/MariadbColumnLengthModel.java b/screw-core/src/main/java/cn/smallbun/screw/core/query/mariadb/model/MariadbColumnLengthModel.java new file mode 100644 index 0000000..9a7b984 --- /dev/null +++ b/screw-core/src/main/java/cn/smallbun/screw/core/query/mariadb/model/MariadbColumnLengthModel.java @@ -0,0 +1,28 @@ +package cn.smallbun.screw.core.query.mariadb.model; + +import cn.smallbun.screw.core.metadata.ColumnLength; +import lombok.Data; + +/** + * mariadb 列长度 + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/8/25 10:56 + */ +@Data +public class MariadbColumnLengthModel implements ColumnLength { + /** + * 表名 + */ + private String tableName; + + /** + * 列名 + */ + private String columnName; + + /** + * 列长度 + */ + private String columnLength; +} diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/query/mysql/MySqlDataBaseQuery.java b/screw-core/src/main/java/cn/smallbun/screw/core/query/mysql/MySqlDataBaseQuery.java index 0ba6c81..fb563f9 100644 --- a/screw-core/src/main/java/cn/smallbun/screw/core/query/mysql/MySqlDataBaseQuery.java +++ b/screw-core/src/main/java/cn/smallbun/screw/core/query/mysql/MySqlDataBaseQuery.java @@ -23,10 +23,7 @@ import cn.smallbun.screw.core.metadata.Column; import cn.smallbun.screw.core.metadata.Database; import cn.smallbun.screw.core.metadata.PrimaryKey; import cn.smallbun.screw.core.query.AbstractDatabaseQuery; -import cn.smallbun.screw.core.query.mysql.model.MySqlColumnModel; -import cn.smallbun.screw.core.query.mysql.model.MySqlDatabaseModel; -import cn.smallbun.screw.core.query.mysql.model.MySqlPrimaryKeyModel; -import cn.smallbun.screw.core.query.mysql.model.MySqlTableModel; +import cn.smallbun.screw.core.query.mysql.model.*; import cn.smallbun.screw.core.util.Assert; import cn.smallbun.screw.core.util.ExceptionUtils; import cn.smallbun.screw.core.util.JdbcUtils; @@ -34,6 +31,7 @@ import cn.smallbun.screw.core.util.JdbcUtils; import javax.sql.DataSource; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import static cn.smallbun.screw.core.constant.DefaultConstants.PERCENT_SIGN; @@ -171,4 +169,27 @@ public class MySqlDataBaseQuery extends AbstractDatabaseQuery { JdbcUtils.close(resultSet); } } + + /** + * 获取列长度 + * + * @return {@link List} + * @throws QueryException QueryException + */ + @Override + public List getColumnLength() throws QueryException { + ResultSet resultSet = null; + try { + // 由于单条循环查询存在性能问题,所以这里通过自定义SQL查询数据库主键信息 + String sql = "SELECT A.TABLE_NAME, A.COLUMN_NAME, A.COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS A WHERE A.TABLE_SCHEMA = '%s' ORDER BY A.COLUMN_NAME"; + // 拼接参数 + resultSet = prepareStatement(String.format(sql, getDataBase().getDatabase())) + .executeQuery(); + return Mapping.convertList(resultSet, MySqlColumnLengthModel.class); + } catch (SQLException e) { + throw new QueryException(e); + } finally { + JdbcUtils.close(resultSet); + } + } } \ No newline at end of file diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/query/mysql/model/MySqlColumnLengthModel.java b/screw-core/src/main/java/cn/smallbun/screw/core/query/mysql/model/MySqlColumnLengthModel.java new file mode 100644 index 0000000..961d0e0 --- /dev/null +++ b/screw-core/src/main/java/cn/smallbun/screw/core/query/mysql/model/MySqlColumnLengthModel.java @@ -0,0 +1,48 @@ +package cn.smallbun.screw.core.query.mysql.model; + +import cn.smallbun.screw.core.mapping.MappingField; +import cn.smallbun.screw.core.metadata.ColumnLength; +import lombok.Data; + +/** + * mysql 列长度 + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/8/25 10:56 + */ +@Data +public class MySqlColumnLengthModel implements ColumnLength { + /** + * 表名 + */ + @MappingField(value = "TABLE_NAME") + private String tableName; + + /** + * 列名 + */ + @MappingField(value = "COLUMN_NAME") + private String columnName; + + /** + * 列长度 + */ + @MappingField(value = "COLUMN_TYPE") + private String columnType; + + /** + * 列长度 + * + * @return {@link String} + */ + @Override + public String getColumnLength() { + String leftParenthesis = "("; + String rightParenthesis = ")"; + if (columnType.contains(leftParenthesis)) { + return getColumnType().substring(columnType.indexOf(leftParenthesis) + 1, + columnType.indexOf(rightParenthesis)); + } + return ""; + } +} diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/query/oracle/OracleDataBaseQuery.java b/screw-core/src/main/java/cn/smallbun/screw/core/query/oracle/OracleDataBaseQuery.java index b7d6290..84520c2 100644 --- a/screw-core/src/main/java/cn/smallbun/screw/core/query/oracle/OracleDataBaseQuery.java +++ b/screw-core/src/main/java/cn/smallbun/screw/core/query/oracle/OracleDataBaseQuery.java @@ -23,10 +23,7 @@ import cn.smallbun.screw.core.metadata.Column; import cn.smallbun.screw.core.metadata.Database; import cn.smallbun.screw.core.metadata.PrimaryKey; import cn.smallbun.screw.core.query.AbstractDatabaseQuery; -import cn.smallbun.screw.core.query.oracle.model.OracleColumnModel; -import cn.smallbun.screw.core.query.oracle.model.OracleDatabaseModel; -import cn.smallbun.screw.core.query.oracle.model.OraclePrimaryKeyModel; -import cn.smallbun.screw.core.query.oracle.model.OracleTableModel; +import cn.smallbun.screw.core.query.oracle.model.*; import cn.smallbun.screw.core.util.Assert; import cn.smallbun.screw.core.util.CollectionUtils; import cn.smallbun.screw.core.util.ExceptionUtils; @@ -36,6 +33,7 @@ import javax.sql.DataSource; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -273,4 +271,15 @@ public class OracleDataBaseQuery extends AbstractDatabaseQuery { JdbcUtils.close(resultSet); } } + + /** + * 获取列长度 + * + * @return {@link List} + * @throws QueryException QueryException + */ + @Override + public List getColumnLength() throws QueryException { + return new ArrayList<>(); + } } diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/query/oracle/model/OracleColumnLengthModel.java b/screw-core/src/main/java/cn/smallbun/screw/core/query/oracle/model/OracleColumnLengthModel.java new file mode 100644 index 0000000..b15d305 --- /dev/null +++ b/screw-core/src/main/java/cn/smallbun/screw/core/query/oracle/model/OracleColumnLengthModel.java @@ -0,0 +1,28 @@ +package cn.smallbun.screw.core.query.oracle.model; + +import cn.smallbun.screw.core.metadata.ColumnLength; +import lombok.Data; + +/** + * oracle 列长度 + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/8/25 10:56 + */ +@Data +public class OracleColumnLengthModel implements ColumnLength { + /** + * 表名 + */ + private String tableName; + + /** + * 列名 + */ + private String columnName; + + /** + * 列长度 + */ + private String columnLength; +} diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/query/postgresql/PostgreSqlDataBaseQuery.java b/screw-core/src/main/java/cn/smallbun/screw/core/query/postgresql/PostgreSqlDataBaseQuery.java index f410ebe..9be7ec8 100644 --- a/screw-core/src/main/java/cn/smallbun/screw/core/query/postgresql/PostgreSqlDataBaseQuery.java +++ b/screw-core/src/main/java/cn/smallbun/screw/core/query/postgresql/PostgreSqlDataBaseQuery.java @@ -23,10 +23,7 @@ import cn.smallbun.screw.core.metadata.Column; import cn.smallbun.screw.core.metadata.Database; import cn.smallbun.screw.core.metadata.PrimaryKey; import cn.smallbun.screw.core.query.AbstractDatabaseQuery; -import cn.smallbun.screw.core.query.postgresql.model.PostgreSqlColumnModel; -import cn.smallbun.screw.core.query.postgresql.model.PostgreSqlDatabaseModel; -import cn.smallbun.screw.core.query.postgresql.model.PostgreSqlPrimaryKeyModel; -import cn.smallbun.screw.core.query.postgresql.model.PostgreSqlTableModel; +import cn.smallbun.screw.core.query.postgresql.model.*; import cn.smallbun.screw.core.util.Assert; import cn.smallbun.screw.core.util.ExceptionUtils; import cn.smallbun.screw.core.util.JdbcUtils; @@ -34,6 +31,7 @@ import cn.smallbun.screw.core.util.JdbcUtils; import javax.sql.DataSource; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import static cn.smallbun.screw.core.constant.DefaultConstants.PERCENT_SIGN; @@ -166,4 +164,15 @@ public class PostgreSqlDataBaseQuery extends AbstractDatabaseQuery { JdbcUtils.close(resultSet); } } + + /** + * 获取列长度 + * + * @return {@link List} + * @throws QueryException QueryException + */ + @Override + public List getColumnLength() throws QueryException { + return new ArrayList<>(); + } } diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/query/postgresql/model/PostgreColumnLengthModel.java b/screw-core/src/main/java/cn/smallbun/screw/core/query/postgresql/model/PostgreColumnLengthModel.java new file mode 100644 index 0000000..3ea6211 --- /dev/null +++ b/screw-core/src/main/java/cn/smallbun/screw/core/query/postgresql/model/PostgreColumnLengthModel.java @@ -0,0 +1,28 @@ +package cn.smallbun.screw.core.query.postgresql.model; + +import cn.smallbun.screw.core.metadata.ColumnLength; +import lombok.Data; + +/** + * Postgre 列长度 + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/8/25 10:56 + */ +@Data +public class PostgreColumnLengthModel implements ColumnLength { + /** + * 表名 + */ + private String tableName; + + /** + * 列名 + */ + private String columnName; + + /** + * 列长度 + */ + private String columnLength; +} diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/query/sqlservice/SqlServerDataBaseQuery.java b/screw-core/src/main/java/cn/smallbun/screw/core/query/sqlservice/SqlServerDataBaseQuery.java index 17cda1b..7f6a48b 100644 --- a/screw-core/src/main/java/cn/smallbun/screw/core/query/sqlservice/SqlServerDataBaseQuery.java +++ b/screw-core/src/main/java/cn/smallbun/screw/core/query/sqlservice/SqlServerDataBaseQuery.java @@ -23,10 +23,7 @@ import cn.smallbun.screw.core.metadata.Column; import cn.smallbun.screw.core.metadata.Database; import cn.smallbun.screw.core.metadata.PrimaryKey; import cn.smallbun.screw.core.query.AbstractDatabaseQuery; -import cn.smallbun.screw.core.query.sqlservice.model.SqlServerColumnModel; -import cn.smallbun.screw.core.query.sqlservice.model.SqlServerDatabaseModel; -import cn.smallbun.screw.core.query.sqlservice.model.SqlServerPrimaryKeyModel; -import cn.smallbun.screw.core.query.sqlservice.model.SqlServerTableModel; +import cn.smallbun.screw.core.query.sqlservice.model.*; import cn.smallbun.screw.core.util.Assert; import cn.smallbun.screw.core.util.CollectionUtils; import cn.smallbun.screw.core.util.ExceptionUtils; @@ -36,6 +33,7 @@ import javax.sql.DataSource; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -239,4 +237,15 @@ public class SqlServerDataBaseQuery extends AbstractDatabaseQuery { JdbcUtils.close(resultSet); } } + + /** + * 获取列长度 + * + * @return {@link List} + * @throws QueryException QueryException + */ + @Override + public List getColumnLength() throws QueryException { + return new ArrayList<>(); + } } diff --git a/screw-core/src/main/java/cn/smallbun/screw/core/query/sqlservice/model/SqlServerColumnLengthModel.java b/screw-core/src/main/java/cn/smallbun/screw/core/query/sqlservice/model/SqlServerColumnLengthModel.java new file mode 100644 index 0000000..6381d59 --- /dev/null +++ b/screw-core/src/main/java/cn/smallbun/screw/core/query/sqlservice/model/SqlServerColumnLengthModel.java @@ -0,0 +1,28 @@ +package cn.smallbun.screw.core.query.sqlservice.model; + +import cn.smallbun.screw.core.metadata.ColumnLength; +import lombok.Data; + +/** + * sqlserver 列长度 + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/8/25 10:56 + */ +@Data +public class SqlServerColumnLengthModel implements ColumnLength { + /** + * 表名 + */ + private String tableName; + + /** + * 列名 + */ + private String columnName; + + /** + * 列长度 + */ + private String columnLength; +} diff --git a/screw-core/src/main/resources/template/freemarker/documentation_html.ftl b/screw-core/src/main/resources/template/freemarker/documentation_html.ftl index 97bd07d..80e5e83 100644 --- a/screw-core/src/main/resources/template/freemarker/documentation_html.ftl +++ b/screw-core/src/main/resources/template/freemarker/documentation_html.ftl @@ -17,4 +17,4 @@ along with this program. If not, see . --> -${title!'数据库设计文档'}

${title!'数据库设计文档'}

数据库名:${database!''}
<#if (version)??>文档版本:${version!''}
<#if (description)??>文档描述:${description!''}
<#list tables><#items as t>
序号表名说明
${t?index+1}${t.tableName}${t.remarks!''}
<#list tables><#items as t>
返回目录表名:${t.tableName}
说明:${t.remarks!''}
数据列:
<#list t.columns><#items as c>
序号名称数据类型长度小数位允许空值主键默认值说明
${c?index+1}${c.columnName!''}${c.typeName!''}${c.columnSize!''}${c.decimalDigits!'0'}${c.nullable!''}${c.primaryKey!''}${c.columnDef!''}${c.remarks!''}
\ No newline at end of file +${title!'数据库设计文档'}

${title!'数据库设计文档'}

数据库名:${database!''}
<#if (version)??>文档版本:${version!''}
<#if (description)??>文档描述:${description!''}
<#list tables><#items as t>
序号表名说明
${t?index+1}${t.tableName}${t.remarks!''}
<#list tables><#items as t>
返回目录表名:${t.tableName}
说明:${t.remarks!''}
数据列:
<#list t.columns><#items as c>
序号名称数据类型长度小数位允许空值主键默认值说明
${c?index+1}${c.columnName!''}${c.typeName!''}${c.columnLength!''}${c.decimalDigits!'0'}${c.nullable!''}${c.primaryKey!''}${c.columnDef!''}${c.remarks!''}
\ No newline at end of file diff --git a/screw-core/src/main/resources/template/freemarker/documentation_md.ftl b/screw-core/src/main/resources/template/freemarker/documentation_md.ftl index c73f73b..b454bfe 100644 --- a/screw-core/src/main/resources/template/freemarker/documentation_md.ftl +++ b/screw-core/src/main/resources/template/freemarker/documentation_md.ftl @@ -50,7 +50,7 @@ | 序号 | 名称 | 数据类型 | 长度 | 小数位 | 允许空值 | 主键 | 默认值 | 说明 | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | <#items as c> -| ${c?index+1} | ${c.columnName!''} | ${c.typeName!''} | ${c.columnSize!''} | ${c.decimalDigits!'0'} | ${c.nullable!''} | ${c.primaryKey!''} | ${c.columnDef!''} | ${c.remarks!''} | +| ${c?index+1} | ${c.columnName!''} | ${c.typeName!''} | ${c.columnLength!''} | ${c.decimalDigits!'0'} | ${c.nullable!''} | ${c.primaryKey!''} | ${c.columnDef!''} | ${c.remarks!''} | \ No newline at end of file diff --git a/screw-core/src/main/resources/template/freemarker/documentation_word.ftl b/screw-core/src/main/resources/template/freemarker/documentation_word.ftl index b8fb121..fcde8d7 100644 --- a/screw-core/src/main/resources/template/freemarker/documentation_word.ftl +++ b/screw-core/src/main/resources/template/freemarker/documentation_word.ftl @@ -17,4 +17,4 @@ along with this program. If not, see . --> -${title!'数据库表结构文档'}数据库名:${database!''}<#if version?trim?length gt 2>文档版本:${version!''}<#if description?trim?length gt 2>文档描述:${description!''}<#--表--><#list tables><#items as t><#if (t.remarks??)&&(t.remarks?length gt 1)>${t.tableName!''} (${t.remarks})<#else>${t.tableName!''}<#--页面设置-->编号名称数据类型长度小数位允许空值主键默认值说明<#--列--><#list t.columns><#items as c>${c?index+1}${c.columnName!''}${c.typeName!''}${c.columnSize!''}${c.decimalDigits!'0'}${c.nullable!''}${c.primaryKey!''}${c.columnDef!''}${c.remarks!''}${title!'数据库表结构文档'}screwscrew20117100Microsoft Office Word011falsefalse116falsefalse16.00002052-11.1.0.9740 \ No newline at end of file +${title!'数据库表结构文档'}数据库名:${database!''}<#if version?trim?length gt 2>文档版本:${version!''}<#if description?trim?length gt 2>文档描述:${description!''}<#--表--><#list tables><#items as t><#if (t.remarks??)&&(t.remarks?length gt 1)>${t.tableName!''} (${t.remarks})<#else>${t.tableName!''}<#--页面设置-->编号名称数据类型长度小数位允许空值主键默认值说明<#--列--><#list t.columns><#items as c>${c?index+1}${c.columnName!''}${c.typeName!''}${c.columnLength!''}${c.decimalDigits!'0'}${c.nullable!''}${c.primaryKey!''}${c.columnDef!''}${c.remarks!''}${title!'数据库表结构文档'}screwscrew20117100Microsoft Office Word011falsefalse116falsefalse16.00002052-11.1.0.9740 \ No newline at end of file diff --git a/screw-core/src/main/resources/template/velocity/documentation_html.vm b/screw-core/src/main/resources/template/velocity/documentation_html.vm index 40f3f91..537b58b 100644 --- a/screw-core/src/main/resources/template/velocity/documentation_html.vm +++ b/screw-core/src/main/resources/template/velocity/documentation_html.vm @@ -15,4 +15,4 @@ * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . *# -#if(${_data.title})${_data.title}#else 数据库设计文档#end

#if(${_data.title})${_data.title}#else 数据库设计文档#end

数据库名:$!{_data.database}
#*文档版本*# #if(${_data.version})文档版本:$!{_data.version}
#end #*文档描述*# #if(${_data.description})文档描述:$!{_data.description}
#end
#foreach($t in $_data.tables)#end
序号表名说明
$!{velocityCount}$!{t.tableName}$!{t.remarks}
#foreach($t in $_data.tables)
返回目录表名:$!{t.tableName}
说明:$!{t.remarks}
数据列:
#foreach($c in $t.columns)#end
序号名称数据类型长度小数位允许空值主键默认值说明
$!{velocityCount}$!{c.columnName}$!{c.typeName}$!{c.columnSize}#if(${c.decimalDigits})${c.decimalDigits}#else 0#end$!{c.nullable}$!{c.primaryKey}$!{c.columnDef}$!{c.remarks}
#end
\ No newline at end of file +#if(${_data.title})${_data.title}#else 数据库设计文档#end

#if(${_data.title})${_data.title}#else 数据库设计文档#end

数据库名:$!{_data.database}
#*文档版本*# #if(${_data.version})文档版本:$!{_data.version}
#end #*文档描述*# #if(${_data.description})文档描述:$!{_data.description}
#end
#foreach($t in $_data.tables)#end
序号表名说明
$!{velocityCount}$!{t.tableName}$!{t.remarks}
#foreach($t in $_data.tables)
返回目录表名:$!{t.tableName}
说明:$!{t.remarks}
数据列:
#foreach($c in $t.columns)#end
序号名称数据类型长度小数位允许空值主键默认值说明
$!{velocityCount}$!{c.columnName}$!{c.typeName}$!{c.columnLength}#if(${c.decimalDigits})${c.decimalDigits}#else 0#end$!{c.nullable}$!{c.primaryKey}$!{c.columnDef}$!{c.remarks}
#end
\ No newline at end of file diff --git a/screw-core/src/main/resources/template/velocity/documentation_md.vm b/screw-core/src/main/resources/template/velocity/documentation_md.vm index 3efd39e..447851e 100644 --- a/screw-core/src/main/resources/template/velocity/documentation_md.vm +++ b/screw-core/src/main/resources/template/velocity/documentation_md.vm @@ -45,6 +45,6 @@ | 序号 | 名称 | 数据类型 | 长度 | 小数位 | 允许空值 | 主键 | 默认值 | 说明 | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | #foreach($c in $t.columns) -| $!{velocityCount} | $!{c.columnName} | $!{c.typeName} | $!{c.columnSize} | #if($!{c.decimalDigits})$!{c.decimalDigits}#else 0#end | $!{c.nullable}| $!{c.primaryKey} | $!{c.columnDef} | $!{c.remarks} | +| $!{velocityCount} | $!{c.columnName} | $!{c.typeName} | $!{c.columnLength} | #if($!{c.decimalDigits})$!{c.decimalDigits}#else 0#end | $!{c.nullable}| $!{c.primaryKey} | $!{c.columnDef} | $!{c.remarks} | #end #end \ No newline at end of file diff --git a/screw-core/src/main/resources/template/velocity/documentation_word.vm b/screw-core/src/main/resources/template/velocity/documentation_word.vm index 1752538..3cd3465 100644 --- a/screw-core/src/main/resources/template/velocity/documentation_word.vm +++ b/screw-core/src/main/resources/template/velocity/documentation_word.vm @@ -14,4 +14,4 @@ * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . - *##if($_data.title)!=""$!{_data.title}#else数据库表结构文档#end数据库名:$!{_data.database}#*版本*# #if(${_data.version}!= "")文档版本:$!{_data.version}#end #*描述*# #if(${_data.description}!= "")文档描述:$!{_data.description}#end #*表名*# #foreach($t in $_data.tables)#if(${t.remarks}!= "")$!{t.tableName} ($!{t.remarks})#else$!{t.tableName}#end编号名称数据类型长度小数位允许空值主键默认值说明#foreach($c in $t.columns)$!{velocityCount}$!{c.columnName}$!{c.typeName}$!{c.columnSize}#if(${c.decimalDigits})${c.decimalDigits}#else 0#end$!{c.nullable}$!{c.primaryKey}$!{c.columnDef}$!{c.remarks}#end#end#if($_data.title)!=""$!{_data.title}#else数据库表结构文档#endscrewscrew20117100Microsoft Office Word011falsefalse116falsefalse16.00002052-11.1.0.9740 \ No newline at end of file + *##if($_data.title)!=""$!{_data.title}#else数据库表结构文档#end数据库名:$!{_data.database}#*版本*# #if(${_data.version}!= "")文档版本:$!{_data.version}#end #*描述*# #if(${_data.description}!= "")文档描述:$!{_data.description}#end #*表名*# #foreach($t in $_data.tables)#if(${t.remarks}!= "")$!{t.tableName} ($!{t.remarks})#else$!{t.tableName}#end编号名称数据类型长度小数位允许空值主键默认值说明#foreach($c in $t.columns)$!{velocityCount}$!{c.columnName}$!{c.typeName}$!{c.columnLength}#if(${c.decimalDigits})${c.decimalDigits}#else 0#end$!{c.nullable}$!{c.primaryKey}$!{c.columnDef}$!{c.remarks}#end#end#if($_data.title)!=""$!{_data.title}#else数据库表结构文档#endscrewscrew20117100Microsoft Office Word011falsefalse116falsefalse16.00002052-11.1.0.9740 \ No newline at end of file diff --git a/screw-extension/src/main/java/cn/smallbun/screw/extension/pojo/dialect/mysql/MysqlTypeDialect.java b/screw-extension/src/main/java/cn/smallbun/screw/extension/pojo/dialect/mysql/MysqlTypeDialect.java index d3fb1ba..a6d90d2 100644 --- a/screw-extension/src/main/java/cn/smallbun/screw/extension/pojo/dialect/mysql/MysqlTypeDialect.java +++ b/screw-extension/src/main/java/cn/smallbun/screw/extension/pojo/dialect/mysql/MysqlTypeDialect.java @@ -27,6 +27,8 @@ import java.util.HashMap; import java.util.Map; /** + * mysql 类型字典 + * * @author liu·yu * Created by 15952866402@163.com on 2020-08-17 */ diff --git a/screw-extension/src/main/java/cn/smallbun/screw/extension/pojo/engine/freemark/FreeMarkerPojoEngine.java b/screw-extension/src/main/java/cn/smallbun/screw/extension/pojo/engine/freemark/FreeMarkerPojoEngine.java index 0d1cf92..582035a 100644 --- a/screw-extension/src/main/java/cn/smallbun/screw/extension/pojo/engine/freemark/FreeMarkerPojoEngine.java +++ b/screw-extension/src/main/java/cn/smallbun/screw/extension/pojo/engine/freemark/FreeMarkerPojoEngine.java @@ -31,6 +31,8 @@ import java.io.*; import static cn.smallbun.screw.core.constant.DefaultConstants.DEFAULT_ENCODING; /** + * freemark pojo 引擎 + * * @author liu·yu * Created by 15952866402@163.com on 2020-08-14 */