org.starhope.appius.sql
Class SQLPeerEnum

java.lang.Object
  extended by org.starhope.appius.sql.SQLPeerDatum
      extended by org.starhope.appius.sql.SQLPeerEnum
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AvatarClass, Currency, GameFlagValue, InventoryItemType, RoomBadge

public abstract class SQLPeerEnum
extends SQLPeerDatum

This is a class for infrequently-changed objects that are enumerated types referenced by integer ID columns. Things like the set of available avatar classes fall into this category.

Author:
brpocock
See Also:
Serialized Form

Field Summary
protected static ConcurrentHashMap<Class<? extends SQLPeerEnum>,ConcurrentHashMap<Integer,String>> enumeration
          enumeration of all possible values
private static ConcurrentHashMap<Class<? extends SQLPeerEnum>,Integer> hasCached
          Index of which classes have been cached already.
protected  int instance
          instance ID
private static HashSet<Class<? extends SQLPeerEnum>> knownChildren
          WRITEME: document this field (brpocock, Dec 11, 2009) knownChildren (SQLPeerEnum)
private static long serialVersionUID
          TODO: document this field (brpocock, Oct 13, 2009) serialVersionUID (long)
 
Constructor Summary
  SQLPeerEnum(Class<? extends SQLPeerEnum> klass)
          TODO
protected SQLPeerEnum(Class<? extends SQLPeerEnum> klass, int id)
          TODO
 
Method Summary
protected  void cache(ResultSet set)
          This method caches into the internal "enumeration" hashmap the results of an SQL query specific to this SQLPeerEnum class of object.
private  void doRealCacheReset()
          Actually flush the cache for all SQLPeerEnums
static void doRealCacheResetStatic()
          TODO: document this method (brpocock, Dec 11, 2009)
 boolean equals(Object o)
          This is an overriding method.
 boolean equals(SQLPeerEnum o)
           
static SQLPeerEnum get(Class<? extends SQLPeerEnum> klass, int id)
          TODO: document this method (brpocock, Nov 19, 2009)
static SQLPeerEnum get(Class<? extends SQLPeerEnum> klass, String str)
          TODO: document this method (brpocock, Nov 19, 2009)
protected  String getCacheUniqueID()
          This is an overriding method.
protected  ConcurrentHashMap<Integer,String> getEnumeration()
           
 int getID()
          WRITEME: document this method (brpocock, Aug 14, 2009)
 int getID(String s)
          WRITEME: document this method (brpocock, Jul 8, 2009)
protected abstract  PreparedStatement getStatement(Connection connection)
          WRITEME: document this method (brpocock, Aug 14, 2009)
 String getString()
          TODO: document this method (brpocock, Oct 13, 2009)
 String getString(int id)
          WRITEME: document this method (brpocock, Jul 8, 2009)
 int hashCode()
          This is an overriding method.
static void invalidateCache()
          TODO: document this method (brpocock, Dec 11, 2009)
static void invalidateCaches()
          TODO: document this method (brpocock, Dec 11, 2009)
protected  void prepCache()
          TODO: document this method (brpocock, Oct 13, 2009)
private static void registerClass(Class<? extends SQLPeerEnum> klass)
          TODO: document this method (brpocock, Dec 11, 2009)
 void resetCache()
          TODO: document this method (brpocock, Oct 13, 2009)
 void set(int id)
          TODO: document this method (brpocock, Nov 19, 2009)
 void set(String str)
          TODO: document this method (brpocock, Nov 19, 2009)
 org.json.JSONObject toJSON()
          This is an overriding method.
 String toString()
          Create a stringified version of this enumeration.
 
Methods inherited from class org.starhope.appius.sql.SQLPeerDatum
changed, findInCache, flush, get, saveInCache, set, set
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

enumeration

protected static final ConcurrentHashMap<Class<? extends SQLPeerEnum>,ConcurrentHashMap<Integer,String>> enumeration
enumeration of all possible values


hasCached

private static final ConcurrentHashMap<Class<? extends SQLPeerEnum>,Integer> hasCached
Index of which classes have been cached already. A value of -1 means that the class is being cached presently; zero or more represents some state of completion, no longer requiring precaching.


knownChildren

private static HashSet<Class<? extends SQLPeerEnum>> knownChildren
WRITEME: document this field (brpocock, Dec 11, 2009) knownChildren (SQLPeerEnum)


serialVersionUID

private static final long serialVersionUID
TODO: document this field (brpocock, Oct 13, 2009) serialVersionUID (long)

