use of com.tvd12.ezyfoxserver.client.entity.EzyObject 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.ezyfoxserver.client.entity.EzyObject in project dahlia by youngmonkeys.
the class CommandUpdateHandler method updateItem.
protected void updateItem(EzyObject item, EzyObject update) {
for (Object key : update.keySet()) {
Object updateValue = update.get(key);
if (updateValue instanceof EzyObject) {
EzyObject itemValue = item.get(key);
updateItem(itemValue, (EzyObject) updateValue);
} else {
item.put(key, updateValue);
}
}
}
use of com.tvd12.ezyfoxserver.client.entity.EzyObject in project dahlia by youngmonkeys.
the class QueryToPredicate method toDefaultPredicate.
protected Predicate<EzyObject> toDefaultPredicate(EzyObject query) {
for (Entry kv : query.entrySet()) {
String field = null;
Object value = kv.getValue();
String fieldOrOperation = (String) kv.getKey();
Operation operation = Operation.valueOfKeyword(fieldOrOperation);
if (operation != null) {
EzyObject oValue = (EzyObject) value;
for (Entry e : oValue.entrySet()) {
field = (String) e.getKey();
value = e.getValue();
break;
}
} else if (value instanceof EzyObject) {
EzyObject oValue = (EzyObject) value;
for (Entry e : oValue.entrySet()) {
String keyword = (String) e.getKey();
operation = Operation.valueOfKeyword(keyword);
value = e.getValue();
break;
}
} else {
field = fieldOrOperation;
operation = Operation.EQ;
}
String qField = field;
Object qValue = value;
Operation qOperation = operation;
return record -> {
Object rValue = record.get(qField);
int compareResult = compareValue(rValue, qValue);
if (qOperation == Operation.GT)
return compareResult > 0;
if (qOperation == Operation.GTE)
return compareResult >= 0;
if (qOperation == Operation.LT)
return compareResult < 0;
if (qOperation == Operation.LTE)
return compareResult <= 0;
if (qOperation == Operation.NEQ)
return compareResult != 0;
return compareResult == 0;
};
}
return record -> false;
}
use of com.tvd12.ezyfoxserver.client.entity.EzyObject 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);
}
use of com.tvd12.ezyfoxserver.client.entity.EzyObject in project dahlia by youngmonkeys.
the class SecondTest method main.
public static void main(String[] args) {
deleteDataDir();
LocalDahlia dahlia = new LocalDahlia("data");
DatabaseSetting databaseSetting = new DatabaseSetting();
databaseSetting.setDatabaseName("hello");
IDatabase database = null;
try {
database = dahlia.createDatabase(databaseSetting);
} catch (DatabaseExistedException e) {
database = dahlia.getDatabase("hello");
}
ICollection collection = null;
try {
collection = database.createCollection("classpath:hello_test_setting2.json");
} catch (CollectionExistedException e) {
collection = database.getCollection("test");
}
EzyObject insertOneData = newObjectBuilder().append("value", 323L).append("name", "dungtv").build();
try {
EzyObject insertOneResult = collection.insert(insertOneData);
System.out.println("insert one result: " + insertOneResult);
} catch (DuplicatedIdException e) {
} catch (Exception e) {
e.printStackTrace();
}
long v1 = 1;
double v2 = 1.1;
System.out.println(v2 == v1);
// EzyObject query1 = newObjectBuilder()
// .append("_id", newObjectBuilder().append(Keywords.LESS_THAN_EQUAL, 3L))
// .build();
// CommandFindOne findOne = new CommandFindOne(collection.getId(), query1);
// EzyObject findOneResult = commandExecutor.execute(findOne);
// System.out.println("findOneResult: " + findOneResult);
// EzyObject query2 = newObjectBuilder()
// .append(Keywords.OR, newArrayBuilder()
// .append(newObjectBuilder().append("_id", newObjectBuilder().append(Keywords.LESS_THAN_EQUAL, 3L)))
// .append(newObjectBuilder().append("value", 223))
// )
// .build();
EzyObject query3 = newObjectBuilder().append(Keywords.OR, newArrayBuilder().append(newObjectBuilder().append("value", 323L))).build();
FindOptions options = new FindOptions().setSkip(0).setLimit(10);
EzyArray findResult = collection.find(query3, options);
System.out.println("findResult = " + findResult);
Long size = collection.count();
System.out.println("size: " + size);
}
Aggregations