Search in sources :

Example 21 with Database

use of com.tvd12.dahlia.core.entity.Database in project dahlia by youngmonkeys.

the class CommandCreateCollectionHandler method handle.

@Override
public Object handle(CommandCreateCollection command) {
    int databaseId = command.getDatabaseId();
    CollectionSetting setting = command.getSetting();
    String collectionName = setting.getCollectionName();
    Database database = databases.getDatabase(databaseId);
    if (database == null)
        throw new DatabaseNotFoundException(databaseId);
    Collection existedCollection = database.getCollection(collectionName);
    if (existedCollection != null)
        throw new CollectionExistedException(collectionName);
    int recordSize = recordSizeReader.read(setting.getAllFields());
    setting.setRecordSize(recordSize);
    Collection collection = collectionFactory.newCollection(setting);
    synchronized (runtimeSetting) {
        runtimeSetting.setMaxCollectionId(collection.getId());
        storage.storeRuntimeSetting(runtimeSetting);
    }
    database.addCollection(collection);
    databases.addCollection(collection);
    CollectionStorage collectionStorage = collectionStorageFactory.newCollectionStorage(collectionName, database.getName());
    storage.addCollectionStorage(collection.getId(), collectionStorage);
    collectionStorage.storeSetting(setting);
    return collection;
}
Also used : CollectionSetting(com.tvd12.dahlia.core.setting.CollectionSetting) DatabaseNotFoundException(com.tvd12.dahlia.exception.DatabaseNotFoundException) CollectionExistedException(com.tvd12.dahlia.exception.CollectionExistedException) Database(com.tvd12.dahlia.core.entity.Database) CommandCreateCollection(com.tvd12.dahlia.core.command.CommandCreateCollection) Collection(com.tvd12.dahlia.core.entity.Collection) CollectionStorage(com.tvd12.dahlia.core.storage.CollectionStorage)

Example 22 with Database

use of com.tvd12.dahlia.core.entity.Database in project dahlia by youngmonkeys.

the class CommandCreateDatabaseHandler method handle.

@Override
public Object handle(CommandCreateDatabase command) {
    DatabaseSetting setting = command.getSetting();
    String databaseName = setting.getDatabaseName();
    Database existedDatabase = databases.getDatabase(databaseName);
    if (existedDatabase != null)
        throw new DatabaseExistedException(databaseName);
    Database database = databaseFactory.newDatabase(setting);
    synchronized (runtimeSetting) {
        runtimeSetting.setMaxDatabaseId(database.getId());
        storage.storeRuntimeSetting(runtimeSetting);
    }
    databases.addDatabase(database);
    DatabaseStorage databaseStorage = databaseStorageFactory.newDatabaseStorage(databaseName);
    storage.addDatabaseStorage(database.getId(), databaseStorage);
    databaseStorage.storeSetting(setting);
    return database;
}
Also used : Database(com.tvd12.dahlia.core.entity.Database) CommandCreateDatabase(com.tvd12.dahlia.core.command.CommandCreateDatabase) DatabaseExistedException(com.tvd12.dahlia.exception.DatabaseExistedException) DatabaseSetting(com.tvd12.dahlia.core.setting.DatabaseSetting) DatabaseStorage(com.tvd12.dahlia.core.storage.DatabaseStorage)

Example 23 with Database

use of com.tvd12.dahlia.core.entity.Database in project dahlia by youngmonkeys.

the class DahliaCoreLoader method newDatabases.

protected Databases newDatabases(DatabaseFactory databaseFactory, CollectionFactory collectionFactory, Map<String, DatabaseSetting> databaseSettings, Map<String, List<CollectionSetting>> collectionSettingsMap) {
    Databases databases = new Databases();
    for (String databaseName : databaseSettings.keySet()) {
        DatabaseSetting databaseSetting = databaseSettings.get(databaseName);
        Database database = databaseFactory.createDatabase(databaseSetting);
        List<CollectionSetting> collectionSettings = collectionSettingsMap.get(databaseName);
        for (CollectionSetting collectionSetting : collectionSettings) {
            Collection collection = collectionFactory.createCollection(collectionSetting);
            database.addCollection(collection);
            databases.addCollection(collection);
        }
        databases.addDatabase(database);
    }
    return databases;
}
Also used : CollectionSetting(com.tvd12.dahlia.core.setting.CollectionSetting) Databases(com.tvd12.dahlia.core.entity.Databases) Database(com.tvd12.dahlia.core.entity.Database) DatabaseSetting(com.tvd12.dahlia.core.setting.DatabaseSetting) Collection(com.tvd12.dahlia.core.entity.Collection)

Aggregations

BaseTest (com.tvd12.test.base.BaseTest)12 Properties (java.util.Properties)12 Test (org.testng.annotations.Test)12 Database (com.tvd12.dahlia.core.entity.Database)8 DatabaseSetting (com.tvd12.dahlia.core.setting.DatabaseSetting)7 Collection (com.tvd12.dahlia.core.entity.Collection)5 CollectionExistedException (com.tvd12.dahlia.exception.CollectionExistedException)5 DatabaseExistedException (com.tvd12.dahlia.exception.DatabaseExistedException)5 CommandCreateDatabase (com.tvd12.dahlia.core.command.CommandCreateDatabase)4 CollectionSetting (com.tvd12.dahlia.core.setting.CollectionSetting)4 DuplicatedIdException (com.tvd12.dahlia.exception.DuplicatedIdException)4 FindOptions (com.tvd12.dahlia.query.FindOptions)4 EzyArray (com.tvd12.ezyfox.entity.EzyArray)4 EzyObject (com.tvd12.ezyfox.entity.EzyObject)4 IDatabase (com.tvd12.dahlia.IDatabase)3 CommandCreateCollection (com.tvd12.dahlia.core.command.CommandCreateCollection)3 ICollection (com.tvd12.dahlia.ICollection)2 DahliaCore (com.tvd12.dahlia.core.DahliaCore)2 DahliaCoreLoader (com.tvd12.dahlia.core.DahliaCoreLoader)2 CommandCount (com.tvd12.dahlia.core.command.CommandCount)2