Skip to content

Commit

Permalink
Merge pull request #35 from Vitalii4as/fix/HCK-3562
Browse files Browse the repository at this point in the history
Add FE and RE of materialized views
  • Loading branch information
mtseluiko authored May 30, 2023
2 parents d511416 + 109a905 commit c907fba
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 28 deletions.
2 changes: 1 addition & 1 deletion forward_engineering/configs/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {

createIndex: 'CREATE${indexType} INDEX ${name} ON ${tableName}${keys}${options};\n',

createView: 'CREATE${orReplace}${force}${viewType} VIEW ${name} \n\tAS ${selectStatement}',
createView: 'CREATE${orReplace}${force}${viewType}${materialized} VIEW ${name} \n\tAS ${selectStatement}',

viewSelectStatement: 'SELECT ${keys}\n\tFROM ${tableName}',

Expand Down
8 changes: 5 additions & 3 deletions forward_engineering/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ module.exports = (baseProvider, options, app) => {
schemaName: viewData.schemaData.schemaName,
description: detailsTab.description,
ifNotExist: detailsTab.ifNotExist,
materialized: detailsTab.materialized,
};
},

Expand All @@ -458,9 +459,10 @@ module.exports = (baseProvider, options, app) => {
wrapIfNotExists(
assignTemplates(templates.createView, {
name: viewName,
orReplace: viewData.orReplace ? ' OR REPLACE' : '',
force: viewData.force ? ' FORCE' : '',
viewType: getViewType(viewData),
orReplace: viewData.orReplace && !viewData.materialized ? ' OR REPLACE' : '',
force: viewData.force && !viewData.materialized ? ' FORCE' : '',
materialized: viewData.materialized ? ' MATERIALIZED' : '',
viewType: !viewData.materialized ? getViewType(viewData) : '',
selectStatement,
}), viewData.ifNotExist
) + comment,
Expand Down
82 changes: 70 additions & 12 deletions properties_pane/view_level/viewLevelConfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright © 2016-2017 by IntegrIT S.A. dba Hackolade. All rights reserved.
*
* The copyright to the computer software herein is the property of IntegrIT S.A.
* The software may be used and/or copied only with the written permission of
* IntegrIT S.A. or in accordance with the terms and conditions stipulated in
* the agreement/contract under which the software has been supplied.
*/
* Copyright © 2016-2017 by IntegrIT S.A. dba Hackolade. All rights reserved.
*
* The copyright to the computer software herein is the property of IntegrIT S.A.
* The software may be used and/or copied only with the written permission of
* IntegrIT S.A. or in accordance with the terms and conditions stipulated in
* the agreement/contract under which the software has been supplied.
*/

[
{
Expand All @@ -19,11 +19,30 @@
"propertyType": "details",
"template": "textarea"
},
{
"propertyName": "Materialized",
"propertyKeyword": "materialized",
"propertyTooltip": "Specify whether to create materialized view.",
"propertyType": "checkbox"
},
{
"propertyName": "Or replace",
"propertyKeyword": "or_replace",
"propertyTooltip": "To re-create the view if it already exists. You can use this clause to change the definition of an existing view without dropping, re-creating, and regranting object privileges previously granted on it.",
"propertyType": "checkbox"
"propertyType": "checkbox",
"dependency": {
"type": "or",
"values": [
{
"key": "materialized",
"value": false
},
{
"key": "materialized",
"exist": false
}
]
}
},
{
"propertyName": "If not exist",
Expand All @@ -34,19 +53,58 @@
"propertyName": "Force",
"propertyKeyword": "force",
"propertyTooltip": "To create the view regardless of whether the base tables of the view or the referenced object types exist or the owner of the schema containing the view has privileges on them.",
"propertyType": "checkbox"
"propertyType": "checkbox",
"dependency": {
"type": "or",
"values": [
{
"key": "materialized",
"value": false
},
{
"key": "materialized",
"exist": false
}
]
}
},
{
"propertyName": "Editionable",
"propertyKeyword": "editionable",
"propertyTooltip": "To specify whether the view becomes an editioned or noneditioned object if editioning is enabled for the schema object type VIEW in schema.",
"propertyType": "checkbox"
"propertyType": "checkbox",
"dependency": {
"type": "or",
"values": [
{
"key": "materialized",
"value": false
},
{
"key": "materialized",
"exist": false
}
]
}
},
{
"propertyName": "Editioning",
"propertyKeyword": "editioning",
"propertyTooltip": "A single-table view that selects all rows from the base table and displays a subset of the base table columns. ",
"propertyType": "checkbox"
"propertyType": "checkbox",
"dependency": {
"type": "or",
"values": [
{
"key": "materialized",
"value": false
},
{
"key": "materialized",
"exist": false
}
]
}
},
{
"propertyName": "Select Statement",
Expand Down Expand Up @@ -74,4 +132,4 @@
}
]
}
]
]
45 changes: 33 additions & 12 deletions reverse_engineering/helpers/oracleHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,27 @@ const viewNamesByUser = ({includeSystemCollection, schemaName }) => selectEntiti
const materializedViewNamesByUser = ({includeSystemCollection, schemaName }) => selectEntities(`SELECT T.OWNER, T.MVIEW_NAME || \' (v)\' FROM ALL_MVIEWS T`, includeSystemCollection, schemaName);

