Nix PercentileRecord.type allow gameId to be fiddled by derive class.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@432 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2007-09-11 21:47:06 +00:00
parent fe3db313bf
commit ea3ab0bf3f
3 changed files with 20 additions and 40 deletions
@@ -215,7 +215,7 @@ public abstract class RatingManagerDelegate extends GameManagerDelegate
}
log.info("Loading " + ratings + "...");
final int gameId = _gmgr.getGameConfig().getGameId();
final int gameId = getGameId();
CrowdServer.invoker.postUnit(new RepositoryUnit("loadRatings") {
public void invokePersist () throws Exception {
// map the records by player id so that we can correlate with the db results
@@ -256,7 +256,7 @@ public abstract class RatingManagerDelegate extends GameManagerDelegate
}
log.info("Saving " + ratings + "...");
final int gameId = _gmgr.getGameConfig().getGameId();
final int gameId = getGameId();
CrowdServer.invoker.postUnit(new RepositoryUnit("saveRatings") {
public void invokePersist () throws Exception {
for (Rating rating : ratings) {
@@ -374,6 +374,14 @@ public abstract class RatingManagerDelegate extends GameManagerDelegate
return MathUtil.bound(MINIMUM_RATING, nrat, MAXIMUM_RATING);
}
/**
* Returns the game id to use when reading and writing ratings.
*/
protected int getGameId ()
{
return _gmgr.getGameConfig().getGameId();
}
/**
* Return the minimum time (in seconds) a game must've lasted for it to count towards rating.
*/
@@ -42,13 +42,6 @@ public class PercentileRecord extends PersistentRecord
public static final ColumnExp GAME_ID_C =
new ColumnExp(PercentileRecord.class, GAME_ID);
/** The column identifier for the {@link #type} field. */
public static final String TYPE = "type";
/** The qualified column identifier for the {@link #type} field. */
public static final ColumnExp TYPE_C =
new ColumnExp(PercentileRecord.class, TYPE);
/** The column identifier for the {@link #data} field. */
public static final String DATA = "data";
@@ -58,16 +51,12 @@ public class PercentileRecord extends PersistentRecord
// AUTO-GENERATED: FIELDS END
/** Increment this value to reflect changes to this object's schema. */
public static final int SCHEMA_VERSION = 2;
public static final int SCHEMA_VERSION = 3;
/** The id of the game for which we're tracking a percentile distribution. */
@Id
public int gameId;
/** The type of percentile distribution (games can maintain multiple distributions). */
@Id
public int type;
/** The raw percentiler data. */
@Column(length=500)
public byte[] data;
@@ -77,12 +66,12 @@ public class PercentileRecord extends PersistentRecord
* Create and return a primary {@link Key} to identify a {@link #PercentileRecord}
* with the supplied key values.
*/
public static Key<PercentileRecord> getKey (int gameId, int type)
public static Key<PercentileRecord> getKey (int gameId)
{
return new Key<PercentileRecord>(
PercentileRecord.class,
new String[] { GAME_ID, TYPE },
new Comparable[] { gameId, type });
new String[] { GAME_ID },
new Comparable[] { gameId });
}
// AUTO-GENERATED: METHODS END
}
@@ -53,6 +53,7 @@ public class RatingRepository extends DepotRepository
// TEMP
ctx.registerMigration(PercentileRecord.class, new EntityMigration.Retype(2, "data"));
ctx.registerMigration(PercentileRecord.class, new EntityMigration.Drop(3, "type"));
// END TEMP
}
@@ -111,42 +112,24 @@ public class RatingRepository extends DepotRepository
}
/**
* Loads all percentile distributions associated with the specified game.
*
* @return a map from type to {@link Percentiler} instance.
* Loads the percentile distribution associated with the specified game. null will never be
* returned, rather a blank percentiler will be created and returned.
*/
public IntMap<Percentiler> loadPercentiles (int gameId)
public Percentiler loadPercentile (int gameId)
throws PersistenceException
{
HashIntMap<Percentiler> results = new HashIntMap<Percentiler>();
Where where = new Where(PercentileRecord.GAME_ID_C, gameId);
for (PercentileRecord record : findAll(PercentileRecord.class, where)) {
results.put(record.type, new Percentiler(record.data));
}
return results;
}
/**
* Loads a particular percentiler for the specified game. null will never be returned, rather a
* blank percentiler will be created and returned.
*/
public Percentiler loadPercentile (int gameId, int type)
throws PersistenceException
{
PercentileRecord record =
load(PercentileRecord.class, PercentileRecord.getKey(gameId, type));
PercentileRecord record = load(PercentileRecord.class, PercentileRecord.getKey(gameId));
return (record == null) ? new Percentiler() : new Percentiler(record.data);
}
/**
* Writes the supplied percentiler's data out to the database.
*/
public void updatePercentile (int gameId, int type, Percentiler tiler)
public void updatePercentile (int gameId, Percentiler tiler)
throws PersistenceException
{
PercentileRecord record = new PercentileRecord();
record.gameId = gameId;
record.type = type;
record.data = tiler.toBytes();
store(record);
}