diff --git a/Mage.Common/src/mage/interfaces/MageServer.java b/Mage.Common/src/mage/interfaces/MageServer.java index 58551a4368..589a7fcdbd 100644 --- a/Mage.Common/src/mage/interfaces/MageServer.java +++ b/Mage.Common/src/mage/interfaces/MageServer.java @@ -30,6 +30,7 @@ package mage.interfaces; import mage.MageException; import mage.cards.decks.DeckCardLists; +import mage.cards.repository.CardInfo; import mage.cards.repository.ExpansionInfo; import mage.game.GameException; import mage.game.match.MatchOptions; @@ -53,6 +54,7 @@ public interface MageServer { // update methods List getMissingExpansionData(List codes); + List getMissingCardsData(List classNames); // user methods boolean setUserData(String userName, String sessionId, UserDataView userDataView) throws MageException; diff --git a/Mage.Server/src/main/java/mage/server/MageServerImpl.java b/Mage.Server/src/main/java/mage/server/MageServerImpl.java index 216ae8c889..119dd02c9e 100644 --- a/Mage.Server/src/main/java/mage/server/MageServerImpl.java +++ b/Mage.Server/src/main/java/mage/server/MageServerImpl.java @@ -30,6 +30,8 @@ package mage.server; import mage.MageException; import mage.cards.decks.DeckCardLists; +import mage.cards.repository.CardInfo; +import mage.cards.repository.CardRepository; import mage.cards.repository.ExpansionInfo; import mage.cards.repository.ExpansionRepository; import mage.game.GameException; @@ -924,4 +926,9 @@ public class MageServerImpl implements MageServer { } return result; } + + @Override + public List getMissingCardsData(List classNames) { + return CardRepository.instance.getMissingCards(classNames); + } } diff --git a/Mage/src/mage/cards/repository/CardInfo.java b/Mage/src/mage/cards/repository/CardInfo.java index 50d140698d..afcac411a8 100644 --- a/Mage/src/mage/cards/repository/CardInfo.java +++ b/Mage/src/mage/cards/repository/CardInfo.java @@ -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; } } diff --git a/Mage/src/mage/cards/repository/CardRepository.java b/Mage/src/mage/cards/repository/CardRepository.java index 0db957d0b2..f296560137 100644 --- a/Mage/src/mage/cards/repository/CardRepository.java +++ b/Mage/src/mage/cards/repository/CardRepository.java @@ -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 cardDao; @@ -210,6 +210,30 @@ public enum CardRepository { return null; } + + public List getClassNames() { + List names = new ArrayList(); + try { + List results = cardDao.queryForAll(); + for (CardInfo card : results) { + names.add(card.getClassName()); + } + } catch (SQLException ex) { + } + return names; + } + + public List getMissingCards(List classNames) { + try { + QueryBuilder queryBuilder = cardDao.queryBuilder(); + queryBuilder.where().not().in("className", classNames); + + return cardDao.query(queryBuilder.prepare()); + } catch (SQLException ex) { + } + return new ArrayList(); + } + /** * * @param name