use of com.tvd12.dahlia.core.setting.FieldSetting in project dahlia by youngmonkeys.
the class LocalCollectionSettingReader method readFieldObjectSetting.
protected FieldSetting readFieldObjectSetting(JSONObject setting) {
FieldObjectSetting field = new FieldObjectSetting();
if (setting.has(SettingFields.FIELDS)) {
JSONObject fieldSettings = setting.getJSONObject(SettingFields.FIELDS);
Map<String, FieldSetting> fields = readFieldSettings(fieldSettings);
field.setFields(fields);
} else {
throw new IllegalArgumentException("'fields' is required");
}
return field;
}
use of com.tvd12.dahlia.core.setting.FieldSetting in project dahlia by youngmonkeys.
the class LocalCollectionSettingReader method readFieldArraySetting.
protected FieldSetting readFieldArraySetting(JSONObject setting) {
FieldArraySetting field = new FieldArraySetting();
if (setting.has(SettingFields.MAX_SIZE))
field.setMaxSize(setting.getInt(SettingFields.MAX_SIZE));
if (setting.has(SettingFields.ITEM)) {
JSONObject itemSetting = setting.getJSONObject(SettingFields.ITEM);
DataType itemType = null;
if (itemSetting.has(SettingFields.TYPE))
itemType = DataType.valueOfName(itemSetting.getString(SettingFields.TYPE));
else
throw new IllegalArgumentException("item 'type' is required");
FieldSetting item = readFieldSetting(itemType, itemSetting);
field.setItem(item);
} else {
throw new IllegalArgumentException("'item' field is required");
}
return field;
}
use of com.tvd12.dahlia.core.setting.FieldSetting in project dahlia by youngmonkeys.
the class CommandInsertHandler method handle.
@Override
public Object handle(CommandInsert command) {
int collectionId = command.getCollectionId();
EzyArray data = command.getData();
Collection collection = databases.getCollection(collectionId);
CollectionSetting setting = collection.getSetting();
FieldSetting sId = setting.getId();
Map<String, FieldSetting> sFields = setting.getFields();
long dataSize = collection.getDataSize();
CollectionStorage collectionStorage = storage.getCollectionStorage(collectionId);
EzyArray answerItems = EzyEntityFactory.newArray();
synchronized (collection) {
for (int i = 0; i < data.size(); ++i) {
EzyObject answerItem = EzyEntityFactory.newObject();
EzyObject item = data.get(i);
Comparable id = item.get(Constants.FIELD_ID);
if (id != null) {
Record existed = collection.findById(id);
if (existed != null) {
answerItem.put(Constants.RESULT_FIELD_EXISTED, true);
answerItems.add(id);
continue;
}
} else {
while (true) {
id = UUID.randomUUID();
Record existed = collection.findById(id);
if (existed == null)
break;
}
}
Record record = new Record(id, dataSize);
collection.insert(record);
collection.increaseDataSize();
collectionStorage.storeRecord(record, sId, sFields, item);
answerItem.put(Constants.FIELD_ID, id);
answerItems.add(id);
}
}
return answerItems;
}
use of com.tvd12.dahlia.core.setting.FieldSetting in project dahlia by youngmonkeys.
the class FieldSimpleReaders method readValue.
@Override
public Object readValue(FileProxy file, FieldSetting setting) throws IOException {
FieldReader reader = readers.get(setting.getType());
Object value = reader.read(this, file, setting);
return value;
}
use of com.tvd12.dahlia.core.setting.FieldSetting in project dahlia by youngmonkeys.
the class FieldObjectWriter method writeValue.
@Override
protected void writeValue(FieldWriters writers, FileProxy file, FieldSetting setting, EzyObject value) throws IOException {
FieldObjectSetting fs = (FieldObjectSetting) setting;
Map<String, FieldSetting> fieldSettings = fs.getFields();
writers.write(file, fieldSettings, value);
}
Aggregations