/*
 COPYRIGHT 2009 ESRI

 TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
 Unpublished material - all rights reserved under the
 Copyright Laws of the United States and applicable international
 laws, treaties, and conventions.

 For additional information, contact:
 Environmental Systems Research Institute, Inc.
 Attn: Contracts and Legal Services Department
 380 New York Street
 Redlands, California, 92373
 USA

 email: contracts@esri.com
 */
//>>built
define("esri/tasks/QueryTask",["dojo/_base/declare","dojo/_base/lang","dojo/_base/array","dojo/_base/Deferred","dojo/_base/json","dojo/has","esri/kernel","esri/request","esri/deferredUtils","esri/geometry/normalizeUtils","esri/tasks/Task","esri/tasks/FeatureSet"],function(_1,_2,_3,_4,_5,_6,_7,_8,_9,_a,_b,_c){var _d=_1(_b,{declaredClass:"esri.tasks.QueryTask",_eventMap:{"complete":["featureSet"],"execute-for-count-complete":["count"],"execute-for-ids-complete":["objectIds"],"execute-relationship-query-complete":["featureSets"]},constructor:function(_e,_f){this._handler=_2.hitch(this,this._handler);this._relationshipQueryHandler=_2.hitch(this,this._relationshipQueryHandler);this._executeForIdsHandler=_2.hitch(this,this._executeForIdsHandler);this._countHandler=_2.hitch(this,this._countHandler);this.source=_f&&_f.source;this.gdbVersion=_f&&_f.gdbVersion;this.registerConnectEvents();},__msigns:[{n:"execute",c:4,a:[{i:0,p:["geometry"]}],e:2},{n:"executeForIds",c:3,a:[{i:0,p:["geometry"]}],e:2},{n:"executeForCount",c:3,a:[{i:0,p:["geometry"]}],e:2}],onComplete:function(){},onExecuteRelationshipQueryComplete:function(){},onExecuteForIdsComplete:function(){},onExecuteForCountComplete:function(){},execute:function(_10,_11,_12,_13,_14){var _15=_14.assembly,_16=this._encode(_2.mixin({},this._url.query,{f:"json"},_10.toJson(_15&&_15[0]))),_17=this._handler,_18=this._errorHandler;if(this.source){var _19={source:this.source.toJson()};_16.layer=_5.toJson(_19);}if(this.gdbVersion){_16.gdbVersion=this.gdbVersion;}return _8({url:this._url.path+"/query",content:_16,callbackParamName:"callback",load:function(r,i){_17(r,i,_11,_12,_14.dfd);},error:function(r){_18(r,_12,_14.dfd);},callbackSuffix:_13});},executeRelationshipQuery:function(_1a,_1b,_1c){var _1d=this._encode(_2.mixin({},this._url.query,{f:"json"},_1a.toJson())),_1e=this._relationshipQueryHandler,_1f=this._errorHandler;if(this.gdbVersion){_1d.gdbVersion=this.gdbVersion;}var dfd=new _4(_9._dfdCanceller);dfd._pendingDfd=_8({url:this._url.path+"/queryRelatedRecords",content:_1d,callbackParamName:"callback",load:function(r,i){_1e(r,i,_1b,_1c,dfd);},error:function(r){_1f(r,_1c,dfd);}});return dfd;},executeForIds:function(_20,_21,_22,_23){var _24=_23.assembly,_25=this._encode(_2.mixin({},this._url.query,{f:"json",returnIdsOnly:true},_20.toJson(_24&&_24[0]))),_26=this._executeForIdsHandler,_27=this._errorHandler;if(this.source){var _28={source:this.source.toJson()};_25.layer=_5.toJson(_28);}if(this.gdbVersion){_25.gdbVersion=this.gdbVersion;}return _8({url:this._url.path+"/query",content:_25,callbackParamName:"callback",load:function(r,i){_26(r,i,_21,_22,_23.dfd);},error:function(r){_27(r,_22,_23.dfd);}});},executeForCount:function(_29,_2a,_2b,_2c){var _2d=_2c.assembly,_2e=this._encode(_2.mixin({},this._url.query,{f:"json",returnIdsOnly:true,returnCountOnly:true},_29.toJson(_2d&&_2d[0]))),_2f=this._countHandler,_30=this._errorHandler;if(this.source){var _31={source:this.source.toJson()};_2e.layer=_5.toJson(_31);}if(this.gdbVersion){_2e.gdbVersion=this.gdbVersion;}return _8({url:this._url.path+"/query",content:_2e,callbackParamName:"callback",load:function(r,i){_2f(r,i,_2a,_2b,_2c.dfd);},error:function(r){_30(r,_2b,_2c.dfd);}});},_handler:function(_32,io,_33,_34,dfd){try{var _35=new _c(_32);this._successHandler([_35],"onComplete",_33,dfd);}catch(err){this._errorHandler(err,_34,dfd);}},_relationshipQueryHandler:function(_36,io,_37,_38,dfd){try{var gt=_36.geometryType,sr=_36.spatialReference,_39={};_3.forEach(_36.relatedRecordGroups,function(gr){var _3a={};_3a.geometryType=gt;_3a.spatialReference=sr;_3a.features=gr.relatedRecords;var _3b=new _c(_3a);_39[gr.objectId]=_3b;});this._successHandler([_39],"onExecuteRelationshipQueryComplete",_37,dfd);}catch(err){this._errorHandler(err,_38,dfd);}},_executeForIdsHandler:function(_3c,io,_3d,_3e,dfd){try{this._successHandler([_3c.objectIds],"onExecuteForIdsComplete",_3d,dfd);}catch(err){this._errorHandler(err,_3e,dfd);}},_countHandler:function(_3f,io,_40,_41,dfd){try{var _42,_43=_3f.features,ids=_3f.objectIds;if(ids){_42=ids.length;}else{if(_43){throw new Error("Unable to perform query. Please check your parameters.");}else{_42=_3f.count;}}this._successHandler([_42],"onExecuteForCountComplete",_40,dfd);}catch(err){this._errorHandler(err,_41,dfd);}}});_a._createWrappers(_d);if(_6("extend-esri")){_2.setObject("tasks.QueryTask",_d,_7);}return _d;});