Skip to content

Commit e55e520

Browse files
authored
Smart devices cache was not working fine in Spring Boot. (#959)
Issue 204052
1 parent 2ad29ae commit e55e520

File tree

1 file changed

+44
-54
lines changed

1 file changed

+44
-54
lines changed

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

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.io.File;
44
import java.io.IOException;
5-
import java.nio.charset.StandardCharsets;
65
import java.util.Date;
76
import java.util.List;
87
import java.util.ListIterator;
@@ -20,6 +19,8 @@
2019
import com.genexus.common.interfaces.SpecificImplementation;
2120
import com.genexus.util.GXDirectory;
2221
import com.genexus.util.GXFileCollection;
22+
import org.springframework.core.io.ClassPathResource;
23+
import org.springframework.core.io.FileSystemResource;
2324
import org.springframework.core.io.Resource;
2425
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
2526

@@ -53,76 +54,65 @@ private void loadQueryTables()
5354
{
5455
String path = SpecificImplementation.Application.getModelContext().getHttpContext().getDefaultPath();
5556
String configurationDirectoryPath = path + File.separatorChar + "Metadata" + File.separatorChar + "TableAccess";
56-
57-
ConcurrentHashMap<String, Vector<String>> qTables = new ConcurrentHashMap();
58-
loadQueryTablesPlatform(configurationDirectoryPath, qTables);
57+
ConcurrentHashMap<String, Vector<String>> qTables = new ConcurrentHashMap<String, Vector<String>>();
58+
if (ApplicationContext.getInstance().isSpringBootApp())
59+
loadQueryTablesSpringBoot(configurationDirectoryPath, qTables);
60+
else
61+
loadQueryTablesFileSystem(configurationDirectoryPath, qTables);
5962
startupDate = CommonUtil.now(false,false);
6063
queryTables = qTables;
6164
}
6265
}
6366

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) {
67+
private void loadQueryTablesFileSystem(String configurationDirectoryPath, ConcurrentHashMap<String, Vector<String>> qTables){
7368
GXDirectory configurationDirectory = new GXDirectory(configurationDirectoryPath);
7469
GXFileCollection files = configurationDirectory.getFiles();
7570
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
71+
boolean anyTables=false;
72+
for(int i=1; i <= files.getItemCount(); i++)
73+
{
8174
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-
}
75+
String xmlFileName = xmlFile.getAbsoluteName();
76+
String xmlFileNameNoExt = xmlFile.getNameNoExt();
77+
anyTables = processXMLFile(reader, anyTables, xmlFileName, xmlFileNameNoExt, qTables);
9378
}
9479
}
9580

96-
public void loadQueryTablesSpringBoot(String configurationDirectoryPath, ConcurrentHashMap<String, Vector<String>> qTables) {
81+
private void loadQueryTablesSpringBoot(String configurationDirectoryPath, ConcurrentHashMap<String, Vector<String>> qTables){
82+
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
9783
try {
98-
Resource[] resources = new PathMatchingResourcePatternResolver().getResources(configurationDirectoryPath + "/*.xml");
84+
Resource[] resources = resolver.getResources("classpath:" + configurationDirectoryPath + "/*");
9985
XMLReader reader = new XMLReader();
100-
reader.setDocEncoding("UTF8");
101-
short ok;
102-
boolean anyTable=false;
103-
String xmlContent;
104-
for (int i = 0; i < resources.length; i++) {
105-
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);
111-
ok = reader.readType(1, "Table");
112-
while (ok == 1) {
113-
anyTable=true;
114-
lst.add(normalizeKey(reader.getAttributeByName("name")));
115-
ok = reader.readType(1, "Table");
116-
}
117-
reader.close();
118-
if (anyTable) {
119-
qTables.put(normalizeKey(resources[i].getFilename().substring(0, resources[i].getFilename().lastIndexOf("."))), lst);
120-
}
86+
boolean anyTables=false;
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);
12192
}
12293
}
123-
catch (IOException e) {
124-
logger.error("Error reading Table Access metadata", e);
94+
catch (IOException e){
95+
logger.error("Error loading Query Tables ", e);
96+
}
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);
125114
}
115+
return anyTables || anyLocalTables;
126116
}
127117

128118
public ConcurrentHashMap<String, Vector<String>> queryTables() {

0 commit comments

Comments
 (0)