@@ -102,22 +102,24 @@ private ADataSourceService getDataSourceService(Query query) throws GeppettoInit
102102 @ Override
103103 public Object caseProcessQuery (ProcessQuery query )
104104 {
105-
106- if (QueryChecker .check (query , getVariable ()))
105+ if (!count || (count && query .isRunForCount ()))
107106 {
108- try
109- {
110- IQueryProcessor queryProcessor = (IQueryProcessor ) ServiceCreator .getNewServiceInstance (query .getQueryProcessorId ());
111- this .results = queryProcessor .process (query , getDataSource (query ), getVariable (), getResults (), geppettoModelAccess );
112- this .processingOutputMap = queryProcessor .getProcessingOutputMap ();
113- }
114- catch (GeppettoInitializationException e )
115- {
116- return new GeppettoVisitingException (e );
117- }
118- catch (GeppettoDataSourceException e )
107+ if (QueryChecker .check (query , getVariable ()))
119108 {
120- return new GeppettoVisitingException (e );
109+ try
110+ {
111+ IQueryProcessor queryProcessor = (IQueryProcessor ) ServiceCreator .getNewServiceInstance (query .getQueryProcessorId ());
112+ this .results = queryProcessor .process (query , getDataSource (query ), getVariable (), getResults (), geppettoModelAccess );
113+ this .processingOutputMap = queryProcessor .getProcessingOutputMap ();
114+ }
115+ catch (GeppettoInitializationException e )
116+ {
117+ return new GeppettoVisitingException (e );
118+ }
119+ catch (GeppettoDataSourceException e )
120+ {
121+ return new GeppettoVisitingException (e );
122+ }
121123 }
122124 }
123125 return super .caseProcessQuery (query );
@@ -131,23 +133,25 @@ public Object caseProcessQuery(ProcessQuery query)
131133 @ Override
132134 public Object caseCompoundQuery (CompoundQuery query )
133135 {
134- ExecuteQueryVisitor runQueryVisitor = new ExecuteQueryVisitor (variable , geppettoModelAccess );
135- runQueryVisitor .processingOutputMap .putAll (processingOutputMap );
136-
137- try
138- {
139- GeppettoModelTraversal .applyDirectChildrenOnly (query , runQueryVisitor );
140- mergeResults (runQueryVisitor .getResults ());
141- }
142- catch (GeppettoVisitingException e )
136+ if (!count || (count && query .isRunForCount ()))
143137 {
144- return e ;
145- }
146- catch (GeppettoDataSourceException e )
147- {
148- return new GeppettoVisitingException (e );
149- }
138+ ExecuteQueryVisitor runQueryVisitor = new ExecuteQueryVisitor (variable , geppettoModelAccess );
139+ runQueryVisitor .processingOutputMap .putAll (processingOutputMap );
150140
141+ try
142+ {
143+ GeppettoModelTraversal .applyDirectChildrenOnly (query , runQueryVisitor );
144+ mergeResults (runQueryVisitor .getResults ());
145+ }
146+ catch (GeppettoVisitingException e )
147+ {
148+ return e ;
149+ }
150+ catch (GeppettoDataSourceException e )
151+ {
152+ return new GeppettoVisitingException (e );
153+ }
154+ }
151155 return super .caseCompoundQuery (query );
152156 }
153157
@@ -157,13 +161,16 @@ public Object caseCompoundQuery(CompoundQuery query)
157161 * @see org.geppetto.model.datasources.util.DatasourcesSwitch#caseCompoundRefQuery(org.geppetto.model.datasources.CompoundRefQuery)
158162 */
159163 @ Override
160- public Object caseCompoundRefQuery (CompoundRefQuery object )
164+ public Object caseCompoundRefQuery (CompoundRefQuery compoundQuery )
161165 {
162- for ( Query query : object . getQueryChain ( ))
166+ if (! count || ( count && compoundQuery . isRunForCount () ))
163167 {
164- this .doSwitch (query );
168+ for (Query query : compoundQuery .getQueryChain ())
169+ {
170+ this .doSwitch (query );
171+ }
165172 }
166- return super .caseCompoundRefQuery (object );
173+ return super .caseCompoundRefQuery (compoundQuery );
167174 }
168175
169176 /*
@@ -174,47 +181,57 @@ public Object caseCompoundRefQuery(CompoundRefQuery object)
174181 @ Override
175182 public Object caseSimpleQuery (SimpleQuery query )
176183 {
177- try
184+ if (! count || ( count && query . isRunForCount ()))
178185 {
179- if ( QueryChecker . check ( query , getVariable ()))
186+ try
180187 {
181- ADataSourceService dataSourceService = getDataSourceService (query );
182- String url = getDataSource (query ).getUrl ();
188+ if (QueryChecker .check (query , getVariable ()))
189+ {
190+ ADataSourceService dataSourceService = getDataSourceService (query );
191+ String url = getDataSource (query ).getUrl ();
192+ String queryString = null ;
193+ if (count )
194+ {
195+ queryString = !query .getCountQuery ().isEmpty () ? query .getCountQuery () : query .getQuery ();
196+ }
197+ else
198+ {
199+ queryString = query .getQuery ();
200+ }
183201
184- String queryString = count ? query .getCountQuery () : query .getQuery ();
202+ Map <String , Object > properties = new HashMap <String , Object >();
203+ properties .put (ID , getVariable ().getId ());
204+ properties .put ("QUERY" , queryString );
185205
186- Map <String , Object > properties = new HashMap <String , Object >();
187- properties .put (ID , getVariable ().getId ());
188- properties .put ("QUERY" , queryString );
206+ if (processingOutputMap != null )
207+ {
208+ properties .putAll (processingOutputMap );
209+ }
189210
190- if (processingOutputMap != null )
191- {
192- properties .putAll (processingOutputMap );
193- }
211+ String processedQueryString = VelocityUtils .processTemplate (dataSourceService .getTemplate (), properties );
194212
195- String processedQueryString = VelocityUtils .processTemplate (dataSourceService .getTemplate (), properties );
213+ String response = null ;
214+ switch (dataSourceService .getConnectionType ())
215+ {
216+ case GET :
217+ response = GeppettoHTTPClient .doGET (url , processedQueryString );
218+ break ;
219+ case POST :
220+ response = GeppettoHTTPClient .doJSONPost (url , processedQueryString );
221+ break ;
222+ }
196223
197- String response = null ;
198- switch (dataSourceService .getConnectionType ())
199- {
200- case GET :
201- response = GeppettoHTTPClient .doGET (url , processedQueryString );
202- break ;
203- case POST :
204- response = GeppettoHTTPClient .doJSONPost (url , processedQueryString );
205- break ;
224+ processResponse (response , dataSourceService );
206225 }
207-
208- processResponse (response , dataSourceService );
209226 }
210- }
211- catch ( GeppettoDataSourceException e )
212- {
213- return new GeppettoVisitingException ( e );
214- }
215- catch ( GeppettoInitializationException e )
216- {
217- return new GeppettoVisitingException ( e );
227+ catch ( GeppettoDataSourceException e )
228+ {
229+ return new GeppettoVisitingException ( e );
230+ }
231+ catch ( GeppettoInitializationException e )
232+ {
233+ return new GeppettoVisitingException ( e );
234+ }
218235 }
219236 return super .caseSimpleQuery (query );
220237 }
0 commit comments