mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
added method for updating cards database
This commit is contained in:
parent
e4ea8adf94
commit
5e3970a0e0
4 changed files with 36 additions and 2 deletions
|
@ -30,6 +30,7 @@ package mage.interfaces;
|
||||||
|
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
import mage.cards.decks.DeckCardLists;
|
import mage.cards.decks.DeckCardLists;
|
||||||
|
import mage.cards.repository.CardInfo;
|
||||||
import mage.cards.repository.ExpansionInfo;
|
import mage.cards.repository.ExpansionInfo;
|
||||||
import mage.game.GameException;
|
import mage.game.GameException;
|
||||||
import mage.game.match.MatchOptions;
|
import mage.game.match.MatchOptions;
|
||||||
|
@ -53,6 +54,7 @@ public interface MageServer {
|
||||||
|
|
||||||
// update methods
|
// update methods
|
||||||
List<ExpansionInfo> getMissingExpansionData(List<String> codes);
|
List<ExpansionInfo> getMissingExpansionData(List<String> codes);
|
||||||
|
List<CardInfo> getMissingCardsData(List<String> classNames);
|
||||||
|
|
||||||
// user methods
|
// user methods
|
||||||
boolean setUserData(String userName, String sessionId, UserDataView userDataView) throws MageException;
|
boolean setUserData(String userName, String sessionId, UserDataView userDataView) throws MageException;
|
||||||
|
|
|
@ -30,6 +30,8 @@ package mage.server;
|
||||||
|
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
import mage.cards.decks.DeckCardLists;
|
import mage.cards.decks.DeckCardLists;
|
||||||
|
import mage.cards.repository.CardInfo;
|
||||||
|
import mage.cards.repository.CardRepository;
|
||||||
import mage.cards.repository.ExpansionInfo;
|
import mage.cards.repository.ExpansionInfo;
|
||||||
import mage.cards.repository.ExpansionRepository;
|
import mage.cards.repository.ExpansionRepository;
|
||||||
import mage.game.GameException;
|
import mage.game.GameException;
|
||||||
|
@ -924,4 +926,9 @@ public class MageServerImpl implements MageServer {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CardInfo> getMissingCardsData(List<String> classNames) {
|
||||||
|
return CardRepository.instance.getMissingCards(classNames);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class CardInfo {
|
||||||
protected int cardNumber;
|
protected int cardNumber;
|
||||||
@DatabaseField
|
@DatabaseField
|
||||||
protected String setCode;
|
protected String setCode;
|
||||||
@DatabaseField
|
@DatabaseField(unique = true)
|
||||||
protected String className;
|
protected String className;
|
||||||
@DatabaseField
|
@DatabaseField
|
||||||
protected String power;
|
protected String power;
|
||||||
|
@ -144,6 +144,7 @@ public class CardInfo {
|
||||||
if (spellAbility != null) {
|
if (spellAbility != null) {
|
||||||
SpellAbilityType spellAbilityType = spellAbility.getSpellAbilityType();
|
SpellAbilityType spellAbilityType = spellAbility.getSpellAbilityType();
|
||||||
if (spellAbilityType == SpellAbilityType.SPLIT_LEFT || spellAbilityType == SpellAbilityType.SPLIT_RIGHT) {
|
if (spellAbilityType == SpellAbilityType.SPLIT_LEFT || spellAbilityType == SpellAbilityType.SPLIT_RIGHT) {
|
||||||
|
this.className = this.setCode + "." + this.name;
|
||||||
this.splitCardHalf = true;
|
this.splitCardHalf = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ public enum CardRepository {
|
||||||
|
|
||||||
private static final String JDBC_URL = "jdbc:sqlite:db/cards.db";
|
private static final String JDBC_URL = "jdbc:sqlite:db/cards.db";
|
||||||
private static final String VERSION_ENTITY_NAME = "card";
|
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 Random random = new Random();
|
||||||
private Dao<CardInfo, Object> cardDao;
|
private Dao<CardInfo, Object> cardDao;
|
||||||
|
@ -210,6 +210,30 @@ public enum CardRepository {
|
||||||
return null;
|
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
|
* @param name
|
||||||
|
|
Loading…
Reference in a new issue