added method for updating cards database

This commit is contained in:
North 2013-07-02 22:29:06 +03:00
parent e4ea8adf94
commit 5e3970a0e0
4 changed files with 36 additions and 2 deletions

View file

@ -59,7 +59,7 @@ public class CardInfo {
protected int cardNumber;
@DatabaseField
protected String setCode;
@DatabaseField
@DatabaseField(unique = true)
protected String className;
@DatabaseField
protected String power;
@ -144,6 +144,7 @@ public class CardInfo {
if (spellAbility != null) {
SpellAbilityType spellAbilityType = spellAbility.getSpellAbilityType();
if (spellAbilityType == SpellAbilityType.SPLIT_LEFT || spellAbilityType == SpellAbilityType.SPLIT_RIGHT) {
this.className = this.setCode + "." + this.name;
this.splitCardHalf = true;
}
}

View file

@ -54,7 +54,7 @@ public enum CardRepository {
private static final String JDBC_URL = "jdbc:sqlite:db/cards.db";
private static final String VERSION_ENTITY_NAME = "card";
private static final long CARD_DB_VERSION = 9;
private static final long CARD_DB_VERSION = 10;
private Random random = new Random();
private Dao<CardInfo, Object> cardDao;
@ -210,6 +210,30 @@ public enum CardRepository {
return null;
}
public List<String> getClassNames() {
List<String> names = new ArrayList<String>();
try {
List<CardInfo> results = cardDao.queryForAll();
for (CardInfo card : results) {
names.add(card.getClassName());
}
} catch (SQLException ex) {
}
return names;
}
public List<CardInfo> getMissingCards(List<String> classNames) {
try {
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
queryBuilder.where().not().in("className", classNames);
return cardDao.query(queryBuilder.prepare());
} catch (SQLException ex) {
}
return new ArrayList<CardInfo>();
}
/**
*
* @param name