Search in sources :

Example 1 with ICollection

use of com.tvd12.dahlia.ICollection in project dahlia by youngmonkeys.

the class LocalDatabase method createCollection.

@Override
public ICollection createCollection(Object setting) {
    CollectionSetting s = null;
    if (setting instanceof CollectionSetting) {
        s = (CollectionSetting) setting;
    } else if (setting instanceof File) {
        s = settingReader.readFileSetting((File) setting);
    } else if (setting instanceof InputStream) {
        s = settingReader.readInputStreamSetting((InputStream) setting);
    } else {
        String ss = (String) setting;
        if (ss.startsWith(PREFIX_FILE))
            s = settingReader.readFileSetting(ss.substring(PREFIX_FILE.length()));
        else if (ss.startsWith(PREFIX_CLASSPATH))
            s = settingReader.readFileSetting(ss.substring(PREFIX_CLASSPATH.length()));
        else
            s = settingReader.readJsonSetting(ss);
    }
    CommandCreateCollection command = new CommandCreateCollection(store.getId(), s);
    Collection collectionStore = commandExecutor.execute(command);
    LocalCollection collection = new LocalCollection(collectionStore, commandExecutor);
    collections.put(collectionStore.getName(), collection);
    return collection;
}
Also used : CollectionSetting(com.tvd12.dahlia.core.setting.CollectionSetting) InputStream(java.io.InputStream) CommandCreateCollection(com.tvd12.dahlia.core.command.CommandCreateCollection) CommandCreateCollection(com.tvd12.dahlia.core.command.CommandCreateCollection) Collection(com.tvd12.dahlia.core.entity.Collection) ICollection(com.tvd12.dahlia.ICollection) File(java.io.File)

Example 2 with ICollection

use of com.tvd12.dahlia.ICollection 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);
}
Also used : FindOptions(com.tvd12.dahlia.query.FindOptions) IDatabase(com.tvd12.dahlia.IDatabase) CollectionExistedException(com.tvd12.dahlia.exception.CollectionExistedException) DatabaseExistedException(com.tvd12.dahlia.exception.DatabaseExistedException) CollectionExistedException(com.tvd12.dahlia.exception.CollectionExistedException) DuplicatedIdException(com.tvd12.dahlia.exception.DuplicatedIdException) DatabaseExistedException(com.tvd12.dahlia.exception.DatabaseExistedException) EzyArray(com.tvd12.ezyfox.entity.EzyArray) DatabaseSetting(com.tvd12.dahlia.core.setting.DatabaseSetting) ICollection(com.tvd12.dahlia.ICollection) EzyObject(com.tvd12.ezyfox.entity.EzyObject) LocalDahlia(com.tvd12.dahlia.local.LocalDahlia) DuplicatedIdException(com.tvd12.dahlia.exception.DuplicatedIdException)

Example 3 with ICollection

use of com.tvd12.dahlia.ICollection 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);
}
Also used : FindOptions(com.tvd12.dahlia.query.FindOptions) IDatabase(com.tvd12.dahlia.IDatabase) CollectionExistedException(com.tvd12.dahlia.exception.CollectionExistedException) DatabaseExistedException(com.tvd12.dahlia.exception.DatabaseExistedException) CollectionExistedException(com.tvd12.dahlia.exception.CollectionExistedException) DuplicatedIdException(com.tvd12.dahlia.exception.DuplicatedIdException) DatabaseExistedException(com.tvd12.dahlia.exception.DatabaseExistedException) EzyArray(com.tvd12.ezyfox.entity.EzyArray) DatabaseSetting(com.tvd12.dahlia.core.setting.DatabaseSetting) ICollection(com.tvd12.dahlia.ICollection) EzyObject(com.tvd12.ezyfox.entity.EzyObject) LocalDahlia(com.tvd12.dahlia.local.LocalDahlia) DuplicatedIdException(com.tvd12.dahlia.exception.DuplicatedIdException)

Aggregations

ICollection (com.tvd12.dahlia.ICollection)3 IDatabase (com.tvd12.dahlia.IDatabase)2 DatabaseSetting (com.tvd12.dahlia.core.setting.DatabaseSetting)2 CollectionExistedException (com.tvd12.dahlia.exception.CollectionExistedException)2 DatabaseExistedException (com.tvd12.dahlia.exception.DatabaseExistedException)2 DuplicatedIdException (com.tvd12.dahlia.exception.DuplicatedIdException)2 LocalDahlia (com.tvd12.dahlia.local.LocalDahlia)2 FindOptions (com.tvd12.dahlia.query.FindOptions)2 EzyArray (com.tvd12.ezyfox.entity.EzyArray)2 EzyObject (com.tvd12.ezyfox.entity.EzyObject)2 CommandCreateCollection (com.tvd12.dahlia.core.command.CommandCreateCollection)1 Collection (com.tvd12.dahlia.core.entity.Collection)1 CollectionSetting (com.tvd12.dahlia.core.setting.CollectionSetting)1 File (java.io.File)1 InputStream (java.io.InputStream)1