Search in sources :

Example 1 with DatabaseStorage

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);
    }
}
Also used : Database(com.tvd12.dahlia.core.entity.Database) DatabaseStorage(com.tvd12.dahlia.core.storage.DatabaseStorage)

Example 2 with 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;
}
Also used : HashMap(java.util.HashMap) DatabaseSetting(com.tvd12.dahlia.core.setting.DatabaseSetting) DatabaseStorage(com.tvd12.dahlia.core.storage.DatabaseStorage)

Example 3 with DatabaseStorage

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);
    }
}
Also used : Collection(com.tvd12.dahlia.core.entity.Collection) CollectionStorage(com.tvd12.dahlia.core.storage.CollectionStorage)

Example 4 with DatabaseStorage

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;
}
Also used : CollectionFactory(com.tvd12.dahlia.core.factory.CollectionFactory) RuntimeSetting(com.tvd12.dahlia.core.setting.RuntimeSetting) Storage(com.tvd12.dahlia.core.storage.Storage) DatabaseStorage(com.tvd12.dahlia.core.storage.DatabaseStorage) CollectionStorage(com.tvd12.dahlia.core.storage.CollectionStorage) Databases(com.tvd12.dahlia.core.entity.Databases) DatabaseFactory(com.tvd12.dahlia.core.factory.DatabaseFactory) DatabaseSetting(com.tvd12.dahlia.core.setting.DatabaseSetting) ArrayList(java.util.ArrayList) List(java.util.List) DatabaseStorage(com.tvd12.dahlia.core.storage.DatabaseStorage)

Example 5 with DatabaseStorage

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;
}
Also used : CollectionSetting(com.tvd12.dahlia.core.setting.CollectionSetting) Storage(com.tvd12.dahlia.core.storage.Storage) DatabaseStorage(com.tvd12.dahlia.core.storage.DatabaseStorage) CollectionStorage(com.tvd12.dahlia.core.storage.CollectionStorage) DatabaseSetting(com.tvd12.dahlia.core.setting.DatabaseSetting) CollectionStorage(com.tvd12.dahlia.core.storage.CollectionStorage) DatabaseStorage(com.tvd12.dahlia.core.storage.DatabaseStorage)

Aggregations

DatabaseStorage (com.tvd12.dahlia.core.storage.DatabaseStorage)6 DatabaseSetting (com.tvd12.dahlia.core.setting.DatabaseSetting)4 CollectionStorage (com.tvd12.dahlia.core.storage.CollectionStorage)3 Database (com.tvd12.dahlia.core.entity.Database)2 Storage (com.tvd12.dahlia.core.storage.Storage)2 HashMap (java.util.HashMap)2 CommandCreateDatabase (com.tvd12.dahlia.core.command.CommandCreateDatabase)1 Collection (com.tvd12.dahlia.core.entity.Collection)1 Databases (com.tvd12.dahlia.core.entity.Databases)1 CollectionFactory (com.tvd12.dahlia.core.factory.CollectionFactory)1 DatabaseFactory (com.tvd12.dahlia.core.factory.DatabaseFactory)1 CollectionSetting (com.tvd12.dahlia.core.setting.CollectionSetting)1 RuntimeSetting (com.tvd12.dahlia.core.setting.RuntimeSetting)1 DatabaseExistedException (com.tvd12.dahlia.exception.DatabaseExistedException)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1