1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/backend/model/ObjectManagerRepository.ts

89 lines
2.9 KiB
TypeScript
Raw Normal View History

2016-12-27 23:09:47 +08:00
import {IUserManager} from "./interfaces/IUserManager";
import {IGalleryManager} from "./interfaces/IGalleryManager";
import {ISearchManager} from "./interfaces/ISearchManager";
import {MySQLConnection} from "./mysql/MySQLConnection";
2017-07-04 01:17:49 +08:00
import {ISharingManager} from "./interfaces/ISharingManager";
import {Logger} from "../Logger";
2016-04-22 19:23:44 +08:00
2016-05-09 23:04:56 +08:00
export class ObjectManagerRepository {
private _galleryManager: IGalleryManager;
private _userManager: IUserManager;
private _searchManager: ISearchManager;
2017-07-04 01:17:49 +08:00
private _sharingManager: ISharingManager;
private static _instance: ObjectManagerRepository = null;
2016-04-22 19:23:44 +08:00
2017-07-14 05:39:09 +08:00
public static async InitMemoryManagers() {
await ObjectManagerRepository.reset();
const GalleryManager = require("./memory/GalleryManager").GalleryManager;
const UserManager = require("./memory/UserManager").UserManager;
const SearchManager = require("./memory/SearchManager").SearchManager;
2017-07-04 01:17:49 +08:00
const SharingManager = require("./memory/SharingManager").SharingManager;
ObjectManagerRepository.getInstance().GalleryManager = new GalleryManager();
ObjectManagerRepository.getInstance().UserManager = new UserManager();
ObjectManagerRepository.getInstance().SearchManager = new SearchManager();
ObjectManagerRepository.getInstance().SharingManager = new SharingManager();
}
2017-07-04 01:17:49 +08:00
public static async InitMySQLManagers() {
2017-07-14 05:39:09 +08:00
await ObjectManagerRepository.reset();
2017-07-04 01:17:49 +08:00
await MySQLConnection.init();
const GalleryManager = require("./mysql/GalleryManager").GalleryManager;
const UserManager = require("./mysql/UserManager").UserManager;
const SearchManager = require("./mysql/SearchManager").SearchManager;
const SharingManager = require("./mysql/SharingManager").SharingManager;
ObjectManagerRepository.getInstance().GalleryManager = new GalleryManager();
ObjectManagerRepository.getInstance().UserManager = new UserManager();
ObjectManagerRepository.getInstance().SearchManager = new SearchManager();
ObjectManagerRepository.getInstance().SharingManager = new SharingManager();
Logger.debug("MySQL DB inited");
}
2016-05-09 23:04:56 +08:00
public static getInstance() {
if (this._instance === null) {
this._instance = new ObjectManagerRepository();
2016-12-27 23:09:47 +08:00
}
return this._instance;
}
2016-12-27 23:09:47 +08:00
2017-07-14 05:39:09 +08:00
public static async reset() {
await MySQLConnection.close();
this._instance = null;
}
2016-04-22 19:23:44 +08:00
2016-05-26 02:17:42 +08:00
2017-07-04 01:17:49 +08:00
get GalleryManager(): IGalleryManager {
return this._galleryManager;
}
2016-04-22 19:23:44 +08:00
2017-07-04 01:17:49 +08:00
set GalleryManager(value: IGalleryManager) {
this._galleryManager = value;
}
2016-04-22 19:23:44 +08:00
2017-07-04 01:17:49 +08:00
get UserManager(): IUserManager {
return this._userManager;
}
2016-04-22 19:23:44 +08:00
2017-07-04 01:17:49 +08:00
set UserManager(value: IUserManager) {
this._userManager = value;
}
2016-04-22 19:23:44 +08:00
2017-07-04 01:17:49 +08:00
get SearchManager(): ISearchManager {
return this._searchManager;
}
2016-05-05 00:34:54 +08:00
2017-07-04 01:17:49 +08:00
set SearchManager(value: ISearchManager) {
this._searchManager = value;
}
2016-05-05 00:34:54 +08:00
2017-07-04 01:17:49 +08:00
get SharingManager(): ISharingManager {
return this._sharingManager;
}
set SharingManager(value: ISharingManager) {
this._sharingManager = value;
}
}