blob: cf36791eba352f5eec0cf319d8b038a5c0e769eb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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!`);
}
}
|