filter for type precision introduced

This commit is contained in:
Ralf Wisser
2020-10-22 10:27:07 +02:00
parent 95a39cb4c6
commit 35231c36f3
5 changed files with 30 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
# Table; Columns
ACTOR; ACTOR_ID DECIMAL(65535, 32767); FIRST_NAME VARCHAR(45); LAST_NAME VARCHAR(45); LAST_UPDATE TIMESTAMP; ;
ACTOR; ACTOR_ID DECIMAL; FIRST_NAME VARCHAR(45); LAST_NAME VARCHAR(45); LAST_UPDATE TIMESTAMP; ;
ADDRESS; ADDRESS_ID INTEGER; ADDRESS VARCHAR(50); ADDRESS2 VARCHAR(50) null; DISTRICT VARCHAR(20); CITY_ID INTEGER; POSTAL_CODE VARCHAR(10) null; PHONE VARCHAR(20); LAST_UPDATE TIMESTAMP; ;
CATEGORY; CATEGORY_ID SMALLINT; NAME VARCHAR(25); LAST_UPDATE TIMESTAMP; ;
CITY; CITY_ID INTEGER; CITY VARCHAR(50); COUNTRY_ID SMALLINT; LAST_UPDATE TIMESTAMP; ;
1 # Table; Columns
2 ACTOR; ACTOR_ID DECIMAL(65535, 32767); FIRST_NAME VARCHAR(45); LAST_NAME VARCHAR(45); LAST_UPDATE TIMESTAMP; ; ACTOR; ACTOR_ID DECIMAL; FIRST_NAME VARCHAR(45); LAST_NAME VARCHAR(45); LAST_UPDATE TIMESTAMP; ;
3 ADDRESS; ADDRESS_ID INTEGER; ADDRESS VARCHAR(50); ADDRESS2 VARCHAR(50) null; DISTRICT VARCHAR(20); CITY_ID INTEGER; POSTAL_CODE VARCHAR(10) null; PHONE VARCHAR(20); LAST_UPDATE TIMESTAMP; ;
4 CATEGORY; CATEGORY_ID SMALLINT; NAME VARCHAR(25); LAST_UPDATE TIMESTAMP; ;
5 CITY; CITY_ID INTEGER; CITY VARCHAR(50); COUNTRY_ID SMALLINT; LAST_UPDATE TIMESTAMP; ;

View File

@@ -1,5 +1,5 @@
# Name; Upsert; Primary Key; ; Author
ACTOR; N; ACTOR_ID DECIMAL(65535, 32767); ; H2 JDBC Driver; ;
ACTOR; N; ACTOR_ID DECIMAL; ; H2 JDBC Driver; ;
ADDRESS; N; ADDRESS_ID INTEGER; ; H2 JDBC Driver; ;
CATEGORY; N; CATEGORY_ID SMALLINT; ; H2 JDBC Driver; ;
CITY; N; CITY_ID INTEGER; ; H2 JDBC Driver; ;
1 # Name; Upsert; Primary Key; ; Author
2 ACTOR; N; ACTOR_ID DECIMAL(65535, 32767); ; H2 JDBC Driver; ; ACTOR; N; ACTOR_ID DECIMAL; ; H2 JDBC Driver; ;
3 ADDRESS; N; ADDRESS_ID INTEGER; ; H2 JDBC Driver; ;
4 CATEGORY; N; CATEGORY_ID SMALLINT; ; H2 JDBC Driver; ;
5 CITY; N; CITY_ID INTEGER; ; H2 JDBC Driver; ;

View File

@@ -1 +1 @@
8.7.5
10.2.1
1 8.7.5 10.2.1

View File

