Source: model/QueryResults.js

Ext.ns('Oracle.BDD.Portlets.Visualization.Model');

/**
 * <b>Do NOT instantiate this class directly.</b> QueryResults are provided as
 * an argument to the callback function of
 * {@link Oracle.BDD.Portlets.Visualization.Renderers.BaseRenderer#executeQuery}
 * <p>
 * For example:
 * 
 * <pre>
 *     init: function() {
 *       
 *        this.executeQuery(&quot;eql&quot;, true, this.renderVisualization);
 *     },
 *   
 *    renderVisualization: function(queryResults) {
 *        var records = queryResults.getRecords();
 *        var queryConfig = queryResults.getQueryConfig();
 *        
 *         ...
 *    }
 * </pre>
 * 
 * @class Oracle.BDD.Portlets.Visualization.Model.QueryResults
 * 
 */
Oracle.BDD.Portlets.Visualization.Model.QueryResults = function(config) {

	var self = this;

	config = config || {};
	config.records = config.records || [];

	if (config.records) {
		this._records = config.records;
		this._totalRecordCount = config.totalRecordCount;

		this._attributeTypeMap = config.attributeTypes;

		Ext.each(config.records, function(rec, idx, allRecs) {

			for ( var prop in rec) {
				if (rec.hasOwnProperty(prop)
						&& self._attributeTypeMap.hasOwnProperty(prop)) {
					var type = self._attributeTypeMap[prop];
					if (!Ext.isArray(rec[prop])) {

						rec[prop] = convertToType(rec[prop], type);

					} else {
						var values = rec[prop];
						var returnValues = [];
						Ext.each(values, function(v) {
							returnValues.push(convertToType(v, type));
						});
						rec[prop] = returnValues;
					}
				}
			}
		});
	}

	function convertToType(value, type) {
		if (type === 'mdex:long' || type === 'mdex:double'
				|| type === 'mdex:int' || type === 'mdex:long-set'
				|| type === 'mdex:double-set' || type === 'mdex:int-set') {
			return Number(value);
		} else if (type === 'mdex:dateTime' || type === 'mdex:dateTime-set') {
			return new Date(value);
		}
		return value;
	}

	this._queryConfig = new Oracle.BDD.Portlets.Visualization.Model.QueryConfig(
			config.queryConfig, config.attributes);

	return this;
};

Oracle.BDD.Portlets.Visualization.Model.QueryResults.prototype = {

	_attributeTypeMap : {},
	_queryConfig : undefined,
	_records : [],
	_totalRecordCount : 0,

	/**
	 * Returns the Oracle.BDD.Portlets.Visualization.Model.QueryConfig that
	 * prompted the query response
	 * 
	 * @return {QueryConfig} The QueryConfig object
	 */
	getQueryConfig : function() {
		return this._queryConfig;
	},

	/**
	 * Returns an array of data records returned by the query. The structure of
	 * a data record is dependent upon on EQL of the query executed.
	 * <p>
	 * For example, the eql query:
	 * 
	 * <pre>
	 * RETURN data AS
	 * SELECT
	 * COALESCE(%metric_1%, 0) as metric_1,
	 * COALESCE(%metric_2%, 0) as metric_2,
	 * %groupby_1% AS groupby_1
	 * FROM &quot;%dataview%&quot;
	 * GROUP BY groupby_1
	 * </pre>
	 * 
	 * <p>
	 * returns:
	 * </p>
	 * 
	 * <pre>
	 * [{metric_1: 12.0, metric_2: 35.5, groupby_1: &quot;Alaska&quot;}, 
	 * {metric_1: 18.2, metric_2: 22.8, groupby_1: &quot;Arizona&quot;}, ...]
	 * </pre>
	 * 
	 * @return {Object[]} An array of data records return by the query
	 */
	getRecords : function() {
		return this._records;
	},

	/**
	 * Gets the number of records returned in the query
	 * 
	 * @return {Number} Record count
	 */
	getRecordCount : function() {
		return this._records.length;
	},

	/**
	 * Gets the total number of records in the query. This may exceed the number
	 * returned by getRecordCount() if the EQL had a paging statement or if the
	 * number of records returned by the query exceeded the maximum number of
	 * records allowed by the portlet (i.e. 1000).
	 * 
	 * @return {Number} Total record count
	 */
	getTotalRecordCount : function() {
		return this._totalRecordCount;
	}
};
// @ sourceURL=QueryResults.js