const getEntitiesNames = async (connectionInfo,logger) => {
const tables = await tableNamesByUser(connectionInfo).catch(e => {
logger.info({ message: 'Cannot retrieve tables' });
const materializedViews = await materializedViewNamesByUser(connectionInfo).catch(e => {
logger.info({ message: 'Cannot retrieve materialized views' });
logger.error(e);

return [];
});

logger.info({ materializedViews });

const materializedViewsNames = materializedViews.map(nameArray => _.join(nameArray, '.').slice(0, -' (v)'.length))

const tables = await tableNamesByUser(connectionInfo)
.then(tables => {
return _.reject(tables, tableNameArray => materializedViewsNames.includes(_.join(tableNameArray, '.')));
})
.catch(e => {
logger.info({ message: 'Cannot retrieve tables' });
logger.error(e);
return [];
});

logger.info({ tables });

const externalTables = await externalTableNamesByUser(connectionInfo).catch(e => {
Expand All @@ -421,15 +436,6 @@ const getEntitiesNames = async (connectionInfo,logger) => {

logger.info({ views });

const materializedViews = await materializedViewNamesByUser(connectionInfo).catch(e => {
logger.info({ message: 'Cannot retrieve materialized views' });
logger.error(e);

return [];
});

logger.info({ materializedViews });

const entities = pairToObj([...tables, ...externalTables, ...views, ...materializedViews]);

return Object.keys(entities).reduce((arr, user) => [...arr, {
Expand Down Expand Up @@ -712,8 +718,16 @@ const getJsonSchema = async (jsonColumns, records) => {

const getViewDDL = async (viewName, logger) => {
try {
const isMaterializedView = await checkEntityMaterializedView(viewName);

await setSQLTerminator();
const queryResult = await execute(`SELECT DBMS_METADATA.GET_DDL('VIEW', VIEW_NAME, OWNER) FROM ALL_VIEWS WHERE VIEW_NAME='${viewName}'`);
let queryResult = null;
if(isMaterializedView) {
queryResult = await execute(`SELECT DBMS_METADATA.GET_DDL('MATERIALIZED_VIEW', MVIEW_NAME, OWNER) FROM ALL_MVIEWS WHERE MVIEW_NAME = '${viewName}'`)
} else {
queryResult = await execute(`SELECT DBMS_METADATA.GET_DDL('VIEW', VIEW_NAME, OWNER) FROM ALL_VIEWS WHERE VIEW_NAME='${viewName}'`);
}

const viewDDL = await _.first(_.first(queryResult)).getData();
return viewDDL;
} catch (err) {
Expand All @@ -729,6 +743,13 @@ const getViewDDL = async (viewName, logger) => {
}
};

const checkEntityMaterializedView = async (name) => {
await setSQLTerminator();
const queryResult = await execute(`SELECT * FROM ALL_MVIEWS WHERE MVIEW_NAME = '${name}'`);

return !_.isEmpty(queryResult);
}

const checkUserHaveRequiredRole = async (logger) => {
try {
const userResult = await execute("SELECT sys_context('USERENV', 'CURRENT_USER') FROM dual");
Expand Down

0 comments on commit c907fba

Please sign in to comment.