Added clearing cache operation.
This commit is contained in:
@@ -25,6 +25,10 @@ public class CollectionDAO {
|
||||
_collectionSerializer = new CollectionSerializer(library);
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
_collections.clear();
|
||||
}
|
||||
|
||||
public MutableCardCollection getCollectionForPlayer(Player player, String type) {
|
||||
Map<String, MutableCardCollection> playerCollections = _collections.get(player.getId());
|
||||
if (playerCollections != null) {
|
||||
|
||||
@@ -19,6 +19,10 @@ public class DeckDAO {
|
||||
_dbAccess = dbAccess;
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
_decks.clear();
|
||||
}
|
||||
|
||||
public DeckVO getDeckForPlayer(Player player, String name) {
|
||||
Map<String, DeckVO> deckMap = getPlayerDecks(player);
|
||||
return deckMap.get(name);
|
||||
|
||||
@@ -20,6 +20,10 @@ public class PlayerDAO {
|
||||
_dbAccess = dbAccess;
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
_players.clear();
|
||||
}
|
||||
|
||||
public Player getPlayer(String playerName) {
|
||||
if (_players.containsKey(playerName))
|
||||
return _players.get(playerName);
|
||||
@@ -40,7 +44,7 @@ public class PlayerDAO {
|
||||
public Player loginUser(String login, String password) throws SQLException {
|
||||
Connection conn = _dbAccess.getDataSource().getConnection();
|
||||
try {
|
||||
PreparedStatement statement = conn.prepareStatement("select id, name from player where name=? and password=?");
|
||||
PreparedStatement statement = conn.prepareStatement("select id, name, type from player where name=? and password=?");
|
||||
try {
|
||||
statement.setString(1, login);
|
||||
statement.setString(2, encodePassword(password));
|
||||
@@ -49,8 +53,9 @@ public class PlayerDAO {
|
||||
if (rs.next()) {
|
||||
int id = rs.getInt(1);
|
||||
String name = rs.getString(2);
|
||||
String type = rs.getString(3);
|
||||
|
||||
return new Player(id, name);
|
||||
return new Player(id, name, type);
|
||||
} else
|
||||
return null;
|
||||
} finally {
|
||||
@@ -145,7 +150,7 @@ public class PlayerDAO {
|
||||
private Player getPlayerFromDB(String playerName) throws SQLException {
|
||||
Connection conn = _dbAccess.getDataSource().getConnection();
|
||||
try {
|
||||
PreparedStatement statement = conn.prepareStatement("select id, name from player where name=?");
|
||||
PreparedStatement statement = conn.prepareStatement("select id, name, type from player where name=?");
|
||||
try {
|
||||
statement.setString(1, playerName);
|
||||
ResultSet rs = statement.executeQuery();
|
||||
@@ -153,8 +158,9 @@ public class PlayerDAO {
|
||||
if (rs.next()) {
|
||||
int id = rs.getInt(1);
|
||||
String name = rs.getString(2);
|
||||
String type = rs.getString(3);
|
||||
|
||||
return new Player(id, name);
|
||||
return new Player(id, name, type);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@ package com.gempukku.lotro.db.vo;
|
||||
public class Player {
|
||||
private int _id;
|
||||
private String _name;
|
||||
private String _type;
|
||||
|
||||
public Player(int id, String name) {
|
||||
public Player(int id, String name, String type) {
|
||||
_id = id;
|
||||
_name = name;
|
||||
_type = type;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
@@ -17,6 +19,10 @@ public class Player {
|
||||
return _name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return _type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
@@ -24,7 +30,6 @@ public class Player {
|
||||
|
||||
Player player = (Player) o;
|
||||
|
||||
if (_id != player._id) return false;
|
||||
if (_name != null ? !_name.equals(player._name) : player._name != null) return false;
|
||||
|
||||
return true;
|
||||
@@ -32,8 +37,6 @@ public class Player {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = _id;
|
||||
result = 31 * result + (_name != null ? _name.hashCode() : 0);
|
||||
return result;
|
||||
return _name != null ? _name.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,25 @@ public class ServerResource {
|
||||
_logger.debug("Resource created");
|
||||
}
|
||||
|
||||
@Path("/clearCache")
|
||||
@GET
|
||||
public String clearCache(@Context HttpServletRequest request) throws Exception {
|
||||
String playerName = getLoggedUser(request);
|
||||
|
||||
Player player = _playerDao.getPlayer(playerName);
|
||||
if (player == null)
|
||||
sendError(Response.Status.UNAUTHORIZED);
|
||||
|
||||
if (!player.getType().equals("a"))
|
||||
sendError(Response.Status.FORBIDDEN);
|
||||
|
||||
_playerDao.clearCache();
|
||||
_collectionDao.clearCache();
|
||||
_lotroServer.getDeckDao().clearCache();
|
||||
|
||||
return "OK";
|
||||
}
|
||||
|
||||
@Path("/login")
|
||||
@POST
|
||||
@Produces("text/html")
|
||||
|
||||
Reference in New Issue
Block a user