X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fperformance%2Fstorage%2FStorage.ts;h=39d0a1b30250b80fd825351f4d476792ef89a3a6;hb=64c14c99f9902d4e96f2a2cd404e536e0584a629;hp=c6cf28963cfda14dbce33507d5a8e914036edb6d;hpb=a19b897d3aa5cb0f12177a42d8168121ce6ada97;p=e-mobility-charging-stations-simulator.git diff --git a/src/performance/storage/Storage.ts b/src/performance/storage/Storage.ts index c6cf2896..39d0a1b3 100644 --- a/src/performance/storage/Storage.ts +++ b/src/performance/storage/Storage.ts @@ -9,25 +9,35 @@ import { type Statistics, StorageType } from '../../types/index.js' -import { logger, setDefaultErrorParams } from '../../utils/index.js' +import { logger } from '../../utils/index.js' export abstract class Storage { protected readonly storageUri: URL protected readonly logPrefix: string protected dbName!: string + private static readonly performanceStatistics = new Map() constructor (storageUri: string, logPrefix: string) { this.storageUri = new URL(storageUri) this.logPrefix = logPrefix } - protected handleDBError ( + protected handleDBStorageError ( type: StorageType, error: Error, table?: string, - params: HandleErrorParams = { throwError: false, consoleOut: false } + params: HandleErrorParams = { + throwError: false, + consoleOut: false + } ): void { - setDefaultErrorParams(params, { throwError: false, consoleOut: false }) + params = { + ...{ + throwError: false, + consoleOut: false + }, + ...params + } const inTableOrCollectionStr = table != null && ` in table or collection '${table}'` logger.error( `${this.logPrefix} ${this.getDBNameFromStorageType(type)} error '${ @@ -42,17 +52,29 @@ export abstract class Storage { protected getDBNameFromStorageType (type: StorageType): DBName | undefined { switch (type) { + case StorageType.SQLITE: + return DBName.SQLITE case StorageType.MARIA_DB: return DBName.MARIA_DB - case StorageType.MONGO_DB: - return DBName.MONGO_DB case StorageType.MYSQL: return DBName.MYSQL - case StorageType.SQLITE: - return DBName.SQLITE + case StorageType.MONGO_DB: + return DBName.MONGO_DB } } + public getPerformanceStatistics (): IterableIterator { + return Storage.performanceStatistics.values() + } + + protected setPerformanceStatistics (performanceStatistics: Statistics): void { + Storage.performanceStatistics.set(performanceStatistics.id, performanceStatistics) + } + + protected clearPerformanceStatistics (): void { + Storage.performanceStatistics.clear() + } + public abstract open (): void | Promise public abstract close (): void | Promise public abstract storePerformanceStatistics (