Commit 3f5e9450 by yuwei

2.0.0项目初始化

parent d8ae570f
......@@ -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 {
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, " +
"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
......
......@@ -20,12 +20,12 @@ public class MySqlDialect extends AbstractDbDialect {
DbColumn entity = new DbColumn();
entity.setColName(rs.getString("COLNAME"));
entity.setDataType(rs.getString("DATATYPE"));
entity.setDataLength(rs.getString("DATALENGTH"));
entity.setDataPrecision(rs.getString("DATAPRECISION"));
entity.setDataScale(rs.getString("DATASCALE"));
// entity.setColKey(rs.getString("COLKEY"));
// entity.setNullable(rs.getString("NULLABLE"));
entity.setColPosition(rs.getString("COLPOSITION"));
entity.setDataLength(rs.getInt("DATALENGTH"));
entity.setDataPrecision(rs.getInt("DATAPRECISION"));
entity.setDataScale(rs.getInt("DATASCALE"));
entity.setNullable("PRI".equals(rs.getString("COLKEY")) ? true : false);
entity.setNullable("YES".equals(rs.getString("NULLABLE")) ? true : false);
entity.setColPosition(rs.getInt("COLPOSITION"));
entity.setDataDefault(rs.getString("DATADEFAULT"));
entity.setColComment(rs.getString("COLCOMMENT"));
return entity;
......
......@@ -3,6 +3,7 @@ package cn.datax.common.database.dialect;
import cn.datax.common.database.core.DbColumn;
import cn.datax.common.database.core.DbTable;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.util.StringUtils;
import java.sql.ResultSet;
......@@ -17,9 +18,14 @@ public class OracleDialect extends AbstractDbDialect {
@Override
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, " +
"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 " +
"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
......@@ -44,12 +50,12 @@ public class OracleDialect extends AbstractDbDialect {
DbColumn entity = new DbColumn();
entity.setColName(rs.getString("COLNAME"));
entity.setDataType(rs.getString("DATATYPE"));
entity.setDataLength(rs.getString("DATALENGTH"));
entity.setDataPrecision(rs.getString("DATAPRECISION"));
entity.setDataScale(rs.getString("DATASCALE"));
// entity.setColKey(rs.getString("COLKEY"));
// entity.setNullable(rs.getString("NULLABLE"));
entity.setColPosition(rs.getString("COLPOSITION"));
entity.setDataLength(rs.getInt("DATALENGTH"));
entity.setDataPrecision(rs.getInt("DATAPRECISION"));
entity.setDataScale(rs.getInt("DATASCALE"));
entity.setNullable("1".equals(rs.getString("COLKEY")) ? true : false);
entity.setNullable("Y".equals(rs.getString("NULLABLE")) ? true : false);
entity.setColPosition(rs.getInt("COLPOSITION"));
entity.setDataDefault(rs.getString("DATADEFAULT"));
entity.setColComment(rs.getString("COLCOMMENT"));
return entity;
......
......@@ -19,17 +19,18 @@ public class SQLServer2008Dialect extends AbstractDbDialect {
@Override
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, " +
"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 " +
"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 " +
"where columns.object_id = object_id('" + tableName + "')";
"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 + "') order by columns.column_id ";
}
@Override
public String tables(String dbName) {
return "select tables.name AS TABLENAME, properties.value AS TABLECOMMENT " +
"from sys.tables tables LEFT JOIN sys.extended_properties properties ON properties.major_id = tables.object_id AND properties.minor_id = 0";
return "select tables.name AS TABLENAME, CAST(ep.value AS NVARCHAR(128)) AS TABLECOMMENT " +
"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) {
......@@ -81,12 +82,12 @@ public class SQLServer2008Dialect extends AbstractDbDialect {
DbColumn entity = new DbColumn();
entity.setColName(rs.getString("COLNAME"));
entity.setDataType(rs.getString("DATATYPE"));
entity.setDataLength(rs.getString("DATALENGTH"));
entity.setDataPrecision(rs.getString("DATAPRECISION"));
entity.setDataScale(rs.getString("DATASCALE"));
// entity.setColKey(rs.getString("COLKEY"));
// entity.setNullable(rs.getString("NULLABLE"));
entity.setColPosition(rs.getString("COLPOSITION"));
entity.setDataLength(rs.getInt("DATALENGTH"));
entity.setDataPrecision(rs.getInt("DATAPRECISION"));
entity.setDataScale(rs.getInt("DATASCALE"));
entity.setNullable("1".equals(rs.getString("COLKEY")) ? true : false);
entity.setNullable("1".equals(rs.getString("NULLABLE")) ? true : false);
entity.setColPosition(rs.getInt("COLPOSITION"));
entity.setDataDefault(rs.getString("DATADEFAULT"));
entity.setColComment(rs.getString("COLCOMMENT"));
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