vooga.network.data
Class DataManager

java.lang.Object
  extended by vooga.network.data.DataManager
Direct Known Subclasses:
LocalDataManager, NetworkDataManager

public abstract class DataManager
extends java.lang.Object

The DataManager class is the superclass for both server-side and local data managers. It defines all shared methods for managing data.

Author:
tanner schmidt

Constructor Summary
protected DataManager(java.lang.String mainDir, VoogaModule module)
          Creates a DataManager for the given module using files stored in the given main directory.
 
Method Summary
 boolean containsData(java.lang.String table, java.util.List<java.lang.String> key)
          Determines if the manager is storing data with the given key in the given table.
 boolean containsData(java.lang.String table, java.lang.String key)
          Determines if the manager is storing data with the given key in the given table.
 boolean containsTable(java.lang.String tableName)
          Determines if the manager has a table with the given name.
 void createTable(java.lang.String tableName)
          Creates a table with the given name.
 void eraseData(java.lang.String table, java.util.List<java.lang.String> key)
          Erases the data in the given table stored with the given key.
 void eraseData(java.lang.String table, java.lang.String key)
          Erases the data in the given table stored with the given key.
 void eraseTable(java.lang.String tableName)
          Erases the given table from the manager.
 java.util.Map<java.util.List<java.lang.String>,java.lang.Object> getAllData(java.lang.String table)
          Gets all data stored in the given table.
 java.lang.Object getData(java.lang.String table, java.util.List<java.lang.String> key)
          Retrieves the data stored in the given table with the given key.
 java.lang.Object getData(java.lang.String table, java.lang.String key)
          Retrieves the data stored in the given table with the given key.
 java.util.Map<java.lang.String,DataTable> getMyData()
           
 VoogaModule getMyModule()
           
protected abstract  void initialize()
          Allows subclasses to perform any additional initialization once the data has been loaded from file.
 java.util.Map<java.lang.String,DataTable> loadData()
          Loads each file in the module's directory into a map of DataTables.
 void saveData()
          Saves all tables that have been updated since the last save to file.
 void storeData(java.lang.String table, java.util.List<java.lang.String> key, java.lang.Object data)
          Stores data in the manager.
 void storeData(java.lang.String table, java.lang.String key, java.lang.Object data)
          Stores data in the manager.
 DataObject synchronize(java.lang.String table, java.util.List<java.lang.String> key, DataObject local)
          Synchronize the DataObject in the specified location with the given DataObject.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataManager

protected DataManager(java.lang.String mainDir,
                      VoogaModule module)
Creates a DataManager for the given module using files stored in the given main directory. This constructor is only used by the subclasses of DataManager.

Parameters:
mainDir -
module -
Method Detail

initialize

protected abstract void initialize()
Allows subclasses to perform any additional initialization once the data has been loaded from file.


getMyData

public java.util.Map<java.lang.String,DataTable> getMyData()

getMyModule

public VoogaModule getMyModule()

loadData

public java.util.Map<java.lang.String,DataTable> loadData()
Loads each file in the module's directory into a map of DataTables.

Returns:
A map of table names to data.

storeData

public void storeData(java.lang.String table,
                      java.lang.String key,
                      java.lang.Object data)
Stores data in the manager.

Parameters:
table - The table in which to store data.
key - The key that will be used to retrieve the data.
data -

storeData

public void storeData(java.lang.String table,
                      java.util.List<java.lang.String> key,
                      java.lang.Object data)
Stores data in the manager.

Parameters:
table - The table in which to store data.
key - The key that will be used to retrieve the data.
data -

eraseData

public void eraseData(java.lang.String table,
                      java.lang.String key)
Erases the data in the given table stored with the given key.

Parameters:
table - The table in which the data to be accessed is stored.
key - The data's key.

eraseData

public void eraseData(java.lang.String table,
                      java.util.List<java.lang.String> key)
Erases the data in the given table stored with the given key.

Parameters:
table - The table in which the data to be accessed is stored.
key - The data's key.

getData

public java.lang.Object getData(java.lang.String table,
                                java.lang.String key)
Retrieves the data stored in the given table with the given key.

Parameters:
table - The table in which the data to be accessed is stored.
key - The data's key.
Returns:

getData

public java.lang.Object getData(java.lang.String table,
                                java.util.List<java.lang.String> key)
Retrieves the data stored in the given table with the given key.

Parameters:
table - The table in which the data to be accessed is stored.
key - The data's key.
Returns:

getAllData

public java.util.Map<java.util.List<java.lang.String>,java.lang.Object> getAllData(java.lang.String table)
Gets all data stored in the given table.

Parameters:
table - The table in which the data to be accessed is stored.
Returns:
A map of keys, as List, to data.

containsData

public boolean containsData(java.lang.String table,
                            java.lang.String key)
Determines if the manager is storing data with the given key in the given table.

Parameters:
table - The table in which the data to be accessed is stored.
key - The data's key.
Returns:
True iff the server is storing data in the specified location.

containsData

public boolean containsData(java.lang.String table,
                            java.util.List<java.lang.String> key)
Determines if the manager is storing data with the given key in the given table.

Parameters:
table - The table in which the data to be accessed is stored.
key - The data's key.
Returns:
True iff the server is storing data in the specified location.

containsTable

public boolean containsTable(java.lang.String tableName)
Determines if the manager has a table with the given name.

Parameters:
tableName - queried table name
Returns:
true if table contains key.

createTable

public void createTable(java.lang.String tableName)
                 throws VoogaNetworkException
Creates a table with the given name.

Parameters:
tableName - name to be given to new table
Throws:
VoogaNetworkException - If the manager already has that table.

eraseTable

public void eraseTable(java.lang.String tableName)
Erases the given table from the manager.

Parameters:
tableName - name of table to be removed

synchronize

public DataObject synchronize(java.lang.String table,
                              java.util.List<java.lang.String> key,
                              DataObject local)
Synchronize the DataObject in the specified location with the given DataObject.

Parameters:
table - The table in which the data to be accessed is stored.
key - The data's key.
local -
Returns:
The most up-to-date DataObject.

saveData

public void saveData()
Saves all tables that have been updated since the last save to file.