@@ -75,11 +75,30 @@ const BASE_RESOLVE_SELECT = [
75
75
`end as sqlType` ,
76
76
] . join ( ` ` ) ;
77
77
78
- let ReferenceCache : Map < string , ResolvedSqlObject > = new Map < string , ResolvedSqlObject > ( ) ;
78
+
79
79
export default class Schemas {
80
+ private static ReferenceCache : Map < string , ResolvedSqlObject > = new Map < string , ResolvedSqlObject > ( ) ;
81
+
80
82
private static buildReferenceCacheKey ( obj : ObjectReference ) : string {
81
83
return `${ obj . schema } .${ obj . name } ` ;
82
84
}
85
+
86
+
87
+ static storeCachedReference ( obj : ObjectReference , resolvedTo : ResolvedSqlObject ) : void {
88
+ if ( obj . name && obj . schema ) {
89
+ const key = Schemas . buildReferenceCacheKey ( obj ) ;
90
+ this . ReferenceCache . set ( key , resolvedTo ) ;
91
+ }
92
+ }
93
+
94
+ static getCachedReference ( obj : ObjectReference ) : ResolvedSqlObject | undefined {
95
+ if ( obj . name && obj . schema ) {
96
+ const key = Schemas . buildReferenceCacheKey ( obj ) ;
97
+ return this . ReferenceCache . get ( key ) ;
98
+ }
99
+ return undefined ;
100
+ }
101
+
83
102
/**
84
103
* Resolves to the following SQL types: SCHEMA, TABLE, VIEW, ALIAS, INDEX, FUNCTION and PROCEDURE
85
104
*/
@@ -96,12 +115,12 @@ export default class Schemas {
96
115
// First, we use OBJECT_STATISTICS to resolve the object based on the library list.
97
116
// But, if the object is qualified with a schema, we need to use that schema to get the correct object.
98
117
for ( const obj of sqlObjects ) {
99
- const key = this . buildReferenceCacheKey ( obj ) ;
100
- // check if we have already resolved this object
101
- if ( ReferenceCache . has ( key ) ) {
102
- resolvedObjects . push ( ReferenceCache . get ( key ! ) ) ;
118
+ const cached = this . getCachedReference ( obj ) ;
119
+ if ( cached ) {
120
+ resolvedObjects . push ( cached ) ;
103
121
continue ;
104
122
}
123
+
105
124
if ( obj . schema ) {
106
125
statements . push (
107
126
`${ BASE_RESOLVE_SELECT } from table(qsys2.object_statistics(?, '*ALL', object_name => ?))`
@@ -169,10 +188,7 @@ export default class Schemas {
169
188
170
189
// add reslved objects to to ReferenceCache
171
190
resolvedObjects . forEach ( ( obj ) => {
172
- const key = this . buildReferenceCacheKey ( obj ) ;
173
- if ( ! ReferenceCache . has ( key ) ) {
174
- ReferenceCache . set ( key , obj ) ;
175
- }
191
+ this . storeCachedReference ( obj , obj ) ;
176
192
} ) ;
177
193
178
194
return resolvedObjects ;
0 commit comments