@@ -53,7 +53,7 @@ VTLSession <- R6Class("VTLSession",
53
53
# ' This method should not be called by the application.
54
54
finalize = function () {
55
55
finalized <- T
56
- private $ instance <- NULL
56
+ private $ clearInstance()
57
57
return (invisible ())
58
58
},
59
59
@@ -73,14 +73,14 @@ VTLSession <- R6Class("VTLSession",
73
73
# ' The editor code to associate this session
74
74
setText = function (code ) {
75
75
self $ text <- code
76
- instance <- NULL
76
+ private $ clearInstance()
77
77
return (invisible (self ))
78
78
},
79
79
80
80
# ' @description
81
81
# ' Compiles the VTL statements submitted for this session.
82
82
compile = function () {
83
- private $ instance = NULL ;
83
+ private $ clearInstance()
84
84
private $ checkInstance()$ compile()
85
85
},
86
86
@@ -107,13 +107,16 @@ VTLSession <- R6Class("VTLSession",
107
107
# ' @param nodes
108
108
# ' a list of names of nodes to compute from this session
109
109
getValues = function (nodes ) {
110
- jnodes <- sapply(X = nodes , private $ checkInstance()$ resolve )
111
- nodesdf <- lapply(names(jnodes ), FUN = function (x , jnodes , jstructs ) {
112
- jnode <- jnodes [[x ]]
110
+ nodesdf <- lapply(nodes , function (node ) {
111
+ df <- get0(node , envir = private $ env )
112
+ if (! is.null(df )) {
113
+ return (df )
114
+ }
115
+
116
+ jnode <- private $ checkInstance()$ resolve(node )
113
117
if (jnode %instanceof % " it.bancaditalia.oss.vtl.model.data.ScalarValue" ) {
114
118
df <- as.data.frame(list (Scalar = jnode $ get()))
115
- }
116
- else if (jnode %instanceof % " it.bancaditalia.oss.vtl.model.data.DataSet" ) {
119
+ } else {
117
120
pager <- .jnew(" it.bancaditalia.oss.vtl.util.Paginator" ,
118
121
.jcast(jnode , " it.bancaditalia.oss.vtl.model.data.DataSet" ), 100L )
119
122
nc <- jnode $ getMetadata()$ size()
@@ -123,13 +126,15 @@ VTLSession <- R6Class("VTLSession",
123
126
})
124
127
attr(df , ' measures' ) <- sapply(jnode $ getMetadata()$ getMeasures(), function (x ) { x $ getVariable()$ getName() })
125
128
attr(df , ' identifiers' ) <- sapply(jnode $ getMetadata()$ getIDs(), function (x ) { x $ getVariable()$ getName() })
129
+ } else {
130
+ stop(paste0(" Unsupported result class: " , jnode $ getClass()$ getName()))
126
131
}
127
- else
128
- stop(paste0(" Unsupported result class: " , jnode $ getClass()$ getName()))
129
132
130
- return (df )
131
- }, jnodes , jstructs )
132
- names(nodesdf ) <- names(jnodes )
133
+ assign(node , df , envir = private $ env )
134
+ return (df )
135
+ })
136
+
137
+ names(nodesdf ) <- nodes
133
138
return (nodesdf )
134
139
},
135
140
@@ -198,6 +203,7 @@ VTLSession <- R6Class("VTLSession",
198
203
),
199
204
private = list (
200
205
instance = NULL ,
206
+ env <- new.env(parent = emptyenv())
201
207
finalized = F ,
202
208
checkInstance = function () {
203
209
if (private $ finalized )
@@ -207,6 +213,11 @@ VTLSession <- R6Class("VTLSession",
207
213
}
208
214
return (invisible (private $ instance ))
209
215
}
216
+ clearInstance = function () {
217
+ self $ instance <- NULL
218
+ self $ env <- new.env(parent = emptyenv())
219
+ .jgc()
220
+ }
210
221
)
211
222
)
212
223
0 commit comments