Updated to new Depot world order.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@797 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2009-01-08 02:10:42 +00:00
parent b748974845
commit a8f4e9fc9b
8 changed files with 72 additions and 151 deletions
+1 -1
View File
@@ -27,7 +27,7 @@
<!-- generates fields for persistent record classes --> <!-- generates fields for persistent record classes -->
<target name="genrecord" depends="prepare"> <target name="genrecord" depends="prepare">
<taskdef name="grecord" classname="com.samskivert.jdbc.depot.tools.GenRecordTask" <taskdef name="grecord" classname="com.samskivert.depot.tools.GenRecordTask"
classpathref="classpath"/> classpathref="classpath"/>
<!-- make sure the record class files are all compiled --> <!-- make sure the record class files are all compiled -->
<javac srcdir="src/java" destdir="${classes.dir}" <javac srcdir="src/java" destdir="${classes.dir}"
@@ -35,26 +35,10 @@ import com.threerings.parlor.rating.util.Percentiler;
public class PercentileRecord extends PersistentRecord public class PercentileRecord extends PersistentRecord
{ {
// AUTO-GENERATED: FIELDS START // AUTO-GENERATED: FIELDS START
/** The column identifier for the {@link #gameId} field. */ public static final Class<PercentileRecord> _R = PercentileRecord.class;
public static final String GAME_ID = "gameId"; public static final ColumnExp GAME_ID = colexp(_R, "gameId");
public static final ColumnExp GAME_MODE = colexp(_R, "gameMode");
/** The qualified column identifier for the {@link #gameId} field. */ public static final ColumnExp DATA = colexp(_R, "data");
public static final ColumnExp GAME_ID_C =
new ColumnExp(PercentileRecord.class, GAME_ID);
/** The column identifier for the {@link #gameMode} field. */
public static final String GAME_MODE = "gameMode";
/** The qualified column identifier for the {@link #gameMode} field. */
public static final ColumnExp GAME_MODE_C =
new ColumnExp(PercentileRecord.class, GAME_MODE);
/** The column identifier for the {@link #data} field. */
public static final String DATA = "data";
/** The qualified column identifier for the {@link #data} field. */
public static final ColumnExp DATA_C =
new ColumnExp(PercentileRecord.class, DATA);
// AUTO-GENERATED: FIELDS END // AUTO-GENERATED: FIELDS END
/** Increment this value to reflect changes to this object's schema. */ /** Increment this value to reflect changes to this object's schema. */
@@ -79,7 +63,7 @@ public class PercentileRecord extends PersistentRecord
{ {
return new Key<PercentileRecord>( return new Key<PercentileRecord>(
PercentileRecord.class, PercentileRecord.class,
new String[] { GAME_ID, GAME_MODE }, new ColumnExp[] { GAME_ID, GAME_MODE },
new Comparable[] { gameId, gameMode }); new Comparable[] { gameId, gameMode });
} }
// AUTO-GENERATED: METHODS END // AUTO-GENERATED: METHODS END
@@ -33,57 +33,25 @@ import com.samskivert.depot.annotation.Id;
import com.samskivert.depot.annotation.Index; import com.samskivert.depot.annotation.Index;
import com.samskivert.depot.expression.ColumnExp; import com.samskivert.depot.expression.ColumnExp;
@Entity(indices={ @Entity
@Index(name="ixPlayerId", fields={ RatingRecord.PLAYER_ID })
})
public class RatingRecord extends PersistentRecord public class RatingRecord extends PersistentRecord
{ {
// AUTO-GENERATED: FIELDS START // AUTO-GENERATED: FIELDS START
/** The column identifier for the {@link #gameId} field. */ public static final Class<RatingRecord> _R = RatingRecord.class;
public static final String GAME_ID = "gameId"; public static final ColumnExp GAME_ID = colexp(_R, "gameId");
public static final ColumnExp PLAYER_ID = colexp(_R, "playerId");
/** The qualified column identifier for the {@link #gameId} field. */ public static final ColumnExp RATING = colexp(_R, "rating");
public static final ColumnExp GAME_ID_C = public static final ColumnExp EXPERIENCE = colexp(_R, "experience");
new ColumnExp(RatingRecord.class, GAME_ID); public static final ColumnExp LAST_UPDATED = colexp(_R, "lastUpdated");
/** The column identifier for the {@link #playerId} field. */
public static final String PLAYER_ID = "playerId";
/** The qualified column identifier for the {@link #playerId} field. */
public static final ColumnExp PLAYER_ID_C =
new ColumnExp(RatingRecord.class, PLAYER_ID);
/** The column identifier for the {@link #rating} field. */
public static final String RATING = "rating";
/** The qualified column identifier for the {@link #rating} field. */
public static final ColumnExp RATING_C =
new ColumnExp(RatingRecord.class, RATING);
/** The column identifier for the {@link #experience} field. */
public static final String EXPERIENCE = "experience";
/** The qualified column identifier for the {@link #experience} field. */
public static final ColumnExp EXPERIENCE_C =
new ColumnExp(RatingRecord.class, EXPERIENCE);
/** The column identifier for the {@link #lastUpdated} field. */
public static final String LAST_UPDATED = "lastUpdated";
/** The qualified column identifier for the {@link #lastUpdated} field. */
public static final ColumnExp LAST_UPDATED_C =
new ColumnExp(RatingRecord.class, LAST_UPDATED);
// AUTO-GENERATED: FIELDS END // AUTO-GENERATED: FIELDS END
public static final int SCHEMA_VERSION = 3; public static final int SCHEMA_VERSION = 3;
/** The identifier of the game we're rating for. */ /** The identifier of the game we're rating for. */
@Id @Id public int gameId;
public int gameId;
/** The identifier of the player we're rating. */ /** The identifier of the player we're rating. */
@Id @Id @Index public int playerId;
public int playerId;
/** The player's current rating. */ /** The player's current rating. */
public int rating; public int rating;
@@ -132,7 +100,7 @@ public class RatingRecord extends PersistentRecord
{ {
return new Key<RatingRecord>( return new Key<RatingRecord>(
RatingRecord.class, RatingRecord.class,
new String[] { GAME_ID, PLAYER_ID }, new ColumnExp[] { GAME_ID, PLAYER_ID },
new Comparable[] { gameId, playerId }); new Comparable[] { gameId, playerId });
} }
// AUTO-GENERATED: METHODS END // AUTO-GENERATED: METHODS END
@@ -85,8 +85,8 @@ public class RatingRepository extends DepotRepository
return Collections.emptyList(); return Collections.emptyList();
} }
return findAll(RatingRecord.class, return findAll(RatingRecord.class,
new Where(new And(new Equals(RatingRecord.GAME_ID_C, gameId), new Where(new And(new Equals(RatingRecord.GAME_ID, gameId),
new In(RatingRecord.PLAYER_ID_C, players)))); new In(RatingRecord.PLAYER_ID, players))));
} }
/** /**
@@ -102,15 +102,15 @@ public class RatingRepository extends DepotRepository
ArrayList<QueryClause> clauses = new ArrayList<QueryClause>(); ArrayList<QueryClause> clauses = new ArrayList<QueryClause>();
if (since > 0L) { if (since > 0L) {
Timestamp when = new Timestamp(System.currentTimeMillis() - since); Timestamp when = new Timestamp(System.currentTimeMillis() - since);
clauses.add(new Where(new And(new Equals(RatingRecord.PLAYER_ID_C, playerId), clauses.add(new Where(new And(new Equals(RatingRecord.PLAYER_ID, playerId),
new GreaterThan(RatingRecord.LAST_UPDATED_C, when)))); new GreaterThan(RatingRecord.LAST_UPDATED, when))));
} else { } else {
clauses.add(new Where(RatingRecord.PLAYER_ID_C, playerId)); clauses.add(new Where(RatingRecord.PLAYER_ID, playerId));
} }
if (count > 0) { if (count > 0) {
clauses.add(new Limit(0, count)); clauses.add(new Limit(0, count));
} }
clauses.add(OrderBy.descending(RatingRecord.LAST_UPDATED_C)); clauses.add(OrderBy.descending(RatingRecord.LAST_UPDATED));
return findAll(RatingRecord.class, clauses); return findAll(RatingRecord.class, clauses);
} }
@@ -126,17 +126,17 @@ public class RatingRepository extends DepotRepository
public List<RatingRecord> getTopRatings (int gameId, int limit, long since, IntSet playerIds) public List<RatingRecord> getTopRatings (int gameId, int limit, long since, IntSet playerIds)
{ {
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, gameId));
if (since > 0L) { if (since > 0L) {
where.add(new GreaterThan(RatingRecord.LAST_UPDATED_C, where.add(new GreaterThan(RatingRecord.LAST_UPDATED,
new Timestamp(System.currentTimeMillis() - since))); new Timestamp(System.currentTimeMillis() - since)));
} }
if (playerIds != null) { if (playerIds != null) {
where.add(new In(RatingRecord.PLAYER_ID_C, playerIds)); where.add(new In(RatingRecord.PLAYER_ID, playerIds));
} }
OrderBy ob = new OrderBy( OrderBy ob = new OrderBy(
new SQLExpression[] { RatingRecord.RATING_C, RatingRecord.LAST_UPDATED_C }, new SQLExpression[] { RatingRecord.RATING, RatingRecord.LAST_UPDATED },
new OrderBy.Order[] { OrderBy.Order.DESC, OrderBy.Order.DESC }); new OrderBy.Order[] { OrderBy.Order.DESC, OrderBy.Order.DESC });
return findAll(RatingRecord.class, new Where(new And(where)), new Limit(0, limit), ob); return findAll(RatingRecord.class, new Where(new And(where)), new Limit(0, limit), ob);
} }
@@ -178,7 +178,7 @@ public class RatingRepository extends DepotRepository
{ {
Map<Integer, Percentiler> tilers = Maps.newHashMap(); Map<Integer, Percentiler> tilers = Maps.newHashMap();
for (PercentileRecord record : findAll( for (PercentileRecord record : findAll(
PercentileRecord.class, new Where(PercentileRecord.GAME_ID_C, gameId))) { PercentileRecord.class, new Where(PercentileRecord.GAME_ID, gameId))) {
tilers.put(record.gameMode, new Percentiler(record.data)); tilers.put(record.gameMode, new Percentiler(record.data));
} }
return tilers; return tilers;
@@ -201,7 +201,7 @@ public class RatingRepository extends DepotRepository
*/ */
public void deletePercentiles (int gameId) public void deletePercentiles (int gameId)
{ {
deleteAll(PercentileRecord.class, new Where(PercentileRecord.GAME_ID_C, gameId)); deleteAll(PercentileRecord.class, new Where(PercentileRecord.GAME_ID, gameId));
} }
/** /**
@@ -13,12 +13,8 @@ import com.samskivert.depot.expression.ColumnExp;
public class MaxStatCodeRecord extends PersistentRecord { public class MaxStatCodeRecord extends PersistentRecord {
// AUTO-GENERATED: FIELDS START // AUTO-GENERATED: FIELDS START
/** The column identifier for the {@link #maxCode} field. */ public static final Class<MaxStatCodeRecord> _R = MaxStatCodeRecord.class;
public static final String MAX_CODE = "maxCode"; public static final ColumnExp MAX_CODE = colexp(_R, "maxCode");
/** The qualified column identifier for the {@link #maxCode} field. */
public static final ColumnExp MAX_CODE_C =
new ColumnExp(MaxStatCodeRecord.class, MAX_CODE);
// AUTO-GENERATED: FIELDS END // AUTO-GENERATED: FIELDS END
@Column @Column
@@ -32,33 +32,11 @@ import com.samskivert.depot.expression.ColumnExp;
public class StatRecord extends PersistentRecord public class StatRecord extends PersistentRecord
{ {
// AUTO-GENERATED: FIELDS START // AUTO-GENERATED: FIELDS START
/** The column identifier for the {@link #playerId} field. */ public static final Class<StatRecord> _R = StatRecord.class;
public static final String PLAYER_ID = "playerId"; public static final ColumnExp PLAYER_ID = colexp(_R, "playerId");
public static final ColumnExp STAT_CODE = colexp(_R, "statCode");
/** The qualified column identifier for the {@link #playerId} field. */ public static final ColumnExp STAT_DATA = colexp(_R, "statData");
public static final ColumnExp PLAYER_ID_C = public static final ColumnExp MOD_COUNT = colexp(_R, "modCount");
new ColumnExp(StatRecord.class, PLAYER_ID);
/** The column identifier for the {@link #statCode} field. */
public static final String STAT_CODE = "statCode";
/** The qualified column identifier for the {@link #statCode} field. */
public static final ColumnExp STAT_CODE_C =
new ColumnExp(StatRecord.class, STAT_CODE);
/** The column identifier for the {@link #statData} field. */
public static final String STAT_DATA = "statData";
/** The qualified column identifier for the {@link #statData} field. */
public static final ColumnExp STAT_DATA_C =
new ColumnExp(StatRecord.class, STAT_DATA);
/** The column identifier for the {@link #modCount} field. */
public static final String MOD_COUNT = "modCount";
/** The qualified column identifier for the {@link #modCount} field. */
public static final ColumnExp MOD_COUNT_C =
new ColumnExp(StatRecord.class, MOD_COUNT);
// AUTO-GENERATED: FIELDS END // AUTO-GENERATED: FIELDS END
public static final int SCHEMA_VERSION = 4; public static final int SCHEMA_VERSION = 4;
@@ -124,7 +102,7 @@ public class StatRecord extends PersistentRecord
{ {
return new Key<StatRecord>( return new Key<StatRecord>(
StatRecord.class, StatRecord.class,
new String[] { PLAYER_ID, STAT_CODE }, new ColumnExp[] { PLAYER_ID, STAT_CODE },
new Comparable[] { playerId, statCode }); new Comparable[] { playerId, statCode });
} }
// AUTO-GENERATED: METHODS END // AUTO-GENERATED: METHODS END
@@ -62,8 +62,8 @@ public class StatRepository extends DepotRepository
*/ */
public <T extends Stat> T updateStat (int playerId, StatModifier<T> modifier) public <T extends Stat> T updateStat (int playerId, StatModifier<T> modifier)
{ {
Where where = new Where(StatRecord.PLAYER_ID_C, playerId, Where where = new Where(StatRecord.PLAYER_ID, playerId,
StatRecord.STAT_CODE_C, modifier.getType().code()); StatRecord.STAT_CODE, modifier.getType().code());
for (int ii = 0; ii < MAX_UPDATE_TRIES; ii++) { for (int ii = 0; ii < MAX_UPDATE_TRIES; ii++) {
StatRecord record = load(StatRecord.class, where); // TODO: force cache skip on ii > 0 StatRecord record = load(StatRecord.class, where); // TODO: force cache skip on ii > 0
@@ -91,7 +91,7 @@ public class StatRepository extends DepotRepository
public ArrayList<Stat> loadStats (int playerId) public ArrayList<Stat> loadStats (int playerId)
{ {
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, playerId);
for (StatRecord record : findAll(StatRecord.class, where)) { for (StatRecord record : findAll(StatRecord.class, where)) {
Stat stat = decodeStat(record.statCode, record.statData, record.modCount); Stat stat = decodeStat(record.statCode, record.statData, record.modCount);
if (stat != null) { if (stat != null) {
@@ -106,7 +106,7 @@ public class StatRepository extends DepotRepository
*/ */
public void deleteStats (final int playerId) public void deleteStats (final int playerId)
{ {
deleteAll(StatRecord.class, new Where(StatRecord.PLAYER_ID_C, playerId)); deleteAll(StatRecord.class, new Where(StatRecord.PLAYER_ID, playerId));
} }
/** /**
@@ -243,9 +243,9 @@ public class StatRepository extends DepotRepository
// update the row in the database only if it has the expected modCount // update the row in the database only if it has the expected modCount
int numRows = updatePartial( int numRows = updatePartial(
StatRecord.class, StatRecord.class,
new Where(StatRecord.PLAYER_ID_C, playerId, new Where(StatRecord.PLAYER_ID, playerId,
StatRecord.STAT_CODE_C, stat.getCode(), StatRecord.STAT_CODE, stat.getCode(),
StatRecord.MOD_COUNT_C, stat.getModCount()), StatRecord.MOD_COUNT, stat.getModCount()),
key, key,
StatRecord.STAT_DATA, data, StatRecord.MOD_COUNT, nextModCount); StatRecord.STAT_DATA, data, StatRecord.MOD_COUNT, nextModCount);
@@ -284,8 +284,8 @@ public class StatRepository extends DepotRepository
MaxStatCodeRecord.class, MaxStatCodeRecord.class,
new FromOverride(StringCodeRecord.class), new FromOverride(StringCodeRecord.class),
new FieldDefinition(MaxStatCodeRecord.MAX_CODE, new FieldDefinition(MaxStatCodeRecord.MAX_CODE,
new FunctionExp("MAX", StringCodeRecord.CODE_C)), new FunctionExp("MAX", StringCodeRecord.CODE)),
new Where(StringCodeRecord.STAT_CODE_C, type.code())); new Where(StringCodeRecord.STAT_CODE, type.code()));
int code = maxRecord != null ? maxRecord.maxCode + 1 : 1; int code = maxRecord != null ? maxRecord.maxCode + 1 : 1;
@@ -327,7 +327,7 @@ public class StatRepository extends DepotRepository
{ {
QueryClause[] clauses; QueryClause[] clauses;
if (type != null) { if (type != null) {
clauses = new QueryClause[] { new Where(StringCodeRecord.STAT_CODE_C, type.code()) }; clauses = new QueryClause[] { new Where(StringCodeRecord.STAT_CODE, type.code()) };
} else { } else {
clauses = new QueryClause[0]; clauses = new QueryClause[0];
} }
@@ -26,46 +26,41 @@ import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.annotation.Column; import com.samskivert.depot.annotation.Column;
import com.samskivert.depot.annotation.Entity; import com.samskivert.depot.annotation.Entity;
import com.samskivert.depot.annotation.Id; import com.samskivert.depot.annotation.Id;
import com.samskivert.depot.annotation.UniqueConstraint; import com.samskivert.depot.annotation.Index;
import com.samskivert.depot.expression.ColumnExp; import com.samskivert.depot.expression.ColumnExp;
@Entity(name="STRING_CODES", uniqueConstraints={ @Entity(name="STRING_CODES", indices={
@UniqueConstraint(fieldNames={ StringCodeRecord.STAT_CODE, StringCodeRecord.VALUE }), @Index(name="statCodeValue", unique=true),
@UniqueConstraint(fieldNames={ StringCodeRecord.STAT_CODE, StringCodeRecord.CODE })}) @Index(name="statCodeCode", unique=true)
})
public class StringCodeRecord extends PersistentRecord public class StringCodeRecord extends PersistentRecord
{ {
// AUTO-GENERATED: FIELDS START // AUTO-GENERATED: FIELDS START
/** The column identifier for the {@link #statCode} field. */ public static final Class<StringCodeRecord> _R = StringCodeRecord.class;
public static final String STAT_CODE = "statCode"; public static final ColumnExp STAT_CODE = colexp(_R, "statCode");
public static final ColumnExp VALUE = colexp(_R, "value");
/** The qualified column identifier for the {@link #statCode} field. */ public static final ColumnExp CODE = colexp(_R, "code");
public static final ColumnExp STAT_CODE_C =
new ColumnExp(StringCodeRecord.class, STAT_CODE);
/** The column identifier for the {@link #value} field. */
public static final String VALUE = "value";
/** The qualified column identifier for the {@link #value} field. */
public static final ColumnExp VALUE_C =
new ColumnExp(StringCodeRecord.class, VALUE);
/** The column identifier for the {@link #code} field. */
public static final String CODE = "code";
/** The qualified column identifier for the {@link #code} field. */
public static final ColumnExp CODE_C =
new ColumnExp(StringCodeRecord.class, CODE);
// AUTO-GENERATED: FIELDS END // AUTO-GENERATED: FIELDS END
public static final int SCHEMA_VERSION = 2; public static final int SCHEMA_VERSION = 2;
/** Defines the statCodeValue unique index. */
public static ColumnExp[] statCodeValue ()
{
return new ColumnExp[] { STAT_CODE, VALUE };
}
/** Defines the statCodeCode unique index. */
public static ColumnExp[] statCodeCode ()
{
return new ColumnExp[] { STAT_CODE, CODE };
}
/** The code of the stat. */ /** The code of the stat. */
@Id @Id @Column(name="STAT_CODE")
@Column(name="STAT_CODE")
public int statCode; public int statCode;
@Id @Id @Column(name="VALUE")
@Column(name="VALUE")
public String value; public String value;
@Column(name="CODE") @Column(name="CODE")
@@ -99,7 +94,7 @@ public class StringCodeRecord extends PersistentRecord
{ {
return new Key<StringCodeRecord>( return new Key<StringCodeRecord>(
StringCodeRecord.class, StringCodeRecord.class,
new String[] { STAT_CODE, VALUE }, new ColumnExp[] { STAT_CODE, VALUE },
new Comparable[] { statCode, value }); new Comparable[] { statCode, value });
} }
// AUTO-GENERATED: METHODS END // AUTO-GENERATED: METHODS END