Modified: olingo/site/trunk/content/doc/javascript/apidoc/handler.js.html URL: http://svn.apache.org/viewvc/olingo/site/trunk/content/doc/javascript/apidoc/handler.js.html?rev=1672271&r1=1672270&r2=1672271&view=diff ============================================================================== --- olingo/site/trunk/content/doc/javascript/apidoc/handler.js.html (original) +++ olingo/site/trunk/content/doc/javascript/apidoc/handler.js.html Thu Apr 9 09:03:39 2015 @@ -25,289 +25,289 @@ <section> <article> - <pre class="prettyprint source"><code>/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** @module odata/handler */ - - -var utils = require('./../odatajs.js').utils; -var oDataUtils = require('./utils.js'); - -// Imports. -var assigned = utils.assigned; -var extend = utils.extend; -var trimString = utils.trimString; -var maxVersion = oDataUtils.maxVersion; -var MAX_DATA_SERVICE_VERSION = "4.0"; - -/** Parses a string into an object with media type and properties. - * @param {String} str - String with media type to parse. - * @return null if the string is empty; an object with 'mediaType' and a 'properties' dictionary otherwise. - */ -function contentType(str) { - - if (!str) { - return null; - } - - var contentTypeParts = str.split(";"); - var properties = {}; - - var i, len; - for (i = 1, len = contentTypeParts.length; i < len; i++) { - var contentTypeParams = contentTypeParts[i].split("="); - properties[trimString(contentTypeParams[0])] = contentTypeParams[1]; - } - - return { mediaType: trimString(contentTypeParts[0]), properties: properties }; -} - -/** Serializes an object with media type and properties dictionary into a string. - * @param contentType - Object with media type and properties dictionary to serialize. - * @return String representation of the media type object; undefined if contentType is null or undefined.</returns> - */ -function contentTypeToString(contentType) { - if (!contentType) { - return undefined; - } - - var result = contentType.mediaType; - var property; - for (property in contentType.properties) { - result += ";" + property + "=" + contentType.properties[property]; - } - return result; -} - -/** Creates an object that is going to be used as the context for the handler's parser and serializer. - * @param contentType - Object with media type and properties dictionary. - * @param {String} dataServiceVersion - String indicating the version of the protocol to use. - * @param context - Operation context. - * @param handler - Handler object that is processing a resquest or response. - * @return Context object.</returns> - */ -function createReadWriteContext(contentType, dataServiceVersion, context, handler) { - - var rwContext = {}; - extend(rwContext, context); - extend(rwContext, { - contentType: contentType, - dataServiceVersion: dataServiceVersion, - handler: handler - }); - - return rwContext; -} - -/** Sets a request header's value. If the header has already a value other than undefined, null or empty string, then this method does nothing. - * @param request - Request object on which the header will be set. - * @param {String} name - Header name. - * @param {String} value - Header value. - */ -function fixRequestHeader(request, name, value) { - if (!request) { - return; - } - - var headers = request.headers; - if (!headers[name]) { - headers[name] = value; - } -} - -/** Sets the DataServiceVersion header of the request if its value is not yet defined or of a lower version. - * @param request - Request object on which the header will be set. - * @param {String} version - Version value. - * If the request has already a version value higher than the one supplied the this function does nothing. - */ -function fixDataServiceVersionHeader(request, version) { - - if (request) { - var headers = request.headers; - var dsv = headers["OData-Version"]; - headers["OData-Version"] = dsv ? maxVersion(dsv, version) : version; - } -} - -/** Gets the value of a request or response header. - * @param requestOrResponse - Object representing a request or a response. - * @param {String} name - Name of the header to retrieve. - * @returns {String} String value of the header; undefined if the header cannot be found. - */ -function getRequestOrResponseHeader(requestOrResponse, name) { - - var headers = requestOrResponse.headers; - return (headers && headers[name]) || undefined; -} - -/** Gets the value of the Content-Type header from a request or response. - * @param requestOrResponse - Object representing a request or a response. - * @returns {Object} Object with 'mediaType' and a 'properties' dictionary; null in case that the header is not found or doesn't have a value. - */ -function getContentType(requestOrResponse) { - - return contentType(getRequestOrResponseHeader(requestOrResponse, "Content-Type")); -} - -var versionRE = /^\s?(\d+\.\d+);?.*$/; -/** Gets the value of the DataServiceVersion header from a request or response. - * @param requestOrResponse - Object representing a request or a response. - * @returns {String} Data service version; undefined if the header cannot be found. - */ -function getDataServiceVersion(requestOrResponse) { - - var value = getRequestOrResponseHeader(requestOrResponse, "OData-Version"); - if (value) { - var matches = versionRE.exec(value); - if (matches && matches.length) { - return matches[1]; - } - } - - // Fall through and return undefined. -} - -/** Checks that a handler can process a particular mime type. - * @param handler - Handler object that is processing a resquest or response. - * @param cType - Object with 'mediaType' and a 'properties' dictionary. - * @returns {Boolean} True if the handler can process the mime type; false otherwise. - * - * The following check isn't as strict because if cType.mediaType = application/; it will match an accept value of "application/xml"; - * however in practice we don't not expect to see such "suffixed" mimeTypes for the handlers. - */ -function handlerAccepts(handler, cType) { - return handler.accept.indexOf(cType.mediaType) >= 0; -} - -/** Invokes the parser associated with a handler for reading the payload of a HTTP response. - * @param handler - Handler object that is processing the response. - * @param {Function} parseCallback - Parser function that will process the response payload. - * @param response - HTTP response whose payload is going to be processed. - * @param context - Object used as the context for processing the response. - * @returns {Boolean} True if the handler processed the response payload and the response.data property was set; false otherwise. - */ -function handlerRead(handler, parseCallback, response, context) { - - if (!response || !response.headers) { - return false; - } - - var cType = getContentType(response); - var version = getDataServiceVersion(response) || ""; - var body = response.body; - - if (!assigned(body)) { - return false; - } - - if (handlerAccepts(handler, cType)) { - var readContext = createReadWriteContext(cType, version, context, handler); - readContext.response = response; - response.data = parseCallback(handler, body, readContext); - return response.data !== undefined; - } - - return false; -} - -/** Invokes the serializer associated with a handler for generating the payload of a HTTP request. - * @param handler - Handler object that is processing the request. - * @param {Function} serializeCallback - Serializer function that will generate the request payload. - * @param response - HTTP request whose payload is going to be generated. - * @param context - Object used as the context for serializing the request. - * @returns {Boolean} True if the handler serialized the request payload and the request.body property was set; false otherwise. - */ -function handlerWrite(handler, serializeCallback, request, context) { - if (!request || !request.headers) { - return false; - } - - var cType = getContentType(request); - var version = getDataServiceVersion(request); - - if (!cType || handlerAccepts(handler, cType)) { - var writeContext = createReadWriteContext(cType, version, context, handler); - writeContext.request = request; - - request.body = serializeCallback(handler, request.data, writeContext); - - if (request.body !== undefined) { - fixDataServiceVersionHeader(request, writeContext.dataServiceVersion || "4.0"); - - fixRequestHeader(request, "Content-Type", contentTypeToString(writeContext.contentType)); - fixRequestHeader(request, "OData-MaxVersion", handler.maxDataServiceVersion); - return true; - } - } - - return false; -} - -/** Creates a handler object for processing HTTP requests and responses. - * @param {Function} parseCallback - Parser function that will process the response payload. - * @param {Function} serializeCallback - Serializer function that will generate the request payload. - * @param {String} accept - String containing a comma separated list of the mime types that this handler can work with. - * @param {String} maxDataServiceVersion - String indicating the highest version of the protocol that this handler can work with. - * @returns {Object} Handler object. - */ -function handler(parseCallback, serializeCallback, accept, maxDataServiceVersion) { - - return { - accept: accept, - maxDataServiceVersion: maxDataServiceVersion, - - read: function (response, context) { - return handlerRead(this, parseCallback, response, context); - }, - - write: function (request, context) { - return handlerWrite(this, serializeCallback, request, context); - } - }; -} - -function textParse(handler, body /*, context */) { - return body; -} - -function textSerialize(handler, data /*, context */) { - if (assigned(data)) { - return data.toString(); - } else { - return undefined; - } -} - - - - -exports.textHandler = handler(textParse, textSerialize, "text/plain", MAX_DATA_SERVICE_VERSION); - -exports.contentType = contentType; -exports.contentTypeToString = contentTypeToString; -exports.handler = handler; -exports.createReadWriteContext = createReadWriteContext; -exports.fixRequestHeader = fixRequestHeader; -exports.getRequestOrResponseHeader = getRequestOrResponseHeader; -exports.getContentType = getContentType; -exports.getDataServiceVersion = getDataServiceVersion; + <pre class="prettyprint source"><code>/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +'use strict'; + +/** @module odata/handler */ + + +var utils = require('./../utils.js'); +var oDataUtils = require('./odatautils.js'); + +// Imports. +var assigned = utils.assigned; +var extend = utils.extend; +var trimString = utils.trimString; +var maxVersion = oDataUtils.maxVersion; +var MAX_DATA_SERVICE_VERSION = "4.0"; + +/** Parses a string into an object with media type and properties. + * @param {String} str - String with media type to parse. + * @return null if the string is empty; an object with 'mediaType' and a 'properties' dictionary otherwise. + */ +function contentType(str) { + + if (!str) { + return null; + } + + var contentTypeParts = str.split(";"); + var properties = {}; + + var i, len; + for (i = 1, len = contentTypeParts.length; i < len; i++) { + var contentTypeParams = contentTypeParts[i].split("="); + properties[trimString(contentTypeParams[0])] = contentTypeParams[1]; + } + + return { mediaType: trimString(contentTypeParts[0]), properties: properties }; +} + +/** Serializes an object with media type and properties dictionary into a string. + * @param contentType - Object with media type and properties dictionary to serialize. + * @return String representation of the media type object; undefined if contentType is null or undefined. + */ +function contentTypeToString(contentType) { + if (!contentType) { + return undefined; + } + + var result = contentType.mediaType; + var property; + for (property in contentType.properties) { + result += ";" + property + "=" + contentType.properties[property]; + } + return result; +} + +/** Creates an object that is going to be used as the context for the handler's parser and serializer. + * @param contentType - Object with media type and properties dictionary. + * @param {String} dataServiceVersion - String indicating the version of the protocol to use. + * @param context - Operation context. + * @param handler - Handler object that is processing a resquest or response. + * @return Context object. + */ +function createReadWriteContext(contentType, dataServiceVersion, context, handler) { + + var rwContext = {}; + extend(rwContext, context); + extend(rwContext, { + contentType: contentType, + dataServiceVersion: dataServiceVersion, + handler: handler + }); + + return rwContext; +} + +/** Sets a request header's value. If the header has already a value other than undefined, null or empty string, then this method does nothing. + * @param request - Request object on which the header will be set. + * @param {String} name - Header name. + * @param {String} value - Header value. + */ +function fixRequestHeader(request, name, value) { + if (!request) { + return; + } + + var headers = request.headers; + if (!headers[name]) { + headers[name] = value; + } +} + +/** Sets the DataServiceVersion header of the request if its value is not yet defined or of a lower version. + * @param request - Request object on which the header will be set. + * @param {String} version - Version value. + * If the request has already a version value higher than the one supplied the this function does nothing. + */ +function fixDataServiceVersionHeader(request, version) { + + if (request) { + var headers = request.headers; + var dsv = headers["OData-Version"]; + headers["OData-Version"] = dsv ? maxVersion(dsv, version) : version; + } +} + +/** Gets the value of a request or response header. + * @param requestOrResponse - Object representing a request or a response. + * @param {String} name - Name of the header to retrieve. + * @returns {String} String value of the header; undefined if the header cannot be found. + */ +function getRequestOrResponseHeader(requestOrResponse, name) { + + var headers = requestOrResponse.headers; + return (headers && headers[name]) || undefined; +} + +/** Gets the value of the Content-Type header from a request or response. + * @param requestOrResponse - Object representing a request or a response. + * @returns {Object} Object with 'mediaType' and a 'properties' dictionary; null in case that the header is not found or doesn't have a value. + */ +function getContentType(requestOrResponse) { + + return contentType(getRequestOrResponseHeader(requestOrResponse, "Content-Type")); +} + +var versionRE = /^\s?(\d+\.\d+);?.*$/; +/** Gets the value of the DataServiceVersion header from a request or response. + * @param requestOrResponse - Object representing a request or a response. + * @returns {String} Data service version; undefined if the header cannot be found. + */ +function getDataServiceVersion(requestOrResponse) { + + var value = getRequestOrResponseHeader(requestOrResponse, "OData-Version"); + if (value) { + var matches = versionRE.exec(value); + if (matches && matches.length) { + return matches[1]; + } + } + + // Fall through and return undefined. +} + +/** Checks that a handler can process a particular mime type. + * @param handler - Handler object that is processing a resquest or response. + * @param cType - Object with 'mediaType' and a 'properties' dictionary. + * @returns {Boolean} True if the handler can process the mime type; false otherwise. + * + * The following check isn't as strict because if cType.mediaType = application/; it will match an accept value of "application/xml"; + * however in practice we don't not expect to see such "suffixed" mimeTypes for the handlers. + */ +function handlerAccepts(handler, cType) { + return handler.accept.indexOf(cType.mediaType) >= 0; +} + +/** Invokes the parser associated with a handler for reading the payload of a HTTP response. + * @param handler - Handler object that is processing the response. + * @param {Function} parseCallback - Parser function that will process the response payload. + * @param response - HTTP response whose payload is going to be processed. + * @param context - Object used as the context for processing the response. + * @returns {Boolean} True if the handler processed the response payload and the response.data property was set; false otherwise. + */ +function handlerRead(handler, parseCallback, response, context) { + + if (!response || !response.headers) { + return false; + } + + var cType = getContentType(response); + var version = getDataServiceVersion(response) || ""; + var body = response.body; + + if (!assigned(body)) { + return false; + } + + if (handlerAccepts(handler, cType)) { + var readContext = createReadWriteContext(cType, version, context, handler); + readContext.response = response; + response.data = parseCallback(handler, body, readContext); + return response.data !== undefined; + } + + return false; +} + +/** Invokes the serializer associated with a handler for generating the payload of a HTTP request. + * @param handler - Handler object that is processing the request. + * @param {Function} serializeCallback - Serializer function that will generate the request payload. + * @param request - HTTP request whose payload is going to be generated. + * @param context - Object used as the context for serializing the request. + * @returns {Boolean} True if the handler serialized the request payload and the request.body property was set; false otherwise. + */ +function handlerWrite(handler, serializeCallback, request, context) { + if (!request || !request.headers) { + return false; + } + + var cType = getContentType(request); + var version = getDataServiceVersion(request); + + if (!cType || handlerAccepts(handler, cType)) { + var writeContext = createReadWriteContext(cType, version, context, handler); + writeContext.request = request; + + request.body = serializeCallback(handler, request.data, writeContext); + + if (request.body !== undefined) { + fixDataServiceVersionHeader(request, writeContext.dataServiceVersion || "4.0"); + + fixRequestHeader(request, "Content-Type", contentTypeToString(writeContext.contentType)); + fixRequestHeader(request, "OData-MaxVersion", handler.maxDataServiceVersion); + return true; + } + } + + return false; +} + +/** Creates a handler object for processing HTTP requests and responses. + * @param {Function} parseCallback - Parser function that will process the response payload. + * @param {Function} serializeCallback - Serializer function that will generate the request payload. + * @param {String} accept - String containing a comma separated list of the mime types that this handler can work with. + * @param {String} maxDataServiceVersion - String indicating the highest version of the protocol that this handler can work with. + * @returns {Object} Handler object. + */ +function handler(parseCallback, serializeCallback, accept, maxDataServiceVersion) { + + return { + accept: accept, + maxDataServiceVersion: maxDataServiceVersion, + + read: function (response, context) { + return handlerRead(this, parseCallback, response, context); + }, + + write: function (request, context) { + return handlerWrite(this, serializeCallback, request, context); + } + }; +} + +function textParse(handler, body /*, context */) { + return body; +} + +function textSerialize(handler, data /*, context */) { + if (assigned(data)) { + return data.toString(); + } else { + return undefined; + } +} + + + + +exports.textHandler = handler(textParse, textSerialize, "text/plain", MAX_DATA_SERVICE_VERSION); +exports.contentType = contentType; +exports.contentTypeToString = contentTypeToString; +exports.handler = handler; +exports.createReadWriteContext = createReadWriteContext; +exports.fixRequestHeader = fixRequestHeader; +exports.getRequestOrResponseHeader = getRequestOrResponseHeader; +exports.getContentType = getContentType; +exports.getDataServiceVersion = getDataServiceVersion; exports.MAX_DATA_SERVICE_VERSION = MAX_DATA_SERVICE_VERSION;</code></pre> </article> </section> @@ -318,13 +318,13 @@ exports.MAX_DATA_SERVICE_VERSION = MAX_D </div> <nav> - <h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-cache.html">cache</a></li><li><a href="source.html">cache/source</a></li><li><a href="module-datajs.html">datajs</a></li><li><a href="deferred.html">datajs/deferred</a></li><li><a href="utils.html">datajs/utils</a></li><li><a href="xml.html">datajs/xml</a></li><li><a href="module-odata.html">odata</a></li><li><a href="batch.html">odata/batch</a></li><li><a href="handler.html">odata/handler</a></li><li><a href="json.html">odata/json</a></li><li><a href="metadata.html">odata/metadata</a></li><li><a href="net.html">odata/net</a></li><li><a href="utils_.html">odata/utils</a></li><li><a href="module-store.html">store</a></li><li><a href="dom.html">store/dom</a></li><li><a href="indexeddb.html">store/indexeddb</a></li><li><a href="memory.html">store/memory</a></li></ul><h3>Classes</h3><ul><li><a href="DataCache.html">DataCache</a></li><li><a href="DataCacheOperation.html">DataCacheOperation</a></li><li><a h ref="DjsDeferred.html">DjsDeferred</a></li><li><a href="dom-DomStore.html">DomStore</a></li><li><a href="indexeddb-IndexedDBStore.html">IndexedDBStore</a></li><li><a href="memory-MemoryStore.html">MemoryStore</a></li><li><a href="ODataCacheSource.html">ODataCacheSource</a></li></ul><h3><a href="global.html">Global</a></h3> + <h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-cache.html">cache</a></li><li><a href="source.html">cache/source</a></li><li><a href="module-odata.html">odata</a></li><li><a href="batch.html">odata/batch</a></li><li><a href="handler.html">odata/handler</a></li><li><a href="json.html">odata/json</a></li><li><a href="metadata.html">odata/metadata</a></li><li><a href="net.html">odata/net</a></li><li><a href="utils.html">odata/utils</a></li><li><a href="deferred.html">odatajs/deferred</a></li><li><a href="utils_.html">odatajs/utils</a></li><li><a href="xml.html">odatajs/xml</a></li><li><a href="module-store.html">store</a></li><li><a href="dom.html">store/dom</a></li><li><a href="indexeddb.html">store/indexeddb</a></li><li><a href="memory.html">store/memory</a></li></ul><h3>Classes</h3><ul><li><a href="DataCache.html">DataCache</a></li><li><a href="DataCacheOperation.html">DataCacheOperation</a></li><li><a href="DjsDeferred.html">DjsDeferred</a></li><l i><a href="dom-DomStore.html">DomStore</a></li><li><a href="indexeddb-IndexedDBStore.html">IndexedDBStore</a></li><li><a href="memory-MemoryStore.html">MemoryStore</a></li><li><a href="ODataCacheSource.html">ODataCacheSource</a></li></ul><h3><a href="global.html">Global</a></h3> </nav> <br clear="both"> <footer> - Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Mon Sep 15 2014 13:07:59 GMT+0200 (MESZ) + Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu Apr 09 2015 08:31:26 GMT+0200 (MESZ) </footer> <script> prettyPrint(); </script>
Modified: olingo/site/trunk/content/doc/javascript/apidoc/index.html URL: http://svn.apache.org/viewvc/olingo/site/trunk/content/doc/javascript/apidoc/index.html?rev=1672271&r1=1672270&r2=1672271&view=diff ============================================================================== --- olingo/site/trunk/content/doc/javascript/apidoc/index.html (original) +++ olingo/site/trunk/content/doc/javascript/apidoc/index.html Thu Apr 9 09:03:39 2015 @@ -48,13 +48,13 @@ </div> <nav> - <h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-cache.html">cache</a></li><li><a href="source.html">cache/source</a></li><li><a href="module-datajs.html">datajs</a></li><li><a href="deferred.html">datajs/deferred</a></li><li><a href="utils.html">datajs/utils</a></li><li><a href="xml.html">datajs/xml</a></li><li><a href="module-odata.html">odata</a></li><li><a href="batch.html">odata/batch</a></li><li><a href="handler.html">odata/handler</a></li><li><a href="json.html">odata/json</a></li><li><a href="metadata.html">odata/metadata</a></li><li><a href="net.html">odata/net</a></li><li><a href="utils_.html">odata/utils</a></li><li><a href="module-store.html">store</a></li><li><a href="dom.html">store/dom</a></li><li><a href="indexeddb.html">store/indexeddb</a></li><li><a href="memory.html">store/memory</a></li></ul><h3>Classes</h3><ul><li><a href="DataCache.html">DataCache</a></li><li><a href="DataCacheOperation.html">DataCacheOperation</a></li><li><a h ref="DjsDeferred.html">DjsDeferred</a></li><li><a href="dom-DomStore.html">DomStore</a></li><li><a href="indexeddb-IndexedDBStore.html">IndexedDBStore</a></li><li><a href="memory-MemoryStore.html">MemoryStore</a></li><li><a href="ODataCacheSource.html">ODataCacheSource</a></li></ul><h3><a href="global.html">Global</a></h3> + <h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-cache.html">cache</a></li><li><a href="source.html">cache/source</a></li><li><a href="module-odata.html">odata</a></li><li><a href="batch.html">odata/batch</a></li><li><a href="handler.html">odata/handler</a></li><li><a href="json.html">odata/json</a></li><li><a href="metadata.html">odata/metadata</a></li><li><a href="net.html">odata/net</a></li><li><a href="utils.html">odata/utils</a></li><li><a href="deferred.html">odatajs/deferred</a></li><li><a href="utils_.html">odatajs/utils</a></li><li><a href="xml.html">odatajs/xml</a></li><li><a href="module-store.html">store</a></li><li><a href="dom.html">store/dom</a></li><li><a href="indexeddb.html">store/indexeddb</a></li><li><a href="memory.html">store/memory</a></li></ul><h3>Classes</h3><ul><li><a href="DataCache.html">DataCache</a></li><li><a href="DataCacheOperation.html">DataCacheOperation</a></li><li><a href="DjsDeferred.html">DjsDeferred</a></li><l i><a href="dom-DomStore.html">DomStore</a></li><li><a href="indexeddb-IndexedDBStore.html">IndexedDBStore</a></li><li><a href="memory-MemoryStore.html">MemoryStore</a></li><li><a href="ODataCacheSource.html">ODataCacheSource</a></li></ul><h3><a href="global.html">Global</a></h3> </nav> <br clear="both"> <footer> - Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Mon Sep 15 2014 13:08:00 GMT+0200 (MESZ) + Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu Apr 09 2015 08:31:26 GMT+0200 (MESZ) </footer> <script> prettyPrint(); </script> Modified: olingo/site/trunk/content/doc/javascript/apidoc/indexeddb-IndexedDBStore.html URL: http://svn.apache.org/viewvc/olingo/site/trunk/content/doc/javascript/apidoc/indexeddb-IndexedDBStore.html?rev=1672271&r1=1672270&r2=1672271&view=diff ============================================================================== --- olingo/site/trunk/content/doc/javascript/apidoc/indexeddb-IndexedDBStore.html (original) +++ olingo/site/trunk/content/doc/javascript/apidoc/indexeddb-IndexedDBStore.html Thu Apr 9 09:03:39 2015 @@ -132,7 +132,7 @@ <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> - <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line152">line 152</a> + <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line153">line 153</a> </li></ul></dd> @@ -234,7 +234,7 @@ <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> - <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line333">line 333</a> + <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line335">line 335</a> </li></ul></dd> @@ -347,7 +347,7 @@ <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> - <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line156">line 156</a> + <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line157">line 157</a> </li></ul></dd> @@ -438,7 +438,7 @@ <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> - <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line169">line 169</a> + <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line170">line 170</a> </li></ul></dd> @@ -646,7 +646,7 @@ <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> - <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line177">line 177</a> + <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line178">line 178</a> </li></ul></dd> @@ -832,7 +832,7 @@ <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> - <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line214">line 214</a> + <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line215">line 215</a> </li></ul></dd> @@ -972,7 +972,7 @@ <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> - <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line252">line 252</a> + <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line253">line 253</a> </li></ul></dd> @@ -1041,7 +1041,7 @@ <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> - <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line269">line 269</a> + <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line271">line 271</a> </li></ul></dd> @@ -1204,7 +1204,7 @@ <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> - <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line280">line 280</a> + <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line282">line 282</a> </li></ul></dd> @@ -1344,7 +1344,7 @@ <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> - <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line302">line 302</a> + <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line304">line 304</a> </li></ul></dd> @@ -1476,8 +1476,7 @@ - <td class="description last">The error callback -If the key does not exist, the success handler will be called with value = undefined</td> + <td class="description last">The error callback If the key does not exist, the success handler will be called with value = undefined</td> </tr> @@ -1508,7 +1507,7 @@ If the key does not exist, the success h <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> - <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line335">line 335</a> + <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line337">line 337</a> </li></ul></dd> @@ -1671,7 +1670,7 @@ If the key does not exist, the success h <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> - <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line371">line 371</a> + <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line373">line 373</a> </li></ul></dd> @@ -1857,7 +1856,7 @@ If the key does not exist, the success h <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> - <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line397">line 397</a> + <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line399">line 399</a> </li></ul></dd> @@ -1898,13 +1897,13 @@ If the key does not exist, the success h </div> <nav> - <h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-cache.html">cache</a></li><li><a href="source.html">cache/source</a></li><li><a href="module-datajs.html">datajs</a></li><li><a href="deferred.html">datajs/deferred</a></li><li><a href="utils.html">datajs/utils</a></li><li><a href="xml.html">datajs/xml</a></li><li><a href="module-odata.html">odata</a></li><li><a href="batch.html">odata/batch</a></li><li><a href="handler.html">odata/handler</a></li><li><a href="json.html">odata/json</a></li><li><a href="metadata.html">odata/metadata</a></li><li><a href="net.html">odata/net</a></li><li><a href="utils_.html">odata/utils</a></li><li><a href="module-store.html">store</a></li><li><a href="dom.html">store/dom</a></li><li><a href="indexeddb.html">store/indexeddb</a></li><li><a href="memory.html">store/memory</a></li></ul><h3>Classes</h3><ul><li><a href="DataCache.html">DataCache</a></li><li><a href="DataCacheOperation.html">DataCacheOperation</a></li><li><a h ref="DjsDeferred.html">DjsDeferred</a></li><li><a href="dom-DomStore.html">DomStore</a></li><li><a href="indexeddb-IndexedDBStore.html">IndexedDBStore</a></li><li><a href="memory-MemoryStore.html">MemoryStore</a></li><li><a href="ODataCacheSource.html">ODataCacheSource</a></li></ul><h3><a href="global.html">Global</a></h3> + <h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-cache.html">cache</a></li><li><a href="source.html">cache/source</a></li><li><a href="module-odata.html">odata</a></li><li><a href="batch.html">odata/batch</a></li><li><a href="handler.html">odata/handler</a></li><li><a href="json.html">odata/json</a></li><li><a href="metadata.html">odata/metadata</a></li><li><a href="net.html">odata/net</a></li><li><a href="utils.html">odata/utils</a></li><li><a href="deferred.html">odatajs/deferred</a></li><li><a href="utils_.html">odatajs/utils</a></li><li><a href="xml.html">odatajs/xml</a></li><li><a href="module-store.html">store</a></li><li><a href="dom.html">store/dom</a></li><li><a href="indexeddb.html">store/indexeddb</a></li><li><a href="memory.html">store/memory</a></li></ul><h3>Classes</h3><ul><li><a href="DataCache.html">DataCache</a></li><li><a href="DataCacheOperation.html">DataCacheOperation</a></li><li><a href="DjsDeferred.html">DjsDeferred</a></li><l i><a href="dom-DomStore.html">DomStore</a></li><li><a href="indexeddb-IndexedDBStore.html">IndexedDBStore</a></li><li><a href="memory-MemoryStore.html">MemoryStore</a></li><li><a href="ODataCacheSource.html">ODataCacheSource</a></li></ul><h3><a href="global.html">Global</a></h3> </nav> <br clear="both"> <footer> - Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Mon Sep 15 2014 13:08:02 GMT+0200 (MESZ) + Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu Apr 09 2015 08:31:27 GMT+0200 (MESZ) </footer> <script> prettyPrint(); </script> Modified: olingo/site/trunk/content/doc/javascript/apidoc/indexeddb.html URL: http://svn.apache.org/viewvc/olingo/site/trunk/content/doc/javascript/apidoc/indexeddb.html?rev=1672271&r1=1672270&r2=1672271&view=diff ============================================================================== --- olingo/site/trunk/content/doc/javascript/apidoc/indexeddb.html (original) +++ olingo/site/trunk/content/doc/javascript/apidoc/indexeddb.html Thu Apr 9 09:03:39 2015 @@ -62,7 +62,7 @@ <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> - <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line3">line 3</a> + <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line21">line 21</a> </li></ul></dd> @@ -215,7 +215,7 @@ <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> - <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line40">line 40</a> + <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line41">line 41</a> </li></ul></dd> @@ -400,7 +400,7 @@ <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> - <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line74">line 74</a> + <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line75">line 75</a> </li></ul></dd> @@ -499,7 +499,7 @@ <td class="type"> -<span class="param-type">Short</span> +<span class="param-type">Integer</span> @@ -586,7 +586,7 @@ <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> - <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line129">line 129</a> + <a href="indexeddb.js.html">store/indexeddb.js</a>, <a href="indexeddb.js.html#line130">line 130</a> </li></ul></dd> @@ -627,13 +627,13 @@ </div> <nav> - <h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-cache.html">cache</a></li><li><a href="source.html">cache/source</a></li><li><a href="module-datajs.html">datajs</a></li><li><a href="deferred.html">datajs/deferred</a></li><li><a href="utils.html">datajs/utils</a></li><li><a href="xml.html">datajs/xml</a></li><li><a href="module-odata.html">odata</a></li><li><a href="batch.html">odata/batch</a></li><li><a href="handler.html">odata/handler</a></li><li><a href="json.html">odata/json</a></li><li><a href="metadata.html">odata/metadata</a></li><li><a href="net.html">odata/net</a></li><li><a href="utils_.html">odata/utils</a></li><li><a href="module-store.html">store</a></li><li><a href="dom.html">store/dom</a></li><li><a href="indexeddb.html">store/indexeddb</a></li><li><a href="memory.html">store/memory</a></li></ul><h3>Classes</h3><ul><li><a href="DataCache.html">DataCache</a></li><li><a href="DataCacheOperation.html">DataCacheOperation</a></li><li><a h ref="DjsDeferred.html">DjsDeferred</a></li><li><a href="dom-DomStore.html">DomStore</a></li><li><a href="indexeddb-IndexedDBStore.html">IndexedDBStore</a></li><li><a href="memory-MemoryStore.html">MemoryStore</a></li><li><a href="ODataCacheSource.html">ODataCacheSource</a></li></ul><h3><a href="global.html">Global</a></h3> + <h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-cache.html">cache</a></li><li><a href="source.html">cache/source</a></li><li><a href="module-odata.html">odata</a></li><li><a href="batch.html">odata/batch</a></li><li><a href="handler.html">odata/handler</a></li><li><a href="json.html">odata/json</a></li><li><a href="metadata.html">odata/metadata</a></li><li><a href="net.html">odata/net</a></li><li><a href="utils.html">odata/utils</a></li><li><a href="deferred.html">odatajs/deferred</a></li><li><a href="utils_.html">odatajs/utils</a></li><li><a href="xml.html">odatajs/xml</a></li><li><a href="module-store.html">store</a></li><li><a href="dom.html">store/dom</a></li><li><a href="indexeddb.html">store/indexeddb</a></li><li><a href="memory.html">store/memory</a></li></ul><h3>Classes</h3><ul><li><a href="DataCache.html">DataCache</a></li><li><a href="DataCacheOperation.html">DataCacheOperation</a></li><li><a href="DjsDeferred.html">DjsDeferred</a></li><l i><a href="dom-DomStore.html">DomStore</a></li><li><a href="indexeddb-IndexedDBStore.html">IndexedDBStore</a></li><li><a href="memory-MemoryStore.html">MemoryStore</a></li><li><a href="ODataCacheSource.html">ODataCacheSource</a></li></ul><h3><a href="global.html">Global</a></h3> </nav> <br clear="both"> <footer> - Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Mon Sep 15 2014 13:08:02 GMT+0200 (MESZ) + Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu Apr 09 2015 08:31:27 GMT+0200 (MESZ) </footer> <script> prettyPrint(); </script> Modified: olingo/site/trunk/content/doc/javascript/apidoc/indexeddb.js.html URL: http://svn.apache.org/viewvc/olingo/site/trunk/content/doc/javascript/apidoc/indexeddb.js.html?rev=1672271&r1=1672270&r2=1672271&view=diff ============================================================================== --- olingo/site/trunk/content/doc/javascript/apidoc/indexeddb.js.html (original) +++ olingo/site/trunk/content/doc/javascript/apidoc/indexeddb.js.html Thu Apr 9 09:03:39 2015 @@ -25,450 +25,452 @@ <section> <article> - <pre class="prettyprint source"><code>/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** @module store/indexeddb */ -var utils = require('./../odatajs.js').utils; - -// Imports. -var throwErrorCallback = utils.throwErrorCallback; -var delay = utils.delay; - - -var indexedDB = utils.inBrowser() ? window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.indexedDB : undefined; -var IDBKeyRange = utils.inBrowser() ? window.IDBKeyRange || window.webkitIDBKeyRange : undefined; -var IDBTransaction = utils.inBrowser() ? window.IDBTransaction || window.webkitIDBTransaction || {} : {} ; - -var IDBT_READ_ONLY = IDBTransaction.READ_ONLY || "readonly"; -var IDBT_READ_WRITE = IDBTransaction.READ_WRITE || "readwrite"; - -/** Returns either a specific error handler or the default error handler - * @param {Function} error - The specific error handler - * @param {Function} defaultError - The default error handler - * @returns {Function} The error callback - */ -function getError(error, defaultError) { - - return function (e) { - var errorFunc = error || defaultError; - if (!errorFunc) { - return; - } - - // Old api quota exceeded error support. - if (Object.prototype.toString.call(e) === "[object IDBDatabaseException]") { - if (e.code === 11 /* IndexedDb disk quota exceeded */) { - errorFunc({ name: "QuotaExceededError", error: e }); - return; - } - errorFunc(e); - return; - } - - var errName; - try { - var errObj = e.target.error || e; - errName = errObj.name; - } catch (ex) { - errName = (e.type === "blocked") ? "IndexedDBBlocked" : "UnknownError"; - } - errorFunc({ name: errName, error: e }); - }; -} - -/** Opens the store object's indexed db database. - * @param {IndexedDBStore} store - The store object - * @param {Function} success - The success callback - * @param {Function} error - The error callback - */ -function openStoreDb(store, success, error) { - - var storeName = store.name; - var dbName = "_datajs_" + storeName; - - var request = indexedDB.open(dbName); - request.onblocked = error; - request.onerror = error; - - request.onupgradeneeded = function () { - var db = request.result; - if (!db.objectStoreNames.contains(storeName)) { - db.createObjectStore(storeName); - } - }; - - request.onsuccess = function (event) { - var db = request.result; - if (!db.objectStoreNames.contains(storeName)) { - // Should we use the old style api to define the database schema? - if ("setVersion" in db) { - var versionRequest = db.setVersion("1.0"); - versionRequest.onsuccess = function () { - var transaction = versionRequest.transaction; - transaction.oncomplete = function () { - success(db); - }; - db.createObjectStore(storeName, null, false); - }; - versionRequest.onerror = error; - versionRequest.onblocked = error; - return; - } - - // The database doesn't have the expected store. - // Fabricate an error object for the event for the schema mismatch - // and error out. - event.target.error = { name: "DBSchemaMismatch" }; - error(event); - return; - } - - db.onversionchange = function(event) { - event.target.close(); - }; - success(db); - }; -} - -/** Opens a new transaction to the store - * @param {IndexedDBStore} store - The store object - * @param {Short} mode - The read/write mode of the transaction (constants from IDBTransaction) - * @param {Function} success - The success callback - * @param {Function} error - The error callback - */ -function openTransaction(store, mode, success, error) { - - var storeName = store.name; - var storeDb = store.db; - var errorCallback = getError(error, store.defaultError); - - if (storeDb) { - success(storeDb.transaction(storeName, mode)); - return; - } - - openStoreDb(store, function (db) { - store.db = db; - success(db.transaction(storeName, mode)); - }, errorCallback); -} - -/** Creates a new IndexedDBStore. - * @class IndexedDBStore - * @constructor - * @param {String} name - The name of the store. - * @returns {Object} The new IndexedDBStore. - */ -function IndexedDBStore(name) { - this.name = name; -} - -/** Creates a new IndexedDBStore. - * @method module:store/indexeddb~IndexedDBStore.create - * @param {String} name - The name of the store. - * @returns {Object} The new IndexedDBStore. - */ -IndexedDBStore.create = function (name) { - if (IndexedDBStore.isSupported()) { - return new IndexedDBStore(name); - } - - throw { message: "IndexedDB is not supported on this browser" }; -}; - -/** Returns whether IndexedDB is supported. - * @method module:store/indexeddb~IndexedDBStore.isSupported - * @returns {Boolean} True if IndexedDB is supported, false otherwise. - */ -IndexedDBStore.isSupported = function () { - return !!indexedDB; -}; - -/** Adds a key/value pair to the store - * @method module:store/indexeddb~IndexedDBStore#add - * @param {String} key - The key - * @param {Object} value - The value - * @param {Function} success - The success callback - * @param {Function} error - The error callback -*/ -IndexedDBStore.prototype.add = function (key, value, success, error) { - var name = this.name; - var defaultError = this.defaultError; - var keys = []; - var values = []; - - if (key instanceof Array) { - keys = key; - values = value; - } else { - keys = [key]; - values = [value]; - } - - openTransaction(this, IDBT_READ_WRITE, function (transaction) { - transaction.onabort = getError(error, defaultError, key, "add"); - transaction.oncomplete = function () { - if (key instanceof Array) { - success(keys, values); - } else { - success(key, value); - } - }; - - for (var i = 0; i < keys.length && i < values.length; i++) { - transaction.objectStore(name).add({ v: values[i] }, keys[i]); - } - }, error); -}; - -/** Adds or updates a key/value pair in the store - * @method module:store/indexeddb~IndexedDBStore#addOrUpdate - * @param {String} key - The key - * @param {Object} value - The value - * @param {Function} success - The success callback - * @param {Function} error - The error callback - */ -IndexedDBStore.prototype.addOrUpdate = function (key, value, success, error) { - var name = this.name; - var defaultError = this.defaultError; - var keys = []; - var values = []; - - if (key instanceof Array) { - keys = key; - values = value; - } else { - keys = [key]; - values = [value]; - } - - openTransaction(this, IDBT_READ_WRITE, function (transaction) { - transaction.onabort = getError(error, defaultError); - transaction.oncomplete = function () { - if (key instanceof Array) { - success(keys, values); - } else { - success(key, value); - } - }; - - for (var i = 0; i < keys.length && i < values.length; i++) { - var record = { v: values[i] }; - transaction.objectStore(name).put(record, keys[i]); - } - }, error); -}; - -/** Clears the store - * @method module:store/indexeddb~IndexedDBStore#clear - * @param {Function} success - The success callback - * @param {Function} error - The error callback - */ -IndexedDBStore.prototype.clear = function (success, error) { - var name = this.name; - var defaultError = this.defaultError; - openTransaction(this, IDBT_READ_WRITE, function (transaction) { - transaction.onerror = getError(error, defaultError); - transaction.oncomplete = function () { - success(); - }; - - transaction.objectStore(name).clear(); - }, error); -}; -/** Closes the connection to the database - * @method module:store/indexeddb~IndexedDBStore#close -*/ -IndexedDBStore.prototype.close = function () { - - if (this.db) { - this.db.close(); - this.db = null; - } -}; - -/** Returns whether the store contains a key - * @method module:store/indexeddb~IndexedDBStore#contains - * @param {String} key - The key - * @param {Function} success - The success callback - * @param {Function} error - The error callback - */ -IndexedDBStore.prototype.contains = function (key, success, error) { - var name = this.name; - var defaultError = this.defaultError; - openTransaction(this, IDBT_READ_ONLY, function (transaction) { - var objectStore = transaction.objectStore(name); - var request = objectStore.get(key); - - transaction.oncomplete = function () { - success(!!request.result); - }; - transaction.onerror = getError(error, defaultError); - }, error); -}; - -IndexedDBStore.prototype.defaultError = throwErrorCallback; - -/** Gets all the keys from the store - * @method module:store/indexeddb~IndexedDBStore#getAllKeys - * @param {Function} success - The success callback - * @param {Function} error - The error callback - */ -IndexedDBStore.prototype.getAllKeys = function (success, error) { - var name = this.name; - var defaultError = this.defaultError; - openTransaction(this, IDBT_READ_WRITE, function (transaction) { - var results = []; - - transaction.oncomplete = function () { - success(results); - }; - - var request = transaction.objectStore(name).openCursor(); - - request.onerror = getError(error, defaultError); - request.onsuccess = function (event) { - var cursor = event.target.result; - if (cursor) { - results.push(cursor.key); - // Some tools have issues because continue is a javascript reserved word. - cursor["continue"].call(cursor); - } - }; - }, error); -}; - -/** Identifies the underlying mechanism used by the store. -*/ -IndexedDBStore.prototype.mechanism = "indexeddb"; - -/** Reads the value for the specified key - * @method module:store/indexeddb~IndexedDBStore#read - * @param {String} key - The key - * @param {Function} success - The success callback - * @param {Function} error - The error callback - * If the key does not exist, the success handler will be called with value = undefined - */ -IndexedDBStore.prototype.read = function (key, success, error) { - var name = this.name; - var defaultError = this.defaultError; - var keys = (key instanceof Array) ? key : [key]; - - openTransaction(this, IDBT_READ_ONLY, function (transaction) { - var values = []; - - transaction.onerror = getError(error, defaultError, key, "read"); - transaction.oncomplete = function () { - if (key instanceof Array) { - success(keys, values); - } else { - success(keys[0], values[0]); - } - }; - - for (var i = 0; i < keys.length; i++) { - // Some tools have issues because get is a javascript reserved word. - var objectStore = transaction.objectStore(name); - var request = objectStore.get.call(objectStore, keys[i]); - request.onsuccess = function (event) { - var record = event.target.result; - values.push(record ? record.v : undefined); - }; - } - }, error); -}; - -/** Removes the specified key from the store - * @method module:store/indexeddb~IndexedDBStore#remove - * @param {String} key - The key - * @param {Function} success - The success callback - * @param {Function} error - The error callback - */ -IndexedDBStore.prototype.remove = function (key, success, error) { - - var name = this.name; - var defaultError = this.defaultError; - var keys = (key instanceof Array) ? key : [key]; - - openTransaction(this, IDBT_READ_WRITE, function (transaction) { - transaction.onerror = getError(error, defaultError); - transaction.oncomplete = function () { - success(); - }; - - for (var i = 0; i < keys.length; i++) { - // Some tools have issues because continue is a javascript reserved word. - var objectStore = transaction.objectStore(name); - objectStore["delete"].call(objectStore, keys[i]); - } - }, error); -}; - -/** Updates a key/value pair in the store - * @method module:store/indexeddb~IndexedDBStore#update - * @param {String} key - The key - * @param {Object} value - The value - * @param {Function} success - The success callback - * @param {Function} error - The error callback - */ -IndexedDBStore.prototype.update = function (key, value, success, error) { - var name = this.name; - var defaultError = this.defaultError; - var keys = []; - var values = []; - - if (key instanceof Array) { - keys = key; - values = value; - } else { - keys = [key]; - values = [value]; - } - - openTransaction(this, IDBT_READ_WRITE, function (transaction) { - transaction.onabort = getError(error, defaultError); - transaction.oncomplete = function () { - if (key instanceof Array) { - success(keys, values); - } else { - success(key, value); - } - }; - - for (var i = 0; i < keys.length && i < values.length; i++) { - var request = transaction.objectStore(name).openCursor(IDBKeyRange.only(keys[i])); - var record = { v: values[i] }; - request.pair = { key: keys[i], value: record }; - request.onsuccess = function (event) { - var cursor = event.target.result; - if (cursor) { - cursor.update(event.target.pair.value); - } else { - transaction.abort(); - } - } - } - }, error); -}; - - + <pre class="prettyprint source"><code>/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +'use strict'; + +/** @module store/indexeddb */ +var utils = require('./../utils.js'); + +// Imports. +var throwErrorCallback = utils.throwErrorCallback; +var delay = utils.delay; + + +var indexedDB = utils.inBrowser() ? window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.indexedDB : undefined; +var IDBKeyRange = utils.inBrowser() ? window.IDBKeyRange || window.webkitIDBKeyRange : undefined; +var IDBTransaction = utils.inBrowser() ? window.IDBTransaction || window.webkitIDBTransaction || {} : {} ; + +var IDBT_READ_ONLY = IDBTransaction.READ_ONLY || "readonly"; +var IDBT_READ_WRITE = IDBTransaction.READ_WRITE || "readwrite"; + +/** Returns either a specific error handler or the default error handler + * @param {Function} error - The specific error handler + * @param {Function} defaultError - The default error handler + * @returns {Function} The error callback + */ +function getError(error, defaultError) { + + return function (e) { + var errorFunc = error || defaultError; + if (!errorFunc) { + return; + } + + // Old api quota exceeded error support. + if (Object.prototype.toString.call(e) === "[object IDBDatabaseException]") { + if (e.code === 11 /* IndexedDb disk quota exceeded */) { + errorFunc({ name: "QuotaExceededError", error: e }); + return; + } + errorFunc(e); + return; + } + + var errName; + try { + var errObj = e.target.error || e; + errName = errObj.name; + } catch (ex) { + errName = (e.type === "blocked") ? "IndexedDBBlocked" : "UnknownError"; + } + errorFunc({ name: errName, error: e }); + }; +} + +/** Opens the store object's indexed db database. + * @param {IndexedDBStore} store - The store object + * @param {Function} success - The success callback + * @param {Function} error - The error callback + */ +function openStoreDb(store, success, error) { + + var storeName = store.name; + var dbName = "_odatajs_" + storeName; + + var request = indexedDB.open(dbName); + request.onblocked = error; + request.onerror = error; + + request.onupgradeneeded = function () { + var db = request.result; + if (!db.objectStoreNames.contains(storeName)) { + db.createObjectStore(storeName); + } + }; + + request.onsuccess = function (event) { + var db = request.result; + if (!db.objectStoreNames.contains(storeName)) { + // Should we use the old style api to define the database schema? + if ("setVersion" in db) { + var versionRequest = db.setVersion("1.0"); + versionRequest.onsuccess = function () { + var transaction = versionRequest.transaction; + transaction.oncomplete = function () { + success(db); + }; + db.createObjectStore(storeName, null, false); + }; + versionRequest.onerror = error; + versionRequest.onblocked = error; + return; + } + + // The database doesn't have the expected store. + // Fabricate an error object for the event for the schema mismatch + // and error out. + event.target.error = { name: "DBSchemaMismatch" }; + error(event); + return; + } + + db.onversionchange = function(event) { + event.target.close(); + }; + success(db); + }; +} + +/** Opens a new transaction to the store + * @param {IndexedDBStore} store - The store object + * @param {Integer} mode - The read/write mode of the transaction (constants from IDBTransaction) + * @param {Function} success - The success callback + * @param {Function} error - The error callback + */ +function openTransaction(store, mode, success, error) { + + var storeName = store.name; + var storeDb = store.db; + var errorCallback = getError(error, store.defaultError); + + if (storeDb) { + success(storeDb.transaction(storeName, mode)); + return; + } + + openStoreDb(store, function (db) { + store.db = db; + success(db.transaction(storeName, mode)); + }, errorCallback); +} + +/** Creates a new IndexedDBStore. + * @class IndexedDBStore + * @constructor + * @param {String} name - The name of the store. + * @returns {Object} The new IndexedDBStore. + */ +function IndexedDBStore(name) { + this.name = name; +} + +/** Creates a new IndexedDBStore. + * @method module:store/indexeddb~IndexedDBStore.create + * @param {String} name - The name of the store. + * @returns {Object} The new IndexedDBStore. + */ +IndexedDBStore.create = function (name) { + if (IndexedDBStore.isSupported()) { + return new IndexedDBStore(name); + } + + throw { message: "IndexedDB is not supported on this browser" }; +}; + +/** Returns whether IndexedDB is supported. + * @method module:store/indexeddb~IndexedDBStore.isSupported + * @returns {Boolean} True if IndexedDB is supported, false otherwise. + */ +IndexedDBStore.isSupported = function () { + return !!indexedDB; +}; + +/** Adds a key/value pair to the store + * @method module:store/indexeddb~IndexedDBStore#add + * @param {String} key - The key + * @param {Object} value - The value + * @param {Function} success - The success callback + * @param {Function} error - The error callback +*/ +IndexedDBStore.prototype.add = function (key, value, success, error) { + var name = this.name; + var defaultError = this.defaultError; + var keys = []; + var values = []; + + if (key instanceof Array) { + keys = key; + values = value; + } else { + keys = [key]; + values = [value]; + } + + openTransaction(this, IDBT_READ_WRITE, function (transaction) { + transaction.onabort = getError(error, defaultError, key, "add"); + transaction.oncomplete = function () { + if (key instanceof Array) { + success(keys, values); + } else { + success(key, value); + } + }; + + for (var i = 0; i < keys.length && i < values.length; i++) { + transaction.objectStore(name).add({ v: values[i] }, keys[i]); + } + }, error); +}; + +/** Adds or updates a key/value pair in the store + * @method module:store/indexeddb~IndexedDBStore#addOrUpdate + * @param {String} key - The key + * @param {Object} value - The value + * @param {Function} success - The success callback + * @param {Function} error - The error callback + */ +IndexedDBStore.prototype.addOrUpdate = function (key, value, success, error) { + var name = this.name; + var defaultError = this.defaultError; + var keys = []; + var values = []; + + if (key instanceof Array) { + keys = key; + values = value; + } else { + keys = [key]; + values = [value]; + } + + openTransaction(this, IDBT_READ_WRITE, function (transaction) { + transaction.onabort = getError(error, defaultError); + transaction.oncomplete = function () { + if (key instanceof Array) { + success(keys, values); + } else { + success(key, value); + } + }; + + for (var i = 0; i < keys.length && i < values.length; i++) { + var record = { v: values[i] }; + transaction.objectStore(name).put(record, keys[i]); + } + }, error); +}; + +/** Clears the store + * @method module:store/indexeddb~IndexedDBStore#clear + * @param {Function} success - The success callback + * @param {Function} error - The error callback + */ +IndexedDBStore.prototype.clear = function (success, error) { + var name = this.name; + var defaultError = this.defaultError; + openTransaction(this, IDBT_READ_WRITE, function (transaction) { + transaction.onerror = getError(error, defaultError); + transaction.oncomplete = function () { + success(); + }; + + transaction.objectStore(name).clear(); + }, error); +}; + +/** Closes the connection to the database + * @method module:store/indexeddb~IndexedDBStore#close +*/ +IndexedDBStore.prototype.close = function () { + + if (this.db) { + this.db.close(); + this.db = null; + } +}; + +/** Returns whether the store contains a key + * @method module:store/indexeddb~IndexedDBStore#contains + * @param {String} key - The key + * @param {Function} success - The success callback + * @param {Function} error - The error callback + */ +IndexedDBStore.prototype.contains = function (key, success, error) { + var name = this.name; + var defaultError = this.defaultError; + openTransaction(this, IDBT_READ_ONLY, function (transaction) { + var objectStore = transaction.objectStore(name); + var request = objectStore.get(key); + + transaction.oncomplete = function () { + success(!!request.result); + }; + transaction.onerror = getError(error, defaultError); + }, error); +}; + +IndexedDBStore.prototype.defaultError = throwErrorCallback; + +/** Gets all the keys from the store + * @method module:store/indexeddb~IndexedDBStore#getAllKeys + * @param {Function} success - The success callback + * @param {Function} error - The error callback + */ +IndexedDBStore.prototype.getAllKeys = function (success, error) { + var name = this.name; + var defaultError = this.defaultError; + openTransaction(this, IDBT_READ_WRITE, function (transaction) { + var results = []; + + transaction.oncomplete = function () { + success(results); + }; + + var request = transaction.objectStore(name).openCursor(); + + request.onerror = getError(error, defaultError); + request.onsuccess = function (event) { + var cursor = event.target.result; + if (cursor) { + results.push(cursor.key); + // Some tools have issues because continue is a javascript reserved word. + cursor["continue"].call(cursor); + } + }; + }, error); +}; + +/** Identifies the underlying mechanism used by the store. +*/ +IndexedDBStore.prototype.mechanism = "indexeddb"; + +/** Reads the value for the specified key + * @method module:store/indexeddb~IndexedDBStore#read + * @param {String} key - The key + * @param {Function} success - The success callback + * @param {Function} error - The error callback + * If the key does not exist, the success handler will be called with value = undefined + */ +IndexedDBStore.prototype.read = function (key, success, error) { + var name = this.name; + var defaultError = this.defaultError; + var keys = (key instanceof Array) ? key : [key]; + + openTransaction(this, IDBT_READ_ONLY, function (transaction) { + var values = []; + + transaction.onerror = getError(error, defaultError, key, "read"); + transaction.oncomplete = function () { + if (key instanceof Array) { + success(keys, values); + } else { + success(keys[0], values[0]); + } + }; + + for (var i = 0; i < keys.length; i++) { + // Some tools have issues because get is a javascript reserved word. + var objectStore = transaction.objectStore(name); + var request = objectStore.get.call(objectStore, keys[i]); + request.onsuccess = function (event) { + var record = event.target.result; + values.push(record ? record.v : undefined); + }; + } + }, error); +}; + +/** Removes the specified key from the store + * @method module:store/indexeddb~IndexedDBStore#remove + * @param {String} key - The key + * @param {Function} success - The success callback + * @param {Function} error - The error callback + */ +IndexedDBStore.prototype.remove = function (key, success, error) { + + var name = this.name; + var defaultError = this.defaultError; + var keys = (key instanceof Array) ? key : [key]; + + openTransaction(this, IDBT_READ_WRITE, function (transaction) { + transaction.onerror = getError(error, defaultError); + transaction.oncomplete = function () { + success(); + }; + + for (var i = 0; i < keys.length; i++) { + // Some tools have issues because continue is a javascript reserved word. + var objectStore = transaction.objectStore(name); + objectStore["delete"].call(objectStore, keys[i]); + } + }, error); +}; + +/** Updates a key/value pair in the store + * @method module:store/indexeddb~IndexedDBStore#update + * @param {String} key - The key + * @param {Object} value - The value + * @param {Function} success - The success callback + * @param {Function} error - The error callback + */ +IndexedDBStore.prototype.update = function (key, value, success, error) { + var name = this.name; + var defaultError = this.defaultError; + var keys = []; + var values = []; + + if (key instanceof Array) { + keys = key; + values = value; + } else { + keys = [key]; + values = [value]; + } + + openTransaction(this, IDBT_READ_WRITE, function (transaction) { + transaction.onabort = getError(error, defaultError); + transaction.oncomplete = function () { + if (key instanceof Array) { + success(keys, values); + } else { + success(key, value); + } + }; + + for (var i = 0; i < keys.length && i < values.length; i++) { + var request = transaction.objectStore(name).openCursor(IDBKeyRange.only(keys[i])); + var record = { v: values[i] }; + request.pair = { key: keys[i], value: record }; + request.onsuccess = function (event) { + var cursor = event.target.result; + if (cursor) { + cursor.update(event.target.pair.value); + } else { + transaction.abort(); + } + } + } + }, error); +}; + + module.exports = IndexedDBStore;</code></pre> </article> </section> @@ -479,13 +481,13 @@ module.exports = IndexedDBStore;</code>< </div> <nav> - <h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-cache.html">cache</a></li><li><a href="source.html">cache/source</a></li><li><a href="module-datajs.html">datajs</a></li><li><a href="deferred.html">datajs/deferred</a></li><li><a href="utils.html">datajs/utils</a></li><li><a href="xml.html">datajs/xml</a></li><li><a href="module-odata.html">odata</a></li><li><a href="batch.html">odata/batch</a></li><li><a href="handler.html">odata/handler</a></li><li><a href="json.html">odata/json</a></li><li><a href="metadata.html">odata/metadata</a></li><li><a href="net.html">odata/net</a></li><li><a href="utils_.html">odata/utils</a></li><li><a href="module-store.html">store</a></li><li><a href="dom.html">store/dom</a></li><li><a href="indexeddb.html">store/indexeddb</a></li><li><a href="memory.html">store/memory</a></li></ul><h3>Classes</h3><ul><li><a href="DataCache.html">DataCache</a></li><li><a href="DataCacheOperation.html">DataCacheOperation</a></li><li><a h ref="DjsDeferred.html">DjsDeferred</a></li><li><a href="dom-DomStore.html">DomStore</a></li><li><a href="indexeddb-IndexedDBStore.html">IndexedDBStore</a></li><li><a href="memory-MemoryStore.html">MemoryStore</a></li><li><a href="ODataCacheSource.html">ODataCacheSource</a></li></ul><h3><a href="global.html">Global</a></h3> + <h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-cache.html">cache</a></li><li><a href="source.html">cache/source</a></li><li><a href="module-odata.html">odata</a></li><li><a href="batch.html">odata/batch</a></li><li><a href="handler.html">odata/handler</a></li><li><a href="json.html">odata/json</a></li><li><a href="metadata.html">odata/metadata</a></li><li><a href="net.html">odata/net</a></li><li><a href="utils.html">odata/utils</a></li><li><a href="deferred.html">odatajs/deferred</a></li><li><a href="utils_.html">odatajs/utils</a></li><li><a href="xml.html">odatajs/xml</a></li><li><a href="module-store.html">store</a></li><li><a href="dom.html">store/dom</a></li><li><a href="indexeddb.html">store/indexeddb</a></li><li><a href="memory.html">store/memory</a></li></ul><h3>Classes</h3><ul><li><a href="DataCache.html">DataCache</a></li><li><a href="DataCacheOperation.html">DataCacheOperation</a></li><li><a href="DjsDeferred.html">DjsDeferred</a></li><l i><a href="dom-DomStore.html">DomStore</a></li><li><a href="indexeddb-IndexedDBStore.html">IndexedDBStore</a></li><li><a href="memory-MemoryStore.html">MemoryStore</a></li><li><a href="ODataCacheSource.html">ODataCacheSource</a></li></ul><h3><a href="global.html">Global</a></h3> </nav> <br clear="both"> <footer> - Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Mon Sep 15 2014 13:08:00 GMT+0200 (MESZ) + Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Thu Apr 09 2015 08:31:26 GMT+0200 (MESZ) </footer> <script> prettyPrint(); </script>
