Skip to content
Snippets Groups Projects
Commit d241ff5e authored by cramakri's avatar cramakri
Browse files

LMS-2347 Further work on query interface.

SVN: 21846
parent 440b037d
No related branches found
No related tags found
No related merge requests found
...@@ -23,11 +23,44 @@ import net.lemnik.eodsql.DataSet; ...@@ -23,11 +23,44 @@ import net.lemnik.eodsql.DataSet;
/** /**
* A service that supports executing queries on a data source configured in the DSS * A service that supports executing queries on a data source configured in the DSS
* service.properties. * service.properties.
* <p>
* Jython usage example:
*
* <pre>
* results = query_service.select("data-source-name", "SELECT * FROM table_name WHERE id > 1")
* [... do stuff with results]
* results.close()
* </pre>
* <p>
* If you need to do this frequently, you may want to extract this into a function
*
* <pre>
* def execute_query(query_service, block, query, params=None):
* if params is None:
* result = query_service.select("data-source-name", query)
* else:
* result = query_service.select("data-source-name", query, params)
* block(result)
* result.close()
* </pre>
* *
* @author Chandrasekhar Ramakrishnan * @author Chandrasekhar Ramakrishnan
*/ */
public interface IDataSourceQueryService public interface IDataSourceQueryService
{ {
/**
* Execute a query against the data source with the specified name.
*
* @param dataSourceName The name of the data source to query against, as declared in the
* service.properties file.
* @param query The SQL query to execute, possibly including parameters marked by '?'.
* @return A List of Maps with the data. Do not forget to close the result when done!
* @throw IllegalArgumentException Throws if there is no data source with the given name.
*/
DataSet<Map<String, Object>> select(String dataSourceName, String query)
throws IllegalArgumentException;
/** /**
* Execute a query against the data source with the specified name. * Execute a query against the data source with the specified name.
* *
......
...@@ -46,4 +46,10 @@ public class DataSourceQueryService implements IDataSourceQueryService ...@@ -46,4 +46,10 @@ public class DataSourceQueryService implements IDataSourceQueryService
return QueryTool.select(dataSource, query, parameters); return QueryTool.select(dataSource, query, parameters);
} }
public DataSet<Map<String, Object>> select(String dataSourceName, String query)
throws IllegalArgumentException
{
return select(dataSourceName, query, new Object[0]);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment