Search in sources :

Example 1 with DatabaseNotFoundException

use of com.tvd12.dahlia.exception.DatabaseNotFoundException 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)

Aggregations

CommandCreateCollection (com.tvd12.dahlia.core.command.CommandCreateCollection)1 Collection (com.tvd12.dahlia.core.entity.Collection)1 Database (com.tvd12.dahlia.core.entity.Database)1 CollectionSetting (com.tvd12.dahlia.core.setting.CollectionSetting)1 CollectionStorage (com.tvd12.dahlia.core.storage.CollectionStorage)1 CollectionExistedException (com.tvd12.dahlia.exception.CollectionExistedException)1 DatabaseNotFoundException (com.tvd12.dahlia.exception.DatabaseNotFoundException)1