Commit 3f5e9450 by yuwei

2.0.0项目初始化

parent d8ae570f
...@@ -18,32 +18,32 @@ public class DbColumn { ...@@ -18,32 +18,32 @@ public class DbColumn {
/** /**
* 数据的长度 * 数据的长度
*/ */
private String dataLength; private Integer dataLength;
/** /**
* 数据的精度 * 数据的精度
*/ */
private String dataPrecision; private Integer dataPrecision;
/** /**
* 数据的小数位 * 数据的小数位
*/ */
private String dataScale; private Integer dataScale;
/** /**
* 是否主键 * 是否主键
*/ */
private boolean colKey; private Boolean colKey;
/** /**
* 是否允许为空 * 是否允许为空
*/ */
private boolean nullable; private Boolean nullable;
/** /**
* 列的序号 * 列的序号
*/ */
private String colPosition; private Integer colPosition;
/** /**
* 列的默认值 * 列的默认值
......
...@@ -14,7 +14,7 @@ public abstract class AbstractDbDialect implements DbDialect { ...@@ -14,7 +14,7 @@ public abstract class AbstractDbDialect implements DbDialect {
public String columns(String dbName, String tableName) { public String columns(String dbName, String tableName) {
return "select column_name AS COLNAME, ordinal_position AS COLPOSITION, column_default AS DATADEFAULT, is_nullable AS NULLABLE, data_type AS DATATYPE, " + return "select column_name AS COLNAME, ordinal_position AS COLPOSITION, column_default AS DATADEFAULT, is_nullable AS NULLABLE, data_type AS DATATYPE, " +
"character_maximum_length AS DATALENGTH, numeric_precision AS DATAPRECISION, numeric_scale AS DATASCALE, column_key AS COLKEY, column_comment AS COLCOMMENT " + "character_maximum_length AS DATALENGTH, numeric_precision AS DATAPRECISION, numeric_scale AS DATASCALE, column_key AS COLKEY, column_comment AS COLCOMMENT " +
"from information_schema.columns where table_schema = '" + dbName + "' and table_name = '" + tableName + "' "; "from information_schema.columns where table_schema = '" + dbName + "' and table_name = '" + tableName + "' order by ordinal_position ";
} }
@Override @Override
......
...@@ -20,12 +20,12 @@ public class MySqlDialect extends AbstractDbDialect { ...@@ -20,12 +20,12 @@ public class MySqlDialect extends AbstractDbDialect {
DbColumn entity = new DbColumn(); DbColumn entity = new DbColumn();
entity.setColName(rs.getString("COLNAME")); entity.setColName(rs.getString("COLNAME"));
entity.setDataType(rs.getString("DATATYPE")); entity.setDataType(rs.getString("DATATYPE"));
entity.setDataLength(rs.getString("DATALENGTH")); entity.setDataLength(rs.getInt("DATALENGTH"));
entity.setDataPrecision(rs.getString("DATAPRECISION")); entity.setDataPrecision(rs.getInt("DATAPRECISION"));
entity.setDataScale(rs.getString("DATASCALE")); entity.setDataScale(rs.getInt("DATASCALE"));
// entity.setColKey(rs.getString("COLKEY")); entity.setNullable("PRI".equals(rs.getString("COLKEY")) ? true : false);
// entity.setNullable(rs.getString("NULLABLE")); entity.setNullable("YES".equals(rs.getString("NULLABLE")) ? true : false);
entity.setColPosition(rs.getString("COLPOSITION")); entity.setColPosition(rs.getInt("COLPOSITION"));
entity.setDataDefault(rs.getString("DATADEFAULT")); entity.setDataDefault(rs.getString("DATADEFAULT"));
entity.setColComment(rs.getString("COLCOMMENT")); entity.setColComment(rs.getString("COLCOMMENT"));
return entity; return entity;
......
...@@ -3,6 +3,7 @@ package cn.datax.common.database.dialect; ...@@ -3,6 +3,7 @@ package cn.datax.common.database.dialect;
import cn.datax.common.database.core.DbColumn; import cn.datax.common.database.core.DbColumn;
import cn.datax.common.database.core.DbTable; import cn.datax.common.database.core.DbTable;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
import org.springframework.util.StringUtils;
import java.sql.ResultSet; import java.sql.ResultSet;
...@@ -17,9 +18,14 @@ public class OracleDialect extends AbstractDbDialect { ...@@ -17,9 +18,14 @@ public class OracleDialect extends AbstractDbDialect {
@Override @Override
public String columns(String dbName, String tableName) { public String columns(String dbName, String tableName) {
return "select columns.column_name AS colName, columns.data_type AS DATATYPE, columns.data_length AS DATALENGTH, columns.data_precision AS DATAPRECISION, " + return "select columns.column_name AS colName, columns.data_type AS DATATYPE, columns.data_length AS DATALENGTH, columns.data_precision AS DATAPRECISION, " +
"columns.data_scale AS DATASCALE, columns.nullable AS NULLABLE, columns.column_id AS COLPOSITION, columns.data_default AS DATADEFAULT, comments.comments AS COLCOMMENT " + "columns.data_scale AS DATASCALE, columns.nullable AS NULLABLE, columns.column_id AS COLPOSITION, columns.data_default AS DATADEFAULT, comments.comments AS COLCOMMENT," +
"case when t.column_name is null then 0 else 1 end as COLKEY " +
"from sys.dba_tab_columns columns LEFT JOIN sys.dba_col_comments comments ON columns.owner = comments.owner AND columns.table_name = comments.table_name AND columns.column_name = comments.column_name " + "from sys.dba_tab_columns columns LEFT JOIN sys.dba_col_comments comments ON columns.owner = comments.owner AND columns.table_name = comments.table_name AND columns.column_name = comments.column_name " +
"where columns.owner = UPPER('" + dbName + "') and columns.table_name = UPPER('" + tableName + "')"; "left join ( " +
"select col.column_name as column_name, con.table_name as table_name from user_constraints con, user_cons_columns col " +
"where con.constraint_name = col.constraint_name and con.constraint_type = 'P' " +
") t on t.table_name = columns.table_name and columns.column_name = t.column_name" +
"where columns.owner = UPPER('" + dbName + "') and columns.table_name = UPPER('" + tableName + "') order by columns.column_id ";
} }
@Override @Override
...@@ -44,12 +50,12 @@ public class OracleDialect extends AbstractDbDialect { ...@@ -44,12 +50,12 @@ public class OracleDialect extends AbstractDbDialect {
DbColumn entity = new DbColumn(); DbColumn entity = new DbColumn();
entity.setColName(rs.getString("COLNAME")); entity.setColName(rs.getString("COLNAME"));
entity.setDataType(rs.getString("DATATYPE")); entity.setDataType(rs.getString("DATATYPE"));
entity.setDataLength(rs.getString("DATALENGTH")); entity.setDataLength(rs.getInt("DATALENGTH"));
entity.setDataPrecision(rs.getString("DATAPRECISION")); entity.setDataPrecision(rs.getInt("DATAPRECISION"));
entity.setDataScale(rs.getString("DATASCALE")); entity.setDataScale(rs.getInt("DATASCALE"));
// entity.setColKey(rs.getString("COLKEY")); entity.setNullable("1".equals(rs.getString("COLKEY")) ? true : false);
// entity.setNullable(rs.getString("NULLABLE")); entity.setNullable("Y".equals(rs.getString("NULLABLE")) ? true : false);
entity.setColPosition(rs.getString("COLPOSITION")); entity.setColPosition(rs.getInt("COLPOSITION"));
entity.setDataDefault(rs.getString("DATADEFAULT")); entity.setDataDefault(rs.getString("DATADEFAULT"));
entity.setColComment(rs.getString("COLCOMMENT")); entity.setColComment(rs.getString("COLCOMMENT"));
return entity; return entity;
......
...@@ -19,17 +19,18 @@ public class SQLServer2008Dialect extends AbstractDbDialect { ...@@ -19,17 +19,18 @@ public class SQLServer2008Dialect extends AbstractDbDialect {
@Override @Override
public String columns(String dbName, String tableName) { public String columns(String dbName, String tableName) {
return "select columns.name AS colName, columns.column_id AS COLPOSITION, columns.max_length AS DATALENGTH, columns.precision AS DATAPRECISION, columns.scale AS DATASCALE, " + return "select columns.name AS colName, columns.column_id AS COLPOSITION, columns.max_length AS DATALENGTH, columns.precision AS DATAPRECISION, columns.scale AS DATASCALE, " +
"columns.is_nullable AS NULLABLE, types.name AS DATATYPE, properties.value AS COLCOMMENT, e.text AS DATADEFAULT " + "columns.is_nullable AS NULLABLE, types.name AS DATATYPE, CAST(ep.value AS NVARCHAR(128)) AS COLCOMMENT, e.text AS DATADEFAULT, " +
"(select top 1 ind.is_primary_key from sys.index_columns ic left join sys.indexes ind on ic.object_id = ind.object_id and ic.index_id = ind.index_id and ind.name like 'PK_%' where ic.object_id=columns.object_id and ic.column_id=columns.column_id) AS COLKEY " +
"from sys.columns columns LEFT JOIN sys.types types ON columns.system_type_id = types.system_type_id " + "from sys.columns columns LEFT JOIN sys.types types ON columns.system_type_id = types.system_type_id " +
"LEFT JOIN syscomments e ON columns.default_object_id= e.id " + "LEFT JOIN syscomments e ON columns.default_object_id= e.id " +
"LEFT JOIN sys.extended_properties properties ON properties.major_id = columns.object_id AND properties.minor_id = columns.column_id " + "LEFT JOIN sys.extended_properties ep ON ep.major_id = columns.object_id AND ep.minor_id = columns.column_id AND ep.name = 'MS_Description' " +
"where columns.object_id = object_id('" + tableName + "')"; "where columns.object_id = object_id('" + tableName + "') order by columns.column_id ";
} }
@Override @Override
public String tables(String dbName) { public String tables(String dbName) {
return "select tables.name AS TABLENAME, properties.value AS TABLECOMMENT " + return "select tables.name AS TABLENAME, CAST(ep.value AS NVARCHAR(128)) AS TABLECOMMENT " +
"from sys.tables tables LEFT JOIN sys.extended_properties properties ON properties.major_id = tables.object_id AND properties.minor_id = 0"; "from sys.tables tables LEFT JOIN sys.extended_properties ep ON ep.major_id = tables.object_id AND ep.minor_id = 0";
} }
private static String getOrderByPart(String sql) { private static String getOrderByPart(String sql) {
...@@ -81,12 +82,12 @@ public class SQLServer2008Dialect extends AbstractDbDialect { ...@@ -81,12 +82,12 @@ public class SQLServer2008Dialect extends AbstractDbDialect {
DbColumn entity = new DbColumn(); DbColumn entity = new DbColumn();
entity.setColName(rs.getString("COLNAME")); entity.setColName(rs.getString("COLNAME"));
entity.setDataType(rs.getString("DATATYPE")); entity.setDataType(rs.getString("DATATYPE"));
entity.setDataLength(rs.getString("DATALENGTH")); entity.setDataLength(rs.getInt("DATALENGTH"));
entity.setDataPrecision(rs.getString("DATAPRECISION")); entity.setDataPrecision(rs.getInt("DATAPRECISION"));
entity.setDataScale(rs.getString("DATASCALE")); entity.setDataScale(rs.getInt("DATASCALE"));
// entity.setColKey(rs.getString("COLKEY")); entity.setNullable("1".equals(rs.getString("COLKEY")) ? true : false);
// entity.setNullable(rs.getString("NULLABLE")); entity.setNullable("1".equals(rs.getString("NULLABLE")) ? true : false);
entity.setColPosition(rs.getString("COLPOSITION")); entity.setColPosition(rs.getInt("COLPOSITION"));
entity.setDataDefault(rs.getString("DATADEFAULT")); entity.setDataDefault(rs.getString("DATADEFAULT"));
entity.setColComment(rs.getString("COLCOMMENT")); entity.setColComment(rs.getString("COLCOMMENT"));
return entity; return entity;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment