// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/tasks/QueryTask","dojo/_base/declare dojo/_base/lang dojo/_base/array dojo/_base/Deferred dojo/_base/json dojo/has ../kernel ../request ../deferredUtils ../geometry/Extent ../geometry/normalizeUtils ./Task ./FeatureSet".split(" "),function(k,g,q,r,m,t,u,l,v,w,x,y,p){k=k(y,{declaredClass:"esri.tasks.QueryTask",_eventMap:{complete:["featureSet"],"execute-for-count-complete":["count"],"execute-for-ids-complete":["objectIds"],"execute-relationship-query-complete":["featureSets"]},constructor:function(a,
f){this._handler=g.hitch(this,this._handler);this._relationshipQueryHandler=g.hitch(this,this._relationshipQueryHandler);this._executeForIdsHandler=g.hitch(this,this._executeForIdsHandler);this._countHandler=g.hitch(this,this._countHandler);this._extentHandler=g.hitch(this,this._extentHandler);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},{n:"executeForExtent",c:3,a:[{i:0,p:["geometry"]}],e:2}],onComplete:function(){},onExecuteRelationshipQueryComplete:function(){},onExecuteForIdsComplete:function(){},onExecuteForCountComplete:function(){},onExecuteForExtentComplete:function(){},execute:function(a,f,d,c,b){c=b.assembly;a=this._encode(g.mixin({},this._url.query,{f:"json"},a.toJson(c&&c[0])));var e=this._handler,h=this._errorHandler;this.source&&(c={source:this.source.toJson()},a.layer=m.toJson(c));
this.gdbVersion&&(a.gdbVersion=this.gdbVersion);return l({url:this._url.path+"/query",content:a,callbackParamName:"callback",load:function(a,c){e(a,c,f,d,b.dfd)},error:function(a){h(a,d,b.dfd)}},this.requestOptions)},executeRelationshipQuery:function(a,f,d){a=this._encode(g.mixin({},this._url.query,{f:"json"},a.toJson()));var c=this._relationshipQueryHandler,b=this._errorHandler;this.gdbVersion&&(a.gdbVersion=this.gdbVersion);var e=new r(v._dfdCanceller);e._pendingDfd=l({url:this._url.path+"/queryRelatedRecords",
content:a,callbackParamName:"callback",load:function(a,b){c(a,b,f,d,e)},error:function(a){b(a,d,e)}},this.requestOptions);return e},executeForIds:function(a,f,d,c){var b=c.assembly;a=this._encode(g.mixin({},this._url.query,{f:"json",returnIdsOnly:!0},a.toJson(b&&b[0])));var e=this._executeForIdsHandler,h=this._errorHandler;this.source&&(b={source:this.source.toJson()},a.layer=m.toJson(b));this.gdbVersion&&(a.gdbVersion=this.gdbVersion);return l({url:this._url.path+"/query",content:a,callbackParamName:"callback",
load:function(a,b){e(a,b,f,d,c.dfd)},error:function(a){h(a,d,c.dfd)}},this.requestOptions)},executeForCount:function(a,f,d,c){var b=c.assembly;a=this._encode(g.mixin({},this._url.query,{f:"json",returnIdsOnly:!0,returnCountOnly:!0},a.toJson(b&&b[0])));var e=this._countHandler,h=this._errorHandler;this.source&&(b={source:this.source.toJson()},a.layer=m.toJson(b));this.gdbVersion&&(a.gdbVersion=this.gdbVersion);return l({url:this._url.path+"/query",content:a,callbackParamName:"callback",load:function(a,
b){e(a,b,f,d,c.dfd)},error:function(a){h(a,d,c.dfd)}},this.requestOptions)},executeForExtent:function(a,f,d,c){var b=c.assembly;a=this._encode(g.mixin({},this._url.query,{f:"json",returnExtentOnly:!0,returnCountOnly:!0},a.toJson(b&&b[0])));var e=this._extentHandler,h=this._errorHandler;this.source&&(b={source:this.source.toJson()},a.layer=m.toJson(b));this.gdbVersion&&(a.gdbVersion=this.gdbVersion);return l({url:this._url.path+"/query",content:a,callbackParamName:"callback",load:function(a,b){e(a,
b,f,d,c.dfd)},error:function(a){h(a,d,c.dfd)}},this.requestOptions)},_handler:function(a,f,d,c,b){try{var e=new p(a);this._successHandler([e],"onComplete",d,b)}catch(h){this._errorHandler(h,c,b)}},_relationshipQueryHandler:function(a,f,d,c,b){try{var e=a.geometryType,h=a.spatialReference,g={};q.forEach(a.relatedRecordGroups,function(a){var b={};b.geometryType=e;b.spatialReference=h;b.features=a.relatedRecords;b=new p(b);if(null!=a.objectId)g[a.objectId]=b;else for(var c in a)a.hasOwnProperty(c)&&
"relatedRecords"!==c&&(g[a[c]]=b)});this._successHandler([g],"onExecuteRelationshipQueryComplete",d,b)}catch(n){this._errorHandler(n,c,b)}},_executeForIdsHandler:function(a,f,d,c,b){try{this._successHandler([a.objectIds],"onExecuteForIdsComplete",d,b)}catch(e){this._errorHandler(e,c,b)}},_countHandler:function(a,f,d,c,b){try{var e,g=a.features,k=a.objectIds;if(k)e=k.length;else{if(g)throw Error("Unable to perform query. Please check your parameters.");e=a.count}this._successHandler([e],"onExecuteForCountComplete",
d,b)}catch(n){this._errorHandler(n,c,b)}},_extentHandler:function(a,f,d,c,b){try{a.extent&&(a.extent=new w(a.extent)),this._successHandler([a],"onExecuteForExtentComplete",d,b)}catch(e){this._errorHandler(e,c,b)}}});x._createWrappers(k);t("extend-esri")&&g.setObject("tasks.QueryTask",k,u);return k});