@@ -508,7 +508,7 @@ public class JDBCMetaDataBasedModelElementFinder implements ModelElementFinder {
length = 0;
precision = -1;
}
Column column = new Column(colName, filterType(sqlType, length, resultSet.getString(6), type, session.dbms, resultSet.getInt(7)), filterLength(length, resultSet.getString(6), type, session.dbms, resultSet.getInt(7)), precision);
Column column = new Column(colName, filterType(sqlType, length, resultSet.getString(6), type, session.dbms, resultSet.getInt(7)), filterLength(length, precision, resultSet.getString(6), type, session.dbms, resultSet.getInt(7)), filterPrecision(length, precision, resultSet.getString(6), type, session.dbms, resultSet.getInt(7)));
for (int i: pk.keySet()) {
if (pk.get(i).name.equals(column.name)) {
pk.put(i, column);
@@ -1354,7 +1354,7 @@ public class JDBCMetaDataBasedModelElementFinder implements ModelElementFinder {
precision = -1;
}
_log.debug("column info: '" + colName + "' '" + sqlType + "' " + type + " '" + resultSet.getString(6) + "'");
Column column = new Column(colName, filterType(sqlType, length, resultSet.getString(6), type, session.dbms, resultSet.getInt(7)), filterLength(length, resultSet.getString(6), type, session.dbms, resultSet.getInt(7)), precision);
Column column = new Column(colName, filterType(sqlType, length, resultSet.getString(6), type, session.dbms, resultSet.getInt(7)), filterLength(length, precision, resultSet.getString(6), type, session.dbms, resultSet.getInt(7)), filterPrecision(length, precision, resultSet.getString(6), type, session.dbms, resultSet.getInt(7)));
column.isNullable = resultSet.getInt(11) == DatabaseMetaData.columnNullable;
Boolean isVirtual = null;
if (session.dbms.getExportBlocks().contains(sqlType)) {
@@ -1415,14 +1415,18 @@ public class JDBCMetaDataBasedModelElementFinder implements ModelElementFinder {
* Filters the length attribute of a column in a DBMS specific way.
*
* @param length the length as given from driver
* @param precision the precision as given from driver
* @param the type name
* @param type the sql type
* @param dbms the DBMS
*
* @return filtered length
*/
public static int filterLength(int length, String typeName, int type, DBMS dbms, int origLength) {
public static int filterLength(int length, int precision, String typeName, int type, DBMS dbms, int origLength) {
if (length > 0) {
if (length == 65535 && precision == 32767 && "DECIMAL".equals(typeName) && DBMS.H2.equals(dbms)) {
return 0;
}
if (DBMS.POSTGRESQL.equals(dbms)) {
if (type == Types.VARCHAR && length >= 10485760) {
length = 0;
@@ -1447,6 +1451,24 @@ public class JDBCMetaDataBasedModelElementFinder implements ModelElementFinder {
return length;
}
/**
* Filters the precision attribute of a column in a DBMS specific way.
*
* @param length the length as given from driver
* @param precision
* @param the type name
* @param type the sql type
* @param dbms the DBMS
*
* @return filtered length
*/
public static int filterPrecision(int length, int precision, String typeName, int type, DBMS dbms, int origLength) {
if (length == 65535 && precision == 32767 && "DECIMAL".equals(typeName) && DBMS.H2.equals(dbms)) {
return -1;
}
return precision;
}
/**
* Filters the type attribute of a column in a DBMS specific way.
*
@@ -1544,7 +1566,7 @@ public class JDBCMetaDataBasedModelElementFinder implements ModelElementFinder {
length = 0;
precision = -1;
}
Column column = new Column(colName, filterType(sqlType, length, metaData.getColumnTypeName(i), type, session.dbms, metaData.getPrecision(i)), filterLength(length, metaData.getColumnTypeName(i), type, session.dbms, metaData.getPrecision(i)), precision);
Column column = new Column(colName, filterType(sqlType, length, metaData.getColumnTypeName(i), type, session.dbms, metaData.getPrecision(i)), filterLength(length, precision, metaData.getColumnTypeName(i), type, session.dbms, metaData.getPrecision(i)), filterPrecision(length, precision, metaData.getColumnTypeName(i), type, session.dbms, metaData.getPrecision(i)));
column.isNullable = metaData.isNullable(i) != ResultSetMetaData.columnNoNulls;
return column;
}

View File

@@ -215,7 +215,7 @@ public class MDTable extends MDObject {
length = 0;
precision = -1;
}
Column column = new Column(colName, JDBCMetaDataBasedModelElementFinder.filterType(sqlType, length, resultSet.getString(6), type, metaDataSource.getSession().dbms, resultSet.getInt(7)), JDBCMetaDataBasedModelElementFinder.filterLength(length, resultSet.getString(6), type, metaDataSource.getSession().dbms, resultSet.getInt(7)), precision);
Column column = new Column(colName, JDBCMetaDataBasedModelElementFinder.filterType(sqlType, length, resultSet.getString(6), type, metaDataSource.getSession().dbms, resultSet.getInt(7)), JDBCMetaDataBasedModelElementFinder.filterLength(length, precision, resultSet.getString(6), type, metaDataSource.getSession().dbms, resultSet.getInt(7)), JDBCMetaDataBasedModelElementFinder.filterPrecision(length, precision, resultSet.getString(6), type, metaDataSource.getSession().dbms, resultSet.getInt(7)));
columnTypes.add(column);
column.isNullable = resultSet.getInt(11) == DatabaseMetaData.columnNullable;
}