|
1 | 1 | package com.genexus; |
2 | 2 |
|
3 | 3 | import java.io.File; |
| 4 | +import java.io.IOException; |
4 | 5 | import java.util.Date; |
5 | 6 | import java.util.List; |
6 | 7 | import java.util.ListIterator; |
|
18 | 19 | import com.genexus.common.interfaces.SpecificImplementation; |
19 | 20 | import com.genexus.util.GXDirectory; |
20 | 21 | import com.genexus.util.GXFileCollection; |
| 22 | +import org.springframework.core.io.ClassPathResource; |
| 23 | +import org.springframework.core.io.FileSystemResource; |
| 24 | +import org.springframework.core.io.Resource; |
| 25 | +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
21 | 26 |
|
22 | 27 | public abstract class BaseProvider implements IGXSmartCacheProvider |
23 | 28 | { |
@@ -50,33 +55,66 @@ private void loadQueryTables() |
50 | 55 | String path = SpecificImplementation.Application.getModelContext().getHttpContext().getDefaultPath(); |
51 | 56 | String configurationDirectoryPath = path + File.separatorChar + "Metadata" + File.separatorChar + "TableAccess"; |
52 | 57 | ConcurrentHashMap<String, Vector<String>> qTables = new ConcurrentHashMap<String, Vector<String>>(); |
53 | | - GXDirectory configurationDirectory = new GXDirectory(configurationDirectoryPath); |
54 | | - GXFileCollection files = configurationDirectory.getFiles(); |
| 58 | + if (ApplicationContext.getInstance().isSpringBootApp()) |
| 59 | + loadQueryTablesSpringBoot(configurationDirectoryPath, qTables); |
| 60 | + else |
| 61 | + loadQueryTablesFileSystem(configurationDirectoryPath, qTables); |
| 62 | + startupDate = CommonUtil.now(false,false); |
| 63 | + queryTables = qTables; |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + private void loadQueryTablesFileSystem(String configurationDirectoryPath, ConcurrentHashMap<String, Vector<String>> qTables){ |
| 68 | + GXDirectory configurationDirectory = new GXDirectory(configurationDirectoryPath); |
| 69 | + GXFileCollection files = configurationDirectory.getFiles(); |
| 70 | + XMLReader reader = new XMLReader(); |
| 71 | + boolean anyTables=false; |
| 72 | + for(int i=1; i <= files.getItemCount(); i++) |
| 73 | + { |
| 74 | + AbstractGXFile xmlFile = files.item(i); |
| 75 | + String xmlFileName = xmlFile.getAbsoluteName(); |
| 76 | + String xmlFileNameNoExt = xmlFile.getNameNoExt(); |
| 77 | + anyTables = processXMLFile(reader, anyTables, xmlFileName, xmlFileNameNoExt, qTables); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + private void loadQueryTablesSpringBoot(String configurationDirectoryPath, ConcurrentHashMap<String, Vector<String>> qTables){ |
| 82 | + PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); |
| 83 | + try { |
| 84 | + Resource[] resources = resolver.getResources("classpath:" + configurationDirectoryPath + "/*"); |
55 | 85 | XMLReader reader = new XMLReader(); |
56 | | - short ok; |
57 | 86 | boolean anyTables=false; |
58 | | - for(int i=1; i <= files.getItemCount(); i++) |
59 | | - { |
60 | | - Vector<String> lst = new Vector<String>(); |
61 | | - lst.add(FORCED_INVALIDATE); // Caso en que se invalido el cache manualmente |
62 | | - AbstractGXFile xmlFile = files.item(i); |
63 | | - reader.open(xmlFile.getAbsoluteName()); |
64 | | - ok = reader.readType(1, "Table"); |
65 | | - while (ok == 1) |
66 | | - { |
67 | | - anyTables=true; |
68 | | - lst.add(normalizeKey((String) reader.getAttributeByName("name"))); |
69 | | - ok = reader.readType(1, "Table"); |
70 | | - } |
71 | | - reader.close(); |
72 | | - if (anyTables) { |
73 | | - qTables.put(normalizeKey((String) xmlFile.getNameNoExt()), lst); |
74 | | - } |
| 87 | + for (Resource resource : resources) { |
| 88 | + String xmlFileName = resource.getFilename(); |
| 89 | + String xmlFileNameNoExt = xmlFileName.substring(0, xmlFileName.lastIndexOf('.')); |
| 90 | + xmlFileName = resource instanceof FileSystemResource? ((FileSystemResource) resource).getPath() : ((ClassPathResource) resource).getPath(); |
| 91 | + anyTables = processXMLFile(reader, anyTables, xmlFileName, xmlFileNameNoExt, qTables); |
75 | 92 | } |
76 | | - startupDate = CommonUtil.now(false,false); |
77 | | - queryTables = qTables; |
| 93 | + } |
| 94 | + catch (IOException e){ |
| 95 | + logger.error("Error loading Query Tables ", e); |
78 | 96 | } |
79 | 97 | } |
| 98 | + |
| 99 | + private boolean processXMLFile(XMLReader reader, boolean anyTables, String xmlFileName, String xmlFileNameNoExt, ConcurrentHashMap<String, Vector<String>> qTables) { |
| 100 | + Vector<String> lst = new Vector<>(); |
| 101 | + lst.add(FORCED_INVALIDATE); // Caso en que se invalido el cache manualmente |
| 102 | + reader.open(xmlFileName); |
| 103 | + short ok = reader.readType(1, "Table"); |
| 104 | + boolean anyLocalTables = false; |
| 105 | + while (ok == 1) |
| 106 | + { |
| 107 | + anyLocalTables = true; |
| 108 | + lst.add(normalizeKey(reader.getAttributeByName("name"))); |
| 109 | + ok = reader.readType(1, "Table"); |
| 110 | + } |
| 111 | + reader.close(); |
| 112 | + if (anyTables || anyLocalTables) { |
| 113 | + qTables.put(normalizeKey(xmlFileNameNoExt), lst); |
| 114 | + } |
| 115 | + return anyTables || anyLocalTables; |
| 116 | + } |
| 117 | + |
80 | 118 | public ConcurrentHashMap<String, Vector<String>> queryTables() { |
81 | 119 | if (queryTables == null) |
82 | 120 | { |
|
0 commit comments