📄 resultset.js
字号:
/*
* Isomorphic SmartClient
* Version 6.5 (2008-04-30)
* Copyright(c) 1998-2007 Isomorphic Software, Inc. All rights reserved.
* "SmartClient" is a trademark of Isomorphic Software, Inc.
*
* licensing@smartclient.com
*
* http://smartclient.com/license
*/
//> @type Criteria// Criteria for selecting only a matching set of records from a DataSource. Criteria can// be applied on the client and server. Unless configured otherwise, criteria will generally// be applied client-side by +link{ResultSet}s via +link{ResultSet.applyFilter()}. // <P>// The criteria format supported by the SmartClient Server built-in SQLDataSource and HibernateDataSource // is a JavaScript Object where each// property specifies the name and required value for a field. Multiple legal values for a field// can be provided as an Array. For example:// <pre>// var criteria = {// field1 : "value1",// field2 : ["value2", "value3"]// }// </pre>// Would select all records where field1 has value "value1" and where field2 has <i>either</i>// "value2" or "value3".// <P>// For custom backends, criteria must be a JavaScript Object but its properties can contain// whatever data you want. When sent to the SmartClient server, the Java representation of the// criteria is described +link{rpcRequest.data,here}. When sent to other servers, the // +link{type:DSProtocol,operationBinding.dataProtocol} affects the format.//// @treeLocation Client Reference/Data Binding// @see CriteriaPolicy// @visibility external//<//> @class ResultSet // ResultSets are an implementation of the +link{List} interface that automatically fetches // DataSource records when items are requested from the List. ResultSets provide robust,// customizable, high-performance cache management for ListGrids and other built-in SmartClient// components, and can be used as cache managers by custom components.// <P>// ResultSets manage data paging, that is, loading records in batches as the user navigates// the data set. A ResultSet will switch to using client-side sorting and filtering when// possible to improve responsiveness and reduce server load. ResultSets also participate in// automatic cache synchronization, observing operations on DataSources and automatically// updating their caches.// <P>// <b>Creation</b>// <P>// A ResultSet can be passed to any component that expects a List, and the List APIs can be// called directly on the ResultSet as long as the caller is able to deal with asynchronous// loading; see +link{method:ResultSet.getRange()}.// <P>// Generally ResultSets do not need to be created directly, but are created by DataBound// components as an automatic consequence of calling // +link{group:dataBoundComponentMethods,DataBound Component Methods}. // For example, the +link{listGrid.fetchData()} causes +link{listGrid.data} to become an// automatically created <code>ResultSet</code> object. Automatically created ResultSets// can be customized via properties on ListGrids such as +link{listGrid.dataPageSize} and// +link{listGrid.dataProperties}. All ResultSets for a given DataSource may also be // customized via setting +link{dataSource.resultSetClass} to the name of a ResultSet // +link{isc.defineClass(),subclass} in which // +link{classMethod:class.addProperties,defaults have been changed}.// <P>// A ResultSet defaults to using data paging, setting +link{dsRequest.startRow} and// +link{dsRequest.endRow} in issued dsRequests. Server code may always return more rows than// the ResultSet requests and the ResultSet will correctly integrate those rows based on// +link{dsResponse.startRow}/+link{dsResponse.endRow,endRow}. // Hence the server can always avoid paging mode by simply returning all matching rows.// <P>// A ResultSet can be created directly with just the ID of a +link{DataSource}:// <pre>// isc.ResultSet.create({// dataSource : "<i>dataSourceID</i>"// })// </pre>// <P>// Directly created ResultSets are typically used by custom components, or as a means of// managing datasets that will be used by several components.// <P>// When created directly rather than via a dataBoundComponent, a newly created ResultSet will// not issue it's first "fetch" +link{DSRequest} until data is accessed (for example, via// +link{resultSet.get,get()}). // <P>// <b>Paging and total dataset length</b>// <P>// When using data paging, the server communicates the total number of records that match the// current search criteria by setting +link{dsResponse.totalRows}. The ResultSet will then// return this number from +link{resultSet.getLength,getLength()}, and ListGrids and other// components will show a scrollbar that allows the user to jump to the end of the dataset// directly.// <P>// However, the ResultSet does not require that the server calculate the true length of the// dataset, which can be costly for an extremely large, searchable dataset. Instead, the// server <i>may</i> simply advertise a <code>totalRows</code> value that is one page larger// than the last row loaded. This results in a UI sometimes called "progressive loading",// where the user may load more rows by scrolling past the end of the currently loaded rows,// but is not allowed to skip to the end of the dataset.// <P>// No client-side settings are required to enable this mode - it is entirely server-driven.// However, it is usually coupled with +link{listGrid.canSort,disabling sorting}, since// server-side sorting would also force the server to traverse the entire dataset.// <P>// <b>Client-side Sorting and Filtering</b>// <P>// If a ResultSet obtains a full cache for the current set of filter criteria, it will // automatically switch to client-side sorting, and will also use client-side filtering // if the filter criteria are later changed but appear to be <i>more restrictive</i> than the// criteria in use when the ResultSet obtained a full cache.// <P>// The +link{resultSet.useClientSorting,useClientSorting} and // +link{resultSet.useClientFiltering,useClientFiltering} flags can be used to disable// client-side sorting and filtering respectively if these behaviors don't match server-based// sorting and filtering. However, because client-side sorting and filtering radically improve// responsiveness and reduce server load, it is better to customize the ResultSet so that it// can match server-side sorting and filtering behaviors.// <P>// Sorting behavior is primarily customized via the "sort normalizer" passed to// +link{resultSet.sortByProperty}, either via direct calls on a standalone ResultSet, or via// +link{listGridField.sortNormalizer} for a ListGrid-managed ResultSet.// <P>// By default, client-side filtering interprets the +link{type:Criteria,criteria} passed to// +link{resultSet.setCriteria,setCriteria()} as a set of field values that records must match// (similarly to the built-in SQL/Hibernate connectors built into the SmartClient Server).// Custom client-side filtering logic can be implemented by overriding// +link{resultSet.applyFilter,applyFilter()}. Overriding// +link{resultSet.compareCriteria,compareCriteria()} allows you to control when the ResultSet// uses client-side vs server-side filtering, and the ResultSet has two default // +link{resultSet.criteriaPolicy,criteria policies} built-in.// <P>// <b>Updates and Automatic Cache Synchronization</b>// <P>// ResultSets observe any successful "update", "add" or "remove" dsRequests against their// DataSource, regardless of the component that initiated them. A ResultSet with a full cache// for the current filter criteria will integrate updates into the cache automatically.// <P>// Updated rows that no longer match the current filter criteria will be removed// automatically. To prevent this, you can set +link{resultSet.neverDropUpdatedRows}.// Added rows will similarly be added to the cache only if they match current filter criteria.// <P>// Note that the client-side filtering described above is also used to determine whether // updated or added rows should be in the cache. If any aspect of automated cache update is// ever incorrect, +link{resultSet.dropCacheOnUpdate,dropCacheOnUpdate} can be set for the// ResultSet or +link{dsResponse.invalidateCache} can be set for an individual dsResponse.// <P>// <b>Data Paging with partial cache</b>// <P>// When in paging mode with a partial cache, a ResultSet relies on server side sorting, setting // +link{dsRequest.sortBy} to the current sort field and direction. In order for the cache to // remain coherant, row numbering must continue to agree between server and client as new// fetches are issued, otherwise, duplicate rows or missing rows may occur. // <P>// If concurrent modifications by other users are allowed, generally the server should set// +link{dsResponse.invalidateCache} to clear the cache when concurrent modification is// detected.// <P>// In paging mode with a partial cache, any successful "update" or "add" operation may cause// client and server row numbering to become out of sync. This happens because the update// may affect the sort order, and client and server cannot be guaranteed to match for sets of// records that have equivalent values for the sort field.// <P>// For this reason, after an "add" or "update" operation with a partial cache, the ResultSet// will automatically mark cache for invalidation the next time a fetch operation is performed.// Alternatively, if +link{resultSet.updatePartialCache} is set to false, the ResultSet will// simply invalidate cache immediately in this circumstance.//// @see interface:DataBoundComponent// @see group:dataBoundComponentMethods// @see DataSource.resultSetClass to customize all ResultSets for a given DataSource// @see resultSet.getRange() for information on handling asynchronous loading//// @implements List// @treeLocation Client Reference/Data Binding// @visibility external//<isc.ClassFactory.defineClass("ResultSet", null, ["List", "DataModel"]);isc.ResultSet.addClassProperties({ // Value returned from resultSet.getLength() if the length of the resultSet is not // yet known (because we're still fetching data from the server). Note that the correct // way to check for this is resultSet.lengthIsKnown(), not checking for this constant, // which could fail. UNKNOWN_LENGTH : 1000 });isc.ResultSet.addProperties({ //localData : null, // the cache of rows //totalRows : isc.ResultSet.UNKNOWN_LENGTH, // total number of rows in the filtered results cachedRows : 0, // numbers of rows we have cached // Fetching // ---------------------------------------------------------------------------------------- // whether to fetch rows beyond those requested fetchAhead : true, //> @type FetchMode // Mode of fetching records from the server. // <P> // Generally, "paged" mode should be used unless the maximum number of records is // guaranteed to be small. // // @value "basic" All records that match the current filter are fetched. Sorting is // performed on the client // @value "paged" Only requested ranges of records are fetched, with predictive fetch // ahead. Sorting is performed on the server. // @value "local" All records available from the DataSource are fetched. Filtering by // search criteria and sorting are both performed on the client // @group fetching // @visibility external //< //> @attr resultSet.fetchMode (FetchMode : null : IRA) // Mode of fetching records from the server. If unset, will default to <code>"local"</code> // if +link{resultSet.allRows} is specified, otherwise <code>"paged"</code>. // // @see type:FetchMode // @group fetching // @visibility external //< //fetchMode : "paged", //> @attr resultSet.initialData (Array of records : null : IA) // You can specify the initial set of data for the ResultSet using this property. // This data will be considered cached meaning sorting and filtering can occur on // the client (no need for server fetch). // This cached data can be dropped via a call to +link{resultSet.invalidateCache()}. // // @group fetching, cacheSync // @visibility external //< //> @attr resultSet.initialLength (integer : null : IA) // Initial value of the data set length. // // @group fetching, cacheSync // @visibility external //< //> @attr resultSet.allRows (Array of records : null : IA) // If the complete set of records for a resultSet is available when the resultSet is created, // it can be made available to the resultSet via this property at initialization time. // This data will then be considered cached meaning sorting and filtering can occur on // the client (no need for server fetch). // This cached data can be dropped via a call to +link{resultSet.invalidateCache()}. // @group fetching, cacheSync // @visibility external //< //> @attr resultSet.resultSize (integer : 75 : IRWA) // How many rows to retrieve at once. // <P> // Applicable only with <code>fetchMode: "paged"</code>. When a paged ResultSet is asked // for rows that have not yet been loaded, it will fetch adjacent rows that are likely to // be required soon, in batches of this size. // // @group fetching // @visibility external //< resultSize : 75, //> @attr resultSet.fetchDelay (integer : 0 : IRWA) // Delay in milliseconds before fetching rows. // <P> // When a get() or getRange() call asked for rows that haven't been loaded, the // ResultSet will wait before actually triggering the request. If, during the delay, more // get() or getRange() calls are made for missing rows, the final fetch to the server will // reflect the most recently requested rows. // <P> // The intent of this delay is to avoid triggering many unnecessary fetches during // drag-scrolling and similar user interactions. // // @group fetching // @visibility external //< fetchDelay : 0, // DataModel // --------------------------------------------------------------------------------------- //> @attr resultSet.dataSource (DataSource or ID : null : IR) // What +link{class:DataSource} is this resultSet associated with? // @include dataModel.dataSource // @visibility external //< //> @attr resultSet.fetchOperation (Operation or ID : null : IR) // @include dataModel.fetchOperation // @visibility external //< //> @attr resultSet.context (DSRequest Properties : null : IRA) // Request properties for all operations performed by this ResultSet //<
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -