/* Copyright (c) 2004-2009, The Dojo Foundation All Rights Reserved. Available via Academic Free License >= 2.1 OR the modified BSD license. see: http://dojotoolkit.org/license for details */ if(!dojo._hasResource["dojox.storage.GearsStorageProvider"]){dojo._hasResource["dojox.storage.GearsStorageProvider"]=true;dojo.provide("dojox.storage.GearsStorageProvider");dojo.require("dojo.gears");dojo.require("dojox.storage.Provider");dojo.require("dojox.storage.manager");dojo.require("dojox.sql");if(dojo.gears.available){(function(){dojo.declare("dojox.storage.GearsStorageProvider",dojox.storage.Provider,{constructor:function(){},TABLE_NAME:"__DOJO_STORAGE",initialized:false,_available:null,_storageReady:false,initialize:function(){if(dojo.config["disableGearsStorage"]==true){return;}this.TABLE_NAME="__DOJO_STORAGE";this.initialized=true;dojox.storage.manager.loaded();},isAvailable:function(){return this._available=dojo.gears.available;},put:function(_1,_2,_3,_4){this._initStorage();if(!this.isValidKey(_1)){throw new Error("Invalid key given: "+_1);}_4=_4||this.DEFAULT_NAMESPACE;if(!this.isValidKey(_4)){throw new Error("Invalid namespace given: "+_1);}if(dojo.isString(_2)){_2="string:"+_2;}else{_2=dojo.toJson(_2);}try{dojox.sql("DELETE FROM "+this.TABLE_NAME+" WHERE namespace = ? AND key = ?",_4,_1);dojox.sql("INSERT INTO "+this.TABLE_NAME+" VALUES (?, ?, ?)",_4,_1,_2);}catch(e){_3(this.FAILED,_1,e.toString(),_4);return;}if(_3){_3(dojox.storage.SUCCESS,_1,null,_4);}},get:function(_5,_6){this._initStorage();if(!this.isValidKey(_5)){throw new Error("Invalid key given: "+_5);}_6=_6||this.DEFAULT_NAMESPACE;if(!this.isValidKey(_6)){throw new Error("Invalid namespace given: "+_5);}var _7=dojox.sql("SELECT * FROM "+this.TABLE_NAME+" WHERE namespace = ? AND "+" key = ?",_6,_5);if(!_7.length){return null;}else{_7=_7[0].value;}if(dojo.isString(_7)&&(/^string:/.test(_7))){_7=_7.substring("string:".length);}else{_7=dojo.fromJson(_7);}return _7;},getNamespaces:function(){this._initStorage();var _8=[dojox.storage.DEFAULT_NAMESPACE];var rs=dojox.sql("SELECT namespace FROM "+this.TABLE_NAME+" DESC GROUP BY namespace");for(var i=0;i