]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojo/data/api/Read.js
Comment class stub
[eow] / static / dojo-release-1.1.1 / dojo / data / api / Read.js
1 if(!dojo._hasResource["dojo.data.api.Read"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojo.data.api.Read"] = true;
3 dojo.provide("dojo.data.api.Read");
4 dojo.require("dojo.data.api.Request");
5
6 dojo.declare("dojo.data.api.Read", null, {
7         //      summary:
8         //              This is an abstract API that data provider implementations conform to.  
9         //              This file defines methods signatures and intentionally leaves all the
10         //              methods unimplemented.  For more information on the dojo.data APIs, 
11         //              please visit: http://www.dojotoolkit.org/node/98
12
13         getValue: function(     /* item */ item, 
14                                                 /* attribute-name-string */ attribute, 
15                                                 /* value? */ defaultValue){
16                 //      summary:
17                 //              Returns a single attribute value.
18                 //              Returns defaultValue if and only if *item* does not have a value for *attribute*.
19                 //              Returns null if and only if null was explicitly set as the attribute value.
20                 //              Returns undefined if and only if the item does not have a value for the
21                 //              given attribute (which is the same as saying the item does not have the attribute). 
22                 // description:
23                 //              Saying that an "item x does not have a value for an attribute y"
24                 //              is identical to saying that an "item x does not have attribute y". 
25                 //              It is an oxymoron to say "that attribute is present but has no values" 
26                 //              or "the item has that attribute but does not have any attribute values".
27                 //              If store.hasAttribute(item, attribute) returns false, then
28                 //              store.getValue(item, attribute) will return undefined.
29                 //
30                 //      item:
31                 //              The item to access values on.
32                 //      attribute:
33                 //              The attribute to access represented as a string.
34                 //      defaultValue:
35                 //              Optional.  A default value to use for the getValue return in the attribute does not exist or has no value.
36                 //
37                 //      exceptions:
38                 //              Throws an exception if *item* is not an item, or *attribute* is not a string
39                 //      example:
40                 //      |       var darthVader = store.getValue(lukeSkywalker, "father");
41                 var attributeValue = null;
42                 throw new Error('Unimplemented API: dojo.data.api.Read.getValue');
43                 return attributeValue; // a literal, an item, null, or undefined (never an array)
44         },
45
46         getValues: function(/* item */ item,
47                                                 /* attribute-name-string */ attribute){
48                 //      summary:
49                 //              This getValues() method works just like the getValue() method, but getValues()
50                 //              always returns an array rather than a single attribute value.  The array
51                 //              may be empty, may contain a single attribute value, or may contain
52                 //              many attribute values.
53                 //              If the item does not have a value for the given attribute, then getValues()
54                 //              will return an empty array: [].  (So, if store.hasAttribute(item, attribute)
55                 //              has a return of false, then store.getValues(item, attribute) will return [].)
56                 //
57                 //      item:
58                 //              The item to access values on.
59                 //      attribute:
60                 //              The attribute to access represented as a string.
61                 //
62                 //      exceptions:
63                 //              Throws an exception if *item* is not an item, or *attribute* is not a string
64                 //      example:
65                 //      |       var friendsOfLuke = store.getValues(lukeSkywalker, "friends");
66                 var array = [];
67                 throw new Error('Unimplemented API: dojo.data.api.Read.getValues');
68                 return array; // an array that may contain literals and items
69         },
70
71         getAttributes: function(/* item */ item){
72                 //      summary:
73                 //              Returns an array with all the attributes that this item has.  This
74                 //              method will always return an array; if the item has no attributes
75                 //              at all, getAttributes() will return an empty array: [].
76                 //
77                 //      item:
78                 //              The item to access attributes on.
79                 //
80                 //      exceptions:
81                 //              Throws an exception if *item* is not an item, or *attribute* is not a string
82                 //      example:
83                 //      |       var array = store.getAttributes(kermit);
84                 var array = [];
85                 throw new Error('Unimplemented API: dojo.data.api.Read.getAttributes');
86                 return array; // array
87         },
88
89         hasAttribute: function( /* item */ item,
90                                                         /* attribute-name-string */ attribute){
91                 //      summary:
92                 //              Returns true if the given *item* has a value for the given *attribute*.
93                 //
94                 //      item:
95                 //              The item to access attributes on.
96                 //      attribute:
97                 //              The attribute to access represented as a string.
98                 //
99                 //      exceptions:
100                 //              Throws an exception if *item* is not an item, or *attribute* is not a string
101                 //      example:
102                 //      |       var trueOrFalse = store.hasAttribute(kermit, "color");
103                 throw new Error('Unimplemented API: dojo.data.api.Read.hasAttribute');
104                 return false; // boolean
105         },
106
107         containsValue: function(/* item */ item,
108                                                         /* attribute-name-string */ attribute, 
109                                                         /* anything */ value){
110                 //      summary:
111                 //              Returns true if the given *value* is one of the values that getValues()
112                 //              would return.
113                 //
114                 //      item:
115                 //              The item to access values on.
116                 //      attribute:
117                 //              The attribute to access represented as a string.
118                 //      value:
119                 //              The value to match as a value for the attribute.
120                 //
121                 //      exceptions:
122                 //              Throws an exception if *item* is not an item, or *attribute* is not a string
123                 //      example:
124                 //      |       var trueOrFalse = store.containsValue(kermit, "color", "green");
125                 throw new Error('Unimplemented API: dojo.data.api.Read.containsValue');
126                 return false; // boolean
127         },
128
129         isItem: function(/* anything */ something){
130                 //      summary:
131                 //              Returns true if *something* is an item and came from the store instance.  
132                 //              Returns false if *something* is a literal, an item from another store instance, 
133                 //              or is any object other than an item.
134                 //
135                 //      something:
136                 //              Can be anything.
137                 //
138                 //      example:
139                 //      |       var yes = store.isItem(store.newItem());
140                 //      |       var no  = store.isItem("green");
141                 throw new Error('Unimplemented API: dojo.data.api.Read.isItem');
142                 return false; // boolean
143         },
144
145         isItemLoaded: function(/* anything */ something) {
146                 //      summary:
147                 //              Returns false if isItem(something) is false.  Returns false if
148                 //              if isItem(something) is true but the the item is not yet loaded
149                 //              in local memory (for example, if the item has not yet been read
150                 //              from the server).
151                 //
152                 //      something:
153                 //              Can be anything.
154                 //
155                 //      example:
156                 //      |       var yes = store.isItemLoaded(store.newItem());
157                 //      |       var no  = store.isItemLoaded("green");
158                 throw new Error('Unimplemented API: dojo.data.api.Read.isItemLoaded');
159                 return false; // boolean
160         },
161
162         loadItem: function(/* object */ keywordArgs){
163                 //      summary:
164                 //              Given an item, this method loads the item so that a subsequent call
165                 //              to store.isItemLoaded(item) will return true.  If a call to
166                 //              isItemLoaded() returns true before loadItem() is even called,
167                 //              then loadItem() need not do any work at all and will not even invoke
168                 //              the callback handlers.  So, before invoking this method, check that
169                 //              the item has not already been loaded.  
170                 //      keywordArgs:
171                 //              An anonymous object that defines the item to load and callbacks to invoke when the 
172                 //              load has completed.  The format of the object is as follows:
173                 //              {
174                 //                      item: object,
175                 //                      onItem: Function,
176                 //                      onError: Function,
177                 //                      scope: object
178                 //              }
179                 //      The *item* parameter.
180                 //              The item parameter is an object that represents the item in question that should be
181                 //              contained by the store.  This attribute is required.
182                 
183                 //      The *onItem* parameter.
184                 //              Function(item)
185                 //              The onItem parameter is the callback to invoke when the item has been loaded.  It takes only one
186                 //              parameter, the fully loaded item.
187                 //
188                 //      The *onError* parameter.
189                 //              Function(error)
190                 //              The onError parameter is the callback to invoke when the item load encountered an error.  It takes only one
191                 //              parameter, the error object
192                 //
193                 //      The *scope* parameter.
194                 //              If a scope object is provided, all of the callback functions (onItem, 
195                 //              onError, etc) will be invoked in the context of the scope object.
196                 //              In the body of the callback function, the value of the "this"
197                 //              keyword will be the scope object.   If no scope object is provided,
198                 //              the callback functions will be called in the context of dojo.global().
199                 //              For example, onItem.call(scope, item, request) vs. 
200                 //              onItem.call(dojo.global(), item, request)
201                 if (!this.isItemLoaded(keywordArgs.item)) {
202                         throw new Error('Unimplemented API: dojo.data.api.Read.loadItem');
203                 }
204         },
205
206         fetch: function(/* Object */ keywordArgs){
207                 //      summary:
208                 //              Given a query and set of defined options, such as a start and count of items to return,
209                 //              this method executes the query and makes the results available as data items.
210                 //              The format and expectations of stores is that they operate in a generally asynchronous 
211                 //              manner, therefore callbacks are always used to return items located by the fetch parameters.
212                 //
213                 //      description:
214                 //              A Request object will always be returned and is returned immediately.
215                 //              The basic request is nothing more than the keyword args passed to fetch and 
216                 //              an additional function attached, abort().  The returned request object may then be used 
217                 //              to cancel a fetch.  All data items returns are passed through the callbacks defined in the 
218                 //              fetch parameters and are not present on the 'request' object.
219                 //
220                 //              This does not mean that custom stores can not add methods and properties to the request object
221                 //              returned, only that the API does not require it.  For more info about the Request API, 
222                 //              see dojo.data.api.Request
223                 //
224                 //      keywordArgs:
225                 //              The keywordArgs parameter may either be an instance of 
226                 //              conforming to dojo.data.api.Request or may be a simple anonymous object
227                 //              that may contain any of the following:
228                 //              { 
229                 //                      query: query-object or query-string,
230                 //                      queryOptions: object,
231                 //                      onBegin: Function,
232                 //                      onItem: Function,
233                 //                      onComplete: Function,
234                 //                      onError: Function,
235                 //                      scope: object,
236                 //                      start: int
237                 //                      count: int
238                 //                      sort: array
239                 //              }
240                 //              All implementations should accept keywordArgs objects with any of
241                 //              the 9 standard properties: query, onBegin, onItem, onComplete, onError 
242                 //              scope, sort, start, and count.  Some implementations may accept additional 
243                 //              properties in the keywordArgs object as valid parameters, such as 
244                 //              {includeOutliers:true}.         
245                 //
246                 //      The *query* parameter.
247                 //              The query may be optional in some data store implementations.
248                 //              The dojo.data.api.Read API does not specify the syntax or semantics
249                 //              of the query itself -- each different data store implementation
250                 //              may have its own notion of what a query should look like.
251                 //              However, as of dojo 0.9, 1.0, and 1.1, all the provided datastores in dojo.data
252                 //              and dojox.data support an object structure query, where the object is a set of 
253                 //              name/value parameters such as { attrFoo: valueBar, attrFoo1: valueBar1}.  Most of the
254                 //              dijit widgets, such as ComboBox assume this to be the case when working with a datastore 
255                 //              when they dynamically update the query.  Therefore, for maximum compatibility with dijit 
256                 //              widgets the recommended query parameter is a key/value object.  That does not mean that the
257                 //              the datastore may not take alternative query forms, such as a simple string, a Date, a number, 
258                 //              or a mix of such.  Ultimately, The dojo.data.api.Read API is agnostic about what the query 
259                 //              format.  
260                 //              Further note:  In general for query objects that accept strings as attribute 
261                 //              value matches, the store should also support basic filtering capability, such as * 
262                 //              (match any character) and ? (match single character).  An example query that is a query object
263                 //              would be like: { attrFoo: "value*"}.  Which generally means match all items where they have 
264                 //              an attribute named attrFoo, with a value that starts with 'value'.
265                 //
266                 //      The *queryOptions* parameter
267                 //              The queryOptions parameter is an optional parameter used to specify optiosn that may modify
268                 //              the query in some fashion, such as doing a case insensitive search, or doing a deep search
269                 //              where all items in a hierarchical representation of data are scanned instead of just the root 
270                 //              items.  It currently defines two options that all datastores should attempt to honor if possible:
271                 //              {
272                 //                      ignoreCase: boolean, //Whether or not the query should match case sensitively or not.  Default behaviour is false.
273                 //                      deep: boolean   //Whether or not a fetch should do a deep search of items and all child 
274                 //                                                      //items instead of just root-level items in a datastore.  Default is false.
275                 //              }
276                 //
277                 //      The *onBegin* parameter.
278                 //              function(size, request);
279                 //              If an onBegin callback function is provided, the callback function
280                 //              will be called just once, before the first onItem callback is called.
281                 //              The onBegin callback function will be passed two arguments, the
282                 //              the total number of items identified and the Request object.  If the total number is
283                 //              unknown, then size will be -1.  Note that size is not necessarily the size of the 
284                 //              collection of items returned from the query, as the request may have specified to return only a 
285                 //              subset of the total set of items through the use of the start and count parameters.
286                 //
287                 //      The *onItem* parameter.
288                 //              function(item, request);
289                 //              If an onItem callback function is provided, the callback function
290                 //              will be called as each item in the result is received. The callback 
291                 //              function will be passed two arguments: the item itself, and the
292                 //              Request object.
293                 //
294                 //      The *onComplete* parameter.
295                 //              function(items, request);
296                 //
297                 //              If an onComplete callback function is provided, the callback function
298                 //              will be called just once, after the last onItem callback is called.
299                 //              Note that if the onItem callback is not present, then onComplete will be passed
300                 //              an array containing all items which matched the query and the request object.  
301                 //              If the onItem callback is present, then onComplete is called as: 
302                 //              onComplete(null, request).
303                 //
304                 //      The *onError* parameter.
305                 //              function(errorData, request); 
306                 //              If an onError callback function is provided, the callback function
307                 //              will be called if there is any sort of error while attempting to
308                 //              execute the query.
309                 //              The onError callback function will be passed two arguments:
310                 //              an Error object and the Request object.
311                 //
312                 //      The *scope* parameter.
313                 //              If a scope object is provided, all of the callback functions (onItem, 
314                 //              onComplete, onError, etc) will be invoked in the context of the scope
315                 //              object.  In the body of the callback function, the value of the "this"
316                 //              keyword will be the scope object.   If no scope object is provided,
317                 //              the callback functions will be called in the context of dojo.global().  
318                 //              For example, onItem.call(scope, item, request) vs. 
319                 //              onItem.call(dojo.global(), item, request)
320                 //
321                 //      The *start* parameter.
322                 //              If a start parameter is specified, this is a indication to the datastore to 
323                 //              only start returning items once the start number of items have been located and
324                 //              skipped.  When this parameter is paired withh 'count', the store should be able
325                 //              to page across queries with millions of hits by only returning subsets of the 
326                 //              hits for each query
327                 //
328                 //      The *count* parameter.
329                 //              If a count parameter is specified, this is a indication to the datastore to 
330                 //              only return up to that many items.  This allows a fetch call that may have 
331                 //              millions of item matches to be paired down to something reasonable.  
332                 //
333                 //      The *sort* parameter.
334                 //              If a sort parameter is specified, this is a indication to the datastore to 
335                 //              sort the items in some manner before returning the items.  The array is an array of 
336                 //              javascript objects that must conform to the following format to be applied to the
337                 //              fetching of items:
338                 //              {
339                 //                      attribute: attribute || attribute-name-string,
340                 //                      descending: true|false;   // Optional.  Default is false.
341                 //              }
342                 //              Note that when comparing attributes, if an item contains no value for the attribute
343                 //              (undefined), then it the default ascending sort logic should push it to the bottom 
344                 //              of the list.  In the descending order case, it such items should appear at the top of the list.
345                 // 
346                 //      returns:
347                 //              The fetch() method will return a javascript object conforming to the API
348                 //              defined in dojo.data.api.Request.  In general, it will be the keywordArgs
349                 //              object returned with the required functions in Request.js attached.
350                 //              Its general purpose is to provide a convenient way for a caller to abort an
351                 //              ongoing fetch.  
352                 // 
353                 //              The Request object may also have additional properties when it is returned
354                 //              such as request.store property, which is a pointer to the datastore object that 
355                 //              fetch() is a method of.
356                 //
357                 //      exceptions:
358                 //              Throws an exception if the query is not valid, or if the query
359                 //              is required but was not supplied.
360                 //
361                 //      example:
362                 //              Fetch all books identified by the query and call 'showBooks' when complete
363                 //              |       var request = store.fetch({query:"all books", onComplete: showBooks});
364                 //      example:
365                 //              Fetch all items in the story and call 'showEverything' when complete.
366                 //              |       var request = store.fetch(onComplete: showEverything);
367                 //      example:
368                 //              Fetch only 10 books that match the query 'all books', starting at the fifth book found during the search.
369                 //              This demonstrates how paging can be done for specific queries.  
370                 //              |       var request = store.fetch({query:"all books", start: 4, count: 10, onComplete: showBooks});
371                 //      example:
372                 //              Fetch all items that match the query, calling 'callback' each time an item is located.
373                 //              |       var request = store.fetch({query:"foo/bar", onItem:callback});
374                 //      example:
375                 //              Fetch the first 100 books by author King, call showKing when up to 100 items have been located.
376                 //              |       var request = store.fetch({query:{author:"King"}, start: 0, count:100, onComplete: showKing});
377                 //      example:
378                 //              Locate the books written by Author King, sort it on title and publisher, then return the first 100 items from the sorted items.
379                 //              |       var request = store.fetch({query:{author:"King"}, sort: [{ attribute: "title", descending: true}, {attribute: "publisher"}], ,start: 0, count:100, onComplete: 'showKing'});
380                 //      example:
381                 //              Fetch the first 100 books by authors starting with the name King, then call showKing when up to 100 items have been located.
382                 //              |       var request = store.fetch({query:{author:"King*"}, start: 0, count:100, onComplete: showKing});
383                 //      example:
384                 //              Fetch the first 100 books by authors ending with 'ing', but only have one character before it (King, Bing, Ling, Sing, etc.), then call showBooks when up to 100 items have been located.
385                 //              |       var request = store.fetch({query:{author:"?ing"}, start: 0, count:100, onComplete: showBooks});
386                 //      example:
387                 //              Fetch the first 100 books by author King, where the name may appear as King, king, KING, kInG, and so on, then call showKing when up to 100 items have been located.
388                 //              |       var request = store.fetch({query:{author:"King"}, queryOptions:(ignoreCase: true}, start: 0, count:100, onComplete: showKing});
389                 //      example:
390                 //              Paging
391                 //              |       var store = new dojo.data.LargeRdbmsStore({url:"jdbc:odbc:foobar"});
392                 //              |       var fetchArgs = {
393                 //              |               query: {type:"employees", name:"Hillary *"}, // string matching
394                 //              |               sort: [{attribute:"department", descending:true}],
395                 //              |               start: 0,
396                 //              |               count: 20,
397                 //              |               scope: displayer,
398                 //              |               onBegin: showThrobber,
399                 //              |               onItem: displayItem,
400                 //              |               onComplete: stopThrobber,
401                 //              |               onError: handleFetchError,
402                 //              |       };
403                 //              |       store.fetch(fetchArgs);
404                 //              |       ...
405                 //              and then when the user presses the "Next Page" button...
406                 //              |       fetchArgs.start += 20;
407                 //              |       store.fetch(fetchArgs);  // get the next 20 items
408                 var request = null; 
409                 throw new Error('Unimplemented API: dojo.data.api.Read.fetch');
410                 return request; // an object conforming to the dojo.data.api.Request API
411         },
412
413         getFeatures: function(){
414                 //      summary:
415                 //              The getFeatures() method returns an simple keyword values object 
416                 //              that specifies what interface features the datastore implements.  
417                 //              A simple CsvStore may be read-only, and the only feature it 
418                 //              implements will be the 'dojo.data.api.Read' interface, so the
419                 //              getFeatures() method will return an object like this one:
420                 //              {'dojo.data.api.Read': true}.
421                 //              A more sophisticated datastore might implement a variety of
422                 //              interface features, like 'dojo.data.api.Read', 'dojo.data.api.Write', 
423                 //              'dojo.data.api.Identity', and 'dojo.data.api.Attribution'.
424                 return {
425                         'dojo.data.api.Read': true
426                 };
427         },
428
429         close: function(/*dojo.data.api.Request || keywordArgs || null */ request){
430                 //      summary:
431                 //              The close() method is intended for instructing the store to 'close' out 
432                 //              any information associated with a particular request.
433                 //
434                 //      description:
435                 //              The close() method is intended for instructing the store to 'close' out 
436                 //              any information associated with a particular request.  In general, this API
437                 //              expects to recieve as a parameter a request object returned from a fetch.  
438                 //              It will then close out anything associated with that request, such as 
439                 //              clearing any internal datastore caches and closing any 'open' connections.
440                 //              For some store implementations, this call may be a no-op.
441                 //
442                 //      request:
443                 //              An instance of a request for the store to use to identify what to close out.
444                 //              If no request is passed, then the store should clear all internal caches (if any)
445                 //              and close out all 'open' connections.  It does not render the store unusable from
446                 //              there on, it merely cleans out any current data and resets the store to initial 
447                 //              state.
448                 //
449                 //      example:
450                 //      |       var request = store.fetch({onComplete: doSomething});
451                 //      |       ...
452                 //      |       store.close(request);
453                 throw new Error('Unimplemented API: dojo.data.api.Read.close');
454         },
455
456         getLabel: function(/* item */ item){
457                 //      summary:
458                 //              Method to inspect the item and return a user-readable 'label' for the item
459                 //              that provides a general/adequate description of what the item is. 
460                 //
461                 //      description:
462                 //              Method to inspect the item and return a user-readable 'label' for the item
463                 //              that provides a general/adequate description of what the item is.  In general
464                 //              most labels will be a specific attribute value or collection of the attribute
465                 //              values that combine to label the item in some manner.  For example for an item
466                 //              that represents a person it may return the label as:  "firstname lastlame" where
467                 //              the firstname and lastname are attributes on the item.  If the store is unable 
468                 //              to determine an adequate human readable label, it should return undefined.  Users that wish
469                 //              to customize how a store instance labels items should replace the getLabel() function on 
470                 //              their instance of the store, or extend the store and replace the function in 
471                 //              the extension class.
472                 //
473                 //      item:
474                 //              The item to return the label for.
475                 //
476                 //      returns: 
477                 //              A user-readable string representing the item or undefined if no user-readable label can 
478                 //              be generated.
479                 throw new Error('Unimplemented API: dojo.data.api.Read.getLabel');
480                 return undefined;
481         },
482
483         getLabelAttributes: function(/* item */ item){
484                 //      summary:
485                 //              Method to inspect the item and return an array of what attributes of the item were used 
486                 //              to generate its label, if any.
487                 //
488                 //      description:
489                 //              Method to inspect the item and return an array of what attributes of the item were used 
490                 //              to generate its label, if any.  This function is to assist UI developers in knowing what
491                 //              attributes can be ignored out of the attributes an item has when displaying it, in cases
492                 //              where the UI is using the label as an overall identifer should they wish to hide 
493                 //              redundant information.
494                 //
495                 //      item:
496                 //              The item to return the list of label attributes for.
497                 //
498                 //      returns: 
499                 //              An array of attribute names that were used to generate the label, or null if public attributes 
500                 //              were not used to generate the label.
501                 throw new Error('Unimplemented API: dojo.data.api.Read.getLabelAttributes');
502                 return null;
503         }
504 });
505
506 }