diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/calendar/providers/storage/CalStorageModelFactory.jsm | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/calendar/providers/storage/CalStorageModelFactory.jsm')
-rw-r--r-- | comm/calendar/providers/storage/CalStorageModelFactory.jsm | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/comm/calendar/providers/storage/CalStorageModelFactory.jsm b/comm/calendar/providers/storage/CalStorageModelFactory.jsm new file mode 100644 index 0000000000..cf36791eba --- /dev/null +++ b/comm/calendar/providers/storage/CalStorageModelFactory.jsm @@ -0,0 +1,52 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +var EXPORTED_SYMBOLS = ["CalStorageModelFactory"]; + +var { CalStorageItemModel } = ChromeUtils.import( + "resource:///modules/calendar/CalStorageItemModel.jsm" +); +var { CalStorageCachedItemModel } = ChromeUtils.import( + "resource:///modules/calendar/CalStorageCachedItemModel.jsm" +); +var { CalStorageOfflineModel } = ChromeUtils.import( + "resource:///modules/calendar/CalStorageOfflineModel.jsm" +); +var { CalStorageMetaDataModel } = ChromeUtils.import( + "resource:///modules/calendar/CalStorageMetaDataModel.jsm" +); + +/** + * CalStorageModelFactory provides a convenience method for creating instances + * of the storage calendar models. Use to avoid having to import each one + * directly. + */ +class CalStorageModelFactory { + /** + * Creates an instance of a CalStorageModel for the specified type. + * + * @param {"item"|"offline"|"metadata"} type - The model type desired. + * @param {mozIStorageAsyncConnection} db - The database connection to use. + * @param {CalStorageStatement} stmts + * @param {CalStorageCalendar} calendar - The calendar associated with the + * model. + */ + static createInstance(type, db, stmts, calendar) { + switch (type) { + case "item": + return new CalStorageItemModel(db, stmts, calendar); + + case "cached-item": + return new CalStorageCachedItemModel(db, stmts, calendar); + + case "offline": + return new CalStorageOfflineModel(db, stmts, calendar); + + case "metadata": + return new CalStorageMetaDataModel(db, stmts, calendar); + } + + throw new Error(`Unknown model type "${type}" specified!`); + } +} |