Commit 10866ad3 by yuwei

2.0.0项目初始化

parent 3f5e9450
......@@ -23,7 +23,7 @@ public class MySqlDialect extends AbstractDbDialect {
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.setColKey("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"));
......
......@@ -24,7 +24,7 @@ public class OracleDialect extends AbstractDbDialect {
"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" +
") 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 ";
}
......@@ -53,7 +53,7 @@ public class OracleDialect extends AbstractDbDialect {
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.setColKey("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"));
......
......@@ -16,34 +16,28 @@ public class PostgreDialect extends AbstractDbDialect {
@Override
public String columns(String dbName, String tableName) {
String sql = "SELECT a.attnum,\n" +
"a.attname AS field,\n" +
"t.typname AS type,\n" +
"a.attlen AS length,\n" +
"a.atttypmod AS lengthvar,\n" +
"a.attnotnull AS notnull,\n" +
"b.description AS comment\n" +
"FROM pg_class c,\n" +
"pg_attribute a\n" +
"LEFT OUTER JOIN pg_description b ON a.attrelid=b.objoid AND a.attnum = b.objsubid,\n" +
"pg_type t\n" +
"WHERE c.relname = 'tableName'\n" +
"and a.attnum > 0\n" +
"and a.attrelid = c.oid\n" +
"and a.atttypid = t.oid\n" +
"ORDER BY a.attnum;";
return sql;
return "select col.column_name AS COLNAME, col.ordinal_position AS COLPOSITION, col.column_default AS DATADEFAULT, col.is_nullable AS NULLABLE, col.udt_name AS DATATYPE, " +
"col.character_maximum_length AS DATALENGTH, col.numeric_precision AS DATAPRECISION, col.numeric_scale AS DATASCALE, des.description AS COLCOMMENT, " +
"case when t.colname is null then 0 else 1 end as COLKEY " +
"from information_schema.columns col left join pg_description des on col.table_name::regclass = des.objoid and col.ordinal_position = des.objsubid " +
"left join ( " +
"select pg_attribute.attname as colname from pg_constraint inner join pg_class on pg_constraint.conrelid = pg_class.oid " +
"inner join pg_attribute on pg_attribute.attrelid = pg_class.oid and pg_attribute.attnum = any(pg_constraint.conkey) " +
"where pg_class.relname = '" + tableName + "' and pg_constraint.contype = 'p' " +
") t on t.colname = col.column_name " +
"where col.table_catalog = '" + dbName + "' and col.table_schema = 'public' and col.table_name = '" + tableName + "' order by col.ordinal_position ";
}
@Override
public String tables(String dbName) {
return "SELECT tablename name FROM pg_tables WHERE schemaname = 'public' AND tableowner = '" + dbName + "' ";
return "select relname AS TABLENAME, cast(obj_description(relfilenode, 'pg_class') as varchar) AS TABLECOMMENT from pg_class " +
"where relname in (select tablename from pg_tables where schemaname = 'public' and tableowner = '" + dbName + "' and position('_2' in tablename) = 0) ";
}
@Override
public String buildPaginationSql(String originalSql, long offset, long count) {
StringBuilder sqlBuilder = new StringBuilder(originalSql);
sqlBuilder.append(" LIMIT ").append(offset).append(" offset ").append(count);
sqlBuilder.append(" LIMIT ").append(count).append(" offset ").append(offset);
return sqlBuilder.toString();
}
......@@ -53,12 +47,12 @@ public class PostgreDialect 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.setColKey("1".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;
......
......@@ -85,7 +85,7 @@ public class SQLServer2008Dialect extends AbstractDbDialect {
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.setColKey("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"));
......
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