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

74 lines
2.5 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";
2016-04-22 19:23:44 +08:00
2016-05-09 23:04:56 +08:00
export class ObjectManagerRepository {
2016-12-27 23:09:47 +08:00
private _galleryManager: IGalleryManager;
private _userManager: IUserManager;
private _searchManager: ISearchManager;
private static _instance: ObjectManagerRepository = null;
2016-04-22 19:23:44 +08:00
2016-12-27 23:09:47 +08:00
public static InitMemoryManagers() {
const GalleryManager = require("./memory/GalleryManager").GalleryManager;
const UserManager = require("./memory/UserManager").UserManager;
const SearchManager = require("./memory/SearchManager").SearchManager;
2016-04-22 19:23:44 +08:00
ObjectManagerRepository.getInstance().setGalleryManager(new GalleryManager());
ObjectManagerRepository.getInstance().setUserManager(new UserManager());
2016-05-05 00:34:54 +08:00
ObjectManagerRepository.getInstance().setSearchManager(new SearchManager());
2016-04-22 19:23:44 +08:00
}
2016-05-09 23:04:56 +08:00
2016-12-27 23:09:47 +08:00
public static InitMySQLManagers(): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
MySQLConnection.init().then(() => {
2016-12-28 03:55:51 +08:00
const GalleryManager = require("./mysql/GalleryManager").GalleryManager;
2016-12-27 23:09:47 +08:00
const UserManager = require("./mysql/UserManager").UserManager;
2016-12-28 18:50:05 +08:00
const SearchManager = require("./mysql/SearchManager").SearchManager;
2016-12-27 23:09:47 +08:00
ObjectManagerRepository.getInstance().setGalleryManager(new GalleryManager());
ObjectManagerRepository.getInstance().setUserManager(new UserManager());
ObjectManagerRepository.getInstance().setSearchManager(new SearchManager());
2016-12-29 22:18:23 +08:00
console.log("MySQL DB inited");
2016-12-27 23:09:47 +08:00
resolve(true);
}).catch(err => reject(err));
});
}
2016-05-09 23:04:56 +08:00
public static getInstance() {
if (this._instance === null) {
2016-04-22 19:23:44 +08:00
this._instance = new ObjectManagerRepository();
}
return this._instance;
}
2016-05-26 02:17:42 +08:00
public static reset() {
this._instance = null;
}
2016-04-22 19:23:44 +08:00
2016-12-27 23:09:47 +08:00
getGalleryManager(): IGalleryManager {
2016-04-22 19:23:44 +08:00
return this._galleryManager;
}
2016-12-27 23:09:47 +08:00
setGalleryManager(value: IGalleryManager) {
2016-04-22 19:23:44 +08:00
this._galleryManager = value;
}
2016-12-27 23:09:47 +08:00
getUserManager(): IUserManager {
2016-04-22 19:23:44 +08:00
return this._userManager;
}
2016-12-27 23:09:47 +08:00
setUserManager(value: IUserManager) {
2016-04-22 19:23:44 +08:00
this._userManager = value;
}
2016-05-05 00:34:54 +08:00
2016-12-27 23:09:47 +08:00
getSearchManager(): ISearchManager {
2016-05-05 00:34:54 +08:00
return this._searchManager;
}
2016-12-27 23:09:47 +08:00
setSearchManager(value: ISearchManager) {
2016-05-05 00:34:54 +08:00
this._searchManager = value;
}
2016-04-22 19:23:44 +08:00
}