2019-12-15 00:27:01 +08:00
|
|
|
import {IUserManager} from './database/interfaces/IUserManager';
|
|
|
|
import {IGalleryManager} from './database/interfaces/IGalleryManager';
|
|
|
|
import {ISearchManager} from './database/interfaces/ISearchManager';
|
|
|
|
import {SQLConnection} from './database/sql/SQLConnection';
|
|
|
|
import {ISharingManager} from './database/interfaces/ISharingManager';
|
2018-03-31 03:30:30 +08:00
|
|
|
import {Logger} from '../Logger';
|
2019-12-15 00:27:01 +08:00
|
|
|
import {IIndexingManager} from './database/interfaces/IIndexingManager';
|
|
|
|
import {IPersonManager} from './database/interfaces/IPersonManager';
|
|
|
|
import {IVersionManager} from './database/interfaces/IVersionManager';
|
|
|
|
import {ITaskManager} from './database/interfaces/ITaskManager';
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2019-02-16 00:47:09 +08:00
|
|
|
export class ObjectManagers {
|
2016-05-09 23:04:56 +08:00
|
|
|
|
2019-02-16 00:47:09 +08:00
|
|
|
private static _instance: ObjectManagers = null;
|
2018-05-13 00:19:51 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
private _galleryManager: IGalleryManager;
|
|
|
|
private _userManager: IUserManager;
|
|
|
|
private _searchManager: ISearchManager;
|
2017-07-04 01:17:49 +08:00
|
|
|
private _sharingManager: ISharingManager;
|
2017-07-26 03:09:37 +08:00
|
|
|
private _indexingManager: IIndexingManager;
|
2019-01-14 00:38:39 +08:00
|
|
|
private _personManager: IPersonManager;
|
2019-02-16 00:47:09 +08:00
|
|
|
private _versionManager: IVersionManager;
|
2019-07-28 04:56:12 +08:00
|
|
|
private _taskManager: ITaskManager;
|
2019-02-16 00:47:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
get VersionManager(): IVersionManager {
|
|
|
|
return this._versionManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
set VersionManager(value: IVersionManager) {
|
|
|
|
this._versionManager = value;
|
|
|
|
}
|
2019-01-14 00:38:39 +08:00
|
|
|
|
|
|
|
get PersonManager(): IPersonManager {
|
|
|
|
return this._personManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
set PersonManager(value: IPersonManager) {
|
|
|
|
this._personManager = value;
|
|
|
|
}
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2017-07-26 03:09:37 +08:00
|
|
|
get IndexingManager(): IIndexingManager {
|
|
|
|
return this._indexingManager;
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
|
|
|
|
2017-07-26 03:09:37 +08:00
|
|
|
set IndexingManager(value: IIndexingManager) {
|
|
|
|
this._indexingManager = value;
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-05-09 23:04:56 +08:00
|
|
|
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
get GalleryManager(): IGalleryManager {
|
2017-06-11 04:32:56 +08:00
|
|
|
return this._galleryManager;
|
|
|
|
}
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
set GalleryManager(value: IGalleryManager) {
|
2017-06-11 04:32:56 +08:00
|
|
|
this._galleryManager = value;
|
|
|
|
}
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
get UserManager(): IUserManager {
|
2017-06-11 04:32:56 +08:00
|
|
|
return this._userManager;
|
|
|
|
}
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
set UserManager(value: IUserManager) {
|
2017-06-11 04:32:56 +08:00
|
|
|
this._userManager = value;
|
|
|
|
}
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
get SearchManager(): ISearchManager {
|
2017-06-11 04:32:56 +08:00
|
|
|
return this._searchManager;
|
|
|
|
}
|
2016-05-05 00:34:54 +08:00
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
set SearchManager(value: ISearchManager) {
|
2017-06-11 04:32:56 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-07-28 04:56:12 +08:00
|
|
|
get TaskManager(): ITaskManager {
|
|
|
|
return this._taskManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
set TaskManager(value: ITaskManager) {
|
|
|
|
this._taskManager = value;
|
|
|
|
}
|
|
|
|
|
2019-01-14 00:38:39 +08:00
|
|
|
public static getInstance() {
|
|
|
|
if (this._instance === null) {
|
2019-02-16 00:47:09 +08:00
|
|
|
this._instance = new ObjectManagers();
|
2019-01-14 00:38:39 +08:00
|
|
|
}
|
|
|
|
return this._instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static async reset() {
|
2019-12-06 22:53:34 +08:00
|
|
|
if (ObjectManagers.getInstance().TaskManager) {
|
|
|
|
ObjectManagers.getInstance().TaskManager.stopSchedules();
|
|
|
|
}
|
2019-01-14 00:38:39 +08:00
|
|
|
await SQLConnection.close();
|
|
|
|
this._instance = null;
|
|
|
|
}
|
|
|
|
|
2019-12-06 22:53:34 +08:00
|
|
|
|
|
|
|
public static async InitCommonManagers() {
|
|
|
|
const TaskManager = require('./tasks/TaskManager').TaskManager;
|
|
|
|
ObjectManagers.getInstance().TaskManager = new TaskManager();
|
|
|
|
}
|
|
|
|
|
2017-07-26 03:09:37 +08:00
|
|
|
public static async InitMemoryManagers() {
|
2019-02-16 00:47:09 +08:00
|
|
|
await ObjectManagers.reset();
|
2019-12-15 00:27:01 +08:00
|
|
|
const GalleryManager = require('./database/memory/GalleryManager').GalleryManager;
|
|
|
|
const UserManager = require('./database/memory/UserManager').UserManager;
|
|
|
|
const SearchManager = require('./database/memory/SearchManager').SearchManager;
|
|
|
|
const SharingManager = require('./database/memory/SharingManager').SharingManager;
|
|
|
|
const IndexingManager = require('./database/memory/IndexingManager').IndexingManager;
|
|
|
|
const PersonManager = require('./database/memory/PersonManager').PersonManager;
|
|
|
|
const VersionManager = require('./database/memory/VersionManager').VersionManager;
|
2019-02-16 00:47:09 +08:00
|
|
|
ObjectManagers.getInstance().GalleryManager = new GalleryManager();
|
|
|
|
ObjectManagers.getInstance().UserManager = new UserManager();
|
|
|
|
ObjectManagers.getInstance().SearchManager = new SearchManager();
|
|
|
|
ObjectManagers.getInstance().SharingManager = new SharingManager();
|
|
|
|
ObjectManagers.getInstance().IndexingManager = new IndexingManager();
|
|
|
|
ObjectManagers.getInstance().PersonManager = new PersonManager();
|
|
|
|
ObjectManagers.getInstance().VersionManager = new VersionManager();
|
2019-12-06 22:53:34 +08:00
|
|
|
this.InitCommonManagers();
|
2017-07-26 03:09:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static async InitSQLManagers() {
|
2019-02-16 00:47:09 +08:00
|
|
|
await ObjectManagers.reset();
|
2017-07-26 03:09:37 +08:00
|
|
|
await SQLConnection.init();
|
2019-12-15 00:27:01 +08:00
|
|
|
const GalleryManager = require('./database/sql/GalleryManager').GalleryManager;
|
|
|
|
const UserManager = require('./database/sql/UserManager').UserManager;
|
|
|
|
const SearchManager = require('./database/sql/SearchManager').SearchManager;
|
|
|
|
const SharingManager = require('./database/sql/SharingManager').SharingManager;
|
|
|
|
const IndexingManager = require('./database/sql/IndexingManager').IndexingManager;
|
|
|
|
const PersonManager = require('./database/sql/PersonManager').PersonManager;
|
|
|
|
const VersionManager = require('./database/sql/VersionManager').VersionManager;
|
2019-02-16 00:47:09 +08:00
|
|
|
ObjectManagers.getInstance().GalleryManager = new GalleryManager();
|
|
|
|
ObjectManagers.getInstance().UserManager = new UserManager();
|
|
|
|
ObjectManagers.getInstance().SearchManager = new SearchManager();
|
|
|
|
ObjectManagers.getInstance().SharingManager = new SharingManager();
|
|
|
|
ObjectManagers.getInstance().IndexingManager = new IndexingManager();
|
|
|
|
ObjectManagers.getInstance().PersonManager = new PersonManager();
|
|
|
|
ObjectManagers.getInstance().VersionManager = new VersionManager();
|
2019-12-06 22:53:34 +08:00
|
|
|
this.InitCommonManagers();
|
2018-03-31 03:30:30 +08:00
|
|
|
Logger.debug('SQL DB inited');
|
2017-07-26 03:09:37 +08:00
|
|
|
}
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|