diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/DbLeagueMatchDAO.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/DbLeagueMatchDAO.java index 05bb68c71..abfc524fd 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/DbLeagueMatchDAO.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/DbLeagueMatchDAO.java @@ -52,39 +52,6 @@ public class DbLeagueMatchDAO implements LeagueMatchDAO { } } - @Override - public Collection 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 result = new HashSet(); - 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 { diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueMatchDAO.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueMatchDAO.java index b6d501463..736457e03 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueMatchDAO.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueMatchDAO.java @@ -9,7 +9,5 @@ import java.util.Collection; public interface LeagueMatchDAO { public Collection getLeagueMatches(League league); - public Collection getLeagueSerieMatches(League league, LeagueSerieData leagueSerie); - public void addPlayedMatch(League league, LeagueSerieData leagueSeason, String winner, String loser); } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/LeagueMatch.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/LeagueMatch.java index 34c029f66..3290288ec 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/LeagueMatch.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/vo/LeagueMatch.java @@ -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() { diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/CachedLeagueMatchDAO.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/CachedLeagueMatchDAO.java index 0622f7575..3cc7c322a 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/CachedLeagueMatchDAO.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/CachedLeagueMatchDAO.java @@ -43,27 +43,6 @@ public class CachedLeagueMatchDAO implements LeagueMatchDAO { } } - @Override - public Collection getLeagueSerieMatches(League league, LeagueSerieData leagueSerie) { - _readWriteLock.readLock().lock(); - try { - Collection 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 getLeagueMatchesInWriteLock(League league) { Collection leagueMatches; leagueMatches = _cachedMatches.get(LeagueMapKeys.getLeagueMapKey(league)); @@ -74,16 +53,6 @@ public class CachedLeagueMatchDAO implements LeagueMatchDAO { return leagueMatches; } - private Collection getLeagueSerieMatchesInWriteLock(League league, LeagueSerieData leagueSerie) { - Collection leagueSerieMatches; - leagueSerieMatches = _cachedMatches.get(LeagueMapKeys.getLeagueSerieMapKey(league, leagueSerie)); - if (leagueSerieMatches == null) { - leagueSerieMatches = new CopyOnWriteArraySet(_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(); diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueService.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueService.java index a5d47e370..871d46616 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueService.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeagueService.java @@ -176,10 +176,10 @@ public class LeagueService { } private Collection getPlayerMatchesInSerie(League league, LeagueSerieData serie, String player) { - final Collection allMatches = _leagueMatchDao.getLeagueSerieMatches(league, serie); + final Collection allMatches = _leagueMatchDao.getLeagueMatches(league); Set result = new HashSet(); 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 createLeagueSerieStandings(League league, LeagueSerieData leagueSerie) { final Map points = _leaguePointsDao.getLeagueSeriePoints(league, leagueSerie); - final Collection matches = _leagueMatchDao.getLeagueSerieMatches(league, leagueSerie); + final Collection matches = _leagueMatchDao.getLeagueMatches(league); - return createStandingsForMatchesAndPoints(points, matches); + Set matchesInSerie = new HashSet(); + for (LeagueMatch match : matches) { + if (match.getSerieName().equals(leagueSerie.getName())) + matchesInSerie.add(match); + } + + return createStandingsForMatchesAndPoints(points, matchesInSerie); } private List createLeagueStandings(League league) { diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeagueServiceTest.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeagueServiceTest.java index fcf9c9483..e7127955f 100644 --- a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeagueServiceTest.java +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeagueServiceTest.java @@ -43,7 +43,6 @@ public class LeagueServiceTest { Set matches = new HashSet(); Mockito.when(leagueMatchDAO.getLeagueMatches(league)).thenReturn(new HashSet(matches)); - Mockito.when(leagueMatchDAO.getLeagueSerieMatches(league, leagueSerie)).thenReturn(new HashSet(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(matches)); - Mockito.when(leagueMatchDAO.getLeagueSerieMatches(league, leagueSerie)).thenReturn(new HashSet(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 matches = new HashSet(); Mockito.when(leagueMatchDAO.getLeagueMatches(league)).thenReturn(new HashSet(matches)); - Mockito.when(leagueMatchDAO.getLeagueSerieMatches(league, leagueSerie)).thenReturn(new HashSet(matches)); LeagueParticipationDAO leagueParticipationDAO = Mockito.mock(LeagueParticipationDAO.class); CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class);