use of com.tvd12.dahlia.core.command.CommandSaveOne in project dahlia by youngmonkeys.
the class CommandSaveOneHandler method handle.
@Override
public Object handle(CommandSaveOne command) {
int collectionId = command.getCollectionId();
EzyObject data = command.getData();
Collection collection = databases.getCollection(collectionId);
CollectionSetting setting = collection.getSetting();
CollectionStorage collectionStorage = storage.getCollectionStorage(collectionId);
Comparable id = data.get(Constants.FIELD_ID);
EzyObject answer = EzyEntityFactory.newObject();
synchronized (collection) {
if (id != null) {
Record existed = collection.findById(id);
if (existed != null)
answer.put(Constants.RESULT_FIELD_EXISTED, true);
} else {
while (true) {
id = UUID.randomUUID();
Record existed = collection.findById(id);
if (existed == null)
break;
}
data.put(Constants.FIELD_ID, id);
}
Record record = new Record(id, collection.getDataSize());
collection.insert(record);
collection.increaseDataSize();
collectionStorage.storeRecord(record, setting.getId(), setting.getFields(), data);
}
answer.put(Constants.FIELD_ID, id);
return answer;
}
use of com.tvd12.dahlia.core.command.CommandSaveOne in project dahlia by youngmonkeys.
the class LocalCollection method save.
@Override
public EzyObject save(EzyObject record) {
CommandSaveOne command = new CommandSaveOne(store.getId(), record);
EzyObject result = commandExecutor.execute(command);
return result;
}
Aggregations