use of com.tvd12.dahlia.core.setting.IndexSetting in project dahlia by youngmonkeys.
the class LocalCollectionSettingReader method readIndexSettings.
protected List<IndexSetting> readIndexSettings(JSONObject settings) {
List<IndexSetting> answer = new ArrayList<>();
for (String indexName : settings.keySet()) {
JSONObject fieldSettings = settings.getJSONObject(indexName);
Map<String, Boolean> fields = readIndexFieldSettings(fieldSettings);
answer.add(new IndexSetting(indexName, fields));
}
return answer;
}
use of com.tvd12.dahlia.core.setting.IndexSetting in project dahlia by youngmonkeys.
the class CollectionFactory method createCollection.
public Collection createCollection(CollectionSetting setting) {
Collection collection = new Collection(setting);
Map<String, IndexSetting> indexes = setting.getIndexes();
for (String indexName : indexes.keySet()) {
IndexSetting indexSetting = indexes.get(indexName);
Index index = new Index(indexSetting);
collection.addIndex(index);
}
return collection;
}
use of com.tvd12.dahlia.core.setting.IndexSetting in project dahlia by youngmonkeys.
the class Indexes method addIndex.
public void addIndex(Index index) {
IndexSetting setting = index.getSetting();
String indexName = setting.getIndexName();
Map<String, Boolean> fields = setting.getFields();
this.indexesByName.put(indexName, index);
this.indexBySetting.put(setting, index);
for (String fieldName : fields.keySet()) {
this.indexesByFieldName.computeIfAbsent(fieldName, k -> new HashSet<>()).add(index);
}
}
use of com.tvd12.dahlia.core.setting.IndexSetting in project dahlia by youngmonkeys.
the class DatabaseTest2 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("test2");
Map<String, FieldSetting> fieldSettings = new HashMap<>();
FieldUuidSetting fieldIdSetting = new FieldUuidSetting();
fieldIdSetting.setNullable(true);
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);
IndexSetting nameIndexSetting = new IndexSetting("nameIndex", EzyMaps.newHashMap("name", true));
collectionSetting.setIndexes(Lists.newArrayList(nameIndexSetting));
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("test2");
}
EzyObject insertOneData = newObjectBuilder().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("value", 323))).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);
}
Aggregations