diff --git a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/model/XSKDataStructureModel.java b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/model/XSKDataStructureModel.java index c1741b7b3..47b677388 100644 --- a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/model/XSKDataStructureModel.java +++ b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/model/XSKDataStructureModel.java @@ -57,6 +57,9 @@ public class XSKDataStructureModel { @Transient private transient XSKDBContentType dbContentType; + @Transient + private transient boolean createDataStructure = false; + /** * Gets the location. * @@ -221,6 +224,14 @@ public void setDbContentType(XSKDBContentType dbContentType) { this.dbContentType = dbContentType; } + public boolean isCreateDataStructure() { + return createDataStructure; + } + + public void setCreateDataStructure(boolean createDataStructure) { + this.createDataStructure = createDataStructure; + } + /** * To json. * diff --git a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/parser/hdbdd/XSKHdbddParser.java b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/parser/hdbdd/XSKHdbddParser.java index 9dcdf8de6..f9019d7b8 100644 --- a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/parser/hdbdd/XSKHdbddParser.java +++ b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/parser/hdbdd/XSKHdbddParser.java @@ -19,6 +19,7 @@ import com.sap.xsk.hdb.ds.model.hdbdd.XSKDataStructureCdsModel; import com.sap.xsk.hdb.ds.model.hdbtable.XSKDataStructureHDBTableModel; import com.sap.xsk.hdb.ds.model.hdbtabletype.XSKDataStructureHDBTableTypeModel; +import com.sap.xsk.hdb.ds.module.XSKHDBModule; import com.sap.xsk.hdb.ds.parser.XSKDataStructureParser; import com.sap.xsk.hdb.ds.transformer.hdbdd.HdbddTransformer; import com.sap.xsk.parser.hdbdd.core.CdsLexer; @@ -61,10 +62,16 @@ public class XSKHdbddParser implements XSKDataStructureParser { private HdbddTransformer hdbddTransformer = new HdbddTransformer(); private IRepository repository = (IRepository) StaticObjects.get(StaticObjects.REPOSITORY); private SymbolTable symbolTable = new SymbolTable(); - private Map> usedFiles = new HashMap<>(); + private Map> dependencyStructure = new HashMap<>(); + private Set parsedNodes = new HashSet<>(); @Override public XSKDataStructureModel parse(String location, String content) throws XSKDataStructuresException, IOException { + XSKDataStructureCdsModel cdsModel = getCdsModelBaseData(location, content); + if (XSKHDBModule.getManagerServices().get(getType()).isParsed(cdsModel, dependencyStructure.get(location) != null)) { + return null; + } + for (String fileLocation : this.getFilesToProcess(location)) { IResource loadedResource = this.repository.getResource("/registry/public/" + fileLocation); String fileContent = new String(loadedResource.getContent()); @@ -77,9 +84,10 @@ public XSKDataStructureModel parse(String location, String content) throws XSKDa } } - XSKDataStructureCdsModel cdsModel = getCdsModel(location, content); + getCdsModelWithParsedData(cdsModel); this.symbolTable.clearSymbolsByFullName(); this.symbolTable.clearEntityGraph(); + parsedNodes.clear(); return cdsModel; } @@ -121,11 +129,15 @@ private void parseHdbdd(String location, String content) throws IOException, XSK entityDefinitionListener.getPackagesUsed().forEach(p -> { String fileLocation = getFileLocation(p); - addUsedFile(fileLocation, location); + addFileToDependencyTree(fileLocation, location); + if(!parsedNodes.isEmpty() && parsedNodes.contains(fileLocation)){ + return; + } try { IResource loadedResource = this.repository.getResource("/registry/public/" + fileLocation); parseHdbdd(fileLocation, new String(loadedResource.getContent())); + parsedNodes.add(fileLocation); } catch (IOException | XSKArtifactParserException e) { XSKCommonsUtils.logCustomErrors(location, XSKCommonsConstants.PARSER_ERROR, "", "", e.getMessage(), "", XSKCommonsConstants.HDBDD_PARSER, XSKCommonsConstants.MODULE_PARSERS, @@ -150,14 +162,14 @@ private void parseHdbdd(String location, String content) throws IOException, XSK } } - private void addUsedFile(String usedFile, String userFile) { - Set userFiles = usedFiles.get(usedFile); - if (userFiles == null) { - userFiles = new HashSet<>(); + private void addFileToDependencyTree(String nodeFile, String rootFile) { + Set rootFiles = dependencyStructure.get(nodeFile); + if (rootFiles == null) { + rootFiles = new HashSet<>(); } - userFiles.add(userFile); - this.usedFiles.put(usedFile, userFiles); + rootFiles.add(rootFile); + this.dependencyStructure.put(nodeFile, rootFiles); } @Override @@ -178,21 +190,32 @@ private List getFilesToProcess(String fileLocation) { } private void getRootFiles(String usedFileName, List rootFiles) { - Set userFiles = usedFiles.get(usedFileName); + Set userFiles = dependencyStructure.get(usedFileName); if (userFiles == null) { rootFiles.add(usedFileName); return; } - usedFiles.get(usedFileName).forEach(f -> { + dependencyStructure.get(usedFileName).forEach(f -> { getRootFiles(f, rootFiles); }); } - private XSKDataStructureCdsModel getCdsModel(String location, String content) { - List parsedEntities = this.symbolTable.getSortedEntities(); - + private XSKDataStructureCdsModel getCdsModelBaseData(String location, String content) { XSKDataStructureCdsModel cdsModel = new XSKDataStructureCdsModel(); + cdsModel.setName(location); + cdsModel.setLocation(location); + cdsModel.setType(getType()); + cdsModel.setCreatedBy(UserFacade.getName()); + cdsModel.setCreatedAt(new Timestamp(new java.util.Date().getTime())); + cdsModel.setHash(DigestUtils.md5Hex(content)); + cdsModel.setDbContentType(XSKDBContentType.XS_CLASSIC); + + return cdsModel; + } + + private void getCdsModelWithParsedData(XSKDataStructureCdsModel cdsModel) { + List parsedEntities = this.symbolTable.getSortedEntities(); List tableModels = new ArrayList<>(); parsedEntities.forEach(e -> { @@ -210,14 +233,6 @@ private XSKDataStructureCdsModel getCdsModel(String location, String content) { cdsModel.setTableModels(tableModels); cdsModel.setTableTypeModels(hdbTableTypeModels); - cdsModel.setName(location); - cdsModel.setLocation(location); - cdsModel.setType(getType()); - cdsModel.setCreatedBy(UserFacade.getName()); - cdsModel.setCreatedAt(new Timestamp(new java.util.Date().getTime())); - cdsModel.setHash(DigestUtils.md5Hex(content)); - cdsModel.setDbContentType(XSKDBContentType.XS_CLASSIC); - return cdsModel; } private String getFileLocation(String fullPackagePath) { diff --git a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKDataStructureManager.java b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKDataStructureManager.java index 01dba1323..b0a28f781 100644 --- a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKDataStructureManager.java +++ b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKDataStructureManager.java @@ -40,4 +40,6 @@ void updateDataStructure(Connection connection, T tableModel) void cleanup() throws XSKDataStructuresException; void clearCache(); + + boolean isParsed(T tableModel, boolean parsedByRoot) throws XSKDataStructuresException; } diff --git a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKEntityManagerService.java b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKEntityManagerService.java index 9be121b55..569b82775 100644 --- a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKEntityManagerService.java +++ b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKEntityManagerService.java @@ -49,23 +49,33 @@ public IXSKEntityManagerService() { entitiesSynchronized = Collections.synchronizedList(new ArrayList<>()); } + public boolean isParsed(XSKDataStructureCdsModel entitiesModel, boolean parsedByRoot) throws XSKDataStructuresException { + XSKDataStructureCdsModel existingModel = getDataStructuresCoreService() + .getDataStructure(entitiesModel.getLocation(), entitiesModel.getType()); + boolean isEmptyExistingModel = existingModel == null; + + if (isEmptyExistingModel && parsedByRoot) { + getDataStructuresCoreService() + .createDataStructure(entitiesModel.getLocation(), entitiesModel.getName(), entitiesModel.getHash(), entitiesModel.getType()); + return true; + } + + entitiesModel.setCreateDataStructure(isEmptyExistingModel); + return !isEmptyExistingModel && existingModel.equals(entitiesModel); + } @Override public void synchronizeRuntimeMetadata(XSKDataStructureCdsModel entitiesModel) throws XSKDataStructuresException { - if (!getDataStructuresCoreService().existsDataStructure(entitiesModel.getLocation(), entitiesModel.getType())) { + if (entitiesModel.isCreateDataStructure()) { getDataStructuresCoreService() .createDataStructure(entitiesModel.getLocation(), entitiesModel.getName(), entitiesModel.getHash(), entitiesModel.getType()); dataStructureEntitiesModel.put(entitiesModel.getName(), entitiesModel); logger.info("Synchronized a new Entities file [{}] from location: {}", entitiesModel.getName(), entitiesModel.getLocation()); } else { - XSKDataStructureCdsModel existing = getDataStructuresCoreService() - .getDataStructure(entitiesModel.getLocation(), entitiesModel.getType()); - if (!entitiesModel.equals(existing)) { - getDataStructuresCoreService() - .updateDataStructure(entitiesModel.getLocation(), entitiesModel.getName(), entitiesModel.getHash(), entitiesModel.getType()); - dataStructureEntitiesModel.put(entitiesModel.getName(), entitiesModel); - logger.info("Synchronized a modified Entities file [{}] from location: {}", entitiesModel.getName(), entitiesModel.getLocation()); - } + getDataStructuresCoreService() + .updateDataStructure(entitiesModel.getLocation(), entitiesModel.getName(), entitiesModel.getHash(), entitiesModel.getType()); + dataStructureEntitiesModel.put(entitiesModel.getName(), entitiesModel); + logger.info("Synchronized a modified Entities file [{}] from location: {}", entitiesModel.getName(), entitiesModel.getLocation()); } if (!entitiesSynchronized.contains(entitiesModel.getLocation())) { entitiesSynchronized.add(entitiesModel.getLocation()); diff --git a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKHDBSequenceManagerService.java b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKHDBSequenceManagerService.java index 73fb55e5a..23d754800 100644 --- a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKHDBSequenceManagerService.java +++ b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKHDBSequenceManagerService.java @@ -107,4 +107,9 @@ public String getDataStructureType() { public void clearCache() { dataStructureSequenceModels.clear(); } + + @Override + public boolean isParsed(XSKDataStructureHDBSequenceModel tableModel, boolean parsedByRoot) throws XSKDataStructuresException { + return false; + } } diff --git a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKProceduresManagerService.java b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKProceduresManagerService.java index 467a08e9b..31102685b 100644 --- a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKProceduresManagerService.java +++ b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKProceduresManagerService.java @@ -107,6 +107,11 @@ public void clearCache() { dataStructureProceduresModels.clear(); } + @Override + public boolean isParsed(XSKDataStructureHDBProcedureModel tableModel, boolean parsedByRoot) throws XSKDataStructuresException { + return false; + } + @Override public Map getDataStructureModels() { return Collections.unmodifiableMap(this.dataStructureProceduresModels); diff --git a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKSchemaManagerService.java b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKSchemaManagerService.java index 3c9e1d091..3744058b1 100644 --- a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKSchemaManagerService.java +++ b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKSchemaManagerService.java @@ -101,6 +101,11 @@ public void clearCache() { dataStructureSchemasModels.clear(); } + @Override + public boolean isParsed(XSKDataStructureHDBSchemaModel tableModel, boolean parsedByRoot) throws XSKDataStructuresException { + return false; + } + @Override public Map getDataStructureModels() { return Collections.unmodifiableMap(this.dataStructureSchemasModels); diff --git a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKSynonymManagerService.java b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKSynonymManagerService.java index 3dbc63752..8e3637485 100644 --- a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKSynonymManagerService.java +++ b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKSynonymManagerService.java @@ -95,4 +95,9 @@ public String getDataStructureType() { public void clearCache() { dataStructureSynonymModels.clear(); } + + @Override + public boolean isParsed(XSKDataStructureHDBSynonymModel tableModel, boolean parsedByRoot) throws XSKDataStructuresException { + return false; + } } diff --git a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKTableFunctionManagerService.java b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKTableFunctionManagerService.java index 2f520dc50..7f9c326cd 100644 --- a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKTableFunctionManagerService.java +++ b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKTableFunctionManagerService.java @@ -106,6 +106,11 @@ public void clearCache() { dataStructureTableFunctionsModels.clear(); } + @Override + public boolean isParsed(XSKDataStructureHDBTableFunctionModel tableModel, boolean parsedByRoot) throws XSKDataStructuresException { + return false; + } + @Override public Map getDataStructureModels() { return Collections.unmodifiableMap(this.dataStructureTableFunctionsModels); diff --git a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKTableManagerService.java b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKTableManagerService.java index 6182a0c07..a279aedc9 100644 --- a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKTableManagerService.java +++ b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKTableManagerService.java @@ -103,4 +103,9 @@ public String getDataStructureType() { public void clearCache() { dataStructureTableModels.clear(); } + + @Override + public boolean isParsed(XSKDataStructureHDBTableModel tableModel, boolean parsedByRoot) throws XSKDataStructuresException { + return false; + } } diff --git a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKTableTypeManagerService.java b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKTableTypeManagerService.java index 9d7ead9d0..55139263a 100644 --- a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKTableTypeManagerService.java +++ b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKTableTypeManagerService.java @@ -105,4 +105,9 @@ public String getDataStructureType() { public void clearCache() { dataStructureHDBTableTypeModels.clear(); } + + @Override + public boolean isParsed(XSKDataStructureHDBTableTypeModel tableModel, boolean parsedByRoot) throws XSKDataStructuresException { + return false; + } } diff --git a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKViewManagerService.java b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKViewManagerService.java index a0a735692..cabe91b56 100644 --- a/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKViewManagerService.java +++ b/modules/engines/engine-hdb/src/main/java/com/sap/xsk/hdb/ds/service/manager/IXSKViewManagerService.java @@ -96,4 +96,9 @@ public String getDataStructureType() { public void clearCache() { dataStructureViewsModels.clear(); } + + @Override + public boolean isParsed(XSKDataStructureHDBViewModel tableModel, boolean parsedByRoot) throws XSKDataStructuresException { + return false; + } }