use of com.tvd12.dahlia.core.storage.DatabaseStorage in project dahlia by youngmonkeys.
the class DahliaCoreLoader method loadAllCollections.
protected void loadAllCollections(Databases databases, Storage storage) {
for (Database database : databases.getDatabaseList()) {
DatabaseStorage databaseStorage = storage.getDatabaseStore(database.getId());
loadCollections(database, databaseStorage);
}
}
use of com.tvd12.dahlia.core.storage.DatabaseStorage in project dahlia by youngmonkeys.
the class DahliaCoreLoader method readDatabaseSettings.
protected Map<String, DatabaseSetting> readDatabaseSettings(Map<String, DatabaseStorage> storages) {
Map<String, DatabaseSetting> settings = new HashMap<>();
for (String databaseName : storages.keySet()) {
DatabaseStorage storage = storages.get(databaseName);
DatabaseSetting setting = storage.readSetting();
settings.put(databaseName, setting);
}
return settings;
}
use of com.tvd12.dahlia.core.storage.DatabaseStorage in project dahlia by youngmonkeys.
the class DahliaCoreLoader method loadCollections.
protected void loadCollections(Database database, DatabaseStorage storage) {
for (Collection collection : database.getCollectionList()) {
CollectionStorage collectionStorage = storage.getCollectionStorage(collection.getId());
loadCollection(collection, collectionStorage);
}
}
use of com.tvd12.dahlia.core.storage.DatabaseStorage in project dahlia by youngmonkeys.
the class DahliaCoreLoader method doLoad.
protected DahliaCore doLoad() {
Map<String, DatabaseStorage> databaseStoreages = newDatabaseStorages();
Set<String> databaseNames = databaseStoreages.keySet();
Map<String, List<CollectionStorage>> collectionStoragesMap = newDatabaseColectionsStorages(databaseNames);
Map<String, DatabaseSetting> databaseSettings = readDatabaseSettings(databaseStoreages);
Map<String, List<CollectionSetting>> collectionSettingsMap = readCollectionSettings(collectionStoragesMap);
Storage storage = newStorage(databaseStoreages, collectionStoragesMap, databaseSettings, collectionSettingsMap);
RuntimeSetting runtimeSetting = storage.readRuntimeSetting();
DatabaseFactory databaseFactory = new DatabaseFactory(runtimeSetting.getMaxDatabaseId());
CollectionFactory collectionFactory = new CollectionFactory(runtimeSetting.getMaxCollectionId());
Databases databases = newDatabases(databaseFactory, collectionFactory, databaseSettings, collectionSettingsMap);
loadAllCollections(databases, storage);
DahliaCore dahlia = DahliaCore.builder().storage(storage).databases(databases).runtimeSetting(runtimeSetting).databaseFactory(databaseFactory).collectionFactory(collectionFactory).databaseStorageFactory(databaseStorageFactory).collectionStorageFactory(collectionStorageFactory).build();
return dahlia;
}
use of com.tvd12.dahlia.core.storage.DatabaseStorage in project dahlia by youngmonkeys.
the class DahliaCoreLoader method newStorage.
protected Storage newStorage(Map<String, DatabaseStorage> databaseStoreages, Map<String, List<CollectionStorage>> collectionStoragesMap, Map<String, DatabaseSetting> databaseSettings, Map<String, List<CollectionSetting>> collectionSettingsMap) {
Storage storage = Storage.builder().directory(storageDirectory).objectSerializer(objectSerializer).objectDeserializer(objectDeserializer).build();
for (String databaseName : databaseStoreages.keySet()) {
DatabaseStorage databaseStorage = databaseStoreages.get(databaseName);
DatabaseSetting databaseSetting = databaseSettings.get(databaseName);
storage.addDatabaseStorage(databaseSetting.getDatabaseId(), databaseStorage);
}
for (String databaseName : databaseStoreages.keySet()) {
DatabaseStorage databaseStorage = databaseStoreages.get(databaseName);
List<CollectionSetting> collectionSettings = collectionSettingsMap.get(databaseName);
List<CollectionStorage> collectionStorages = collectionStoragesMap.get(databaseName);
for (int i = 0; i < collectionSettings.size(); ++i) {
CollectionSetting collectionSetting = collectionSettings.get(i);
CollectionStorage collectionStorage = collectionStorages.get(i);
databaseStorage.addCollectionStorage(collectionSetting.getCollectionId(), collectionStorage);
storage.addCollectionStorage(collectionSetting.getCollectionId(), collectionStorage);
}
}
return storage;
}
Aggregations