See Also:
Constant Field Values

instance

protected int instance
instance ID

Constructor Detail

SQLPeerEnum

public SQLPeerEnum(Class<? extends SQLPeerEnum> klass)
TODO

Parameters:
klass - WRITEME

SQLPeerEnum

protected SQLPeerEnum(Class<? extends SQLPeerEnum> klass,
                      int id)
TODO

Parameters:
klass - WRITEME
id - the specific ID
Method Detail

doRealCacheResetStatic

public static void doRealCacheResetStatic()
TODO: document this method (brpocock, Dec 11, 2009)


get

public static SQLPeerEnum get(Class<? extends SQLPeerEnum> klass,
                              int id)
TODO: document this method (brpocock, Nov 19, 2009)

Parameters:
klass - WRITEME
id - WRITEME
Returns:
WRITEME

get

public static SQLPeerEnum get(Class<? extends SQLPeerEnum> klass,
                              String str)
TODO: document this method (brpocock, Nov 19, 2009)

Parameters:
klass - WRITEME WRITEME
str - WRITEME WRITEME
Returns:
WRITEME WRITEME

invalidateCache

public static void invalidateCache()
TODO: document this method (brpocock, Dec 11, 2009)


invalidateCaches

public static void invalidateCaches()
TODO: document this method (brpocock, Dec 11, 2009)


registerClass

private static void registerClass(Class<? extends SQLPeerEnum> klass)
TODO: document this method (brpocock, Dec 11, 2009)

Parameters:
klass - WRITEME

cache

protected void cache(ResultSet set)
              throws SQLException
This method caches into the internal "enumeration" hashmap the results of an SQL query specific to this SQLPeerEnum class of object. The ResultSet must have a long (probably INT UNSIGNED) in the first column of the results, and the string value for it in column 1.

Parameters:
set - The ResultSet from the SQL query
Throws:
SQLException - if anything goes wrong from the query

doRealCacheReset

private void doRealCacheReset()
Actually flush the cache for all SQLPeerEnums


equals

public boolean equals(Object o)
This is an overriding method.

Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

equals

public boolean equals(SQLPeerEnum o)
Parameters:
o - The other type
Returns:
true if the two types are equal
See Also:
Object.equals(Object)

getCacheUniqueID

protected String getCacheUniqueID()
This is an overriding method.

Specified by:
getCacheUniqueID in class SQLPeerDatum
Returns:
The local (Stringified) version of an unique ID; usually the database ID column
See Also:
SQLPeerDatum.getCacheUniqueID()

getEnumeration

protected ConcurrentHashMap<Integer,String> getEnumeration()
Returns:
the enumeration

getID

public int getID()
WRITEME: document this method (brpocock, Aug 14, 2009)

Returns:
WRITEME

getID

public int getID(String s)
WRITEME: document this method (brpocock, Jul 8, 2009)

Parameters:
s - the string value for which to search
Returns:
the ID (number) of the string value, or -1 if it's not found

getStatement

protected abstract PreparedStatement getStatement(Connection connection)
WRITEME: document this method (brpocock, Aug 14, 2009)

Parameters:
connection - WRITEME
Returns:
WRITEME

getString

public String getString()
TODO: document this method (brpocock, Oct 13, 2009)

Returns:
WRITEME

getString

public String getString(int id)
WRITEME: document this method (brpocock, Jul 8, 2009)

Parameters:
id - The value
Returns:
the string related to that value

hashCode

public int hashCode()
This is an overriding method.

Overrides:
hashCode in class Object
See Also:
Object.hashCode()

prepCache

protected void prepCache()
TODO: document this method (brpocock, Oct 13, 2009)


resetCache

public void resetCache()
TODO: document this method (brpocock, Oct 13, 2009)


set

public void set(int id)
TODO: document this method (brpocock, Nov 19, 2009)

Parameters:
id - WRITEME

set

public void set(String str)
TODO: document this method (brpocock, Nov 19, 2009)

Parameters:
str - WRITEME

toJSON

public org.json.JSONObject toJSON()
This is an overriding method.

Overrides:
toJSON in class SQLPeerDatum
Returns:
This object's data, serialized into JSON form.
See Also:
SQLPeerDatum.toJSON()

toString

public String toString()
Create a stringified version of this enumeration. Usually the integer ID, a colon, and the string name, but might be overridden in a child class.

Overrides:
toString in class Object
See Also:
Object.toString()