Skip to content

Commit 08a4c92

Browse files
committed
Smart devices cache was not working fine in Spring Boot.
Issue 204052 459dbff
1 parent 0d66b44 commit 08a4c92

File tree

1 file changed

+60
-22
lines changed

1 file changed

+60
-22
lines changed

common/src/main/java/com/genexus/BaseProvider.java

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.genexus;
22

33
import java.io.File;
4+
import java.io.IOException;
45
import java.util.Date;
56
import java.util.List;
67
import java.util.ListIterator;
@@ -18,6 +19,10 @@
1819
import com.genexus.common.interfaces.SpecificImplementation;
1920
import com.genexus.util.GXDirectory;
2021
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;
2126

2227
public abstract class BaseProvider implements IGXSmartCacheProvider
2328
{
@@ -50,33 +55,66 @@ private void loadQueryTables()
5055
String path = SpecificImplementation.Application.getModelContext().getHttpContext().getDefaultPath();
5156
String configurationDirectoryPath = path + File.separatorChar + "Metadata" + File.separatorChar + "TableAccess";
5257
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 + "/*");
5585
XMLReader reader = new XMLReader();
56-
short ok;
5786
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);
7592
}
76-
startupDate = CommonUtil.now(false,false);
77-
queryTables = qTables;
93+
}
94+
catch (IOException e){
95+
logger.error("Error loading Query Tables ", e);
7896
}
7997
}
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+
80118
public ConcurrentHashMap<String, Vector<String>> queryTables() {
81119
if (queryTables == null)
82120
{

0 commit comments

Comments
 (0)