forked from External/mage
* Fixed a bug of deck import not finding cards that were never included in regular core or expansion sets (e.g. Command Tower). The deck imports are now case insensitive (and also a little bit slower).
This commit is contained in:
parent
9a22cd2068
commit
c0c7dc5900
5 changed files with 32 additions and 10 deletions
|
|
@ -29,6 +29,7 @@ package mage.cards.repository;
|
|||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import com.j256.ormlite.dao.GenericRawResults;
|
||||
import com.j256.ormlite.jdbc.JdbcConnectionSource;
|
||||
import com.j256.ormlite.stmt.QueryBuilder;
|
||||
import com.j256.ormlite.stmt.SelectArg;
|
||||
|
|
@ -40,7 +41,6 @@ import java.io.File;
|
|||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
|
@ -318,11 +318,16 @@ public enum CardRepository {
|
|||
return null;
|
||||
}
|
||||
|
||||
public CardInfo findPreferedCoreExpansionCard(String name) {
|
||||
List<CardInfo> cards = findCards(name);
|
||||
public CardInfo findPreferedCoreExpansionCard(String name, boolean caseInsensitive) {
|
||||
List<CardInfo> cards;
|
||||
if (caseInsensitive) {
|
||||
cards = findCardsCaseInsensitive(name);
|
||||
} else {
|
||||
cards = findCards(name);
|
||||
}
|
||||
if (!cards.isEmpty()) {
|
||||
Date lastReleaseDate = new GregorianCalendar(1900, 1, 1).getTime();
|
||||
Date lastExpansionDate = new GregorianCalendar(1900, 1, 1).getTime();
|
||||
Date lastReleaseDate = null;
|
||||
Date lastExpansionDate = null;
|
||||
CardInfo cardToUse = null;
|
||||
for (CardInfo cardinfo : cards) {
|
||||
ExpansionInfo set = ExpansionRepository.instance.getSetByCode(cardinfo.getSetCode());
|
||||
|
|
@ -353,6 +358,23 @@ public enum CardRepository {
|
|||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<CardInfo> findCardsCaseInsensitive(String name) {
|
||||
try {
|
||||
String sqlName = name.toLowerCase().replaceAll("\'", "\'\'");
|
||||
GenericRawResults<CardInfo> rawResults = cardDao.queryRaw(
|
||||
"select * from " + CardRepository.VERSION_ENTITY_NAME + " where lower(name) = '" + sqlName + "'",
|
||||
cardDao.getRawRowMapper());
|
||||
List<CardInfo> result = new ArrayList<>();
|
||||
for (CardInfo cardinfo : rawResults) {
|
||||
result.add(cardinfo);
|
||||
}
|
||||
return result;
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(CardRepository.class).error("Error during execution of raw sql statement", ex);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<CardInfo> findCards(CardCriteria criteria) {
|
||||
try {
|
||||
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue