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