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 -->
<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"/>
<!-- make sure the record class files are all compiled -->
<javac srcdir="src/java" destdir="${classes.dir}"
@@ -35,26 +35,10 @@ import com.threerings.parlor.rating.util.Percentiler;
public class PercentileRecord extends PersistentRecord
{
// AUTO-GENERATED: FIELDS START
/** The column identifier for the {@link #gameId} field. */
public static final String GAME_ID = "gameId";
/** The qualified column identifier for the {@link #gameId} field. */
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);
public static final Class<PercentileRecord> _R = PercentileRecord.class;
public static final ColumnExp GAME_ID = colexp(_R, "gameId");
public static final ColumnExp GAME_MODE = colexp(_R, "gameMode");
public static final ColumnExp DATA = colexp(_R, "data");
// AUTO-GENERATED: FIELDS END
/** Increment this value to reflect changes to this object's schema. */
@@ -79,7 +63,7 @@ public class PercentileRecord extends PersistentRecord
{
return new Key<PercentileRecord>(
PercentileRecord.class,
new String[] { GAME_ID, GAME_MODE },
new ColumnExp[] { GAME_ID, GAME_MODE },
new Comparable[] { gameId, gameMode });
}
// AUTO-GENERATED: METHODS END
@@ -33,57 +33,25 @@ import com.samskivert.depot.annotation.Id;
import com.samskivert.depot.annotation.Index;
import com.samskivert.depot.expression.ColumnExp;
@Entity(indices={
@Index(name="ixPlayerId", fields={ RatingRecord.PLAYER_ID })
})
@Entity
public class RatingRecord extends PersistentRecord
{
// AUTO-GENERATED: FIELDS START
/** The column identifier for the {@link #gameId} field. */
public static final String GAME_ID = "gameId";
/** The qualified column identifier for the {@link #gameId} field. */
public static final ColumnExp GAME_ID_C =
new ColumnExp(RatingRecord.class, GAME_ID);
/** 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);
public static final Class<RatingRecord> _R = RatingRecord.class;
public static final ColumnExp GAME_ID = colexp(_R, "gameId");
public static final ColumnExp PLAYER_ID = colexp(_R, "playerId");
public static final ColumnExp RATING = colexp(_R, "rating");
public static final ColumnExp EXPERIENCE = colexp(_R, "experience");
public static final ColumnExp LAST_UPDATED = colexp(_R, "lastUpdated");
// AUTO-GENERATED: FIELDS END
public static final int SCHEMA_VERSION = 3;
/** The identifier of the game we're rating for. */
@Id
public int gameId;
@Id public int gameId;
/** The identifier of the player we're rating. */
@Id
public int playerId;
@Id @Index public int playerId;
/** The player's current rating. */
public int rating;
@@ -132,7 +100,7 @@ public class RatingRecord extends PersistentRecord
{
return new Key<RatingRecord>(
RatingRecord.class,
new String[] { GAME_ID, PLAYER_ID },
new ColumnExp[] { GAME_ID, PLAYER_ID },
new Comparable[] { gameId, playerId });
}
// AUTO-GENERATED: METHODS END
@@ -85,8 +85,8 @@ public class RatingRepository extends DepotRepository
return Collections.emptyList();
}
return findAll(RatingRecord.class,
new Where(new And(new Equals(RatingRecord.GAME_ID_C, gameId),
new In(RatingRecord.PLAYER_ID_C, players))));
new Where(new And(new Equals(RatingRecord.GAME_ID, gameId),
new In(RatingRecord.PLAYER_ID, players))));
}
/**
@@ -102,15 +102,15 @@ public class RatingRepository extends DepotRepository
ArrayList<QueryClause> clauses = new ArrayList<QueryClause>();
if (since > 0L) {
Timestamp when = new Timestamp(System.currentTimeMillis() - since);
clauses.add(new Where(new And(new Equals(RatingRecord.PLAYER_ID_C, playerId),
new GreaterThan(RatingRecord.LAST_UPDATED_C, when))));
clauses.add(new Where(new And(new Equals(RatingRecord.PLAYER_ID, playerId),
new GreaterThan(RatingRecord.LAST_UPDATED, when))));
} else {
clauses.add(new Where(RatingRecord.PLAYER_ID_C, playerId));
clauses.add(new Where(RatingRecord.PLAYER_ID, playerId));
}
if (count > 0) {
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);
}
@@ -126,17 +126,17 @@ public class RatingRepository extends DepotRepository
public List<RatingRecord> getTopRatings (int gameId, int limit, long since, IntSet playerIds)
{
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) {
where.add(new GreaterThan(RatingRecord.LAST_UPDATED_C,
where.add(new GreaterThan(RatingRecord.LAST_UPDATED,
new Timestamp(System.currentTimeMillis() - since)));
}
if (playerIds != null) {
where.add(new In(RatingRecord.PLAYER_ID_C, playerIds));
where.add(new In(RatingRecord.PLAYER_ID, playerIds));
}
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 });
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();
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));
}
return tilers;
@@ -201,7 +201,7 @@ public class RatingRepository extends DepotRepository
*/
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 {
// AUTO-GENERATED: FIELDS START
/** The column identifier for the {@link #maxCode} field. */
public static final String MAX_CODE = "maxCode";
/** The qualified column identifier for the {@link #maxCode} field. */
public static final ColumnExp MAX_CODE_C =
new ColumnExp(MaxStatCodeRecord.class, MAX_CODE);
public static final Class<MaxStatCodeRecord> _R = MaxStatCodeRecord.class;
public static final ColumnExp MAX_CODE = colexp(_R, "maxCode");
// AUTO-GENERATED: FIELDS END
@Column
@@ -32,33 +32,11 @@ import com.samskivert.depot.expression.ColumnExp;
public class StatRecord extends PersistentRecord
{
// AUTO-GENERATED: FIELDS START
/** 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(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);
public static final Class<StatRecord> _R = StatRecord.class;
public static final ColumnExp PLAYER_ID = colexp(_R, "playerId");
public static final ColumnExp STAT_CODE = colexp(_R, "statCode");
public static final ColumnExp STAT_DATA = colexp(_R, "statData");
public static final ColumnExp MOD_COUNT = colexp(_R, "modCount");
// AUTO-GENERATED: FIELDS END
public static final int SCHEMA_VERSION = 4;
@@ -124,7 +102,7 @@ public class StatRecord extends PersistentRecord
{
return new Key<StatRecord>(
StatRecord.class,
new String[] { PLAYER_ID, STAT_CODE },
new ColumnExp[] { PLAYER_ID, STAT_CODE },
new Comparable[] { playerId, statCode });
}
// AUTO-GENERATED: METHODS END
@@ -62,8 +62,8 @@ public class StatRepository extends DepotRepository
*/
public <T extends Stat> T updateStat (int playerId, StatModifier<T> modifier)
{
Where where = new Where(StatRecord.PLAYER_ID_C, playerId,
StatRecord.STAT_CODE_C, modifier.getType().code());
Where where = new Where(StatRecord.PLAYER_ID, playerId,
StatRecord.STAT_CODE, modifier.getType().code());
for (int ii = 0; ii < MAX_UPDATE_TRIES; ii++) {
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)
{
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)) {
Stat stat = decodeStat(record.statCode, record.statData, record.modCount);
if (stat != null) {
@@ -106,7 +106,7 @@ public class StatRepository extends DepotRepository
*/
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
int numRows = updatePartial(
StatRecord.class,
new Where(StatRecord.PLAYER_ID_C, playerId,
StatRecord.STAT_CODE_C, stat.getCode(),
StatRecord.MOD_COUNT_C, stat.getModCount()),
new Where(StatRecord.PLAYER_ID, playerId,
StatRecord.STAT_CODE, stat.getCode(),
StatRecord.MOD_COUNT, stat.getModCount()),
key,
StatRecord.STAT_DATA, data, StatRecord.MOD_COUNT, nextModCount);
@@ -284,8 +284,8 @@ public class StatRepository extends DepotRepository
MaxStatCodeRecord.class,
new FromOverride(StringCodeRecord.class),
new FieldDefinition(MaxStatCodeRecord.MAX_CODE,
new FunctionExp("MAX", StringCodeRecord.CODE_C)),
new Where(StringCodeRecord.STAT_CODE_C, type.code()));
new FunctionExp("MAX", StringCodeRecord.CODE)),
new Where(StringCodeRecord.STAT_CODE, type.code()));
int code = maxRecord != null ? maxRecord.maxCode + 1 : 1;
@@ -327,7 +327,7 @@ public class StatRepository extends DepotRepository
{
QueryClause[] clauses;
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 {
clauses = new QueryClause[0];
}
@@ -26,46 +26,41 @@ import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.annotation.Column;
import com.samskivert.depot.annotation.Entity;
import com.samskivert.depot.annotation.Id;
import com.samskivert.depot.annotation.UniqueConstraint;
import com.samskivert.depot.annotation.Index;
import com.samskivert.depot.expression.ColumnExp;
@Entity(name="STRING_CODES", uniqueConstraints={
@UniqueConstraint(fieldNames={ StringCodeRecord.STAT_CODE, StringCodeRecord.VALUE }),
@UniqueConstraint(fieldNames={ StringCodeRecord.STAT_CODE, StringCodeRecord.CODE })})
@Entity(name="STRING_CODES", indices={
@Index(name="statCodeValue", unique=true),
@Index(name="statCodeCode", unique=true)
})
public class StringCodeRecord extends PersistentRecord
{
// AUTO-GENERATED: FIELDS START
/** 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(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);
public static final Class<StringCodeRecord> _R = StringCodeRecord.class;
public static final ColumnExp STAT_CODE = colexp(_R, "statCode");
public static final ColumnExp VALUE = colexp(_R, "value");
public static final ColumnExp CODE = colexp(_R, "code");
// AUTO-GENERATED: FIELDS END
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. */
@Id
@Column(name="STAT_CODE")
@Id @Column(name="STAT_CODE")
public int statCode;
@Id
@Column(name="VALUE")
@Id @Column(name="VALUE")
public String value;
@Column(name="CODE")
@@ -99,7 +94,7 @@ public class StringCodeRecord extends PersistentRecord
{
return new Key<StringCodeRecord>(
StringCodeRecord.class,
new String[] { STAT_CODE, VALUE },
new ColumnExp[] { STAT_CODE, VALUE },
new Comparable[] { statCode, value });
}
// AUTO-GENERATED: METHODS END