зеркало из https://github.com/mozilla/gecko-dev.git
Bug 836513 - Support multiple object stores in IndexedDBHelper.jsm. r=gwagner
This commit is contained in:
Родитель
53d4ff720b
Коммит
24db28157f
|
@ -40,7 +40,7 @@ ActivitiesDb.prototype = {
|
|||
let idbManager = Cc["@mozilla.org/dom/indexeddb/manager;1"]
|
||||
.getService(Ci.nsIIndexedDatabaseManager);
|
||||
idbManager.initWindowless(idbGlobal);
|
||||
this.initDBHelper(DB_NAME, DB_VERSION, STORE_NAME, idbGlobal);
|
||||
this.initDBHelper(DB_NAME, DB_VERSION, [STORE_NAME], idbGlobal);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -88,7 +88,7 @@ ActivitiesDb.prototype = {
|
|||
|
||||
// Add all the activities carried in the |aObjects| array.
|
||||
add: function actdb_add(aObjects, aSuccess, aError) {
|
||||
this.newTxn("readwrite", function (txn, store) {
|
||||
this.newTxn("readwrite", STORE_NAME, function (txn, store) {
|
||||
aObjects.forEach(function (aObject) {
|
||||
let object = {
|
||||
manifest: aObject.manifest,
|
||||
|
@ -105,7 +105,7 @@ ActivitiesDb.prototype = {
|
|||
|
||||
// Remove all the activities carried in the |aObjects| array.
|
||||
remove: function actdb_remove(aObjects) {
|
||||
this.newTxn("readwrite", function (txn, store) {
|
||||
this.newTxn("readwrite", STORE_NAME, function (txn, store) {
|
||||
aObjects.forEach(function (aObject) {
|
||||
let object = {
|
||||
manifest: aObject.manifest,
|
||||
|
@ -120,7 +120,7 @@ ActivitiesDb.prototype = {
|
|||
find: function actdb_find(aObject, aSuccess, aError, aMatch) {
|
||||
debug("Looking for " + aObject.options.name);
|
||||
|
||||
this.newTxn("readonly", function (txn, store) {
|
||||
this.newTxn("readonly", STORE_NAME, function (txn, store) {
|
||||
let index = store.index("name");
|
||||
let request = index.mozGetAll(aObject.options.name);
|
||||
request.onsuccess = function findSuccess(aEvent) {
|
||||
|
|
|
@ -34,7 +34,7 @@ AlarmDB.prototype = {
|
|||
init: function init(aGlobal) {
|
||||
debug("init()");
|
||||
|
||||
this.initDBHelper(ALARMDB_NAME, ALARMDB_VERSION, ALARMSTORE_NAME, aGlobal);
|
||||
this.initDBHelper(ALARMDB_NAME, ALARMDB_VERSION, [ALARMSTORE_NAME], aGlobal);
|
||||
},
|
||||
|
||||
upgradeSchema: function upgradeSchema(aTransaction, aDb, aOldVersion, aNewVersion) {
|
||||
|
@ -65,6 +65,7 @@ AlarmDB.prototype = {
|
|||
|
||||
this.newTxn(
|
||||
"readwrite",
|
||||
ALARMSTORE_NAME,
|
||||
function txnCb(aTxn, aStore) {
|
||||
debug("Going to add " + JSON.stringify(aAlarm));
|
||||
aStore.put(aAlarm).onsuccess = function setTxnResult(aEvent) {
|
||||
|
@ -94,6 +95,7 @@ AlarmDB.prototype = {
|
|||
|
||||
this.newTxn(
|
||||
"readwrite",
|
||||
ALARMSTORE_NAME,
|
||||
function txnCb(aTxn, aStore) {
|
||||
debug("Going to remove " + aId);
|
||||
|
||||
|
@ -135,6 +137,7 @@ AlarmDB.prototype = {
|
|||
|
||||
this.newTxn(
|
||||
"readonly",
|
||||
ALARMSTORE_NAME,
|
||||
function txnCb(aTxn, aStore) {
|
||||
if (!aTxn.result)
|
||||
aTxn.result = [];
|
||||
|
|
|
@ -97,21 +97,23 @@ IndexedDBHelper.prototype = {
|
|||
*
|
||||
* @param txn_type
|
||||
* Type of transaction (e.g. "readwrite")
|
||||
* @param store_name
|
||||
* The object store you want to be passed to the callback
|
||||
* @param callback
|
||||
* Function to call when the transaction is available. It will
|
||||
* be invoked with the transaction and the 'aDBStoreName' object store.
|
||||
* be invoked with the transaction and the `store' object store.
|
||||
* @param successCb
|
||||
* Success callback to call on a successful transaction commit.
|
||||
* The result is stored in txn.result.
|
||||
* @param failureCb
|
||||
* Error callback to call when an error is encountered.
|
||||
*/
|
||||
newTxn: function newTxn(txn_type, callback, successCb, failureCb) {
|
||||
newTxn: function newTxn(txn_type, store_name, callback, successCb, failureCb) {
|
||||
this.ensureDB(function () {
|
||||
if (DEBUG) debug("Starting new transaction" + txn_type);
|
||||
let txn = this._db.transaction(this.dbName, txn_type);
|
||||
let txn = this._db.transaction(this.dbStoreNames, txn_type);
|
||||
if (DEBUG) debug("Retrieving object store", this.dbName);
|
||||
let store = txn.objectStore(this.dbStoreName);
|
||||
let store = txn.objectStore(store_name);
|
||||
|
||||
txn.oncomplete = function (event) {
|
||||
if (DEBUG) debug("Transaction complete. Returning to callback.");
|
||||
|
@ -145,10 +147,10 @@ IndexedDBHelper.prototype = {
|
|||
* @param aGlobal
|
||||
* Global object that has indexedDB property.
|
||||
*/
|
||||
initDBHelper: function initDBHelper(aDBName, aDBVersion, aDBStoreName, aGlobal) {
|
||||
initDBHelper: function initDBHelper(aDBName, aDBVersion, aDBStoreNames, aGlobal) {
|
||||
this.dbName = aDBName;
|
||||
this.dbVersion = aDBVersion;
|
||||
this.dbStoreName = aDBStoreName;
|
||||
this.dbStoreNames = aDBStoreNames;
|
||||
this.dbGlobal = aGlobal;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ ContactDB.prototype = {
|
|||
* }
|
||||
*/
|
||||
if (DEBUG) debug("create schema");
|
||||
objectStore = db.createObjectStore(this.dbStoreName, {keyPath: "id"});
|
||||
objectStore = db.createObjectStore(STORE_NAME, {keyPath: "id"});
|
||||
|
||||
// Properties indexes
|
||||
objectStore.createIndex("familyName", "properties.familyName", { multiEntry: true });
|
||||
|
@ -384,7 +384,7 @@ ContactDB.prototype = {
|
|||
|
||||
saveContact: function saveContact(aContact, successCb, errorCb) {
|
||||
let contact = this.makeImport(aContact);
|
||||
this.newTxn("readwrite", function (txn, store) {
|
||||
this.newTxn("readwrite", STORE_NAME, function (txn, store) {
|
||||
if (DEBUG) debug("Going to update" + JSON.stringify(contact));
|
||||
|
||||
// Look up the existing record and compare the update timestamp.
|
||||
|
@ -413,14 +413,14 @@ ContactDB.prototype = {
|
|||
},
|
||||
|
||||
removeContact: function removeContact(aId, aSuccessCb, aErrorCb) {
|
||||
this.newTxn("readwrite", function (txn, store) {
|
||||
this.newTxn("readwrite", STORE_NAME, function (txn, store) {
|
||||
if (DEBUG) debug("Going to delete" + aId);
|
||||
store.delete(aId);
|
||||
}, aSuccessCb, aErrorCb);
|
||||
},
|
||||
|
||||
clear: function clear(aSuccessCb, aErrorCb) {
|
||||
this.newTxn("readwrite", function (txn, store) {
|
||||
this.newTxn("readwrite", STORE_NAME, function (txn, store) {
|
||||
if (DEBUG) debug("Going to clear all!");
|
||||
store.clear();
|
||||
}, aSuccessCb, aErrorCb);
|
||||
|
@ -441,7 +441,7 @@ ContactDB.prototype = {
|
|||
find: function find(aSuccessCb, aFailureCb, aOptions) {
|
||||
if (DEBUG) debug("ContactDB:find val:" + aOptions.filterValue + " by: " + aOptions.filterBy + " op: " + aOptions.filterOp + "\n");
|
||||
let self = this;
|
||||
this.newTxn("readonly", function (txn, store) {
|
||||
this.newTxn("readonly", STORE_NAME, function (txn, store) {
|
||||
if (aOptions && (aOptions.filterOp == "equals" || aOptions.filterOp == "contains")) {
|
||||
self._findWithIndex(txn, store, aOptions);
|
||||
} else {
|
||||
|
@ -527,6 +527,6 @@ ContactDB.prototype = {
|
|||
},
|
||||
|
||||
init: function init(aGlobal) {
|
||||
this.initDBHelper(DB_NAME, DB_VERSION, STORE_NAME, aGlobal);
|
||||
this.initDBHelper(DB_NAME, DB_VERSION, [STORE_NAME], aGlobal);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -29,7 +29,7 @@ this.NetworkStatsDB = function NetworkStatsDB(aGlobal) {
|
|||
if (DEBUG) {
|
||||
debug("Constructor");
|
||||
}
|
||||
this.initDBHelper(DB_NAME, DB_VERSION, STORE_NAME, aGlobal);
|
||||
this.initDBHelper(DB_NAME, DB_VERSION, [STORE_NAME], aGlobal);
|
||||
}
|
||||
|
||||
NetworkStatsDB.prototype = {
|
||||
|
@ -42,7 +42,7 @@ NetworkStatsDB.prototype = {
|
|||
function errorCb(error) {
|
||||
txnCb(error, null);
|
||||
}
|
||||
return this.newTxn(txn_type, callback, successCb, errorCb);
|
||||
return this.newTxn(txn_type, STORE_NAME, callback, successCb, errorCb);
|
||||
},
|
||||
|
||||
upgradeSchema: function upgradeSchema(aTransaction, aDb, aOldVersion, aNewVersion) {
|
||||
|
|
|
@ -109,6 +109,6 @@ SettingsDB.prototype = {
|
|||
|
||||
init: function init(aGlobal) {
|
||||
this.initDBHelper(SETTINGSDB_NAME, SETTINGSDB_VERSION,
|
||||
SETTINGSSTORE_NAME, aGlobal);
|
||||
[SETTINGSSTORE_NAME], aGlobal);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче