Search in sources :

Example 1 with Database

use of com.tvd12.dahlia.core.entity.Database in project dahlia by youngmonkeys.

the class LocalDahlia method createDatabase.

@Override
public IDatabase createDatabase(Object setting) {
    DatabaseSetting s = (DatabaseSetting) setting;
    CommandCreateDatabase command = new CommandCreateDatabase(s);
    Database databaseStore = commandExecutor.execute(command);
    LocalDatabase database = new LocalDatabase(databaseStore, commandExecutor);
    databases.put(databaseStore.getName(), database);
    return database;
}
Also used : CommandCreateDatabase(com.tvd12.dahlia.core.command.CommandCreateDatabase) Database(com.tvd12.dahlia.core.entity.Database) IDatabase(com.tvd12.dahlia.IDatabase) CommandCreateDatabase(com.tvd12.dahlia.core.command.CommandCreateDatabase) DatabaseSetting(com.tvd12.dahlia.core.setting.DatabaseSetting)

Example 2 with Database

use of com.tvd12.dahlia.core.entity.Database 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 Database

use of com.tvd12.dahlia.core.entity.Database in project dahlia by youngmonkeys.

the class DahliaCoreLoader method loadAllCollections.

protected void loadAllCollections(Databases databases, Storage storage) {
    for (Database database : databases.getDatabaseList()) {
        DatabaseStorage databaseStorage = storage.getDatabaseStore(database.getId());
        loadCollections(database, databaseStorage);
    }
}
Also used : Database(com.tvd12.dahlia.core.entity.Database) DatabaseStorage(com.tvd12.dahlia.core.storage.DatabaseStorage)

Example 4 with Database

use of com.tvd12.dahlia.core.entity.Database in project dahlia by youngmonkeys.

the class DahliaCoreLoader method loadCollections.

protected void loadCollections(Database database, DatabaseStorage storage) {
    for (Collection collection : database.getCollectionList()) {
        CollectionStorage collectionStorage = storage.getCollectionStorage(collection.getId());
        loadCollection(collection, collectionStorage);
    }
}
Also used : Collection(com.tvd12.dahlia.core.entity.Collection) CollectionStorage(com.tvd12.dahlia.core.storage.CollectionStorage)

Example 5 with Database

use of com.tvd12.dahlia.core.entity.Database in project properties-file by tvd12.

the class PropertiesUtilTest method getFirstPropertyKeysWithFirstDotIndex0.

@Test
public void getFirstPropertyKeysWithFirstDotIndex0() {
    // given
    Properties properties = new Properties();
    properties.put("", "foo");
    properties.put(".", "database");
    properties.put("hello", "world");
    properties.put("hello.1", "world");
    properties.put("hello1.2", "world");
    // when
    Set<String> actual = PropertiesUtil.getFirstPropertyKeys(properties);
    // then
    Set<String> expected = new HashSet<>(Arrays.asList("", ".", "hello", "hello1"));
    assertEquals(actual, expected);
}
Also used : Properties(java.util.Properties) HashSet(java.util.HashSet) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Aggregations

BaseTest (com.tvd12.test.base.BaseTest)12 Properties (java.util.Properties)12 Test (org.testng.annotations.Test)12 Database (com.tvd12.dahlia.core.entity.Database)8 DatabaseSetting (com.tvd12.dahlia.core.setting.DatabaseSetting)7 Collection (com.tvd12.dahlia.core.entity.Collection)5 CollectionExistedException (com.tvd12.dahlia.exception.CollectionExistedException)5 DatabaseExistedException (com.tvd12.dahlia.exception.DatabaseExistedException)5 CommandCreateDatabase (com.tvd12.dahlia.core.command.CommandCreateDatabase)4 CollectionSetting (com.tvd12.dahlia.core.setting.CollectionSetting)4 DuplicatedIdException (com.tvd12.dahlia.exception.DuplicatedIdException)4 FindOptions (com.tvd12.dahlia.query.FindOptions)4 EzyArray (com.tvd12.ezyfox.entity.EzyArray)4 EzyObject (com.tvd12.ezyfox.entity.EzyObject)4 IDatabase (com.tvd12.dahlia.IDatabase)3 CommandCreateCollection (com.tvd12.dahlia.core.command.CommandCreateCollection)3 ICollection (com.tvd12.dahlia.ICollection)2 DahliaCore (com.tvd12.dahlia.core.DahliaCore)2 DahliaCoreLoader (com.tvd12.dahlia.core.DahliaCoreLoader)2 CommandCount (com.tvd12.dahlia.core.command.CommandCount)2