use of com.tvd12.ezyfox.entity.EzyArray in project dahlia by youngmonkeys.
the class LocalCollection method insert.
@Override
public EzyArray insert(EzyArray records) {
CommandInsert command = new CommandInsert(store.getId(), records);
EzyArray result = commandExecutor.execute(command);
return result;
}
use of com.tvd12.ezyfox.entity.EzyArray in project dahlia by youngmonkeys.
the class LocalCollection method update.
@Override
public EzyArray update(EzyObject query, EzyObject update) {
CommandUpdate command = new CommandUpdate(store.getId(), query, update);
EzyArray result = commandExecutor.execute(command);
return result;
}
use of com.tvd12.ezyfox.entity.EzyArray in project dahlia by youngmonkeys.
the class FirstTest 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_setting.json");
} catch (CollectionExistedException e) {
collection = database.getCollection("test");
}
EzyObject insertOneData1 = newObjectBuilder().append(SettingFields.ID, 2).append("value", 323L).append("name", "dungtv").build();
try {
EzyObject insertOneResult = collection.insert(insertOneData1);
System.out.println("insert one result 1: " + insertOneResult);
} catch (DuplicatedIdException e) {
} catch (Exception e) {
e.printStackTrace();
}
EzyObject insertOneData2 = newObjectBuilder().append(SettingFields.ID, 3).append("value", 325L).append("name", "dungtv").build();
try {
EzyObject insertOneResult = collection.insert(insertOneData2);
System.out.println("insert one result 2: " + insertOneResult);
} catch (DuplicatedIdException e) {
} catch (Exception e) {
e.printStackTrace();
}
EzyObject insertOneData3 = newObjectBuilder().append(SettingFields.ID, 4).append("value", 321L).append("name", "dungtv").build();
try {
EzyObject insertOneResult = collection.insert(insertOneData3);
System.out.println("insert one result 3: " + 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(Keywords.LESS_THAN_EQUAL, newObjectBuilder().append("_id", 100L))).append(newObjectBuilder().append("value", 323L))).build();
FindOptions options = new FindOptions().setSkip(0).setLimit(10).sortBy("value");
EzyArray findResult = collection.find(query3, options);
System.out.println("findResult = " + findResult);
Long size = collection.count();
System.out.println("size: " + size);
}
use of com.tvd12.ezyfox.entity.EzyArray in project dahlia by youngmonkeys.
the class DatabaseTest method main.
public static void main(String[] args) {
// deleteDataDir();
DahliaCoreLoader loader = new DahliaCoreLoader().storageDirectory("data");
DahliaCore dahlia = loader.load();
CommandExecutor commandExecutor = dahlia.getCommandExecutor();
DatabaseSetting databaseSetting = new DatabaseSetting();
databaseSetting.setDatabaseName("hello");
CommandCreateDatabase commandCreateDatabase = new CommandCreateDatabase(databaseSetting);
Database database = null;
try {
database = commandExecutor.execute(commandCreateDatabase);
} catch (DatabaseExistedException e) {
database = dahlia.getDatabases().getDatabase("hello");
}
CollectionSetting collectionSetting = new CollectionSetting();
collectionSetting.setCollectionId(1);
collectionSetting.setCollectionName("test");
Map<String, FieldSetting> fieldSettings = new HashMap<>();
FieldLongSetting fieldIdSetting = new FieldLongSetting();
fieldIdSetting.setNullable(true);
fieldIdSetting.setDefaultValue(100L);
fieldSettings.put("_id", fieldIdSetting);
FieldLongSetting fieldValueSetting = new FieldLongSetting();
fieldValueSetting.setNullable(true);
fieldValueSetting.setDefaultValue(300L);
fieldSettings.put("value", fieldValueSetting);
FieldTextSetting fieldNameSetting = new FieldTextSetting();
fieldNameSetting.setNullable(false);
fieldSettings.put("name", fieldNameSetting);
collectionSetting.setFields(fieldSettings);
System.out.println(collectionSetting.toMap());
CommandCreateCollection commandCreateCollection = new CommandCreateCollection(database.getId(), collectionSetting);
Collection collection = null;
try {
collection = commandExecutor.execute(commandCreateCollection);
} catch (CollectionExistedException e) {
collection = database.getCollection("test");
}
EzyObject insertOneData = newObjectBuilder().append("_id", 2L).append("value", 323L).append("name", "dungtv").build();
CommandInsertOne commandInsertOne = new CommandInsertOne(collection.getId(), insertOneData);
try {
EzyObject insertOneResult = commandExecutor.execute(commandInsertOne);
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(Keywords.LESS_THAN_EQUAL, newObjectBuilder().append("_id", 3L))).append(newObjectBuilder().append("value", 223))).build();
FindOptions options = new FindOptions().setSkip(0).setLimit(10);
CommandFind commandFind = new CommandFind(collection.getId(), query3, options.toObject());
EzyArray findResult = commandExecutor.execute(commandFind);
System.out.println("findResult = " + findResult);
Long size = dahlia.execute(new CommandCount(collection.getId()));
System.out.println("size: " + size);
}
use of com.tvd12.ezyfox.entity.EzyArray in project dahlia by youngmonkeys.
the class CommandFindHandler method getResult.
protected EzyArray getResult(List<EzyObject> list, int skip, int limit) {
EzyArray answer = EzyEntityFactory.newArray();
if (list.size() < skip)
return answer;
int min = Math.min(skip + limit, list.size());
for (int i = skip; i < min; ++i) answer.add(list.get(i));
return answer;
}
Aggregations