3535import java .util .ArrayList ;
3636import java .util .List ;
3737
38+ import org .geppetto .core .datasources .GeppettoDataSourceException ;
3839import org .geppetto .core .datasources .IDataSourceService ;
40+ import org .geppetto .core .datasources .IQueryListener ;
3941import org .geppetto .core .datasources .QueryChecker ;
4042import org .geppetto .core .model .GeppettoModelAccess ;
4143import org .geppetto .core .services .AService ;
4244import org .geppetto .model .datasources .DataSource ;
4345import org .geppetto .model .datasources .Query ;
46+ import org .geppetto .model .datasources .QueryResults ;
47+ import org .geppetto .model .util .GeppettoModelTraversal ;
48+ import org .geppetto .model .util .GeppettoVisitingException ;
4449import org .geppetto .model .variables .Variable ;
50+ import org .geppetto .model .variables .VariablesFactory ;
4551
4652/**
4753 * @author matteocantarelli
5056public abstract class ADataSourceService extends AService implements IDataSourceService
5157{
5258
59+ public abstract ConnectionType getConnectionType ();
60+
61+ public abstract IQueryResponseProcessor getQueryResponseProcessor ();
62+
5363 public enum ConnectionType
5464 {
5565 GET , POST
5666 }
5767
68+ protected IQueryResponseProcessor queryResponseProcessor ;
69+
5870 private DataSource configuration ;
5971
6072 private String dataSourceTemplate ;
@@ -91,17 +103,7 @@ protected DataSource getConfiguration()
91103 return configuration ;
92104 }
93105
94- /**
95- * @param url
96- * @param queryString
97- * @return
98- */
99- protected String getQueryURL (String url , String queryString )
100- {
101- String queryURL = null ;
102- // TODO Do we need a template? Plain concatenation?
103- return queryURL ;
104- }
106+
105107
106108 /*
107109 * (non-Javadoc)
@@ -122,6 +124,84 @@ public List<Query> getAvailableQueries(Variable variable)
122124 return availableQueries ;
123125 }
124126
127+ /*
128+ * (non-Javadoc)
129+ *
130+ * @see org.geppetto.core.model.QueryProvider#execute(org.geppetto.core.model.Query, org.geppetto.model.variables.Variable, org.geppetto.core.model.QueryListener)
131+ */
132+ @ Override
133+ public QueryResults execute (Query query , Variable variable , IQueryListener listener ) throws GeppettoDataSourceException
134+ {
135+ ExecuteQueryVisitor runQueryVisitor = new ExecuteQueryVisitor (variable , getGeppettoModelAccess ());
136+ runQueryVisitor .doSwitch (query );
137+ return runQueryVisitor .getResults ();
138+ }
139+
140+ /*
141+ * (non-Javadoc)
142+ *
143+ * @see org.geppetto.core.model.QueryProvider#getNumberOfResults(org.geppetto.core.model.Query, org.geppetto.model.variables.Variable, org.geppetto.core.model.QueryResults)
144+ */
145+ @ Override
146+ public int getNumberOfResults (Query query , Variable variable , QueryResults results ) throws GeppettoDataSourceException
147+ {
148+ // TODO Auto-generated method stub
149+ return 0 ;
150+ }
151+
152+
153+ /*
154+ * (non-Javadoc)
155+ *
156+ * @see org.geppetto.core.model.QueryProvider#getNumberOfResults(org.geppetto.core.model.Query, org.geppetto.model.variables.Variable)
157+ */
158+ @ Override
159+ public int getNumberOfResults (Query query , Variable variable ) throws GeppettoDataSourceException
160+ {
161+ Query fetchVariableQuery = getConfiguration ().getFetchVariableQuery ();
162+ ExecuteQueryVisitor runQueryVisitor = new ExecuteQueryVisitor (variable , getGeppettoModelAccess ());
163+ try
164+ {
165+ GeppettoModelTraversal .applyDirectChildren (fetchVariableQuery , runQueryVisitor );
166+
167+ }
168+ catch (GeppettoVisitingException e )
169+ {
170+ throw new GeppettoDataSourceException (e );
171+ }
172+
173+ return runQueryVisitor .getCount ();
174+ }
175+
176+ /*
177+ * (non-Javadoc)
178+ *
179+ * @see org.geppetto.core.model.QueryProvider#execute(org.geppetto.core.model.Query, org.geppetto.model.variables.Variable, org.geppetto.core.model.QueryResults,
180+ * org.geppetto.core.model.QueryListener)
181+ */
182+ @ Override
183+ public QueryResults execute (Query query , Variable variable , QueryResults results , IQueryListener listener ) throws GeppettoDataSourceException
184+ {
185+ // TODO Auto-generated method stub
186+ return null ;
187+ }
188+
189+ /*
190+ * (non-Javadoc)
191+ *
192+ * @see org.geppetto.core.model.IDataSource#fetchVariable(java.lang.String)
193+ */
194+ @ Override
195+ public void fetchVariable (String variableId ) throws GeppettoDataSourceException
196+ {
197+ Variable fetchedVariable = VariablesFactory .eINSTANCE .createVariable ();
198+ fetchedVariable .setId (variableId );
199+ getGeppettoModelAccess ().addVariable (fetchedVariable );
200+ Query fetchVariableQuery = getConfiguration ().getFetchVariableQuery ();
201+ ExecuteQueryVisitor runQueryVisitor = new ExecuteQueryVisitor (fetchedVariable , getGeppettoModelAccess ());
202+ runQueryVisitor .doSwitch (fetchVariableQuery );
203+ }
204+
125205 /*
126206 * (non-Javadoc)
127207 *
@@ -133,4 +213,6 @@ public void registerGeppettoService() throws Exception
133213 // Nothing to do here
134214 }
135215
216+
217+
136218}
0 commit comments