No longer need the cache invalidator for deleteAll(), also updated some logging
calls. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@744 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -19,7 +19,6 @@ import com.samskivert.io.ByteArrayOutInputStream;
|
|||||||
import com.samskivert.util.IntMap;
|
import com.samskivert.util.IntMap;
|
||||||
import com.samskivert.util.IntMaps;
|
import com.samskivert.util.IntMaps;
|
||||||
|
|
||||||
import com.samskivert.jdbc.depot.CacheInvalidator;
|
|
||||||
import com.samskivert.jdbc.depot.DatabaseException;
|
import com.samskivert.jdbc.depot.DatabaseException;
|
||||||
import com.samskivert.jdbc.depot.DepotRepository;
|
import com.samskivert.jdbc.depot.DepotRepository;
|
||||||
import com.samskivert.jdbc.depot.DuplicateKeyException;
|
import com.samskivert.jdbc.depot.DuplicateKeyException;
|
||||||
@@ -112,18 +111,7 @@ public class StatRepository extends DepotRepository
|
|||||||
*/
|
*/
|
||||||
public void deleteStats (final int playerId)
|
public void deleteStats (final int playerId)
|
||||||
{
|
{
|
||||||
CacheInvalidator invalidator = new CacheInvalidator() {
|
deleteAll(StatRecord.class, new Where(StatRecord.PLAYER_ID_C, playerId));
|
||||||
public void invalidate (PersistenceContext ctx) {
|
|
||||||
ctx.cacheTraverse(
|
|
||||||
StatRecord.class.getName(), new CacheEvictionFilter<StatRecord>() {
|
|
||||||
@Override
|
|
||||||
public boolean testForEviction (Serializable key, StatRecord record) {
|
|
||||||
return record != null && record.playerId == playerId;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
deleteAll(StatRecord.class, new Where(StatRecord.PLAYER_ID_C, playerId), invalidator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -134,8 +122,7 @@ public class StatRepository extends DepotRepository
|
|||||||
{
|
{
|
||||||
for (int ii = 0; ii < stats.length; ii++) {
|
for (int ii = 0; ii < stats.length; ii++) {
|
||||||
try {
|
try {
|
||||||
if (stats[ii].getType().isPersistent() &&
|
if (stats[ii].getType().isPersistent() && stats[ii].isModified()) {
|
||||||
stats[ii].isModified()) {
|
|
||||||
updateStat(playerId, stats[ii], true);
|
updateStat(playerId, stats[ii], true);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -173,19 +160,17 @@ public class StatRepository extends DepotRepository
|
|||||||
IntMap<String> map = _codeToString.get(type);
|
IntMap<String> map = _codeToString.get(type);
|
||||||
String value = (map == null) ? null : map.get(code);
|
String value = (map == null) ? null : map.get(code);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
// our value may have been mapped on a different server, so refresh
|
// our value may have been mapped on a different server, so refresh this mapping table
|
||||||
// this mapping table from the database; then try again
|
// from the database; then try again
|
||||||
try {
|
try {
|
||||||
loadStringCodes(type);
|
loadStringCodes(type);
|
||||||
} catch (DatabaseException pe) {
|
} catch (DatabaseException pe) {
|
||||||
log.warning("Failed to reload string codes " +
|
log.warning("Failed to reload string codes", "type", type, "code", code, pe);
|
||||||
"[type=" + type + ", code=" + code + "].", pe);
|
|
||||||
}
|
}
|
||||||
map = _codeToString.get(type);
|
map = _codeToString.get(type);
|
||||||
value = (map == null) ? null : map.get(code);
|
value = (map == null) ? null : map.get(code);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
log.warning("Missing reverse maping [type=" + type +
|
log.warning("Missing reverse maping", "type", type, "code", code);
|
||||||
", code=" + code + "].");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
@@ -207,7 +192,7 @@ public class StatRepository extends DepotRepository
|
|||||||
{
|
{
|
||||||
Stat.Type type = Stat.getType(statCode);
|
Stat.Type type = Stat.getType(statCode);
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
log.warning("Unable to decode stat, unknown type [code=" + statCode + "].");
|
log.warning("Unable to decode stat, unknown type", "code", statCode);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return decodeStat(type.newStat(), data, modCount);
|
return decodeStat(type.newStat(), data, modCount);
|
||||||
@@ -237,7 +222,7 @@ public class StatRepository extends DepotRepository
|
|||||||
errmsg = "Unable to decode stat";
|
errmsg = "Unable to decode stat";
|
||||||
}
|
}
|
||||||
|
|
||||||
log.warning(errmsg + " [type=" + stat.getType() + "]", error);
|
log.warning(errmsg, "type", stat.getType(), error);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,8 +272,7 @@ public class StatRepository extends DepotRepository
|
|||||||
if (numRows == 0 && forceWrite) {
|
if (numRows == 0 && forceWrite) {
|
||||||
log.warning("Possible collision while storing StatRecord",
|
log.warning("Possible collision while storing StatRecord",
|
||||||
"playerId", playerId, "stat", stat.getType().name(),
|
"playerId", playerId, "stat", stat.getType().name(),
|
||||||
"modCount", nextModCount,
|
"modCount", nextModCount, "overwriting", load(StatRecord.class, key));
|
||||||
"overwriting", load(StatRecord.class, key));
|
|
||||||
store(new StatRecord(playerId, stat.getCode(), data, nextModCount));
|
store(new StatRecord(playerId, stat.getCode(), data, nextModCount));
|
||||||
numRows = 1;
|
numRows = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user