|
1 | 1 | package com.genexus; |
2 | 2 |
|
3 | 3 | import java.io.File; |
4 | | -import java.io.IOException; |
5 | | -import java.nio.charset.StandardCharsets; |
6 | 4 | import java.util.Date; |
7 | 5 | import java.util.List; |
8 | 6 | import java.util.ListIterator; |
|
20 | 18 | import com.genexus.common.interfaces.SpecificImplementation; |
21 | 19 | import com.genexus.util.GXDirectory; |
22 | 20 | import com.genexus.util.GXFileCollection; |
23 | | -import org.springframework.core.io.Resource; |
24 | | -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
25 | 21 |
|
26 | 22 | public abstract class BaseProvider implements IGXSmartCacheProvider |
27 | 23 | { |
@@ -53,78 +49,34 @@ private void loadQueryTables() |
53 | 49 | { |
54 | 50 | String path = SpecificImplementation.Application.getModelContext().getHttpContext().getDefaultPath(); |
55 | 51 | String configurationDirectoryPath = path + File.separatorChar + "Metadata" + File.separatorChar + "TableAccess"; |
56 | | - |
57 | | - ConcurrentHashMap<String, Vector<String>> qTables = new ConcurrentHashMap(); |
58 | | - loadQueryTablesPlatform(configurationDirectoryPath, qTables); |
59 | | - startupDate = CommonUtil.now(false,false); |
60 | | - queryTables = qTables; |
61 | | - } |
62 | | - } |
63 | | - |
64 | | - public void loadQueryTablesPlatform(String configurationDirectoryPath, ConcurrentHashMap<String, Vector<String>> qTables) { |
65 | | - if (ApplicationContext.getInstance().isSpringBootApp()) |
66 | | - loadQueryTablesSpringBoot(configurationDirectoryPath, qTables); |
67 | | - else |
68 | | - loadQueryTablesNone(configurationDirectoryPath, qTables); |
69 | | - |
70 | | - } |
71 | | - |
72 | | - public void loadQueryTablesNone(String configurationDirectoryPath, ConcurrentHashMap<String, Vector<String>> qTables) { |
73 | | - GXDirectory configurationDirectory = new GXDirectory(configurationDirectoryPath); |
74 | | - GXFileCollection files = configurationDirectory.getFiles(); |
75 | | - XMLReader reader = new XMLReader(); |
76 | | - short ok; |
77 | | - boolean anyTable=false; |
78 | | - for(int i=1; i <= files.getItemCount(); i++) { |
79 | | - Vector<String> lst = new Vector<String>(); |
80 | | - lst.add(FORCED_INVALIDATE); // Caso en que se invalido el cache manualmente |
81 | | - AbstractGXFile xmlFile = files.item(i); |
82 | | - reader.open(xmlFile.getAbsoluteName()); |
83 | | - ok = reader.readType(1, "Table"); |
84 | | - while (ok == 1) { |
85 | | - anyTable=true; |
86 | | - lst.add(normalizeKey(reader.getAttributeByName("name"))); |
87 | | - ok = reader.readType(1, "Table"); |
88 | | - } |
89 | | - reader.close(); |
90 | | - if (anyTable) { |
91 | | - qTables.put(normalizeKey(xmlFile.getNameNoExt()), lst); |
92 | | - } |
93 | | - } |
94 | | - } |
95 | | - |
96 | | - public void loadQueryTablesSpringBoot(String configurationDirectoryPath, ConcurrentHashMap<String, Vector<String>> qTables) { |
97 | | - try { |
98 | | - Resource[] resources = new PathMatchingResourcePatternResolver().getResources(configurationDirectoryPath + "/*.xml"); |
| 52 | + ConcurrentHashMap<String, Vector<String>> qTables = new ConcurrentHashMap<String, Vector<String>>(); |
| 53 | + GXDirectory configurationDirectory = new GXDirectory(configurationDirectoryPath); |
| 54 | + GXFileCollection files = configurationDirectory.getFiles(); |
99 | 55 | XMLReader reader = new XMLReader(); |
100 | | - reader.setDocEncoding("UTF8"); |
101 | 56 | short ok; |
102 | | - boolean anyTable=false; |
103 | | - String xmlContent; |
104 | | - for (int i = 0; i < resources.length; i++) { |
| 57 | + boolean anyTables=false; |
| 58 | + for(int i=1; i <= files.getItemCount(); i++) |
| 59 | + { |
105 | 60 | Vector<String> lst = new Vector<String>(); |
106 | | - lst.add(FORCED_INVALIDATE); |
107 | | - xmlContent = resources[i].getContentAsString(StandardCharsets.UTF_8); |
108 | | - if (!xmlContent.startsWith("<")) |
109 | | - xmlContent = xmlContent.substring(1); //Avoid BOM |
110 | | - reader.openFromString(xmlContent); |
| 61 | + lst.add(FORCED_INVALIDATE); // Caso en que se invalido el cache manualmente |
| 62 | + AbstractGXFile xmlFile = files.item(i); |
| 63 | + reader.open(xmlFile.getAbsoluteName()); |
111 | 64 | ok = reader.readType(1, "Table"); |
112 | | - while (ok == 1) { |
113 | | - anyTable=true; |
114 | | - lst.add(normalizeKey(reader.getAttributeByName("name"))); |
| 65 | + while (ok == 1) |
| 66 | + { |
| 67 | + anyTables=true; |
| 68 | + lst.add(normalizeKey((String) reader.getAttributeByName("name"))); |
115 | 69 | ok = reader.readType(1, "Table"); |
116 | 70 | } |
117 | 71 | reader.close(); |
118 | | - if (anyTable) { |
119 | | - qTables.put(normalizeKey(resources[i].getFilename().substring(0, resources[i].getFilename().lastIndexOf("."))), lst); |
| 72 | + if (anyTables) { |
| 73 | + qTables.put(normalizeKey((String) xmlFile.getNameNoExt()), lst); |
120 | 74 | } |
121 | 75 | } |
122 | | - } |
123 | | - catch (IOException e) { |
124 | | - logger.error("Error reading Table Access metadata", e); |
| 76 | + startupDate = CommonUtil.now(false,false); |
| 77 | + queryTables = qTables; |
125 | 78 | } |
126 | 79 | } |
127 | | - |
128 | 80 | public ConcurrentHashMap<String, Vector<String>> queryTables() { |
129 | 81 | if (queryTables == null) |
130 | 82 | { |
|
0 commit comments