Search in sources :

Example 1 with FieldSetting

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;
}
Also used : FieldSetting(com.tvd12.dahlia.core.setting.FieldSetting) JSONObject(org.json.JSONObject) FieldObjectSetting(com.tvd12.dahlia.core.setting.FieldObjectSetting)

Example 2 with FieldSetting

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;
}
Also used : FieldSetting(com.tvd12.dahlia.core.setting.FieldSetting) FieldArraySetting(com.tvd12.dahlia.core.setting.FieldArraySetting) JSONObject(org.json.JSONObject) DataType(com.tvd12.dahlia.core.data.DataType)

Example 3 with FieldSetting

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;
}
Also used : FieldSetting(com.tvd12.dahlia.core.setting.FieldSetting) CollectionSetting(com.tvd12.dahlia.core.setting.CollectionSetting) EzyArray(com.tvd12.ezyfox.entity.EzyArray) Collection(com.tvd12.dahlia.core.entity.Collection) Record(com.tvd12.dahlia.core.entity.Record) EzyObject(com.tvd12.ezyfox.entity.EzyObject) CollectionStorage(com.tvd12.dahlia.core.storage.CollectionStorage)

Example 4 with FieldSetting

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;
}
Also used : EzyObject(com.tvd12.ezyfox.entity.EzyObject)

Example 5 with FieldSetting

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);
}
Also used : FieldSetting(com.tvd12.dahlia.core.setting.FieldSetting) FieldObjectSetting(com.tvd12.dahlia.core.setting.FieldObjectSetting)

Aggregations

FieldSetting (com.tvd12.dahlia.core.setting.FieldSetting)25 EzyObject (com.tvd12.ezyfox.entity.EzyObject)20 CollectionSetting (com.tvd12.dahlia.core.setting.CollectionSetting)11 EzyArray (com.tvd12.ezyfox.entity.EzyArray)10 Collection (com.tvd12.dahlia.core.entity.Collection)9 Record (com.tvd12.dahlia.core.entity.Record)9 CollectionStorage (com.tvd12.dahlia.core.storage.CollectionStorage)7 RecordConsumer (com.tvd12.dahlia.core.function.RecordConsumer)5 CollectionNotFoundException (com.tvd12.dahlia.exception.CollectionNotFoundException)5 FieldArraySetting (com.tvd12.dahlia.core.setting.FieldArraySetting)4 FieldObjectSetting (com.tvd12.dahlia.core.setting.FieldObjectSetting)4 HashMap (java.util.HashMap)4 DataType (com.tvd12.dahlia.core.data.DataType)3 ArrayList (java.util.ArrayList)3 JSONObject (org.json.JSONObject)3 DahliaCore (com.tvd12.dahlia.core.DahliaCore)2 DahliaCoreLoader (com.tvd12.dahlia.core.DahliaCoreLoader)2 CommandCount (com.tvd12.dahlia.core.command.CommandCount)2 CommandCreateCollection (com.tvd12.dahlia.core.command.CommandCreateCollection)2 CommandCreateDatabase (com.tvd12.dahlia.core.command.CommandCreateDatabase)2