use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.
the class ImportMergingTest method testMergeQATxtIntoDb.
@SmallTest
@Test
public void testMergeQATxtIntoDb() throws Exception {
srcFilePath = AMEnv.DEFAULT_ROOT_PATH + "/" + "qa-text-test.txt";
destFilePath = AMEnv.DEFAULT_ROOT_PATH + "/" + "qa-text-test.db";
new File(srcFilePath).delete();
new File(destFilePath).delete();
AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(getContext(), destFilePath);
try {
// Create an new db with some contents
helper.getCardDao().createCards(newDbCardList);
} finally {
AnyMemoDBOpenHelperManager.releaseHelper(helper);
}
amFileUtil.copyFileFromAsset("qa-text-test.txt", new File(srcFilePath));
Converter converter = new QATxtImporter(amFileUtil);
converter.convert(srcFilePath, destFilePath);
helper = AnyMemoDBOpenHelperManager.getHelper(getContext(), destFilePath);
try {
List<Card> cards = helper.getCardDao().getAllCards(null);
assertEquals(4, cards.size());
assertEquals(1, (int) cards.get(0).getId());
assertEquals(1, (int) cards.get(0).getOrdinal());
assertEquals("old question 1", cards.get(0).getQuestion());
assertEquals("old answer 1", cards.get(0).getAnswer());
assertEquals(2, (int) cards.get(1).getId());
assertEquals(2, (int) cards.get(1).getOrdinal());
assertEquals("old question 2", cards.get(1).getQuestion());
assertEquals("old answer 2", cards.get(1).getAnswer());
assertEquals(3, (int) cards.get(2).getId());
assertEquals(3, (int) cards.get(2).getOrdinal());
assertEquals("This is question1", cards.get(2).getQuestion());
assertEquals("Answer1", cards.get(2).getAnswer());
assertEquals(4, (int) cards.get(3).getId());
assertEquals(4, (int) cards.get(3).getOrdinal());
assertEquals("Question2", cards.get(3).getQuestion());
assertEquals("Answer2", cards.get(3).getAnswer());
} finally {
AnyMemoDBOpenHelperManager.releaseHelper(helper);
}
}
use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.
the class CardDaoImpl method getNewCards.
public List<Card> getNewCards(Category filterCategory, Iterable<Card> exclusion, int limit) {
try {
LearningDataDao learningDataDao = getHelper().getLearningDataDao();
CategoryDao categoryDao = getHelper().getCategoryDao();
QueryBuilder<LearningData, Integer> learnQb = learningDataDao.queryBuilder();
learnQb.selectColumns("id");
learnQb.where().eq("acqReps", "0");
QueryBuilder<Card, Integer> cardQb = this.queryBuilder();
// The "isNotNull" statement is dummy so the "and()" can be cascaded
// for the following conditions
Where<Card, Integer> where = cardQb.where().isNotNull("learningData_id");
if (filterCategory != null) {
where.and().eq("category_id", filterCategory.getId());
}
if (exclusion != null) {
List<Integer> exclusionList = new ArrayList<Integer>();
for (Card c : exclusion) {
exclusionList.add(c.getId());
}
where.and().notIn("id", exclusionList);
}
cardQb.setWhere(where);
cardQb.join(learnQb).orderByRaw("cards.ordinal").limit((long) limit);
List<Card> cs = cardQb.query();
for (Card c : cs) {
categoryDao.refresh(c.getCategory());
learningDataDao.refresh(c.getLearningData());
}
return cs;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.
the class CardDaoImpl method getCardsByOrdinalAndSize.
public List<Card> getCardsByOrdinalAndSize(long startOrd, long size) {
LearningDataDao learningDataDao = getHelper().getLearningDataDao();
QueryBuilder<Card, Integer> qb = queryBuilder();
qb.limit(size);
try {
Where<Card, Integer> where = qb.where().ge("ordinal", startOrd);
qb.setWhere(where);
qb.orderBy("ordinal", true);
PreparedQuery<Card> pq = qb.prepare();
List<Card> result = query(pq);
for (Card c : result) {
learningDataDao.refresh(c.getLearningData());
}
return result;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.
the class CardDaoImpl method create.
@Override
public int create(Card c) {
try {
Integer cardOrdinal = c.getOrdinal();
// Null ordinal means we need to put the max oridinal + 1 here
if (cardOrdinal == null) {
Card last = queryLastOrdinal();
// If it is a new db the last oridinal will be null.
if (last == null) {
cardOrdinal = 1;
} else {
cardOrdinal = last.getOrdinal() + 1;
}
c.setOrdinal(cardOrdinal);
} else {
// We are adding the card at the middle. Should update other card's ordinal.
UpdateBuilder<Card, Integer> updateBuilder = updateBuilder();
updateBuilder.updateColumnExpression("ordinal", "ordinal + 1");
updateBuilder.where().ge("ordinal", cardOrdinal).prepare();
update(updateBuilder.prepare());
}
int res = super.create(c);
return res;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.
the class CardPlayerActivity method gotoCardId.
// Query out the card id and display that card
protected void gotoCardId(final int cardId) {
Card card = cardDao.queryForId(cardId);
gotoCard(card);
}
Aggregations