Updated to use new DatabaseException.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@738 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2008-09-03 16:20:32 +00:00
parent 24455b4ab8
commit 36c3607585
2 changed files with 9 additions and 25 deletions
@@ -32,7 +32,6 @@ import com.google.common.collect.Lists;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.samskivert.io.PersistenceException;
import com.samskivert.util.IntSet; import com.samskivert.util.IntSet;
import com.samskivert.jdbc.depot.DepotRepository; import com.samskivert.jdbc.depot.DepotRepository;
@@ -67,7 +66,6 @@ public class RatingRepository extends DepotRepository
* {@link RatingRecord} object, or null if the player has no previous rating for the game. * {@link RatingRecord} object, or null if the player has no previous rating for the game.
*/ */
public RatingRecord getRating (int gameId, int playerId) public RatingRecord getRating (int gameId, int playerId)
throws PersistenceException
{ {
return load(RatingRecord.class, RatingRecord.getKey(gameId, playerId)); return load(RatingRecord.class, RatingRecord.getKey(gameId, playerId));
} }
@@ -78,7 +76,6 @@ public class RatingRepository extends DepotRepository
* and no greater than the number of given players. * and no greater than the number of given players.
*/ */
public List<RatingRecord> getRatings (int gameId, Integer... players) public List<RatingRecord> getRatings (int gameId, Integer... players)
throws PersistenceException
{ {
if (players.length == 0) { if (players.length == 0) {
return Collections.emptyList(); return Collections.emptyList();
@@ -97,7 +94,6 @@ public class RatingRepository extends DepotRepository
* @param count the maximum number of ratings to return or -1 for all ratings. * @param count the maximum number of ratings to return or -1 for all ratings.
*/ */
public List<RatingRecord> getRatings (int playerId, long since, int count) public List<RatingRecord> getRatings (int playerId, long since, int count)
throws PersistenceException
{ {
ArrayList<QueryClause> clauses = new ArrayList<QueryClause>(); ArrayList<QueryClause> clauses = new ArrayList<QueryClause>();
if (since > 0L) { if (since > 0L) {
@@ -124,7 +120,6 @@ public class RatingRepository extends DepotRepository
* @param playerIds an optional list of player ids to which to limit the top-rankings search. * @param playerIds an optional list of player ids to which to limit the top-rankings search.
*/ */
public List<RatingRecord> getTopRatings (int gameId, int limit, long since, IntSet playerIds) public List<RatingRecord> getTopRatings (int gameId, int limit, long since, IntSet playerIds)
throws PersistenceException
{ {
List<SQLExpression> where = Lists.newArrayList(); List<SQLExpression> where = Lists.newArrayList();
where.add(new Equals(RatingRecord.GAME_ID_C, gameId)); where.add(new Equals(RatingRecord.GAME_ID_C, gameId));
@@ -147,7 +142,6 @@ public class RatingRepository extends DepotRepository
* or create a row. * or create a row.
*/ */
public void setRating (int gameId, int playerId, int rating, int experience) public void setRating (int gameId, int playerId, int rating, int experience)
throws PersistenceException
{ {
store(new RatingRecord(gameId, playerId, rating, experience)); store(new RatingRecord(gameId, playerId, rating, experience));
} }
@@ -156,7 +150,6 @@ public class RatingRepository extends DepotRepository
* Deletes the specified rating record. * Deletes the specified rating record.
*/ */
public void deleteRating (int gameId, int playerId) public void deleteRating (int gameId, int playerId)
throws PersistenceException
{ {
delete(RatingRecord.class, RatingRecord.getKey(gameId, playerId)); delete(RatingRecord.class, RatingRecord.getKey(gameId, playerId));
} }
@@ -166,7 +159,6 @@ public class RatingRepository extends DepotRepository
* returned, rather a blank percentiler will be created and returned. * returned, rather a blank percentiler will be created and returned.
*/ */
public Percentiler loadPercentile (int gameId) public Percentiler loadPercentile (int gameId)
throws PersistenceException
{ {
PercentileRecord record = load(PercentileRecord.class, PercentileRecord.getKey(gameId)); PercentileRecord record = load(PercentileRecord.class, PercentileRecord.getKey(gameId));
return (record == null) ? new Percentiler() : new Percentiler(record.data); return (record == null) ? new Percentiler() : new Percentiler(record.data);
@@ -176,7 +168,6 @@ public class RatingRepository extends DepotRepository
* Writes the supplied percentiler's data out to the database. * Writes the supplied percentiler's data out to the database.
*/ */
public void updatePercentile (int gameId, Percentiler tiler) public void updatePercentile (int gameId, Percentiler tiler)
throws PersistenceException
{ {
PercentileRecord record = new PercentileRecord(); PercentileRecord record = new PercentileRecord();
record.gameId = gameId; record.gameId = gameId;
@@ -16,15 +16,15 @@ import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.samskivert.io.ByteArrayOutInputStream; import com.samskivert.io.ByteArrayOutInputStream;
import com.samskivert.io.PersistenceException;
import com.samskivert.util.IntMap; import com.samskivert.util.IntMap;
import com.samskivert.util.IntMaps; import com.samskivert.util.IntMaps;
import com.samskivert.jdbc.DuplicateKeyException;
import com.samskivert.jdbc.depot.CacheInvalidator; import com.samskivert.jdbc.depot.CacheInvalidator;
import com.samskivert.jdbc.depot.DatabaseException;
import com.samskivert.jdbc.depot.DepotRepository; import com.samskivert.jdbc.depot.DepotRepository;
import com.samskivert.jdbc.depot.PersistenceContext.CacheEvictionFilter; import com.samskivert.jdbc.depot.DuplicateKeyException;
import com.samskivert.jdbc.depot.Key; import com.samskivert.jdbc.depot.Key;
import com.samskivert.jdbc.depot.PersistenceContext.CacheEvictionFilter;
import com.samskivert.jdbc.depot.PersistenceContext; import com.samskivert.jdbc.depot.PersistenceContext;
import com.samskivert.jdbc.depot.PersistentRecord; import com.samskivert.jdbc.depot.PersistentRecord;
import com.samskivert.jdbc.depot.clause.FieldDefinition; import com.samskivert.jdbc.depot.clause.FieldDefinition;
@@ -52,7 +52,6 @@ public class StatRepository extends DepotRepository
* Constructs a new statistics repository with the specified persistence context. * Constructs a new statistics repository with the specified persistence context.
*/ */
@Inject public StatRepository (PersistenceContext context) @Inject public StatRepository (PersistenceContext context)
throws PersistenceException
{ {
super(context); super(context);
@@ -68,7 +67,6 @@ public class StatRepository extends DepotRepository
* no effect on the stat's data. * no effect on the stat's data.
*/ */
public <T extends Stat> T updateStat (int playerId, StatModifier<T> modifier) public <T extends Stat> T updateStat (int playerId, StatModifier<T> modifier)
throws PersistenceException
{ {
Where where = new Where(StatRecord.PLAYER_ID_C, playerId, Where where = new Where(StatRecord.PLAYER_ID_C, playerId,
StatRecord.STAT_CODE_C, modifier.getType().code()); StatRecord.STAT_CODE_C, modifier.getType().code());
@@ -87,7 +85,7 @@ public class StatRepository extends DepotRepository
} }
} }
throw new PersistenceException( throw new DatabaseException(
"Unable to update stat after " + MAX_UPDATE_TRIES + " attempts " + "Unable to update stat after " + MAX_UPDATE_TRIES + " attempts " +
"[stat=" + modifier.getType() + ", pid=" + playerId + "]"); "[stat=" + modifier.getType() + ", pid=" + playerId + "]");
} }
@@ -97,7 +95,6 @@ public class StatRepository extends DepotRepository
* *
*/ */
public ArrayList<Stat> loadStats (int playerId) public ArrayList<Stat> loadStats (int playerId)
throws PersistenceException
{ {
ArrayList<Stat> stats = new ArrayList<Stat>(); ArrayList<Stat> stats = new ArrayList<Stat>();
Where where = new Where(StatRecord.PLAYER_ID_C, playerId); Where where = new Where(StatRecord.PLAYER_ID_C, playerId);
@@ -114,7 +111,6 @@ public class StatRepository extends DepotRepository
* Deletes all stats associated with the specified player. * Deletes all stats associated with the specified player.
*/ */
public void deleteStats (final int playerId) public void deleteStats (final int playerId)
throws PersistenceException
{ {
CacheInvalidator invalidator = new CacheInvalidator() { CacheInvalidator invalidator = new CacheInvalidator() {
public void invalidate (PersistenceContext ctx) { public void invalidate (PersistenceContext ctx) {
@@ -159,7 +155,7 @@ public class StatRepository extends DepotRepository
if (code == null) { if (code == null) {
try { try {
code = assignStringCode(type, value); code = assignStringCode(type, value);
} catch (PersistenceException pe) { } catch (DatabaseException pe) {
log.warning("Failed to assign code [type=" + type + log.warning("Failed to assign code [type=" + type +
", value=" + value + "].", pe); ", value=" + value + "].", pe);
// at this point the database is probably totally hosed, so we can just punt here, // at this point the database is probably totally hosed, so we can just punt here,
@@ -181,7 +177,7 @@ public class StatRepository extends DepotRepository
// this mapping table from the database; then try again // this mapping table from the database; then try again
try { try {
loadStringCodes(type); loadStringCodes(type);
} catch (PersistenceException 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);
} }
@@ -252,13 +248,12 @@ public class StatRepository extends DepotRepository
* simultaneously modified by another database client. * simultaneously modified by another database client.
*/ */
protected boolean updateStat (int playerId, final Stat stat, boolean forceWrite) protected boolean updateStat (int playerId, final Stat stat, boolean forceWrite)
throws PersistenceException
{ {
ByteArrayOutInputStream out = new ByteArrayOutInputStream(); ByteArrayOutInputStream out = new ByteArrayOutInputStream();
try { try {
stat.persistTo(new ObjectOutputStream(out), this); stat.persistTo(new ObjectOutputStream(out), this);
} catch (IOException ioe) { } catch (IOException ioe) {
throw new PersistenceException("Error serializing stat " + stat, ioe); throw new DatabaseException("Error serializing stat " + stat, ioe);
} }
byte[] data = out.toByteArray(); byte[] data = out.toByteArray();
@@ -304,7 +299,6 @@ public class StatRepository extends DepotRepository
/** Helper function for {@link #getStringCode}. */ /** Helper function for {@link #getStringCode}. */
protected Integer assignStringCode (final Stat.Type type, final String value) protected Integer assignStringCode (final Stat.Type type, final String value)
throws PersistenceException
{ {
for (int ii = 0; ii < 10; ii++) { for (int ii = 0; ii < 10; ii++) {
MaxStatCodeRecord maxRecord = load( MaxStatCodeRecord maxRecord = load(
@@ -325,7 +319,7 @@ public class StatRepository extends DepotRepository
insert(new StringCodeRecord(type.code(), value, code)); insert(new StringCodeRecord(type.code(), value, code));
return code; return code;
} catch (PersistenceException pe) { } catch (DatabaseException pe) {
// if this is not a duplicate row exception, something is booched and we // if this is not a duplicate row exception, something is booched and we
// just fail // just fail
@@ -349,13 +343,12 @@ public class StatRepository extends DepotRepository
", value=" + value + "]."); ", value=" + value + "].");
} }
} }
throw new PersistenceException( throw new DatabaseException(
"Unable to assign code after 10 attempts [type=" + type + ", value=" + value + "]"); "Unable to assign code after 10 attempts [type=" + type + ", value=" + value + "]");
} }
/** Helper function used at repository startup. */ /** Helper function used at repository startup. */
protected void loadStringCodes (Stat.Type type) protected void loadStringCodes (Stat.Type type)
throws PersistenceException
{ {
QueryClause[] clauses; QueryClause[] clauses;
if (type != null) { if (type != null) {