com.threerings.stats.server.persist
Class StatRepository

java.lang.Object
  extended by com.samskivert.depot.DepotRepository
      extended by com.threerings.stats.server.persist.StatRepository
All Implemented Interfaces:
Stat.AuxDataSource

public class StatRepository
extends DepotRepository
implements Stat.AuxDataSource

Responsible for the persistent storage of per-player statistics.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.samskivert.depot.DepotRepository
DepotRepository.CacheStrategy
 
Constructor Summary
StatRepository(PersistenceContext context)
          Constructs a new statistics repository with the specified persistence context.
 
Method Summary
 void clearMapping(Stat.Type type, String value)
          This is only used for testing.
 void deleteStats(int playerId)
          Deletes all stats associated with the specified player.
 String getCodeString(Stat.Type type, int code)
          Maps the specified unique code back to its string value.
 int getStringCode(Stat.Type type, String value)
          Maps the specified string to a unique integer value.
 ArrayList<Stat> loadStats(int playerId)
          Loads the stats associated with the specified player.
 void purgePlayers(Collection<Integer> playerIds)
          Deletes all data associated with the supplied players.
<T extends Stat>
T
updateStat(int playerId, StatModifier<T> modifier)
          Applies a modification to a single stat.
 void writeModified(int playerId, Iterable<Stat> stats)
          Writes out any of the stats in the supplied iterable that have been modified since they were first loaded.
 void writeModified(int playerId, Stat[] stats)
          Writes out any of the stats in the supplied array that have been modified since they were first loaded.
 
Methods inherited from class com.samskivert.depot.DepotRepository
delete, delete, deleteAll, deleteAll, findAll, findAll, findAll, findAll, findAllKeys, findAllKeys, from, insert, load, load, load, load, loadAll, loadAll, store, update, update, updatePartial, updatePartial, updatePartial, updatePartial, updatePartial
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StatRepository

@Inject
public StatRepository(PersistenceContext context)
Constructs a new statistics repository with the specified persistence context.

Method Detail

updateStat

public <T extends Stat> T updateStat(int playerId,
                                     StatModifier<T> modifier)
Applies a modification to a single stat. If the stat in question does not exist, a blank instance will be created via Stat.Type.newStat().

Returns:
the modified Stat, if any modification took place; or null if the modification had no effect on the stat's data.

loadStats

public ArrayList<Stat> loadStats(int playerId)
Loads the stats associated with the specified player.


deleteStats

public void deleteStats(int playerId)
Deletes all stats associated with the specified player.


writeModified

public void writeModified(int playerId,
                          Stat[] stats)
Writes out any of the stats in the supplied array that have been modified since they were first loaded. Exceptions that occur while writing the stats will be caught and logged.


writeModified

public void writeModified(int playerId,
                          Iterable<Stat> stats)
Writes out any of the stats in the supplied iterable that have been modified since they were first loaded. Exceptions that occur while writing the stats will be caught and logged.


getStringCode

public int getStringCode(Stat.Type type,
                         String value)
Description copied from interface: Stat.AuxDataSource
Maps the specified string to a unique integer value.

Specified by:
getStringCode in interface Stat.AuxDataSource

getCodeString

public String getCodeString(Stat.Type type,
                            int code)
Description copied from interface: Stat.AuxDataSource
Maps the specified unique code back to its string value.

Specified by:
getCodeString in interface Stat.AuxDataSource

clearMapping

public void clearMapping(Stat.Type type,
                         String value)
This is only used for testing. Do not call this method.


purgePlayers

public void purgePlayers(Collection<Integer> playerIds)
Deletes all data associated with the supplied players.



Copyright © 2011. All Rights Reserved.