Track the last update time for ratings.
git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@439 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -21,8 +21,11 @@
|
|||||||
|
|
||||||
package com.threerings.parlor.rating.server.persist;
|
package com.threerings.parlor.rating.server.persist;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
import com.samskivert.jdbc.depot.Key;
|
import com.samskivert.jdbc.depot.Key;
|
||||||
import com.samskivert.jdbc.depot.PersistentRecord;
|
import com.samskivert.jdbc.depot.PersistentRecord;
|
||||||
|
import com.samskivert.jdbc.depot.annotation.Column;
|
||||||
import com.samskivert.jdbc.depot.annotation.Entity;
|
import com.samskivert.jdbc.depot.annotation.Entity;
|
||||||
import com.samskivert.jdbc.depot.annotation.Id;
|
import com.samskivert.jdbc.depot.annotation.Id;
|
||||||
import com.samskivert.jdbc.depot.annotation.Index;
|
import com.samskivert.jdbc.depot.annotation.Index;
|
||||||
@@ -63,9 +66,16 @@ public class RatingRecord extends PersistentRecord
|
|||||||
/** The qualified column identifier for the {@link #experience} field. */
|
/** The qualified column identifier for the {@link #experience} field. */
|
||||||
public static final ColumnExp EXPERIENCE_C =
|
public static final ColumnExp EXPERIENCE_C =
|
||||||
new ColumnExp(RatingRecord.class, EXPERIENCE);
|
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 = 2;
|
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
|
||||||
@@ -81,6 +91,10 @@ public class RatingRecord extends PersistentRecord
|
|||||||
/** The number of times the player has played this game. */
|
/** The number of times the player has played this game. */
|
||||||
public int experience;
|
public int experience;
|
||||||
|
|
||||||
|
/** The last time this rating was updated. */
|
||||||
|
@Column(type="TIMESTAMP", defaultValue="CURRENT_TIMESTAMP")
|
||||||
|
public Timestamp lastUpdated;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An empty constructor for unmarshalling.
|
* An empty constructor for unmarshalling.
|
||||||
*/
|
*/
|
||||||
@@ -100,6 +114,7 @@ public class RatingRecord extends PersistentRecord
|
|||||||
this.playerId = playerId;
|
this.playerId = playerId;
|
||||||
this.rating = rating;
|
this.rating = rating;
|
||||||
this.experience = experience;
|
this.experience = experience;
|
||||||
|
this.lastUpdated = new Timestamp(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from Object
|
@Override // from Object
|
||||||
|
|||||||
@@ -21,6 +21,9 @@
|
|||||||
|
|
||||||
package com.threerings.parlor.rating.server.persist;
|
package com.threerings.parlor.rating.server.persist;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -33,6 +36,9 @@ import com.samskivert.jdbc.depot.DepotRepository;
|
|||||||
import com.samskivert.jdbc.depot.EntityMigration;
|
import com.samskivert.jdbc.depot.EntityMigration;
|
||||||
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.Limit;
|
||||||
|
import com.samskivert.jdbc.depot.clause.OrderBy;
|
||||||
|
import com.samskivert.jdbc.depot.clause.QueryClause;
|
||||||
import com.samskivert.jdbc.depot.clause.Where;
|
import com.samskivert.jdbc.depot.clause.Where;
|
||||||
import com.samskivert.jdbc.depot.operator.Conditionals.*;
|
import com.samskivert.jdbc.depot.operator.Conditionals.*;
|
||||||
import com.samskivert.jdbc.depot.operator.Logic.And;
|
import com.samskivert.jdbc.depot.operator.Logic.And;
|
||||||
@@ -84,12 +90,29 @@ public class RatingRepository extends DepotRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch and return all the registered {@link RatingRecord} rows for the given player.
|
* Fetch and return all the registered {@link RatingRecord} rows for the given player. Ratings
|
||||||
|
* will be returned in order of most recently to least recently updated.
|
||||||
|
*
|
||||||
|
* @param since ratings last updated more than this number of milliseconds in the past will be
|
||||||
|
* ommitted from the result list. Supplying -1 will return all ratings regardless of age.
|
||||||
|
* @param count the maximum number of ratings to return or -1 for all ratings.
|
||||||
*/
|
*/
|
||||||
public List<RatingRecord> getRatings (int playerId)
|
public List<RatingRecord> getRatings (int playerId, long since, int count)
|
||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
return findAll(RatingRecord.class, new Where(RatingRecord.PLAYER_ID_C, playerId));
|
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))));
|
||||||
|
} else {
|
||||||
|
clauses.add(new Where(RatingRecord.PLAYER_ID_C, playerId));
|
||||||
|
}
|
||||||
|
if (count > 0) {
|
||||||
|
clauses.add(new Limit(0, count));
|
||||||
|
}
|
||||||
|
clauses.add(OrderBy.descending(RatingRecord.LAST_UPDATED_C));
|
||||||
|
return findAll(RatingRecord.class, clauses.toArray(new QueryClause[clauses.size()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user