1 /** 2 * The Render Engine 3 * PersistentStorage 4 * 5 * @fileoverview A storage object where data is maintained between browser sessions. 6 * 7 * @author: Brett Fattori (brettf@renderengine.com) 8 * @author: $Author: bfattori $ 9 * @version: $Revision: 1555 $ 10 * 11 * Copyright (c) 2011 Brett Fattori (brettf@renderengine.com) 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining a copy 14 * of this software and associated documentation files (the "Software"), to deal 15 * in the Software without restriction, including without limitation the rights 16 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 * copies of the Software, and to permit persons to whom the Software is 18 * furnished to do so, subject to the following conditions: 19 * 20 * The above copyright notice and this permission notice shall be included in 21 * all copies or substantial portions of the Software. 22 * 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 * THE SOFTWARE. 30 * 31 */ 32 33 // The class this file defines and its required classes 34 R.Engine.define({ 35 "class":"R.storage.PersistentStorage", 36 "requires":[ 37 "R.storage.BrowserStorage" 38 ] 39 }); 40 41 /** 42 * @class <tt>R.storage.PersistentStorage</tt> is used to maintain data between browser 43 * sessions. The schema and data tables will persist in the user's browser 44 * between restarts. This is a good place to store configuration data, 45 * high score tables, and other data which needs to be maintained. 46 * <p/> 47 * Data is stored and retrieved using a SQL-like syntax. For information 48 * about the SQL syntax, see http://code.google.com/p/trimpath/wiki/TrimQuery 49 * 50 * @param name {String} The name of the object 51 * @extends R.storage.BrowserStorage 52 * @constructor 53 * @description This class of storage is used to persist data between browser sessions. 54 */ 55 R.storage.PersistentStorage = function () { 56 return R.storage.BrowserStorage.extend(/** @scope R.storage.PersistentStorage.prototype */{ 57 58 enabled:null, 59 60 /** @private */ 61 constructor:function (name) { 62 this.enabled = R.engine.Support.sysInfo().support.storage.local; 63 AssertWarn(this.enabled, "PersistentStorage is not supported by browser - DISABLED"); 64 this.base(name); 65 }, 66 67 /** 68 * Release the object back into the object pool. 69 */ 70 release:function () { 71 this.base(); 72 this.enabled = null; 73 }, 74 75 /** 76 * Initialize the storage object to the localStorage browser object 77 * @return {Object} The <tt>localStorage</tt> object 78 */ 79 initStorageObject:function () { 80 return window.localStorage; 81 }, 82 83 /** 84 * A unique identifier for the table name. 85 * @param name {String} The table name 86 * @return {String} A unique identifier 87 */ 88 getTableUID:function (name) { 89 return this.base(name) + "PS"; 90 } 91 92 }, /** @scope R.storage.PersistentStorage.prototype */ { 93 94 /** 95 * Get the class name of this object 96 * 97 * @return {String} "R.storage.PersistentStorage" 98 */ 99 getClassName:function () { 100 return "R.storage.PersistentStorage"; 101 } 102 103 }); 104 105 }; 106