sap.ui.model.odata.ODataModel.extend(sClassName, oClassInfo?, FNMetaImpl?): function
Creates a new subclass of class sap.ui.model.odata.ODataModel with name
sClassName
and enriches it with the information contained in
oClassInfo
.
oClassInfo
might contain the same kind of information as described in sap.ui.model.Model.extend.
Parameters:
{string} | sClassName | Name of the class being created |
{object} | oClassInfo? | Object literal with information about the class |
{function} | FNMetaImpl? | Constructor function for the metadata object; if not given, it defaults to sap.ui.core.ElementMetadata |
Returns:
{function} | Created class / constructor function |
Returns a metadata object for class sap.ui.model.odata.ODataModel.
Returns:
addAnnotationUrl(vUrl): Promise
Adds (a) new URL(s) to the be parsed for OData annotations, which are then merged into the annotations object which can be retrieved by calling the getServiceAnnotations()-method. If a $metadata url is passed the data will also be merged into the metadata object, which can be reached by calling the getServiceMetadata() method.
Parameters:
{string|sting[]} | vUrl | Either one URL as string or an array or URL strings |
Returns:
{Promise} | The Promise to load the given URL(s), resolved if all URLs have been loaded, rejected if at least one fails to load. If this promise resolves it returns the following parameters: annotations: The annotation object entitySets: An array of EntitySet objects containing the newly merged EntitySets from a $metadata requests. the structure is the same as in the metadata object reached by the getServiceMetadata() method. For non $metadata requests the array will be empty. |
addAnnotationXML(sXMLContent, bSuppressEvents?): Promise
Adds new xml content to be parsed for OData annotations, which are then merged into the annotations object which can be retrieved by calling the getServiceAnnotations()-method.
Parameters:
{string} | sXMLContent | The string that should be parsed as annotation XML |
{boolean} | bSuppressEvents? | Whether not to fire annotationsLoaded event on the annotationParser |
Returns:
{Promise} | The Promise to parse the given XML-String, resolved if parsed without errors, rejected if errors occur |
addBatchChangeOperations(aChangeOperations)
Appends the change batch operations to the end of the batch stack. Only PUT, POST or DELETE batch operations should be included in the specified array. The operations in the array will be included in a single changeset. To embed change operations in different change sets call this method with the corresponding change operations again. If an illegal batch operation is added to the change set nothing will be performed and false will be returned.
Parameters:
{any[]} | aChangeOperations | an array of change batch operations created via createBatchOperation and sMethod = POST, PUT, MERGE or DELETE |
addBatchReadOperations(aReadOperations)
Appends the read batch operations to the end of the batch stack. Only GET batch operations should be included in the specified array. If an illegal batch operation is added to the batch nothing will be performed and false will be returned.
Parameters:
{any[]} | aReadOperations | an array of read batch operations created via createBatchOperation and sMethod = GET |
Attach event-handler fnFunction
to the 'annotationsFailed' event of this sap.ui.model.odata.ODataModel
.
Parameters:
{object} | oData? | The object, that should be passed along with the event-object when firing the event. |
{function} | fnFunction | The function to call, when the event occurs. This function will be called on the oListener-instance (if present) or in a 'static way'. |
{object} | oListener? | Object on which to call the given function. If empty, the global context (window) is used. |
Returns:
Attach event-handler
fnFunction
to the 'annotationsLoaded' event of this
sap.ui.model.odata.ODataModel
.
Experimental API:The API is NOT stable yet. Use at your own risk.
Parameters:
{object} | oData? | The object, that should be passed along with the event-object when firing the event. |
{function} | fnFunction | The function to call, when the event occurs. This function will be called on the oListener-instance (if present) or in a 'static way'. |
{object} | oListener? | Object on which to call the given function. If empty, the global context (window) is used. |
- Experimental:
- The API is NOT stable yet. Use at your own risk.
Returns:
Attach event-handler fnFunction
to the 'metadataFailed' event of this sap.ui.model.odata.ODataModel
.
Parameters:
{object} | oData? | The object, that should be passed along with the event-object when firing the event. |
{function} | fnFunction | The function to call, when the event occurs. This function will be called on the oListener-instance (if present) or in a 'static way'. |
{object} | oListener? | Object on which to call the given function. If empty, the global context (window) is used. |
Returns:
Attach event-handler fnFunction
to the 'metadataLoaded' event of this sap.ui.model.odata.ODataModel
.
Parameters:
{object} | oData? | The object, that should be passed along with the event-object when firing the event. |
{function} | fnFunction | The function to call, when the event occurs. This function will be called on the oListener-instance (if present) or in a 'static way'. |
{object} | oListener? | Object on which to call the given function. If empty, the global context (window) is used. |
Returns:
callFunction(sFunctionName, mParameters?): object
Trigger a request to the function import odata service that was specified in the model constructor.
Parameters:
{string} | sFunctionName | A string containing the name of the function to call. The name is concatenated to the sServiceUrl which was specified in the model constructor. |
{map} | mParameters? | Optional parameter map containing any of the following properties: |
{string} | mParameters.method? | A string containing the type of method to call this function with |
{map} | mParameters.urlParameters? | A map containing the parameters that will be passed as query strings |
{object} | mParameters.context? | If specified the sPath has to be relative to the path given with the context. |
{function} | mParameters.success? | a callback function which is called when the data has been successfully retrieved. The handler can have the following parameters: oData and response . |
{function} | mParameters.error? | a callback function which is called when the request failed. The handler can have the parameter: oError which contains additional error information. |
{boolean} | mParameters.async? | Whether or not to send the request asynchronously. Default: false In case sMethod is "GET", the request is always asynchronous. Please be advised that this feature is officially unsupported as using asynchronous requests can lead to data inconsistencies if the application does not make sure that the request was completed before continuing to work with the data. |
Returns:
{object} | an object which has an abort function to abort the current request. |
clearBatch()
Removes all operations in the current batch.
create(sPath, oData, mParameters?): object
Trigger a POST request to the odata service that was specified in the model constructor. Please note that deep creates are not supported and may not work.
Parameters:
{string} | sPath | A string containing the path to the collection where an entry should be created. The path is concatenated to the sServiceUrl which was specified in the model constructor. |
{object} | oData | data of the entry that should be created. |
{map} | mParameters? | Optional parameter map containing any of the following properties: |
{object} | mParameters.context? | If specified the sPath has to be relative to the path given with the context. |
{function} | mParameters.success? | a callback function which is called when the data has been successfully retrieved. The handler can have the following parameters: oData and response. |
{function} | mParameters.error? | a callback function which is called when the request failed. The handler can have the parameter oError which contains additional error information. |
{boolean} | mParameters.async? | Whether the request should be done asynchronously. Default: false Please be advised that this feature is officially unsupported as using asynchronous requests can lead to data inconsistencies if the application does not make sure that the request was completed before continuing to work with the data. |
{map} | mParameters.urlParameters? | A map containing the parameters that will be passed as query strings |
Returns:
{object} | an object which has an abort function to abort the current request. |
createBatchOperation(sPath, sMethod, oData?, oParameters?)
Creates a single batch operation (read or change operation) which can be used in a batch request.
Parameters:
{string} | sPath | A string containing the path to the collection or entry where the batch operation should be performed. The path is concatenated to the sServiceUrl which was specified in the model constructor. |
{string} | sMethod | for the batch operation. Possible values are GET, PUT, MERGE, POST, DELETE |
{object} | oData? | optional data payload which should be created, updated, deleted in a change batch operation. |
{object} | oParameters? | optional parameter for additional information introduced in SAPUI5 1.9.1, |
{string} | oParameters.sETag? | an ETag which can be used for concurrency control. If it is specified, it will be used in an If-Match-Header in the request to the server for this entry. |
Creates a new entry object which is described by the metadata of the entity type of the specified sPath Name. A context object is returned which can be used to bind against the newly created object.
For each created entry a request is created and stored in a request queue. The request queue can be submitted by calling submitChanges. To delete a created entry from the request queue call deleteCreateEntry.
The optional vProperties parameter can be used as follows:
- vProperties could be an array containing the property names which should be included in the new entry. Other properties defined in the entity type are not included. - vProperties could be an object which includes the desired properties and the values which should be used for the created entry.
If vProperties is not specified, all properties in the entity type will be included in the created entry.
If there are no values specified the properties will have undefined values.
Please note that deep creates (including data defined by navigationproperties) are not supported
Parameters:
{String} | sPath | Name of the path to the collection |
{array|object} | vProperties | An array that specifies a set of properties or the entry |
Returns:
createKey(sCollection, oKeyParameters, bDecode)
Creates the key from the given collection name and property map
Parameters:
{string} | sCollection | The name of the collection |
{object} | oKeyParameters | The object containing at least all the key properties of the entity type |
{boolean} | bDecode | Whether the URI decoding should be applied on the key |
deleteCreatedEntry(oContext)
Deletes a created entry from the request queue and the model.
Parameters:
destroy()
See:
sap.ui.model.Model.prototype.destroy |
Detach event-handler
fnFunction
from the 'annotationsFailed' event of this
sap.ui.model.odata.ODataModel
.
The passed function and listener object must match the ones previously used for event registration.
Parameters:
{function} | fnFunction | The function to call, when the event occurs. |
{object} | oListener | Object on which the given function had to be called. |
Returns:
Detach event-handler
fnFunction
from the 'annotationsLoaded' event of this
sap.ui.model.odata.ODataModel
.
Experimental API:The API is NOT stable yet. Use at your own risk.
Parameters:
{function} | fnFunction | The function to call, when the event occurs. |
{object} | oListener | Object on which the given function had to be called. |
- Experimental:
- The API is NOT stable yet. Use at your own risk.
Returns:
Detach event-handler
fnFunction
from the 'metadataFailed' event of this
sap.ui.model.odata.ODataModel
.
The passed function and listener object must match the ones previously used for event registration.
Parameters:
{function} | fnFunction | The function to call, when the event occurs. |
{object} | oListener | Object on which the given function had to be called. |
Returns:
Detach event-handler
fnFunction
from the 'metadataLoaded' event of this
sap.ui.model.odata.ODataModel
.
The passed function and listener object must match the ones previously used for event registration.
Parameters:
{function} | fnFunction | The function to call, when the event occurs. |
{object} | oListener | Object on which the given function had to be called. |
Returns:
Fire event annotationsFailed to attached listeners.
Parameters:
{object} | mArguments? | the arguments to pass along with the event. |
{string} | mArguments.message? | A text that describes the failure. |
{string} | mArguments.statusCode? | HTTP status code returned by the request (if available) |
{string} | mArguments.statusText? | The status as a text, details not specified, intended only for diagnosis output |
{string} | mArguments.responseText? | Response that has been received for the request ,as a text string |
Returns:
Fire event annotationsLoaded to attached listeners.
Parameters:
Returns:
Fire event metadataFailed to attached listeners.
Parameters:
{object} | mArguments? | the arguments to pass along with the event. |
{string} | mArguments.message? | A text that describes the failure. |
{string} | mArguments.statusCode? | HTTP status code returned by the request (if available) |
{string} | mArguments.statusText? | The status as a text, details not specified, intended only for diagnosis output |
{string} | mArguments.responseText? | Response that has been received for the request ,as a text string |
Returns:
Fire event metadataLoaded to attached listeners.
Parameters:
Returns:
Returns the default count mode for retrieving the count of collections
- Since:
- 1.20
Returns:
getHeaders(): object
Returns all headers and custom headers which are stored in the OData model.
Returns:
getKey(oObject, bDecode)
Returns the key part from the entry URI or the given context or object
Parameters:
{object|sap.ui.model.Context} | oObject | The context or object |
{boolean} | bDecode | Whether the URI decoding should be applied on the key |
Returns an instance of an OData meta model which offers a unified access to both OData V2 meta data and V4 annotations. It uses the existing
sap.ui.model.odata.ODataMetadata as a foundation and merges V4 annotations from the existing
sap.ui.model.odata.ODataAnnotations directly into the corresponding model element.
BEWARE: Access to this OData meta model will fail before the promise returned by loaded has been resolved!
Returns:
getProperty(sPath, oContext?, bIncludeExpandEntries?)
Returns the value for the property with the given sPath
. If the path points to a navigation property which has been loaded via $expand then the bIncludeExpandEntries
parameter determines if the navigation property should be included in the returned value or not. Please note that this currently works for 1..1 navigation properties only.
Parameters:
{string} | sPath | the path/name of the property |
{object} | oContext? | the context if available to access the property value |
{boolean} | bIncludeExpandEntries? | This parameter should be set when a URI or custom parameter with a $expand System Query Option was used to retrieve associated entries embedded/inline. If true then the getProperty function returns a desired property value/entry and includes the associated expand entries (if any). If false the associated/expanded entry properties are removed and not included in the desired entry as properties at all. This is useful for performing updates on the base entry only. Note: A copy and not a reference of the entry will be returned. |
getSecurityToken(): string
Returns the current security token. If the token has not been requested from the server it will be requested first.
Returns:
{string} | the CSRF security token |
getServiceAnnotations
(): Object Return the annotation object. Please note that when using the model with bLoadMetadataAsync = true then this function might return undefined because the metadata has not been loaded yet. In this case attach to the
annotationsLoaded
event to get notified when the annotations are available and then call this function.
Experimental API:This feature has not been tested due to the lack of OData testing infrastructure. The API is NOT stable yet. Use at your own risk.
- Experimental:
- This feature has not been tested due to the lack of OData testing infrastructure. The API is NOT stable yet. Use at your own risk.
Returns:
Return the metadata object. Please note that when using the model with bLoadMetadataAsync = true then this function might return undefined because the metadata has not been loaded yet. In this case attach to the metadataLoaded
event to get notified when the metadata is available and then call this function.
Returns:
hasPendingChanges(): boolean
Checks if there exist pending changes in the model created by the setProperty method.
Returns:
read(sPath, mParameters?): object
Trigger a GET request to the odata service that was specified in the model constructor. The data will not be stored in the model. The requested data is returned with the response.
Parameters:
{string} | sPath | A string containing the path to the data which should be retrieved. The path is concatenated to the sServiceUrl which was specified in the model constructor. |
{map} | mParameters? | Optional parameter map containing any of the following properties: |
{object} | mParameters.context? | If specified the sPath has to be is relative to the path given with the context. |
{map} | mParameters.urlParameters? | A map containing the parameters that will be passed as query strings |
{boolean} | mParameters.async?, Default: true | true for asynchronous requests. |
{array} | mParameters.filters? | an array of sap.ui.model.Filter to be included in the request URL |
{array} | mParameters.sorters? | an array of sap.ui.model.Sorter to be included in the request URL |
{function} | mParameters.success? | a callback function which is called when the data has been successfully retrieved. The handler can have the following parameters: oData and response. |
{function} | mParameters.error? | a callback function which is called when the request failed. The handler can have the parameter: oError which contains additional error information. |
Returns:
{object} | an object which has an abort function to abort the current request. |
refresh(bForceUpdate?, bRemoveData?)
Refresh the model. This will check all bindings for updated data and update the controls if data has been changed.
Parameters:
{boolean} | bForceUpdate? | Force update of controls |
{boolean} | bRemoveData? | If set to true then the model data will be removed/cleared. Please note that the data might not be there when calling e.g. getProperty too early before the refresh call returned. |
refreshMetadata()
refreshes the metadata for model, e.g. in case the first request for metadata has failed
refreshSecurityToken(fnSuccess?, fnError?, bAsync?): object
refresh XSRF token by performing a GET request against the service root URL.
Parameters:
{function} | fnSuccess? | a callback function which is called when the data has been successfully retrieved. |
{function} | fnError? | a callback function which is called when the request failed. The handler can have the parameter: oError which contains additional error information. |
{boolean} | bAsync? | true for asynchronous requests. |
Returns:
{object} | an object which has an abort function to abort the current request. |
remove(sPath, mParameters?): object
Trigger a DELETE request to the odata service that was specified in the model constructor.
Parameters:
{string} | sPath | A string containing the path to the data that should be removed. The path is concatenated to the sServiceUrl which was specified in the model constructor. |
{object} | mParameters? | Optional, can contain the following attributes: oContext, fnSuccess, fnError, sETag: |
{object} | mParameters.context? | If specified the sPath has to be relative to the path given with the context. |
{function} | mParameters.success? | a callback function which is called when the data has been successfully retrieved. The handler can have the following parameters: oData and response . |
{function} | mParameters.error? | a callback function which is called when the request failed. The handler can have the parameter: oError which contains additional error information. |
{string} | mParameters.eTag? | If specified, the If-Match-Header will be set to this Etag. |
{object} | mParameters.payload? | if specified, this optional variable can be used to pass a payload into the delete function, e.g. if the entry which should be deleted has not been bound to any control, but has been retrieved via read, only. |
{boolean} | mParameters.async? | Whether the request should be done asynchronously. Please be advised that this feature is officially unsupported as using asynchronous requests can lead to data inconsistencies if the application does not make sure that the request was completed before continuing to work with the data. |
{map} | mParameters.urlParameters? | A map containing the parameters that will be passed as query strings |
Returns:
{object} | an object which has an abort function to abort the current request. |
resetChanges(fnSuccess?, fnError?)
Resets the collected changes by the setProperty method and reloads the data from the server.
Parameters:
{function} | fnSuccess? | a callback function which is called when the data has been successfully resetted. The handler can have the following parameters: oData and response. |
{function} | fnError? | a callback function which is called when the request failed |
setDefaultCountMode(sCountMode)
Sets the default way to retrieve the count of collections in this model. Count can be determined either by sending a separate $count request, including $inlinecount=allpages in data requests, both of them or not at all.
Parameters:
- Since:
- 1.20
setHeaders(mHeaders)
Set custom headers which are provided in a key/value map. These headers are used for requests against the OData backend. Private headers which are set in the ODataModel cannot be modified. These private headers are: accept, accept-language, x-csrf-token, MaxDataServiceVersion, DataServiceVersion.
To remove these headers simply set the mCustomHeaders parameter to null. Please also note that when calling this method again all previous custom headers are removed unless they are specified again in the mCustomHeaders parameter.
Parameters:
{object} | mHeaders | the header name/value map. |
setProperty(sPath, oValue, oContext?, bAsyncUpdate?): boolean
Sets a new value for the given property
sPropertyName
in the model without triggering a server request. This can be done by the submitChanges method.
Note: Only one entry of one collection can be updated at once. Otherwise a fireRejectChange event is fired.
Before updating a different entry the existing changes of the current entry have to be submitted or resetted by the corresponding methods: submitChanges, resetChanges.
IMPORTANT: All pending changes are resetted in the model if the application triggeres any kind of refresh on that entry. Make sure to submit the pending changes first. To determine if there are any pending changes call the hasPendingChanges method.
Parameters:
{string} | sPath | path of the property to set |
{any} | oValue | value to set the property to |
{object} | oContext? | the context which will be used to set the property |
{boolean} | bAsyncUpdate? | whether to update other bindings dependent on this property asynchronously |
Returns:
{boolean} | true if the value was set correctly and false if errors occurred like the entry was not found or another entry was already updated. |
setRefreshAfterChange(bRefreshAfterChange)
Enable/Disable automatic updates of all Bindings after change operations
Parameters:
{boolean} | bRefreshAfterChange | |
- Since:
- 1.16.3
setTokenHandlingEnabled(bTokenHandling?)
Enable/Disable XCSRF-Token handling
Parameters:
{boolean} | bTokenHandling?, Default: true | whether to use token handling or not |
setUseBatch(bUseBatch?)
Enable/Disable batch for all requests
Parameters:
{boolean} | bUseBatch? | whether the requests should be encapsulated in a batch request |
submitBatch(fnSuccess?, fnError?, bAsync?, bImportData): object
Submits the collected changes in the batch which were collected via addBatchReadOperations
or addBatchChangeOperations
. The batch will be cleared afterwards. If the batch is empty no request will be performed and false will be returned. Note: No data will be stored in the model.
Parameters:
{function} | fnSuccess? | a callback function which is called when the batch request has been successfully sent. Note: There might have errors occured in the single batch operations. These errors can be accessed in the aErrorResponses parameter in the callback handler. The handler can have the following parameters: oData, oResponse and aErrorResponses. |
{function} | fnError? | a callback function which is called when the batch request failed. The handler can have the parameter: oError which contains additional error information. |
{boolean} | bAsync? | true for asynchronous request. Default is true. |
{boolean} | bImportData | |
Returns:
{object} | an object which has an abort function to abort the current request. Returns false if no request will be performed because the batch is empty. |
submitChanges(fnSuccess?, fnError?, oParameters?): object
Submits the collected changes which were collected by the setProperty method. A MERGE request will be triggered to only update the changed properties. If a URI with a $expand System Query Option was used then the expand entries will be removed from the collected changes. Changes to this entries should be done on the entry itself. So no deep updates are supported.
Parameters:
{function} | fnSuccess? | a callback function which is called when the data has been successfully updated. The handler can have the following parameters: oData and response. |
{function} | fnError? | a callback function which is called when the request failed. The handler can have the parameter: oError which contains additional error information |
{object} | oParameters? | optional parameter for additional information introduced in SAPUI5 1.9.1 |
{string} | oParameters.sETag? | an ETag which can be used for concurrency control. If it is specified, it will be used in an If-Match-Header in the request to the server for this entry. |
Returns:
{object} | an object which has an abort function to abort the current request. |
update(sPath, oData, mParameters?): object
Trigger a PUT/MERGE request to the odata service that was specified in the model constructor. Please note that deep updates are not supported and may not work. These should be done seperate on the entry directly.
Parameters:
{string} | sPath | A string containing the path to the data that should be updated. The path is concatenated to the sServiceUrl which was specified in the model constructor. |
{object} | oData | data of the entry that should be updated. |
{map} | mParameters? | Optional, can contain the following attributes: |
{object} | mParameters.context? | If specified the sPath has to be is relative to the path given with the context. |
{function} | mParameters.success? | a callback function which is called when the data has been successfully updated. |
{function} | mParameters.error? | a callback function which is called when the request failed. The handler can have the parameter oError which contains additional error information. |
{boolean} | mParameters.merge? | trigger a MERGE request instead of a PUT request to perform a differential update |
{string} | mParameters.eTag? | If specified, the If-Match-Header will be set to this Etag. |
{boolean} | mParameters.async? | Whether the request should be done asynchronously. Please be advised that this feature is officially unsupported as using asynchronous requests can lead to data inconsistencies if the application does not make sure that the request was completed before continuing to work with the data. |
{map} | mParameters.urlParameters? | A map containing the parameters that will be passed as query strings |
Returns:
{object} | an object which has an abort function to abort the current request. |
updateBindings(bForceUpdate?)
update all bindings
Parameters:
{boolean} | bForceUpdate? | If set to false an update will only be done when the value of a binding changed. |
forceNoCache(bForceNoCache?)
Force no caching
Parameters:
{boolean} | bForceNoCache? | whether to force no caching |
- Deprecated:
- The caching should be controlled by the backend by setting the correct cache control header
getData(sPath, oContext?, bIncludeExpandEntries?): object
Return requested data as object if the data has already been loaded and stored in the model.
Parameters:
{string} | sPath | A string containing the path to the data object that should be returned. |
{object} | oContext? | the optional context which is used with the sPath to retrieve the requested data. |
{boolean} | bIncludeExpandEntries? | This parameter should be set when a URI or custom parameter with a $expand System Query Option was used to retrieve associated entries embedded/inline. If true then the getProperty function returns a desired property value/entry and includes the associated expand entries (if any). If false the associated/expanded entry properties are removed and not included in the desired entry as properties at all. This is useful for performing updates on the base entry only. Note: A copy and not a reference of the entry will be returned. |
- Deprecated:
- please use getProperty instead
Returns:
{object} | oData Object containing the requested data if the path is valid. |
isCountSupported(): boolean
Returns whether this model supports the $count on its collections This method is deprecated, please use getDefaultCountMode instead.
- Deprecated:
- true
Returns:
setCountSupported(bCountSupported)
Sets whether this OData service supports $count on its collections. This method is deprecated, please use setDefaultCountMode instead.
Parameters:
- Deprecated:
- true