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