From a8f4e9fc9bac10d916fc4b55382e5be6dbb3b466 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 8 Jan 2009 02:10:42 +0000 Subject: [PATCH] Updated to new Depot world order. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@797 c613c5cb-e716-0410-b11b-feb51c14d237 --- build.xml | 2 +- .../server/persist/PercentileRecord.java | 26 ++------- .../rating/server/persist/RatingRecord.java | 52 ++++------------- .../server/persist/RatingRepository.java | 24 ++++---- .../server/persist/MaxStatCodeRecord.java | 8 +-- .../stats/server/persist/StatRecord.java | 34 ++--------- .../stats/server/persist/StatRepository.java | 20 +++---- .../server/persist/StringCodeRecord.java | 57 +++++++++---------- 8 files changed, 72 insertions(+), 151 deletions(-) diff --git a/build.xml b/build.xml index e2fbe085..a407c34e 100644 --- a/build.xml +++ b/build.xml @@ -27,7 +27,7 @@ - _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.class, - new String[] { GAME_ID, GAME_MODE }, + new ColumnExp[] { GAME_ID, GAME_MODE }, new Comparable[] { gameId, gameMode }); } // AUTO-GENERATED: METHODS END diff --git a/src/java/com/threerings/parlor/rating/server/persist/RatingRecord.java b/src/java/com/threerings/parlor/rating/server/persist/RatingRecord.java index 7536d180..9e2f1787 100644 --- a/src/java/com/threerings/parlor/rating/server/persist/RatingRecord.java +++ b/src/java/com/threerings/parlor/rating/server/persist/RatingRecord.java @@ -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 _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.class, - new String[] { GAME_ID, PLAYER_ID }, + new ColumnExp[] { GAME_ID, PLAYER_ID }, new Comparable[] { gameId, playerId }); } // AUTO-GENERATED: METHODS END diff --git a/src/java/com/threerings/parlor/rating/server/persist/RatingRepository.java b/src/java/com/threerings/parlor/rating/server/persist/RatingRepository.java index 3f6c84d6..d554709d 100644 --- a/src/java/com/threerings/parlor/rating/server/persist/RatingRepository.java +++ b/src/java/com/threerings/parlor/rating/server/persist/RatingRepository.java @@ -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 clauses = new ArrayList(); 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 getTopRatings (int gameId, int limit, long since, IntSet playerIds) { List 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 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)); } /** diff --git a/src/java/com/threerings/stats/server/persist/MaxStatCodeRecord.java b/src/java/com/threerings/stats/server/persist/MaxStatCodeRecord.java index 390c11ad..7d12ef3d 100644 --- a/src/java/com/threerings/stats/server/persist/MaxStatCodeRecord.java +++ b/src/java/com/threerings/stats/server/persist/MaxStatCodeRecord.java @@ -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 _R = MaxStatCodeRecord.class; + public static final ColumnExp MAX_CODE = colexp(_R, "maxCode"); // AUTO-GENERATED: FIELDS END @Column diff --git a/src/java/com/threerings/stats/server/persist/StatRecord.java b/src/java/com/threerings/stats/server/persist/StatRecord.java index a366a374..b540c41d 100644 --- a/src/java/com/threerings/stats/server/persist/StatRecord.java +++ b/src/java/com/threerings/stats/server/persist/StatRecord.java @@ -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 _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.class, - new String[] { PLAYER_ID, STAT_CODE }, + new ColumnExp[] { PLAYER_ID, STAT_CODE }, new Comparable[] { playerId, statCode }); } // AUTO-GENERATED: METHODS END diff --git a/src/java/com/threerings/stats/server/persist/StatRepository.java b/src/java/com/threerings/stats/server/persist/StatRepository.java index ef421ab3..80611d3b 100644 --- a/src/java/com/threerings/stats/server/persist/StatRepository.java +++ b/src/java/com/threerings/stats/server/persist/StatRepository.java @@ -62,8 +62,8 @@ public class StatRepository extends DepotRepository */ public T updateStat (int playerId, StatModifier 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 loadStats (int playerId) { ArrayList stats = new ArrayList(); - 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]; } diff --git a/src/java/com/threerings/stats/server/persist/StringCodeRecord.java b/src/java/com/threerings/stats/server/persist/StringCodeRecord.java index 86fc3e67..af2c2ab4 100644 --- a/src/java/com/threerings/stats/server/persist/StringCodeRecord.java +++ b/src/java/com/threerings/stats/server/persist/StringCodeRecord.java @@ -26,51 +26,46 @@ 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 _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") public int code; - + /** * An empty constructor for unmarshalling. */ @@ -99,7 +94,7 @@ public class StringCodeRecord extends PersistentRecord { return new Key( StringCodeRecord.class, - new String[] { STAT_CODE, VALUE }, + new ColumnExp[] { STAT_CODE, VALUE }, new Comparable[] { statCode, value }); } // AUTO-GENERATED: METHODS END