Skip to content

Commit d8c3b3a

Browse files
HCK-14707: Identity params (#89)
<!--do not remove this marker, its needed to replace info when ticket title is updated --> <!--jira-description-action-hidden-marker-start--> <table> <td> <a href="https://hackolade.atlassian.net/browse/HCK-14707" title="HCK-14707" target="_blank"><img alt="Emergency" src="https://hackolade.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10564?size=medium" />HCK-14707</a> [Deloitte][DB2] Add support for CACHE and ORDER identity param in RE and FE </td></table> <br /> <!--jira-description-action-hidden-marker-end--> ## Content * include new properties of `AS IDENTITY` in the FE script * RE those properties back correctly --------- Co-authored-by: Yevhenii Moroziuk <yevhen.moroziuk@hackolade.com>
1 parent a4cd073 commit d8c3b3a

6 files changed

Lines changed: 115 additions & 37 deletions

File tree

constants/constants.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const ERROR_MESSAGE = {
66
/**
77
* @enum {string}
88
*/
9-
const TABLE_TYPE = {
9+
const OBJECT_TYPE = {
1010
table: 'TABLE',
1111
view: 'VIEW',
1212
};
@@ -24,7 +24,7 @@ const CONSTRAINT_POSTFIX = {
2424

2525
module.exports = {
2626
ERROR_MESSAGE,
27-
TABLE_TYPE,
27+
OBJECT_TYPE,
2828
INLINE_COMMENT,
2929
CONSTRAINT_POSTFIX,
3030
};

forward_engineering/ddlProvider/ddlHelpers/columnDefinition/getColumnDefault.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ const isGeneratedAsIdentity = ({ identity, type }) => {
2626
* @param {{ start?: number, increment?: number, minValue?: number, maxValue?: number, cycle?: string }} param0
2727
* @returns {string}
2828
*/
29-
const getIdentityOptions = ({ start, increment, minValue, maxValue, cycle }) => {
29+
const getIdentityOptions = ({ start, increment, minValue, maxValue, cycle, cache, cacheValue, order }) => {
3030
const startWith = start ? `START WITH ${start}` : '';
3131
const incrementBy = increment ? `INCREMENT BY ${increment}` : '';
3232
const minimumValue = minValue ? `MINVALUE ${minValue}` : '';
3333
const maximumValue = maxValue ? `MAXVALUE ${maxValue}` : '';
34+
const cacheOption = cacheValue ? `CACHE ${cacheValue}` : cache;
3435

35-
return [startWith, incrementBy, cycle, minimumValue, maximumValue].filter(Boolean).join(', ');
36+
return [startWith, incrementBy, cycle, minimumValue, maximumValue, cacheOption, order].filter(Boolean).join(', ');
3637
};
3738

3839
/**

properties_pane/field_level/fieldLevelConfig.json

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,6 @@ making sure that you maintain a proper JSON format.
10161016
"value": "decimal"
10171017
}
10181018
},
1019-
10201019
{
10211020
"propertyName": "Default",
10221021
"propertyKeyword": "default",
@@ -1237,6 +1236,65 @@ making sure that you maintain a proper JSON format.
12371236
]
12381237
}
12391238
}
1239+
},
1240+
{
1241+
"propertyName": "Cache",
1242+
"propertyKeyword": "cache",
1243+
"propertyTooltip": "Specify how many values of the sequence the database preallocates and keeps in memory for faster access. Specify NOCACHE to indicate that values of the sequence are not preallocated. If you omit both CACHE and NOCACHE, then the database caches 20 sequence numbers by default.",
1244+
"propertyType": "select",
1245+
"options": ["", "CACHE", "NO CACHE"],
1246+
"dependency": {
1247+
"type": "not",
1248+
"values": {
1249+
"type": "or",
1250+
"values": [
1251+
{
1252+
"key": "generated",
1253+
"exist": false
1254+
},
1255+
{
1256+
"key": "generated",
1257+
"value": ""
1258+
}
1259+
]
1260+
}
1261+
}
1262+
},
1263+
{
1264+
"propertyName": "Cache value",
1265+
"propertyKeyword": "cacheValue",
1266+
"propertyType": "numeric",
1267+
"valueType": "number",
1268+
"propertyTooltip": "This integer value can have 28 or fewer digits. The minimum value for this parameter is 2.",
1269+
"minValue": 2,
1270+
"defaultValue": 20,
1271+
"dependency": {
1272+
"key": "cache",
1273+
"value": "CACHE"
1274+
}
1275+
},
1276+
{
1277+
"propertyName": "Order",
1278+
"propertyKeyword": "order",
1279+
"propertyTooltip": "Specify ORDER to guarantee that sequence numbers are generated in order of request. Specify NO ORDER if you do not want to guarantee sequence numbers are generated in order of request.",
1280+
"propertyType": "select",
1281+
"options": ["", "ORDER", "NO ORDER"],
1282+
"dependency": {
1283+
"type": "not",
1284+
"values": {
1285+
"type": "or",
1286+
"values": [
1287+
{
1288+
"key": "generated",
1289+
"exist": false
1290+
},
1291+
{
1292+
"key": "generated",
1293+
"value": ""
1294+
}
1295+
]
1296+
}
1297+
}
12401298
}
12411299
],
12421300
"dependency": {

reverse_engineering/api.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { mapSeries } = require('async');
1111
const { connectionHelper } = require('../shared/helpers/connectionHelper');
1212
const { instanceHelper } = require('../shared/helpers/instanceHelper');
1313
const { logHelper } = require('../shared/helpers/logHelper');
14-
const { TABLE_TYPE } = require('../constants/constants');
14+
const { OBJECT_TYPE } = require('../constants/constants');
1515
const { nameHelper } = require('../shared/helpers/nameHelper');
1616
const { testConnection } = require('../shared/api/testConnection');
1717

@@ -83,7 +83,7 @@ const getDbCollectionsNames = async (connectionInfo, appLogger, callback, app) =
8383

8484
const tableNames = await instanceHelper.getDatabasesWithTableNames({
8585
connection,
86-
tableType: TABLE_TYPE.table,
86+
objectType: OBJECT_TYPE.table,
8787
includeSystemCollection: connectionInfo.includeSystemCollection,
8888
tableNameModifier: identity,
8989
});
@@ -92,7 +92,7 @@ const getDbCollectionsNames = async (connectionInfo, appLogger, callback, app) =
9292

9393
const viewNames = await instanceHelper.getDatabasesWithTableNames({
9494
connection,
95-
tableType: TABLE_TYPE.view,
95+
objectType: OBJECT_TYPE.view,
9696
includeSystemCollection: connectionInfo.includeSystemCollection,
9797
tableNameModifier: nameHelper.setViewSign,
9898
});
@@ -153,7 +153,7 @@ const getDbCollectionsData = async (connectionInfo, appLogger, callback, app) =>
153153
connection,
154154
schemaName,
155155
tableName,
156-
tableType: TABLE_TYPE.table,
156+
objectType: OBJECT_TYPE.table,
157157
logger,
158158
});
159159

@@ -185,7 +185,7 @@ const getDbCollectionsData = async (connectionInfo, appLogger, callback, app) =>
185185
connection,
186186
schemaName,
187187
tableName: viewName,
188-
tableType: TABLE_TYPE.view,
188+
objectType: OBJECT_TYPE.view,
189189
logger,
190190
});
191191

shared/helpers/instanceHelper.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* @typedef {import("../types").Logger} Logger
55
*/
66

7-
const { TABLE_TYPE } = require('../../constants/constants');
87
const { queryHelper } = require('./queryHelper');
98

109
/**
@@ -32,11 +31,11 @@ const getSchemaNames = async ({ connection }) => {
3231
};
3332

3433
/**
35-
* @param {{ connection: Connection, tableType: string, includeSystemCollection: boolean, tableNameModifier: (name: string) => string }}
34+
* @param {{ connection: Connection, objectType: string, includeSystemCollection: boolean, tableNameModifier: (name: string) => string }}
3635
* @returns {Promise<NameMap>}
3736
*/
38-
const getDatabasesWithTableNames = async ({ connection, tableType, includeSystemCollection, tableNameModifier }) => {
39-
const query = queryHelper.getTableNamesQuery({ tableType, includeSystemCollection });
37+
const getDatabasesWithTableNames = async ({ connection, objectType, includeSystemCollection, tableNameModifier }) => {
38+
const query = queryHelper.getTableNamesQuery({ objectType, includeSystemCollection });
4039
const result = await connection.execute({ query });
4140

4241
return result.reduce((result, { SCHEMANAME, TABLENAME }) => {
@@ -73,17 +72,26 @@ const getSchemaProperties = async ({ connection, schemaName, logger }) => {
7372
* @param {{ connection: Connection, schemaName: string, tableName: string, tableName: string, logger: Logger}}
7473
* @returns {Promise<string>}
7574
*/
76-
const getTableDdl = async ({ connection, schemaName, tableName, tableType, logger }) => {
75+
const getTableDdl = async ({ connection, schemaName, tableName, objectType, logger }) => {
7776
try {
78-
const generateQuery = queryHelper.getGenerateTableDdlQuery({ schemaName, tableName, tableType });
77+
const generateQuery = queryHelper.getGenerateTableDdlQuery({ schemaName, tableName, objectType });
78+
7979
const opToken = await connection.execute({ query: generateQuery, callable: true });
80-
const selectQuery = queryHelper.getSelectTableDdlQuery({ opToken, tableType });
80+
81+
const selectQuery = queryHelper.getSelectTableDdlQuery({
82+
opToken,
83+
schemaName,
84+
objectName: tableName,
85+
objectType,
86+
});
87+
8188
const ddlResult = await connection.execute({ query: selectQuery });
89+
8290
const clearQuery = queryHelper.getClearTableDdlQuery();
8391

8492
await connection.execute({ query: clearQuery, callable: true, inparam: opToken });
8593

86-
return ddlResult.map(row => row.SQL_STMT + ';').join('\n');
94+
return ddlResult.map(row => queryHelper.ensureTerminator({ query: row.SQL_STMT })).join('\n');
8795
} catch (error) {
8896
logger.error(error);
8997

shared/helpers/queryHelper.js

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
const { TABLE_TYPE } = require('../../constants/constants');
1+
const { OBJECT_TYPE } = require('../../constants/constants');
22

33
/**
4-
* @param {{ query: string }}
4+
* @param {{ query: string }} params
55
* @returns {string}
66
*/
77
const cleanUpQuery = ({ query = '' }) => query.replaceAll(/\s+/g, ' ');
88

9+
const ensureTerminator = ({ query = '' }) => (query.trimEnd().endsWith(';') ? query : `${query};`);
10+
911
/**
10-
* @param {{ query: string, schemaNameKeyword: string }}
12+
* @param {{ query: string, schemaNameKeyword: string }} params
1113
* @returns {string}
1214
*/
1315
const getNonSystemSchemaWhereClause = ({ query, schemaNameKeyword }) => {
@@ -43,19 +45,19 @@ const getSchemasQuery = () => {
4345
};
4446

4547
/**
46-
* @param {{ schemaName: string }}
48+
* @param {{ schemaName: string }} params
4749
* @returns {string}
4850
*/
4951
const getSchemaQuery = ({ schemaName }) => {
5052
return `SELECT * FROM SYSCAT.SCHEMATA WHERE SCHEMANAME = '${schemaName}'`;
5153
};
5254

5355
/**
54-
* @param {{ tableType: string, includeSystemCollection: boolean }}
56+
* @param {{ objectType: string, includeSystemCollection: boolean }} params
5557
* @returns {string}
5658
*/
57-
const getTableNamesQuery = ({ tableType, includeSystemCollection }) => {
58-
const baseQuery = `SELECT TABLE_SCHEM AS SCHEMANAME, TABLE_NAME AS TABLENAME FROM SYSIBM.SQLTABLES WHERE TABLE_TYPE = '${tableType}'`;
59+
const getTableNamesQuery = ({ objectType, includeSystemCollection }) => {
60+
const baseQuery = `SELECT TABLE_SCHEM AS SCHEMANAME, TABLE_NAME AS TABLENAME FROM SYSIBM.SQLTABLES WHERE TABLE_TYPE = '${objectType}'`;
5961

6062
if (includeSystemCollection) {
6163
return baseQuery;
@@ -67,27 +69,35 @@ const getTableNamesQuery = ({ tableType, includeSystemCollection }) => {
6769
};
6870

6971
/**
70-
* @param {{ schemaName: string, tableName: string, tableType: string }}
72+
* @param {{ schemaName: string, tableName: string, objectType: string }} params
7173
* @returns {string};
7274
*/
73-
const getGenerateTableDdlQuery = ({ schemaName, tableName, tableType }) => {
74-
const tableArgument = tableType === TABLE_TYPE.table ? '-t' : '-v';
75+
const getGenerateTableDdlQuery = ({ schemaName, tableName, objectType }) => {
76+
const objectArgument = objectType === OBJECT_TYPE.table ? '-t' : '-v';
7577

76-
return `CALL SYSPROC.DB2LK_GENERATE_DDL('-a -e -z "${schemaName}" ${tableArgument} "${tableName}"', ?);`;
78+
return `CALL SYSPROC.DB2LK_GENERATE_DDL('-a -e -z "${schemaName}" ${objectArgument} "${tableName}"', ?);`;
7779
};
7880

7981
/**
80-
* @param {{ opToken: number, tableType: string }}
82+
* @param {{ opToken: number, schemaName: string, objectName: string, objectType: string }} params
8183
* @returns {string}
8284
*/
83-
const getSelectTableDdlQuery = ({ opToken, tableType }) => {
84-
const objectTypeOperator = tableType === TABLE_TYPE.table ? '!=' : '=';
85+
const getSelectTableDdlQuery = ({ opToken, schemaName, objectName, objectType }) => {
86+
const predicate =
87+
objectType === OBJECT_TYPE.view
88+
? `SQL_STMT LIKE 'CREATE%VIEW %"${schemaName}%"."${objectName}"%'
89+
OR SQL_STMT LIKE 'CREATE%VIEW "${objectName}"%'
90+
OR SQL_STMT LIKE 'CREATE%VIEW ${objectName}%'
91+
OR SQL_STMT LIKE 'COMMENT ON TABLE %"${schemaName}%"."${objectName}"%'`
92+
: `SQL_STMT LIKE '%"${schemaName}%"."${objectName}"%'`;
93+
8594
const query = `
86-
SELECT SQL_STMT
87-
FROM SYSTOOLS.DB2LOOK_INFO
88-
WHERE OP_TOKEN= ${opToken}
89-
AND OBJ_TYPE ${objectTypeOperator} '${TABLE_TYPE.view}'
90-
ORDER BY CREATION_TIME, OP_SEQUENCE;`;
95+
SELECT SQL_STMT
96+
FROM SYSTOOLS.DB2LOOK_INFO
97+
WHERE OP_TOKEN = ${opToken}
98+
AND ( ${predicate} )
99+
ORDER BY CREATION_TIME, OP_SEQUENCE
100+
`;
91101

92102
return cleanUpQuery({ query });
93103
};
@@ -108,6 +118,7 @@ const queryHelper = {
108118
getGenerateTableDdlQuery,
109119
getSelectTableDdlQuery,
110120
getClearTableDdlQuery,
121+
ensureTerminator,
111122
};
112123

113124
module.exports = {

0 commit comments

Comments
 (0)