Search in sources :

Example 1 with CategoryDao

use of org.liberty.android.fantastischmemo.dao.CategoryDao in project AnyMemo by helloworld1.

the class DatabaseUtil method mergeDatabases.

public void mergeDatabases(String destPath, String srcPath) throws Exception {
    AnyMemoDBOpenHelper destHelper = AnyMemoDBOpenHelperManager.getHelper(mContext, destPath);
    AnyMemoDBOpenHelper srcHelper = AnyMemoDBOpenHelperManager.getHelper(mContext, srcPath);
    final CardDao cardDaoDest = destHelper.getCardDao();
    final LearningDataDao learningDataDaoSrc = srcHelper.getLearningDataDao();
    final CategoryDao categoryDaoSrc = srcHelper.getCategoryDao();
    final CardDao cardDaoSrc = srcHelper.getCardDao();
    final List<Card> srcCards = cardDaoSrc.queryForAll();
    cardDaoSrc.callBatchTasks(new Callable<Void>() {

        public Void call() throws Exception {
            for (Card c : srcCards) {
                // Make sure to create a new ordinal
                c.setOrdinal(null);
                learningDataDaoSrc.refresh(c.getLearningData());
                categoryDaoSrc.refresh(c.getCategory());
            }
            return null;
        }
    });
    cardDaoDest.createCards(srcCards);
    System.out.println("DatabaseUtils release destPath");
    AnyMemoDBOpenHelperManager.releaseHelper(destHelper);
    System.out.println("DatabaseUtils release srcPath");
    AnyMemoDBOpenHelperManager.releaseHelper(srcHelper);
}
Also used : AnyMemoDBOpenHelper(org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper) CategoryDao(org.liberty.android.fantastischmemo.dao.CategoryDao) LearningDataDao(org.liberty.android.fantastischmemo.dao.LearningDataDao) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Card(org.liberty.android.fantastischmemo.entity.Card)

Example 2 with CategoryDao

use of org.liberty.android.fantastischmemo.dao.CategoryDao in project AnyMemo by helloworld1.

the class CardDaoTest method testGetCardsByCategory.

@SmallTest
@Test
public void testGetCardsByCategory() throws Exception {
    CardDao cardDao = helper.getCardDao();
    CategoryDao categoryDao = helper.getCategoryDao();
    setupThreeCategories();
    Category filterCategory1 = categoryDao.createOrReturn("My category");
    // If category specified is null, return all cards up to limit
    List<Card> cards1 = cardDao.getCardsByCategory(null, false, 50);
    assertEquals(28, cards1.size());
    // No category specified but with limit
    List<Card> cards2 = cardDao.getCardsByCategory(null, false, 10);
    assertEquals(10, cards2.size());
    // Get by category
    List<Card> cards3 = cardDao.getCardsByCategory(filterCategory1, false, 50);
    assertEquals(3, cards3.size());
    // Get by category with limit
    List<Card> cards4 = cardDao.getCardsByCategory(filterCategory1, false, 2);
    assertEquals(2, cards4.size());
    // Random cards shouldn't affect number of cards to get
    List<Card> cards5 = cardDao.getCardsByCategory(filterCategory1, true, 50);
    assertEquals(3, cards5.size());
}
Also used : Category(org.liberty.android.fantastischmemo.entity.Category) CategoryDao(org.liberty.android.fantastischmemo.dao.CategoryDao) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Card(org.liberty.android.fantastischmemo.entity.Card) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) AbstractExistingDBTest(org.liberty.android.fantastischmemo.test.AbstractExistingDBTest) SmallTest(android.support.test.filters.SmallTest)

Example 3 with CategoryDao

use of org.liberty.android.fantastischmemo.dao.CategoryDao in project AnyMemo by helloworld1.

the class CardDaoTest method setupThreeCategories.

/*
     * Card with "My Category" in ID 2, 5, 8
     */
private void setupThreeCategories() throws SQLException {
    CardDao cardDao = helper.getCardDao();
    CategoryDao categoryDao = helper.getCategoryDao();
    Card c = cardDao.queryForId(2);
    Category ct = new Category();
    ct.setName("My category");
    categoryDao.create(ct);
    c.setCategory(ct);
    cardDao.update(c);
    c = cardDao.queryForId(5);
    c.setCategory(ct);
    cardDao.update(c);
    c = cardDao.queryForId(8);
    c.setCategory(ct);
    cardDao.update(c);
}
Also used : Category(org.liberty.android.fantastischmemo.entity.Category) CategoryDao(org.liberty.android.fantastischmemo.dao.CategoryDao) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Card(org.liberty.android.fantastischmemo.entity.Card)

Example 4 with CategoryDao

use of org.liberty.android.fantastischmemo.dao.CategoryDao in project AnyMemo by helloworld1.

the class CardDaoTest method testGetScheduledCardCount.

@SmallTest
@Test
public void testGetScheduledCardCount() throws Exception {
    CardDao cardDao = helper.getCardDao();
    assertEquals(0L, cardDao.getScheduledCardCount(null));
    setupThreeCategories();
    CategoryDao categoryDao = helper.getCategoryDao();
    List<Category> cts = categoryDao.queryForEq("name", "My category");
    Category ct = cts.get(0);
    assertEquals(0L, cardDao.getScheduledCardCount(ct));
}
Also used : Category(org.liberty.android.fantastischmemo.entity.Category) CategoryDao(org.liberty.android.fantastischmemo.dao.CategoryDao) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) AbstractExistingDBTest(org.liberty.android.fantastischmemo.test.AbstractExistingDBTest) SmallTest(android.support.test.filters.SmallTest)

Example 5 with CategoryDao

use of org.liberty.android.fantastischmemo.dao.CategoryDao in project AnyMemo by helloworld1.

the class CardDaoTest method testGetNewCardCount.

@SmallTest
@Test
public void testGetNewCardCount() throws Exception {
    CardDao cardDao = helper.getCardDao();
    assertEquals(28L, cardDao.getNewCardCount(null));
    setupThreeCategories();
    CategoryDao categoryDao = helper.getCategoryDao();
    List<Category> cts = categoryDao.queryForEq("name", "My category");
    Category ct = cts.get(0);
    assertEquals(3L, cardDao.getNewCardCount(ct));
}
Also used : Category(org.liberty.android.fantastischmemo.entity.Category) CategoryDao(org.liberty.android.fantastischmemo.dao.CategoryDao) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) AbstractExistingDBTest(org.liberty.android.fantastischmemo.test.AbstractExistingDBTest) SmallTest(android.support.test.filters.SmallTest)

Aggregations

CategoryDao (org.liberty.android.fantastischmemo.dao.CategoryDao)23 CardDao (org.liberty.android.fantastischmemo.dao.CardDao)22 Card (org.liberty.android.fantastischmemo.entity.Card)20 Category (org.liberty.android.fantastischmemo.entity.Category)19 SmallTest (android.support.test.filters.SmallTest)13 Test (org.junit.Test)13 AbstractExistingDBTest (org.liberty.android.fantastischmemo.test.AbstractExistingDBTest)13 AnyMemoDBOpenHelper (org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper)10 LearningDataDao (org.liberty.android.fantastischmemo.dao.LearningDataDao)8 LearningData (org.liberty.android.fantastischmemo.entity.LearningData)5 FileWriter (java.io.FileWriter)3 BufferedWriter (java.io.BufferedWriter)2 File (java.io.File)2 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 CSVWriter (com.opencsv.CSVWriter)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1