1 /** 2 * The Render Engine 3 * AbstractDBStorage 4 * 5 * @fileoverview The base object from which all database storage objects are derived. 6 * 7 * @author: Brett Fattori (brettf@renderengine.com) 8 * @author: $Author: bfattori@gmail.com $ 9 * @version: $Revision: 1559 $ 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.AbstractDBStorage", 36 "requires":[ 37 "R.storage.AbstractStorage" 38 ] 39 }); 40 41 /** 42 * @class <tt>R.storage.AbstractStorage</tt> is the base class of all storage objects. 43 * Currently, The Render Engine supports three types of storage, 44 * all with the ability to export their data remotely 45 * and to import data from a remote source. 46 * 47 * @param name {String} The name of the object 48 * @extends R.storage.AbstractStorage 49 * @constructor 50 * @description This base class is considered abstract and should not be 51 * instantiated directly. See {@link R.storage.TransientStorage}, 52 * {@link R.storage.PersistentStorage}, or {@link R.storage.IndexedStorage} for 53 * implementations. 54 */ 55 R.storage.AbstractDBStorage = function () { 56 return R.storage.AbstractStorage.extend(/** @scope R.storage.AbstractDBStorage.prototype */{ 57 58 schema:null, 59 60 /** @private */ 61 constructor:function (name) { 62 this.schema = null; 63 this.base(name || "AbstractDBStorage"); 64 }, 65 66 /** 67 * Get the data storage schema from the storage object. 68 * @return {Array} An array of tables for the storage object 69 */ 70 getSchema:function () { 71 return this.schema; 72 }, 73 74 /** 75 * Set the data storage schema for the storage object. 76 * @schema {Array} An array of table names 77 */ 78 setSchema:function (schema) { 79 this.schema = schema; 80 }, 81 82 /** 83 * [ABSTRACT] Finalize any pending storage requests. 84 */ 85 flush:function () { 86 }, 87 88 /** 89 * Create a new table to store data in. 90 * 91 * @param name {String} The name of the table 92 * @param def {Object} Table definition object 93 * @return {Boolean} <code>true</code> if the table was created. <code>false</code> if 94 * the table already exists or couldn't be created for another reason. 95 */ 96 createTable:function (name, def) { 97 return false; 98 }, 99 100 /** 101 * Drop a table by its given name 102 * 103 * @param name {String} The name of the table to drop 104 */ 105 dropTable:function (name) { 106 if (!this.schema) { 107 return; 108 } 109 delete this.schema[name]; 110 }, 111 112 /** 113 * Returns <tt>true</tt> if the table with the given name exists 114 * @param name {String} The name of the table 115 * @return {Boolean} 116 */ 117 tableExists:function (name) { 118 return false; 119 }, 120 121 /** 122 * Set the data, for the given table, in the storage. 123 * 124 * @param name {String} The name of the table 125 * @param data {Object} The table data to store 126 * @return {Number} 1 if the data was stored, or 0 if the table doesn't exist 127 */ 128 setTableData:function (name, data) { 129 return 0; 130 }, 131 132 /** 133 * Get the schema object, for the given table. 134 * @param name {String} The name of the table 135 * @return {Object} The data object, or <tt>null</tt> if no table with the given name exists 136 */ 137 getTableDef:function (name) { 138 return null; 139 }, 140 141 /** 142 * Get the data object, for the given table. 143 * @param name {String} The name of the table 144 * @return {Object} The data object, or <tt>null</tt> if no table with the given name exists 145 */ 146 getTableData:function (name) { 147 return null; 148 }, 149 150 /** 151 * Execute SQL on the storage object, which may be one of <tt>SELECT</tt>, 152 * <tt>UPDATE</tt>, <tt>INSERT</tt>, or <tt>DELETE</tt>. 153 * @param sqlString {String} The SQL to execute 154 * @param bindings {Array} An optional array of bindings 155 * @return {Object} If the SQL is a <tt>SELECT</tt>, the object will be the result of 156 * the statement, otherwise the result will be a <tt>Boolean</tt> if the statement was 157 * successful. 158 */ 159 execSql:function (sqlString, bindings) { 160 return false; 161 } 162 163 }, /** @scope R.storage.AbstractStorage.prototype */ { 164 165 /** 166 * Get the class name of this object 167 * 168 * @return {String} "R.storage.AbstractStorage" 169 */ 170 getClassName:function () { 171 return "R.storage.AbstractStorage"; 172 } 173 174 }); 175 176 };