Search in sources :

Example 11 with CollectionSetting

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;
}
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 12 with CollectionSetting

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;
}
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)

Example 13 with CollectionSetting

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;
}
Also used : CollectionSetting(com.tvd12.dahlia.core.setting.CollectionSetting) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CollectionStorage(com.tvd12.dahlia.core.storage.CollectionStorage)

Example 14 with CollectionSetting

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

Example 15 with CollectionSetting

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

Aggregations

CollectionSetting (com.tvd12.dahlia.core.setting.CollectionSetting)22 Collection (com.tvd12.dahlia.core.entity.Collection)16 CollectionStorage (com.tvd12.dahlia.core.storage.CollectionStorage)13 EzyObject (com.tvd12.ezyfox.entity.EzyObject)13 FieldSetting (com.tvd12.dahlia.core.setting.FieldSetting)11 Record (com.tvd12.dahlia.core.entity.Record)10 EzyArray (com.tvd12.ezyfox.entity.EzyArray)8 RecordConsumer (com.tvd12.dahlia.core.function.RecordConsumer)5 DatabaseSetting (com.tvd12.dahlia.core.setting.DatabaseSetting)5 CollectionNotFoundException (com.tvd12.dahlia.exception.CollectionNotFoundException)5 ArrayList (java.util.ArrayList)5 CommandCreateCollection (com.tvd12.dahlia.core.command.CommandCreateCollection)4 Database (com.tvd12.dahlia.core.entity.Database)4 CollectionExistedException (com.tvd12.dahlia.exception.CollectionExistedException)3 DuplicatedIdException (com.tvd12.dahlia.exception.DuplicatedIdException)3 HashMap (java.util.HashMap)3 DahliaCore (com.tvd12.dahlia.core.DahliaCore)2 DahliaCoreLoader (com.tvd12.dahlia.core.DahliaCoreLoader)2 CommandCount (com.tvd12.dahlia.core.command.CommandCount)2 CommandCreateDatabase (com.tvd12.dahlia.core.command.CommandCreateDatabase)2