Search in sources :

Example 1 with LitePalDB

use of org.litepal.LitePalDB in project LitePal by LitePalFramework.

the class MultiDatabaseTest method testMultiDatabase.

public void testMultiDatabase() {
    LitePal.deleteDatabase("db2");
    SQLiteDatabase db = LitePal.getDatabase();
    assertTrue(DBUtility.isTableExists("Album", db));
    assertTrue(DBUtility.isTableExists("Song", db));
    assertTrue(DBUtility.isTableExists("Singer", db));
    assertTrue(DBUtility.isTableExists("Classroom", db));
    assertTrue(DBUtility.isTableExists("Teacher", db));
    assertTrue(DBUtility.isTableExists("IdCard", db));
    assertTrue(DBUtility.isTableExists("Student", db));
    assertTrue(DBUtility.isTableExists("Cellphone", db));
    assertTrue(DBUtility.isTableExists("Computer", db));
    assertTrue(DBUtility.isTableExists("Book", db));
    assertTrue(DBUtility.isTableExists("Product", db));
    assertTrue(DBUtility.isTableExists("Headset", db));
    assertTrue(DBUtility.isTableExists("WeChatMessage", db));
    assertTrue(DBUtility.isTableExists("WeiboMessage", db));
    LitePalDB litePalDB = new LitePalDB("db2", 1);
    litePalDB.addClassName(Classroom.class.getName());
    litePalDB.addClassName(Product.class.getName());
    litePalDB.setExternalStorage(true);
    LitePal.use(litePalDB);
    db = LitePal.getDatabase();
    assertFalse(DBUtility.isTableExists("Album", db));
    assertFalse(DBUtility.isTableExists("Song", db));
    assertFalse(DBUtility.isTableExists("Singer", db));
    assertTrue(DBUtility.isTableExists("Classroom", db));
    assertFalse(DBUtility.isTableExists("Teacher", db));
    assertFalse(DBUtility.isTableExists("IdCard", db));
    assertFalse(DBUtility.isTableExists("Student", db));
    assertFalse(DBUtility.isTableExists("Cellphone", db));
    assertFalse(DBUtility.isTableExists("Computer", db));
    assertFalse(DBUtility.isTableExists("Book", db));
    assertTrue(DBUtility.isTableExists("Product", db));
    assertFalse(DBUtility.isTableExists("Headset", db));
    assertFalse(DBUtility.isTableExists("WeChatMessage", db));
    assertFalse(DBUtility.isTableExists("WeiboMessage", db));
    litePalDB = new LitePalDB("db2", 2);
    litePalDB.addClassName(Computer.class.getName());
    litePalDB.addClassName(Product.class.getName());
    litePalDB.addClassName(Headset.class.getName());
    litePalDB.setExternalStorage(true);
    LitePal.use(litePalDB);
    db = LitePal.getDatabase();
    assertFalse(DBUtility.isTableExists("Album", db));
    assertFalse(DBUtility.isTableExists("Song", db));
    assertFalse(DBUtility.isTableExists("Singer", db));
    assertFalse(DBUtility.isTableExists("Classroom", db));
    assertFalse(DBUtility.isTableExists("Teacher", db));
    assertFalse(DBUtility.isTableExists("IdCard", db));
    assertFalse(DBUtility.isTableExists("Student", db));
    assertFalse(DBUtility.isTableExists("Cellphone", db));
    assertTrue(DBUtility.isTableExists("Computer", db));
    assertFalse(DBUtility.isTableExists("Book", db));
    assertTrue(DBUtility.isTableExists("Product", db));
    assertTrue(DBUtility.isTableExists("Headset", db));
    assertFalse(DBUtility.isTableExists("WeChatMessage", db));
    assertFalse(DBUtility.isTableExists("WeiboMessage", db));
    LitePal.useDefault();
    db = LitePal.getDatabase();
    assertTrue(DBUtility.isTableExists("Album", db));
    assertTrue(DBUtility.isTableExists("Song", db));
    assertTrue(DBUtility.isTableExists("Singer", db));
    assertTrue(DBUtility.isTableExists("Classroom", db));
    assertTrue(DBUtility.isTableExists("Teacher", db));
    assertTrue(DBUtility.isTableExists("IdCard", db));
    assertTrue(DBUtility.isTableExists("Student", db));
    assertTrue(DBUtility.isTableExists("Cellphone", db));
    assertTrue(DBUtility.isTableExists("Computer", db));
    assertTrue(DBUtility.isTableExists("Book", db));
    assertTrue(DBUtility.isTableExists("Product", db));
    assertTrue(DBUtility.isTableExists("Headset", db));
    assertTrue(DBUtility.isTableExists("WeChatMessage", db));
    assertTrue(DBUtility.isTableExists("WeiboMessage", db));
}
Also used : Headset(com.litepaltest.model.Headset) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) LitePalDB(org.litepal.LitePalDB) Classroom(com.litepaltest.model.Classroom) Computer(com.litepaltest.model.Computer) Product(com.litepaltest.model.Product)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Classroom (com.litepaltest.model.Classroom)1 Computer (com.litepaltest.model.Computer)1 Headset (com.litepaltest.model.Headset)1 Product (com.litepaltest.model.Product)1 LitePalDB (org.litepal.LitePalDB)1