Skip to content
Snippets Groups Projects
Commit db4a77f7 authored by buczekp's avatar buczekp
Browse files

[LMS-2301] fixed example scripts and documentation of IDataSourceQueryService

SVN: 22049
parent cfa247c0
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ DATA_SOURCE = "openbis-metadata" ...@@ -2,7 +2,7 @@ DATA_SOURCE = "openbis-metadata"
QUERY = """ QUERY = """
SELECT d.code as "DATA_SET_CODE", prty.code as "PROPERTY_CODE", dsp.value as "PROPERTY_VALUE" SELECT d.code as "DATA_SET_CODE", prty.code as "PROPERTY_CODE", dsp.value as "PROPERTY_VALUE"
FROM data d, data_set_properties dsp, data_set_type_property_types dstpt, property_types prty FROM data d, data_set_properties dsp, data_set_type_property_types dstpt, property_types prty
WHERE d.code = ? AND dsp.ds_id = d.id AND dsp.dstpt_id = dstpt.id AND dstpt.prty_id = prty.id WHERE d.code = ?{1} AND dsp.ds_id = d.id AND dsp.dstpt_id = dstpt.id AND dstpt.prty_id = prty.id
""" """
DATA_SET_CODE = "Data Set" DATA_SET_CODE = "Data Set"
...@@ -16,8 +16,10 @@ def describe(dataSets, tableBuilder): ...@@ -16,8 +16,10 @@ def describe(dataSets, tableBuilder):
tableBuilder.addHeader(PROPERTY_VALUE) tableBuilder.addHeader(PROPERTY_VALUE)
for dataSet in dataSets: for dataSet in dataSets:
results = query_service.select(DATA_SOURCE, QUERY, dataSet.getDataSetCode()) results = queryService.select(DATA_SOURCE, QUERY, [dataSet.getDataSetCode()])
for r in results: print "Found " + str(len(results)) + " results for data set '" + dataSet.getDataSetCode() + "':"
for r in results:
print r # debugging
row = tableBuilder.addRow() row = tableBuilder.addRow()
row.setCell(DATA_SET_CODE, r.get("DATA_SET_CODE")) row.setCell(DATA_SET_CODE, r.get("DATA_SET_CODE"))
row.setCell(PROPERTY_CODE, r.get("PROPERTY_CODE")) row.setCell(PROPERTY_CODE, r.get("PROPERTY_CODE"))
......
DATA_SOURCE = "path-info-db" DATA_SOURCE = "path-info-db"
QUERY = """ QUERY = """
SELECT ds.code as "DATA_SET_CODE", dsf.* SELECT ds.code as "data_set_code", dsf.*
FROM data_sets ds, data_set_files dsf FROM data_sets ds, data_set_files dsf
WHERE ds.code = ? AND dsf.dase_id = ds.id WHERE ds.code = ?{1} AND dsf.dase_id = ds.id
""" """
"""reporting table column names""" """reporting table column names"""
...@@ -23,13 +23,15 @@ def describe(dataSets, tableBuilder): ...@@ -23,13 +23,15 @@ def describe(dataSets, tableBuilder):
tableBuilder.addHeader(LAST_MODIFIED) tableBuilder.addHeader(LAST_MODIFIED)
for dataSet in dataSets: for dataSet in dataSets:
results = query_service.select(DATA_SOURCE, QUERY, dataSet.getDataSetCode()) results = queryService.select(DATA_SOURCE, QUERY, [dataSet.getDataSetCode()])
print "Found " + str(len(results)) + " results for data set '" + dataSet.getDataSetCode() + "':"
for r in results: for r in results:
print r # debugging
row = tableBuilder.addRow() row = tableBuilder.addRow()
row.setCell(DATA_SET_CODE, r.get("DATA_SET_CODE")) row.setCell(DATA_SET_CODE, r.get("DATA_SET_CODE".lower()))
row.setCell(RELATIVE_PATH, r.get("RELATIVE_PATH")) row.setCell(RELATIVE_PATH, r.get("RELATIVE_PATH".lower()))
row.setCell(FILE_NAME, r.get("FILE_NAME")) row.setCell(FILE_NAME, r.get("FILE_NAME".lower()))
row.setCell(SIZE_IN_BYTES, r.get("SIZE_IN_BYTES")) row.setCell(SIZE_IN_BYTES, r.get("SIZE_IN_BYTES".lower()))
row.setCell(IS_DIRECTORY, r.get("IS_DIRECTORY")) row.setCell(IS_DIRECTORY, r.get("IS_DIRECTORY".lower()))
row.setCell(LAST_MODIFIED, r.get("LAST_MODIFIED")) row.setCell(LAST_MODIFIED, r.get("LAST_MODIFIED".lower()))
results.close() results.close()
\ No newline at end of file
...@@ -54,7 +54,8 @@ public interface IDataSourceQueryService ...@@ -54,7 +54,8 @@ public interface IDataSourceQueryService
* *
* @param dataSourceName The name of the data source to query against, as declared in the * @param dataSourceName The name of the data source to query against, as declared in the
* service.properties file. * service.properties file.
* @param query The SQL query to execute, possibly including parameters marked by '?'. * @param query The SQL query to execute, possibly including parameters marked by '?{X}' where X
* is the parameter number.
* @return A List of Maps with the data. Do not forget to close the result when done! * @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. * @throw IllegalArgumentException Throws if there is no data source with the given name.
* @throw InvalidQueryException Thrown the given query string cannot be parsed, or doesn't match * @throw InvalidQueryException Thrown the given query string cannot be parsed, or doesn't match
...@@ -68,7 +69,8 @@ public interface IDataSourceQueryService ...@@ -68,7 +69,8 @@ public interface IDataSourceQueryService
* *
* @param dataSourceName The name of the data source to query against, as declared in the * @param dataSourceName The name of the data source to query against, as declared in the
* service.properties file. * service.properties file.
* @param query The SQL query to execute, possibly including parameters marked by '?'. * @param query The SQL query to execute, possibly including parameters marked by '?{X}' where X
* is the parameter number.
* @param parameters The values for filling in the query parameters. * @param parameters The values for filling in the query parameters.
* @return A List of Maps with the data. Do not forget to close the result when done! * @return A List of Maps with the data. Do not forget to close the result when done!
* @throw IllegalArgumentException Thrown if there is no data source with the given name. * @throw IllegalArgumentException Thrown if there is no data source with the given name.
......
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