Add an index, document index use for Depot operations. Do you think this is worthwhile? We should really just about never see a non-indexed query during normal production use and one way to maintain that discipline is with a comment line like this.
git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@399 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -25,9 +25,12 @@ import com.samskivert.jdbc.depot.Key;
|
||||
import com.samskivert.jdbc.depot.PersistentRecord;
|
||||
import com.samskivert.jdbc.depot.annotation.Entity;
|
||||
import com.samskivert.jdbc.depot.annotation.Id;
|
||||
import com.samskivert.jdbc.depot.annotation.Index;
|
||||
import com.samskivert.jdbc.depot.expression.ColumnExp;
|
||||
|
||||
@Entity
|
||||
@Entity(indices={
|
||||
@Index(name="ixPlayerId", columns={ RatingRecord.PLAYER_ID })
|
||||
})
|
||||
public class RatingRecord extends PersistentRecord
|
||||
{
|
||||
// AUTO-GENERATED: FIELDS START
|
||||
@@ -60,19 +63,19 @@ public class RatingRecord extends PersistentRecord
|
||||
new ColumnExp(RatingRecord.class, EXPERIENCE);
|
||||
// AUTO-GENERATED: FIELDS END
|
||||
|
||||
public static final int SCHEMA_VERSION = 1;
|
||||
public static final int SCHEMA_VERSION = 2;
|
||||
|
||||
/** The identifier of the game we're rating for. */
|
||||
@Id
|
||||
public int gameId;
|
||||
|
||||
/** The identifier of the player we're rating. */
|
||||
/** The identifier of the player we're rating. */
|
||||
@Id
|
||||
public int playerId;
|
||||
|
||||
|
||||
/** The player's current rating. */
|
||||
public int rating;
|
||||
|
||||
|
||||
/** The number of times the player has played this game. */
|
||||
public int experience;
|
||||
|
||||
@@ -83,14 +86,14 @@ public class RatingRecord extends PersistentRecord
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A constructor that populates all our fields.
|
||||
*/
|
||||
public RatingRecord (int gameId, int playerId, int rating, int experience)
|
||||
{
|
||||
super();
|
||||
|
||||
|
||||
this.gameId = gameId;
|
||||
this.playerId = playerId;
|
||||
this.rating = rating;
|
||||
|
||||
@@ -54,15 +54,16 @@ public class RatingRepository extends DepotRepository
|
||||
public RatingRecord getRating (int gameId, int playerId)
|
||||
throws PersistenceException
|
||||
{
|
||||
return load(RatingRecord.class,
|
||||
RatingRecord.GAME_ID, gameId,
|
||||
RatingRecord.PLAYER_ID, playerId);
|
||||
// INDEX: Full primary key.
|
||||
return load(RatingRecord.class, RatingRecord.getKey(gameId, playerId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the ratings registered for any of the given players for the given game and return
|
||||
* them as a list of {@link RatingRecord} objects. The size of this list is no less than zero
|
||||
* and no greater than the number of given players.
|
||||
*
|
||||
* INDEXING: Uses primary key.
|
||||
*/
|
||||
public List<RatingRecord> getRatings (int gameId, Integer... players)
|
||||
throws PersistenceException
|
||||
@@ -70,17 +71,19 @@ public class RatingRepository extends DepotRepository
|
||||
if (players.length == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// INDEX: Full primary key.
|
||||
return findAll(RatingRecord.class,
|
||||
new Where(new And(new Equals(RatingRecord.GAME_ID_C, gameId),
|
||||
new In(RatingRecord.PLAYER_ID_C, players))));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public List<RatingRecord> getRatings (int playerId)
|
||||
throws PersistenceException
|
||||
{
|
||||
// INDEX: ixPlayerId
|
||||
return findAll(RatingRecord.class, new Where(RatingRecord.PLAYER_ID_C, playerId));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user