📄 resultset.js
字号:
//> @type CriteriaPolicy // @value "dropOnChange" Cache is dropped whenever criteria changes. // @value "dropOnShortening" Cache is retained as along as the only changes to criteria // are lengthening of criteria values for known, String-valued // DataSource fields, or the addition of fields that weren't // present before. // @visibility external //< //> @attr resultSet.criteria (Criteria : null : IRW) // Filter criteria used whenever records are retrieved. // <P> // Changing the filter criteria via <code>setCriteria</code> will cause the current cached // records to be dropped. // @see setCriteria() // @visibility external //< //> @attr resultSet.criteriaPolicy (CriteriaPolicy : null : IRWA) // Decides under what conditions the cache should be dropped when the +link{criteria} // changes // @see criteria // @see dataSource.criteriaPolicy // @visibility external //< // Local Operations // ---------------------------------------------------------------------------------------- //> @attr resultSet.useClientSorting (boolean : true : IRWA) // Whether to sort data locally when all records matching the current criteria have been // cached. // <P> // This may need to be disabled if client-side sort order differs from server-side sort // order in a way that affects functionality or is surprising. // // @visibility external //< useClientSorting: true, shouldUseClientSorting : function () { //>Offline if (!isc.RPCManager.onLine) return true; //<Offline return this.useClientSorting; }, //> @attr resultSet.useClientFiltering (boolean : true : IRWA) // Whether to filter data locally when all DataSource records have been loaded (that is, // criteria is blank and cache is complete). // <P> // This may need to be disabled if client-side filtering differs from server-side filtering // in a way that affects functionality or is surprising. // <P> // This setting is distinct from <code>fetchMode:"local"</code>, which explicitly loads all // available DataSource records up front. // <P> // See +link{resultSet.applyFilter()} for default filtering behavior. // <P> // <b>NOTE:</b> even with useClientFiltering false, client-side filtering will be used // during cache sync to determine if an updated or added row matches the current criteria. // To avoid relying on client-side filtering in this case, either:<br> // - avoid returning update data when the updated row doesn't match the current filter<br> // - set dropCacheOnUpdate<br> // // @visibility external //< useClientFiltering:true, shouldUseClientFiltering : function () { //>Offline if (!isc.RPCManager.onLine) return true; //<Offline return this.useClientFiltering; }, // Caching // ---------------------------------------------------------------------------------------- //> @attr resultSet.updateCacheFromRequest (boolean : true : IRA) // When a successful Add, Update or Remove type operation fires on this ResultSet's // dataSource, if +link{dsResponse.data} is unset, should we integrate the submitted // data values (from the request) into our data-set? // // @group cacheSync // @visibility external //< updateCacheFromRequest:true, //> @attr resultSet.dropCacheOnUpdate (boolean : false : IRA) // Whether to discard all cached rows when a modification operation (add, update, remove) // occurs on the ResultSet's DataSource. // <P> // A ResultSet that has a complete cache for the current filter criteria can potentially // incorporate a newly created or updated row based on the data that the server returns // when a modification operation completes. However this is not always possible for // ResultSets that show some types of joins, or when the server cannot easily return update // data. In this case set <code>dropCacheOnUpdate</code> to cause the cache to be // discarded when an update occurs. // <P> // <code>dropCacheOnUpdate</code> can be set either directly on a ResultSet, or on a // DataSource in order to affect all ResultSets on that DataSource. // // @group cacheSync // @visibility external //< //> @attr resultSet.dropCacheOnLengthChange (boolean : true : IRA) // Whether to discard all cached rows when the server reports a change in the number of // total rows. // @group cacheSync // @visibility internal //< // Not yet implemented: // <P> // This works as a simple form of cache staleness detection if the server is not capable of // supporting the more sophisticated <code>cacheTimestamp</code> mechanism. // // @see attr dsResponse.cacheTimestamp //> @attr resultSet.disableCacheSync (boolean : false : IRA) // By default when the data of this ResultSet's dataSource is modified, the ResultSet will // be updated to display these changes. // Set this flag to true to disable this behavior. // @group cacheSync // @visibility external //< // Note: This can be set to false after init, but if already false, setting to true would // lead to unpredictable results as we'd be attempting to integrate changes into a possibly // out of date cache //> @attr resultSet.neverDropUpdatedRows (boolean : false : IRA) // By default when a a row is returned by the server, the current +link{setCriteria,filter // criteria} are applied to it, and it may disappear from the cache. // <P> // Set this flag to true to disable this behavior. // @group cacheSync // @visibility external //< shouldNeverDropUpdatedRows : function () { //>Offline if (!isc.RPCManager.onLine) return true; //<Offline return this.neverDropUpdatedRows; }, //> @attr resultSet.updatePartialCache (boolean : true : IRA) // If set to true, updated and added rows will be integrated into the client-side cache // even if paging is enabled and cache is partial. If <code>updatePartialCache</code> is // false, the cache will be invalidated and new data fetched. // <P> // If updatePartialCache is enabled and an "add" or "update" operation succeeds with a partial // cache: // <ul> // <li> updated rows will remain in their current position. No attempt will be made to sort // them into a new position even if the sort field was updated. // <li> newly added rows will be added at either the end (first preference) or beginning of // the dataset if that part of the dataset is cached and was most recently requested. // If not, the new row is added at the end of the most recently requested contiguously // cached range // </ul> // The cache will then be dropped the next time rows are fetched, to prevent problems with // inconsistent row numbering between the server and client, which could otherwise lead to // duplicate rows or rows being skipped entirely. // // @group cacheSync // @visibility external //< updatePartialCache:true, shouldUpdatePartialCache : function () { //>Offline if (!isc.RPCManager.onLine) return true; //<Offline return this.updatePartialCache; }});isc.ResultSet.addMethods({init : function () { // get a global ID so we can be called in the global scope isc.ClassFactory.addGlobalID(this); //>!BackCompat 2004.7.30 // custom operation for fetching passed in as just "operation" if (this.operation != null) this.fetchOperation = this.operation; //<!BackCompat // get the fetchOperation since several ResultSet-related settings are legal on it. // NOTE: order depedency: if we were passed an operation, getOperation() will return it // without looking at this.dataSource, so we can use that operation to automatically derive // the dataSource. Otherwise, if not passed an operation, we require this.dataSource, and // getOperation will derive an operation from it. var fetchOperation = this.getOperation("fetch"); // if fetchOperation is an explicitly defined operation, operation.dataSource may be a list // of DataSources var dsNames = fetchOperation.dataSource; if (!isc.isAn.Array(dsNames)) dsNames = [dsNames]; for (var i = 0; i < dsNames.length; i++) { var ds = isc.DS.get(dsNames[i]); // observe dataChanged for cache synch this.observe(ds, "dataChanged", "observer.dataSourceDataChanged(dsRequest,dsResponse)"); // keep track of the datasources we've registered with so we can deregister on destroy() if (!this._registeredDS) this._registeredDS = []; this._registeredDS.add(ds); // support automatically deriving the DataSource from the operation (take the first // DataSource listed if more than one) if (!this.dataSource) this.dataSource = ds; } // context.dataPageSize may be set if specified on a DataBoundComponent that created us var context = this.context; this.resultSize = (context && context.dataPageSize != null ? context.dataPageSize : this.resultSize); // whether to invalidate our cache when an update occurs on one of our datasources. // Default is update the current cache in place. if (this.dropCacheOnUpdate == null) { this.dropCacheOnUpdate = this._firstNonNull(fetchOperation.dropCacheOnUpdate, this.getDataSource().dropCacheOnUpdate); } this.context = this.context || {}; // backcompat for old name for criteria: "filter" this.criteria = this.criteria || this.filter || {}; if (this.criteria) this.setCriteria(this.criteria); // if we're given the set of all rows on construction, derive the current filter set right // away, so that this.localData is not null, making us think we have no data if (this.fetchMode == null) this.fetchMode = (this.allRows ? "local" : "paged"); if (this.allRows != null && (this.isLocal() || this.shouldUseClientFiltering()) && this.localData == null) { this.filterLocalData(); } // support for seeding a ResultSet with data on init if (this.initialData) { this.fillCacheData(this.initialData); this.setFullLength(this.initialLength || this.totalRows || this.initialData.length); } else if (this.isPaged()) { this.localData = []; } //>Offline this.observe(isc, "goOffline", this.getID()+".goOffline()"); this.observe(isc.RPCManager, "offlineTransactionPlaybackComplete", this.getID()+".offlinePlaybackComplete()"); //<Offline},//>OfflinegoOffline : function () {},offlinePlaybackComplete : function () { if (this.haveOfflineRecords) { this.invalidateCache(); this.haveOfflineRecords = false; }},//<Offline// de-register from related DataSources on destroy() to prevent leaksdestroy : function () { // remove the window.ID pointer to us. NOTE: don't destroy the global variable if it no longer // points to this instance (this might happen if you create a new instance with the same ID) if (window[this.ID] == this) window[this.ID] = null; //>Offline this.ignore(isc, "goOffline"); this.ignore(isc.RPCManager, "offlineTransactionPlaybackComplete"); //<Offline if (!this._registeredDS) return; for (var i = 0; i < this._registeredDS.length; i++) { var ds = this._registeredDS[i]; if (ds) { // clear up observations this.ignore(ds, "dataChanged"); } }}, isPaged : function () { return this.fetchMode == "paged" },isLocal : function () { return this.fetchMode == "local" },//> @method ResultSet.allMatchingRowsCached() [A]// Do we have a complete client-side cache of records for the current filter criteria?// Returns false if this is a paged data set, and the entire set of records that match// the current criteria has not been retrieved from the server.// @visibility external//<allMatchingRowsCached : function () { // data has been loaded, and if paged, cache is full for current filter return (this.localData != null && (!this.isPaged() || (this.allRows != null ||(this.cachedRows == this.totalRows))));},//> @method ResultSet.allRowsCached() [A]// Do we have a complete client-side cache of all records for this dataSource?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -