Skip to content

Commit 3503e97

Browse files
committed
Cross data source queries
1 parent 6fb4616 commit 3503e97

10 files changed

Lines changed: 259 additions & 338 deletions

src/main/java/org/geppetto/datasources/ADataSourceService.java

Lines changed: 93 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,19 @@
3535
import java.util.ArrayList;
3636
import java.util.List;
3737

38+
import org.geppetto.core.datasources.GeppettoDataSourceException;
3839
import org.geppetto.core.datasources.IDataSourceService;
40+
import org.geppetto.core.datasources.IQueryListener;
3941
import org.geppetto.core.datasources.QueryChecker;
4042
import org.geppetto.core.model.GeppettoModelAccess;
4143
import org.geppetto.core.services.AService;
4244
import org.geppetto.model.datasources.DataSource;
4345
import 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;
4449
import org.geppetto.model.variables.Variable;
50+
import org.geppetto.model.variables.VariablesFactory;
4551

4652
/**
4753
* @author matteocantarelli
@@ -50,11 +56,17 @@
5056
public 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
}

src/main/java/org/geppetto/datasources/AQueryProcessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public void addFeature(IFeature feature)
4141

4242
}
4343

44-
/* (non-Javadoc)
44+
/*
45+
* (non-Javadoc)
46+
*
4547
* @see org.geppetto.core.datasources.IQueryProcessor#getProcessingOutputMap()
4648
*/
4749
@Override

src/main/java/org/geppetto/datasources/DummyDataSourceService.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.geppetto.core.datasources.GeppettoDataSourceException;
3636
import org.geppetto.core.datasources.IDataSourceService;
3737
import org.geppetto.core.datasources.IQueryListener;
38+
import org.geppetto.datasources.neo4j.Neo4jResponseProcessor;
3839
import org.geppetto.model.GeppettoLibrary;
3940
import org.geppetto.model.datasources.DataSource;
4041
import org.geppetto.model.datasources.DataSourceLibraryConfiguration;
@@ -118,22 +119,23 @@ public void fetchVariable(String variableId) throws GeppettoDataSourceException
118119
fetchedVariable.setId(variableId);
119120
getGeppettoModelAccess().addVariable(fetchedVariable);
120121
ImportType importType = TypesFactory.eINSTANCE.createImportType();
121-
importType.setId("Type"+variableId); //an SWC for instance
122-
importType.setUrl(""); //an SWC for instance
122+
importType.setId("Type" + variableId); // an SWC for instance
123+
importType.setUrl(""); // an SWC for instance
123124
fetchedVariable.getTypes().add(importType);
124125
importType.setModelInterpreterId("swcModelInterpreter");
125-
getGeppettoModelAccess().addTypeToLibrary(importType, getLibraryFor(getConfiguration(),"swc"));
126-
126+
getGeppettoModelAccess().addTypeToLibrary(importType, getLibraryFor(getConfiguration(), "swc"));
127+
127128
}
128-
129+
129130
/**
130131
* @param dataSource
131132
* @param format
132133
* @return
133134
*/
134135
private GeppettoLibrary getLibraryFor(DataSource dataSource, String format)
135136
{
136-
for(DataSourceLibraryConfiguration lc: dataSource.getLibraryConfigurations()){
137+
for(DataSourceLibraryConfiguration lc : dataSource.getLibraryConfigurations())
138+
{
137139
if(lc.getFormat().equals(format))
138140
{
139141
return lc.getLibrary();
@@ -142,4 +144,20 @@ private GeppettoLibrary getLibraryFor(DataSource dataSource, String format)
142144
return null;
143145
}
144146

147+
@Override
148+
public ConnectionType getConnectionType()
149+
{
150+
return ConnectionType.POST;
151+
}
152+
153+
@Override
154+
public IQueryResponseProcessor getQueryResponseProcessor()
155+
{
156+
if(queryResponseProcessor == null)
157+
{
158+
queryResponseProcessor = new Neo4jResponseProcessor();
159+
}
160+
return queryResponseProcessor;
161+
}
162+
145163
}

0 commit comments

Comments
 (0)