org.starhope.appius.game
Class SimpleDataEnumSQLLoader<T extends SimpleDataEnum<?>,L extends SimpleDataEnumSQLLoader<T,?>>

java.lang.Object
  extended by org.starhope.appius.game.SimpleDataEnumSQLLoader<T,L>
Type Parameters:
T - the data record class
L - the child class
All Implemented Interfaces:
RecordLoader<T>, HasSubversionRevision
Direct Known Subclasses:
DamageAreaSQLLoader

public abstract class SimpleDataEnumSQLLoader<T extends SimpleDataEnum<?>,L extends SimpleDataEnumSQLLoader<T,?>>
extends Object
implements RecordLoader<T>

WRITEME: Document this type.

Author:
brpocock@star-hope.org

Field Summary
private  String idColumn
          WRITEME: Document this brpocock@star-hope.org
private  String nameColumn
          WRITEME: Document this brpocock@star-hope.org
private  String tableName
          WRITEME: Document this brpocock@star-hope.org
 
Constructor Summary
protected SimpleDataEnumSQLLoader(String theTableName, String theIDColumnName, String theNameColumnName)
          Constructor to be used by child classes
 
Method Summary
 void changed(T changedRecord)
          accept a notification from a record that it has been changed.
protected abstract  Class<T> getRecordClass()
           
protected abstract  Class<L> getRecordLoaderImplClass()
           
private  T getRecordObject()
           
 String getSubversionRevision()
           Return the Subversion revision level of this class's source code file, as supplied via the special "$Rev: " sequence.
 void initializeStorage(String storageURL)
          Prepare the RecordLoader for accessing a given storage medium.
 boolean isRealtime()
           
 T loadRecord(int id)
          Load the record with the given ID number from the storage system
 T loadRecord(String identifier)
          Load the data record identified from the storage system.
private  void loadRecord(T o, ResultSet rs)
           
 void refresh(T record)
          Refreshes the record: Re-read the contents of the database into the given record.
 void removeRecord(T record)
           
 void saveRecord(T record)
          Save a record back to the storage system
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tableName

private final String tableName
WRITEME: Document this brpocock@star-hope.org


idColumn

private final String idColumn
WRITEME: Document this brpocock@star-hope.org


nameColumn

private final String nameColumn
WRITEME: Document this brpocock@star-hope.org

Constructor Detail

SimpleDataEnumSQLLoader

protected SimpleDataEnumSQLLoader(String theTableName,
                                  String theIDColumnName,
                                  String theNameColumnName)
Constructor to be used by child classes

Parameters:
theTableName - SQL table name
theIDColumnName - integer ID column name
theNameColumnName - the enumerated value's column name
Method Detail

changed

public void changed(T changedRecord)
Description copied from interface: RecordLoader
accept a notification from a record that it has been changed.

Specified by:
changed in interface RecordLoader<T extends SimpleDataEnum<?>>
Parameters:
changedRecord - the record that has been changed
See Also:
RecordLoader.changed(org.starhope.appius.util.DataRecord)

getRecordClass

protected abstract Class<T> getRecordClass()
Returns:
the klass

getRecordLoaderImplClass

protected abstract Class<L> getRecordLoaderImplClass()
Returns:
the child

getRecordObject

private T getRecordObject()
                                             throws NotFoundException
Returns:
a new instance of the record type
Throws:
NotFoundException - if the class can't be loaded or doesn't have

getSubversionRevision

public String getSubversionRevision()
Description copied from interface: HasSubversionRevision

Return the Subversion revision level of this class's source code file, as supplied via the special "$Rev: " sequence.

As an example,the Subversion revision string for this file is "$Rev: 1968 $"

 
 @Override
 public String getSubversionRevision () {
        return "$Rev: ";
 }
 

Specified by:
getSubversionRevision in interface HasSubversionRevision
Returns:
The Subversion revision level for this class's source code file.
See Also:
HasSubversionRevision.getSubversionRevision()

initializeStorage

public void initializeStorage(String storageURL)
                       throws NotReadyException
Description copied from interface: RecordLoader
Prepare the RecordLoader for accessing a given storage medium. Usually identifies a URL for the storage mechanism, but can also pull information from AppiusConfig.

Specified by:
initializeStorage in interface RecordLoader<T extends SimpleDataEnum<?>>
Parameters:
storageURL - A URL or identifier of the storage engine. The syntax is specific to the RecordLoader implementation.
Throws:
NotReadyException - if the storage engine can't be initialised
See Also:
RecordLoader.initializeStorage(java.lang.String)

isRealtime

public boolean isRealtime()
Specified by:
isRealtime in interface RecordLoader<T extends SimpleDataEnum<?>>
Returns:
true, if this is a type that requires realtime performance on changes. Note that I/O bound storage such as SQL database saves and file writes will generally return false, whereas RPC mirroring will probably want to return true, unless latency is not an issue.
See Also:
RecordLoader.isRealtime()

loadRecord

public T loadRecord(int id)
                                       throws NotFoundException
Description copied from interface: RecordLoader
Load the record with the given ID number from the storage system

Specified by:
loadRecord in interface RecordLoader<T extends SimpleDataEnum<?>>
Parameters:
id - the ID number for the record
Returns:
the data record in question
Throws:
NotFoundException - if the record can't be loaded
See Also:
RecordLoader.loadRecord(int)

loadRecord

public T loadRecord(String identifier)
                                       throws NotFoundException
Description copied from interface: RecordLoader
Load the data record identified from the storage system. The format and interpretation of the identifier is specific to the data record type, but must be a guaranteed-unique

Specified by:
loadRecord in interface RecordLoader<T extends SimpleDataEnum<?>>
Parameters:
identifier - the identifier for the record
Returns:
the data record in question
Throws:
NotFoundException - if the record can't be loaded
See Also:
RecordLoader.loadRecord(java.lang.String)

loadRecord

private void loadRecord(T o,
                        ResultSet rs)
                 throws SQLException
Parameters:
o - the record object to be loaded into
rs - result set from a query
Throws:
SQLException - if there is a database record format error

refresh

public void refresh(T record)
Description copied from interface: RecordLoader
Refreshes the record: Re-read the contents of the database into the given record. This is a rather cruel hack to work around some of the legacy tools in Tootsvilleâ„¢ that aren't hooked into the game server properly, and might be fiddling around with the SQL backing-store directly. This works together with e.g. SimpleDataRecord.checkStale() to try to reload data when it might have been changed: it's trading elegance and efficiency for expediency, but eventually, it should be removed.

Specified by:
refresh in interface RecordLoader<T extends SimpleDataEnum<?>>
Parameters:
record - the record to be reloaded.
See Also:
RecordLoader.refresh(org.starhope.appius.util.DataRecord)

removeRecord

public void removeRecord(T record)
Specified by:
removeRecord in interface RecordLoader<T extends SimpleDataEnum<?>>
Parameters:
record - Record to be deleted/removed
See Also:
RecordLoader.removeRecord(org.starhope.appius.util.DataRecord)

saveRecord

public void saveRecord(T record)
Description copied from interface: RecordLoader
Save a record back to the storage system

Specified by:
saveRecord in interface RecordLoader<T extends SimpleDataEnum<?>>
Parameters:
record - the record to be saved
See Also:
RecordLoader.saveRecord(org.starhope.appius.util.DataRecord)