Removing method for listing matches in serie, instead all matches from league are filtered in code.

This commit is contained in:
marcins78@gmail.com
2012-05-04 10:46:13 +00:00
parent 219934c413
commit 96242d189f
6 changed files with 15 additions and 81 deletions

View File

@@ -52,39 +52,6 @@ public class DbLeagueMatchDAO implements LeagueMatchDAO {
}
}
@Override
public Collection<LeagueMatch> getLeagueSerieMatches(League league, LeagueSerieData leagueSerie) {
try {
Connection conn = _dbAccess.getDataSource().getConnection();
try {
PreparedStatement statement = conn.prepareStatement("select winner, loser from league_match where league_type=? and season_type=?");
try {
statement.setString(1, league.getType());
statement.setString(2, leagueSerie.getName());
ResultSet rs = statement.executeQuery();
try {
Set<LeagueMatch> result = new HashSet<LeagueMatch>();
while (rs.next()) {
String winner = rs.getString(1);
String loser = rs.getString(2);
result.add(new LeagueMatch(leagueSerie.getName(), winner, loser));
}
return result;
} finally {
rs.close();
}
} finally {
statement.close();
}
} finally {
conn.close();
}
} catch (SQLException exp) {
throw new RuntimeException(exp);
}
}
@Override
public void addPlayedMatch(League league, LeagueSerieData leagueSeason, String winner, String loser) {
try {

View File

@@ -9,7 +9,5 @@ import java.util.Collection;
public interface LeagueMatchDAO {
public Collection<LeagueMatch> getLeagueMatches(League league);
public Collection<LeagueMatch> getLeagueSerieMatches(League league, LeagueSerieData leagueSerie);
public void addPlayedMatch(League league, LeagueSerieData leagueSeason, String winner, String loser);
}

View File

@@ -3,16 +3,16 @@ package com.gempukku.lotro.db.vo;
public class LeagueMatch {
private String _winner;
private String _loser;
private String _serie;
private String _serieName;
public LeagueMatch(String serie, String winner, String loser) {
_serie = serie;
public LeagueMatch(String serieName, String winner, String loser) {
_serieName = serieName;
_winner = winner;
_loser = loser;
}
public String getSerie() {
return _serie;
public String getSerieName() {
return _serieName;
}
public String getLoser() {

View File

@@ -43,27 +43,6 @@ public class CachedLeagueMatchDAO implements LeagueMatchDAO {
}
}
@Override
public Collection<LeagueMatch> getLeagueSerieMatches(League league, LeagueSerieData leagueSerie) {
_readWriteLock.readLock().lock();
try {
Collection<LeagueMatch> leagueSerieMatches = _cachedMatches.get(LeagueMapKeys.getLeagueSerieMapKey(league, leagueSerie));
if (leagueSerieMatches == null) {
_readWriteLock.readLock().unlock();
_readWriteLock.writeLock().lock();
try {
leagueSerieMatches = getLeagueSerieMatchesInWriteLock(league, leagueSerie);
} finally {
_readWriteLock.readLock().lock();
_readWriteLock.writeLock().unlock();
}
}
return Collections.unmodifiableCollection(leagueSerieMatches);
} finally {
_readWriteLock.readLock().unlock();
}
}
private Collection<LeagueMatch> getLeagueMatchesInWriteLock(League league) {
Collection<LeagueMatch> leagueMatches;
leagueMatches = _cachedMatches.get(LeagueMapKeys.getLeagueMapKey(league));
@@ -74,16 +53,6 @@ public class CachedLeagueMatchDAO implements LeagueMatchDAO {
return leagueMatches;
}
private Collection<LeagueMatch> getLeagueSerieMatchesInWriteLock(League league, LeagueSerieData leagueSerie) {
Collection<LeagueMatch> leagueSerieMatches;
leagueSerieMatches = _cachedMatches.get(LeagueMapKeys.getLeagueSerieMapKey(league, leagueSerie));
if (leagueSerieMatches == null) {
leagueSerieMatches = new CopyOnWriteArraySet<LeagueMatch>(_leagueMatchDAO.getLeagueSerieMatches(league, leagueSerie));
_cachedMatches.put(LeagueMapKeys.getLeagueSerieMapKey(league, leagueSerie), leagueSerieMatches);
}
return leagueSerieMatches;
}
@Override
public void addPlayedMatch(League league, LeagueSerieData leagueSerie, String winner, String loser) {
_readWriteLock.writeLock().lock();
@@ -91,7 +60,6 @@ public class CachedLeagueMatchDAO implements LeagueMatchDAO {
LeagueMatch match = new LeagueMatch(leagueSerie.getName(), winner, loser);
getLeagueMatchesInWriteLock(league).add(match);
getLeagueSerieMatchesInWriteLock(league, leagueSerie).add(match);
_leagueMatchDAO.addPlayedMatch(league, leagueSerie, winner, loser);
} finally {
_readWriteLock.writeLock().unlock();

View File

@@ -176,10 +176,10 @@ public class LeagueService {
}
private Collection<LeagueMatch> getPlayerMatchesInSerie(League league, LeagueSerieData serie, String player) {
final Collection<LeagueMatch> allMatches = _leagueMatchDao.getLeagueSerieMatches(league, serie);
final Collection<LeagueMatch> allMatches = _leagueMatchDao.getLeagueMatches(league);
Set<LeagueMatch> result = new HashSet<LeagueMatch>();
for (LeagueMatch match : allMatches) {
if (match.getWinner().equals(player) || match.getLoser().equals(player))
if (match.getSerieName().equals(serie.getName()) && (match.getWinner().equals(player) || match.getLoser().equals(player)))
result.add(match);
}
return result;
@@ -209,9 +209,15 @@ public class LeagueService {
private List<PlayerStanding> createLeagueSerieStandings(League league, LeagueSerieData leagueSerie) {
final Map<String, LeaguePointsDAO.Points> points = _leaguePointsDao.getLeagueSeriePoints(league, leagueSerie);
final Collection<LeagueMatch> matches = _leagueMatchDao.getLeagueSerieMatches(league, leagueSerie);
final Collection<LeagueMatch> matches = _leagueMatchDao.getLeagueMatches(league);
return createStandingsForMatchesAndPoints(points, matches);
Set<LeagueMatch> matchesInSerie = new HashSet<LeagueMatch>();
for (LeagueMatch match : matches) {
if (match.getSerieName().equals(leagueSerie.getName()))
matchesInSerie.add(match);
}
return createStandingsForMatchesAndPoints(points, matchesInSerie);
}
private List<PlayerStanding> createLeagueStandings(League league) {

View File

@@ -43,7 +43,6 @@ public class LeagueServiceTest {
Set<LeagueMatch> matches = new HashSet<LeagueMatch>();
Mockito.when(leagueMatchDAO.getLeagueMatches(league)).thenReturn(new HashSet<LeagueMatch>(matches));
Mockito.when(leagueMatchDAO.getLeagueSerieMatches(league, leagueSerie)).thenReturn(new HashSet<LeagueMatch>(matches));
LeagueParticipationDAO leagueParticipationDAO = Mockito.mock(LeagueParticipationDAO.class);
CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class);
@@ -60,7 +59,6 @@ public class LeagueServiceTest {
assertTrue(leagueService.canPlayRankedGameAgainst(league, leagueSerie, "player1", "player3"));
Mockito.verify(leagueMatchDAO).getLeagueMatches(league);
Mockito.verify(leagueMatchDAO).getLeagueSerieMatches(league, leagueSerie);
Mockito.verify(leagueMatchDAO).addPlayedMatch(league, leagueSerie, "player1", "player2");
Mockito.verifyNoMoreInteractions(leagueMatchDAO);
@@ -100,7 +98,6 @@ public class LeagueServiceTest {
matches.add(new LeagueMatch(leagueSerie.getName(), "player1", "player2"));
Mockito.when(leagueMatchDAO.getLeagueMatches(league)).thenReturn(new HashSet<LeagueMatch>(matches));
Mockito.when(leagueMatchDAO.getLeagueSerieMatches(league, leagueSerie)).thenReturn(new HashSet<LeagueMatch>(matches));
LeagueParticipationDAO leagueParticipationDAO = Mockito.mock(LeagueParticipationDAO.class);
CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class);
@@ -114,7 +111,6 @@ public class LeagueServiceTest {
leagueService.reportLeagueGameResult(league, leagueSerie, "player1", "player3");
Mockito.verify(leagueMatchDAO).getLeagueMatches(league);
Mockito.verify(leagueMatchDAO).getLeagueSerieMatches(league, leagueSerie);
Mockito.verify(leagueMatchDAO).addPlayedMatch(league, leagueSerie, "player1", "player3");
Mockito.verifyNoMoreInteractions(leagueMatchDAO);
@@ -148,7 +144,6 @@ public class LeagueServiceTest {
Set<LeagueMatch> matches = new HashSet<LeagueMatch>();
Mockito.when(leagueMatchDAO.getLeagueMatches(league)).thenReturn(new HashSet<LeagueMatch>(matches));
Mockito.when(leagueMatchDAO.getLeagueSerieMatches(league, leagueSerie)).thenReturn(new HashSet<LeagueMatch>(matches));
LeagueParticipationDAO leagueParticipationDAO = Mockito.mock(LeagueParticipationDAO.class);
CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class);