(function ($, rho, rhoUtil) { 'use strict'; var moduleNS = 'Rho.Database'; var executeSql = function(db, sqlStmt, isBatch, args) { return (sqlStmt === undefined) ? [] : db.execute(sqlStmt, isBatch, args); }; // === Database class definition === function Database() { var id = null; this.getId = function () {return id;}; if (1 == arguments.length && arguments[0][rhoUtil.rhoIdParam()]) { if (moduleNS != arguments[0][rhoUtil.rhoClassParam()]) { throw "Wrong class instantiation!"; } id = arguments[0][rhoUtil.rhoIdParam()]; } else { id = rhoUtil.nextId(); // constructor methods are following: this.initialize.apply(this, arguments); } } // === Database instance members === Database.prototype.initialize = function(dbPath,dbPartition) { this.dbPath = dbPath; this.db = new Rho.Database.SQLite3(dbPath, dbPartition); }; Database.prototype.close = function() { if (this.db === null) { return false; } this.db.close(); this.dbPath = null; this.db = null; return true; }; Database.prototype.startTransaction = function() { this.db.startTransaction(); }; Database.prototype.commitTransaction = function() { this.db.commitTransaction(); }; Database.prototype.rollbackTransaction = function() { this.db.rollbackTransaction(); }; Database.prototype.lockDb = function() { this.db.lockDb(); }; Database.prototype.unlockDb = function() { this.db.unlockDb(); }; Database.prototype.isUiWaitForDb = function() { return this.db.isUiWaitForDb(); }; Database.prototype.executeSql = function(/* const rho::String& */ sqlStmt, /* const rho::Vector& */ args) { return executeSql(this.db, sqlStmt, false, args); }; Database.prototype.executeBatchSql = function(/* const rho::String& */ sqlStmt) { return executeSql(this.db, sqlStmt, true, []); }; Database.prototype.destroyTable = function(/* const rho::String& */ tableName) { this.db.destroyTables([tableName], []); }; Database.prototype.destroyTables = function(/* const rho::Hashtable& */ propertyMap) { this.db.destroyTables(propertyMap['include'], propertyMap['exclude']); }; Database.prototype.isTableExist = function(/* const rho::String& */ tableName) { return this.db.isTableExist(tableName); }; Database.prototype.setDoNotBackupAttribute = function(/* bool */ setFlag) { setFlag = (setFlag === undefined) ? true : setFlag; if (Rho.System.getProperty('platform') === 'APPLE') { Rho.System.setDoNotBackupAttribute(this.dbPath , setFlag); Rho.System.setDoNotBackupAttribute(this.dbPath + '.version', setFlag); } }; // === Database static members === // === Database default instance support === rhoUtil.namespace(moduleNS, Database, true); })(Rho.jQuery, Rho, Rho.util);