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