// This is a template to demonstrate the existing functions
// you can use in a global data-source script. All functions and
// global variables you define here will be available for the
// all query scripts.
//
// Feel free to delete any function you don't use.
//
// you can process scripts via
//   scriptHelper.eval("println ('Hello World');", "ECMAscript");
//
// or your can load your own ECMA/JavaScript files and execute them via
//   scriptHelper.evalFile ("/your/file/here.js", "ECMAscript");
//
// both inline scripts and files will be executed in the global context -
// any function or variable defined there will be available globally.
//
// The following global variables exist by default:
//    resourceManager : The ResourceManager can be used to load files
//    contextKey      : ResourceKey the context key points to the prpt-bundle
//    dataFactory     : The current datafactory instance
//    configuration   : The current report configuration
//    resourceBundleFactory : Access to translations and locale information
//    scriptHelper    : Allows to load and evaluate other scripts

function initQuery()
{
  // place all initialization logic here. This is the right space to prepare complex lookup tables or
  // to fill global variables.

  // this method is called once during initialization. This function will
  // only be called when the associated query is used.
}

function shutdownQuery()
{
  // place all shutdown logic here. If you use any persistent resources like files or connections
  // make sure you close them here.

  // this method is called once during the data-source shut-down. It
  // will only be called if the associated query has been fired.
}

function computeQuery (query, queryName, dataRow)
{
  // computes the query string that is used to query the data-source.
  // query contains the statically defined query (MQL-text)
  // queryName is the logical name for this query given at design-time
  // dataRow contains all parameters that will be used to execute the query

  return query;
}

function computeQueryFields (query, queryName)
{
  // return any additional fields that may affect caching. If you rewrite
  // the query dynamically in the 'computeQuery' function, include all fields
  // that may take part of the query or query computation.
  //
  // if you do not want any caching, return <null>.
  return [];
}

function postProcessResult(query, queryName, dataRow, tableModel)
{
  // optionally post-process the query result. Usually you would not
  // manipulate the given table-model directly, but you can either copy
  // data into a new model or you can wrap it with a custom table-model
  // implementation of your own making.

  // if you discard the original tablemodel in the process, make sure
  // you close it properly or you may leak resources.
  return tableModel;
}
