use of com.tvd12.dahlia.core.setting.CollectionSetting 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.setting.CollectionSetting 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;
}
use of com.tvd12.dahlia.core.setting.CollectionSetting in project dahlia by youngmonkeys.
the class DahliaCoreLoader method readCollectionSettings.
protected Map<String, List<CollectionSetting>> readCollectionSettings(Map<String, List<CollectionStorage>> storages) {
Map<String, List<CollectionSetting>> settings = new HashMap<>();
for (String databaseName : storages.keySet()) {
List<CollectionSetting> collectionSettings = new ArrayList<>();
List<CollectionStorage> collectionStorages = storages.get(databaseName);
for (CollectionStorage storage : collectionStorages) {
CollectionSetting setting = storage.readSetting();
collectionSettings.add(setting);
}
settings.put(databaseName, collectionSettings);
}
return settings;
}
use of com.tvd12.dahlia.core.setting.CollectionSetting in project dahlia by youngmonkeys.
the class CollectionFactory method createCollection.
public Collection createCollection(CollectionSetting setting) {
Collection collection = new Collection(setting);
Map<String, IndexSetting> indexes = setting.getIndexes();
for (String indexName : indexes.keySet()) {
IndexSetting indexSetting = indexes.get(indexName);
Index index = new Index(indexSetting);
collection.addIndex(index);
}
return collection;
}
use of com.tvd12.dahlia.core.setting.CollectionSetting in project dahlia by youngmonkeys.
the class CollectionFactory method newCollection.
public Collection newCollection(CollectionSetting setting) {
int collectionId = maxCollectionId.incrementAndGet();
setting.setCollectionId(collectionId);
Collection collection = createCollection(setting);
return collection;
}
Aggregations