refactored getSetCodes to be used from ExpansionReposiitory

This commit is contained in:
North 2013-06-18 22:46:09 +03:00
parent e2152c59a2
commit 0166975e83
5 changed files with 52 additions and 72 deletions

View file

@ -4,10 +4,12 @@ import mage.constants.CardType;
import mage.constants.ColoredManaSymbol; import mage.constants.ColoredManaSymbol;
import mage.Mana; import mage.Mana;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.ExpansionSet;
import mage.cards.decks.Deck; import mage.cards.decks.Deck;
import mage.cards.repository.CardCriteria; import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo; import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository; import mage.cards.repository.CardRepository;
import mage.cards.repository.ExpansionRepository;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.util.gui.ColorsChooser; import mage.client.util.gui.ColorsChooser;
import mage.client.util.sets.ConstructedFormats; import mage.client.util.sets.ConstructedFormats;
@ -28,8 +30,6 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.UUID; import java.util.UUID;
import mage.cards.ExpansionSet;
/** /**
* Generates random card pool and builds a deck. * Generates random card pool and builds a deck.
* *
@ -140,7 +140,7 @@ public class DeckGenerator {
List<String> setsToUse = ConstructedFormats.getSetsByFormat(format); List<String> setsToUse = ConstructedFormats.getSetsByFormat(format);
if (setsToUse.isEmpty()) { if (setsToUse.isEmpty()) {
// use all // use all
setsToUse = CardRepository.instance.getSetCodes(); setsToUse = ExpansionRepository.instance.getSetCodes();
} }
if (selectedColors.contains("X")) { if (selectedColors.contains("X")) {

View file

@ -36,6 +36,7 @@ import mage.cards.CardImpl;
import mage.cards.repository.CardCriteria; import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo; import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository; import mage.cards.repository.CardRepository;
import mage.cards.repository.ExpansionRepository;
import mage.client.cards.BigCard; import mage.client.cards.BigCard;
import mage.client.components.HoverButton; import mage.client.components.HoverButton;
import mage.client.plugins.impl.Plugins; import mage.client.plugins.impl.Plugins;
@ -301,7 +302,7 @@ public class MageBook extends JComponent {
this.setsToDisplay = ConstructedFormats.getSetsByFormat(format); this.setsToDisplay = ConstructedFormats.getSetsByFormat(format);
if (this.setsToDisplay.isEmpty()) { if (this.setsToDisplay.isEmpty()) {
// display all // display all
this.setsToDisplay = CardRepository.instance.getSetCodes(); this.setsToDisplay = ExpansionRepository.instance.getSetCodes();
} }
addSetTabs(); addSetTabs();
tabs.get(0).execute(); tabs.get(0).execute();

View file

@ -5,9 +5,8 @@ import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import mage.cards.ExpansionSet; import mage.cards.repository.ExpansionInfo;
import mage.cards.Sets; import mage.cards.repository.ExpansionRepository;
import mage.cards.repository.CardRepository;
/** /**
* Utility class for constructed formats (expansions and other editions). * Utility class for constructed formats (expansions and other editions).
@ -16,7 +15,8 @@ import mage.cards.repository.CardRepository;
*/ */
public class ConstructedFormats { public class ConstructedFormats {
private static final String[] constructedFormats = {"- All Sets", "- Standard", "- Extended", "- Modern", private static final String[] constructedFormats = {
"- All Sets", "- Standard", "- Extended", "- Modern",
"Modern Masters", "Modern Masters",
"* Return to Ravnica Block", "Dragon's Maze", "Gatecrash", "Return to Ravnica", "* Return to Ravnica Block", "Dragon's Maze", "Gatecrash", "Return to Ravnica",
"Magic 2013", "Planechase 2012", "Magic 2013", "Planechase 2012",
@ -379,9 +379,7 @@ public class ConstructedFormats {
} }
private static void buildLists() { private static void buildLists() {
for (String setCode : CardRepository.instance.getSetCodes()) { for (ExpansionInfo set : ExpansionRepository.instance.getAll()) {
ExpansionSet set = Sets.findSet(setCode);
if (set.getReleaseDate().after(standardDate)) { if (set.getReleaseDate().after(standardDate)) {
standard.add(set.getCode()); standard.add(set.getCode());
} }

View file

@ -1,6 +1,7 @@
package org.mage.card.arcane; package org.mage.card.arcane;
import mage.cards.repository.CardRepository; import mage.cards.repository.CardRepository;
import mage.cards.repository.ExpansionRepository;
import mage.client.dialog.PreferencesDialog; import mage.client.dialog.PreferencesDialog;
import mage.client.util.ImageHelper; import mage.client.util.ImageHelper;
import mage.client.util.gui.BufferedImageBuilder; import mage.client.util.gui.BufferedImageBuilder;
@ -49,7 +50,7 @@ public class ManaSymbols {
} catch (Exception e) { } catch (Exception e) {
} }
} }
List<String> setCodes = CardRepository.instance.getSetCodes(); List<String> setCodes = ExpansionRepository.instance.getSetCodes();
for (String set : setCodes) { for (String set : setCodes) {
File file = new File(getSymbolsPath() + Constants.RESOURCE_PATH_SET + set + "-C.jpg"); File file = new File(getSymbolsPath() + Constants.RESOURCE_PATH_SET + set + "-C.jpg");
try { try {
@ -106,7 +107,7 @@ public class ManaSymbols {
} }
File file; File file;
for (String set : CardRepository.instance.getSetCodes()) { for (String set : ExpansionRepository.instance.getSetCodes()) {
file = new File(getSymbolsPath() + Constants.RESOURCE_PATH_SET_SMALL); file = new File(getSymbolsPath() + Constants.RESOURCE_PATH_SET_SMALL);
if (!file.exists()) { if (!file.exists()) {
break; break;

View file

@ -32,7 +32,6 @@ import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.jdbc.JdbcConnectionSource; import com.j256.ormlite.jdbc.JdbcConnectionSource;
import com.j256.ormlite.stmt.QueryBuilder; import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.SelectArg; import com.j256.ormlite.stmt.SelectArg;
import com.j256.ormlite.stmt.Where;
import com.j256.ormlite.support.ConnectionSource; import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils; import com.j256.ormlite.table.TableUtils;
import java.io.File; import java.io.File;
@ -54,7 +53,8 @@ public enum CardRepository {
instance; instance;
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 long DB_VERSION = 7; private static final String VERSION_ENTITY_NAME = "card";
private static final long CARD_DB_VERSION = 7;
private Random random = new Random(); private Random random = new Random();
private Dao<CardInfo, Object> cardDao; private Dao<CardInfo, Object> cardDao;
@ -67,16 +67,10 @@ public enum CardRepository {
} }
try { try {
ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL); ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL);
TableUtils.createTableIfNotExists(connectionSource, DatabaseVersion.class); boolean obsolete = RepositoryUtil.isDatabaseObsolete(connectionSource, VERSION_ENTITY_NAME, CARD_DB_VERSION);
Dao<DatabaseVersion, Object> dbVersionDao = DaoManager.createDao(connectionSource, DatabaseVersion.class);
List<DatabaseVersion> dbVersions = dbVersionDao.queryForAll(); if (obsolete) {
if (dbVersions.isEmpty() || dbVersions.get(0).getVersion() != DB_VERSION) {
TableUtils.dropTable(connectionSource, CardInfo.class, true); TableUtils.dropTable(connectionSource, CardInfo.class, true);
if (dbVersions.isEmpty()) {
DatabaseVersion dbVersion = new DatabaseVersion();
dbVersion.setVersion(DB_VERSION);
dbVersionDao.create(dbVersion);
}
} }
TableUtils.createTableIfNotExists(connectionSource, CardInfo.class); TableUtils.createTableIfNotExists(connectionSource, CardInfo.class);
@ -123,20 +117,6 @@ public enum CardRepository {
return false; return false;
} }
public List<String> getSetCodes() {
List<String> setCodes = new ArrayList<String>();
try {
QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
qb.distinct().selectColumns("setCode");
List<CardInfo> results = cardDao.query(qb.prepare());
for (CardInfo card : results) {
setCodes.add(card.getSetCode());
}
} catch (SQLException ex) {
}
return setCodes;
}
public Set<String> getNames() { public Set<String> getNames() {
Set<String> names = new TreeSet<String>(); Set<String> names = new TreeSet<String>();
try { try {
@ -183,8 +163,10 @@ public enum CardRepository {
try { try {
QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder(); QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
qb.distinct().selectColumns("name"); qb.distinct().selectColumns("name");
Where where = qb.where(); qb.where()
where.and(where.not().like("types", '%' + CardType.CREATURE.name() +'%'),where.not().like("types", '%' + CardType.LAND.name() + '%')); .not().like("types", '%' + CardType.CREATURE.name() + '%')
.and()
.not().like("types", '%' + CardType.LAND.name() + '%');
List<CardInfo> results = cardDao.query(qb.prepare()); List<CardInfo> results = cardDao.query(qb.prepare());
for (CardInfo card : results) { for (CardInfo card : results) {
int result = card.getName().indexOf(" // "); int result = card.getName().indexOf(" // ");
@ -265,9 +247,7 @@ public enum CardRepository {
public List<CardInfo> getAllCards() { public List<CardInfo> getAllCards() {
try { try {
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder(); return cardDao.queryForAll();
return cardDao.query(queryBuilder.prepare());
} catch (SQLException ex) { } catch (SQLException ex) {
} }
return new ArrayList<CardInfo>(); return new ArrayList<CardInfo>();