editor
Class StorageHandler

java.lang.Object
  extended by editor.StorageHandler
All Implemented Interfaces:
shared.network.MessageHandler

public class StorageHandler
extends java.lang.Object
implements shared.network.MessageHandler

Handles network connection and storage of objects to harddrive.

Author:
thorgrun

Method Summary
 void deleteEnemyNPC(int npcId)
          Sends EnemyNPCid to database for deletion.
 void deleteFriendlyNPC(int npcId)
          Sends FriendlyNPCid to database for deletion.
 void deleteQuestion(int questionId)
          Deletes question from database with questionId
 void deleteStaticObject(int objId)
          Sends StaticObjectid to database for deletion.
static StorageHandler getInstance()
          Returns the singleton of the StorageHandler class
 void getMessage(shared.network.messages.Message msg)
           
static void initialize(ModelUpdater listener)
          Initializes the StorageHandler singleton
 void loadWorldFromHarddrive(java.lang.String filePath)
          Loads kingdom from a file.
 void loadZoneTemplate(java.lang.String templateName)
          Sends a message to the database, requesting a Zone template with the given name.
 void lostConnection()
           
 void newENPC(shared.models.EnemyNPC npc)
          Sends a new EnemyNPC object to the Database for insertion.
 void newFNPC(shared.models.FriendlyNPC npc)
          Sends a new FriendlyNPC object to the Database for insertion.
 void newQuestion(shared.models.Question question)
          Sends a new Question to Database for insertion.
 void newStaticObject(shared.models.StaticObject obj)
          Sends a new StaticObject to the database for insertion.
 void reconnectToDB()
          Tries to reconnect to the Database Server.
 void requestAllEnemyNPC()
          Sends a request to the Database for all EnemyNPCs.
 void requestAllFriendlyNPC()
          Sends a request to the Database for all FriendlyNPCs.
 void requestAllKingdomNames()
          Sends a request to the Database for all Kingdom names.
 void requestAllPlayerNames()
          Sends a request to the Database for all Player names.
 void requestAllQuestions()
          Sends a request to the Database for all Questions.
 void requestAllStaticObject()
          Sends a request to the Database for all Static objects.
 void requestAllThemeTopics()
          Sends a request to the Database for all Theme topics.
 void requestAllZoneTemplateNames()
          Sends a request to the Database for all Zone Templates.
 void requestKingdom(java.lang.String kingdomName)
          Sends a request to the Database for a kingdom with the given name.
 void saveKingdom(java.lang.String kingdomName, java.lang.String subjectName, int kingdomId, java.util.HashMap<java.lang.String,shared.models.Zone> zoneList, java.lang.String zoneName, java.util.ArrayList<java.lang.String> playerAccessList)
          Sends a message containing the kingdom for saving in the database.
 void saveTemplate(java.lang.String templateName, shared.models.Zone zone)
          Sends a message with a Zone template and name for saving in database.
 boolean saveWorldToHarddrive(java.lang.String kingdomName, java.lang.String subjectName, int kingdomId, java.util.HashMap<java.lang.String,shared.models.Zone> zoneList, java.lang.String zoneName, java.util.ArrayList<java.lang.String> playerAccessList)
          Stores a kingdom on the Harddrive as a serializable object.
 void updateEnemyNPC(shared.models.EnemyNPC npc)
          Sends an existing EnemyNPC to the Database for updating.
 void updateFriendlyNPC(shared.models.FriendlyNPC npc)
          Sends a existing FriendlyNPC to the Database for updating.
 void updateQuestion(shared.models.Question question)
          Updates existing question in Database.
 void updateStaticObject(shared.models.StaticObject obj)
          Sends an existing StaticObject to the Database for updating.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static StorageHandler getInstance()
Returns the singleton of the StorageHandler class

Returns:

initialize

public static void initialize(ModelUpdater listener)
Initializes the StorageHandler singleton

Parameters:
listener - - ModelUpdater, StorageHandler receives updates from database that are forwarded to the ModelUpdater.

reconnectToDB

public void reconnectToDB()
Tries to reconnect to the Database Server. Does nothing if already connected.


newENPC

public void newENPC(shared.models.EnemyNPC npc)
Sends a new EnemyNPC object to the Database for insertion.

Parameters:
npc -

newFNPC

public void newFNPC(shared.models.FriendlyNPC npc)
Sends a new FriendlyNPC object to the Database for insertion.

Parameters:
npc -

newStaticObject

public void newStaticObject(shared.models.StaticObject obj)
Sends a new StaticObject to the database for insertion.

Parameters:
obj -

updateEnemyNPC

public void updateEnemyNPC(shared.models.EnemyNPC npc)
Sends an existing EnemyNPC to the Database for updating.

Parameters:
npc -

updateFriendlyNPC

public void updateFriendlyNPC(shared.models.FriendlyNPC npc)
Sends a existing FriendlyNPC to the Database for updating.

Parameters:
npc -

updateStaticObject

public void updateStaticObject(shared.models.StaticObject obj)
Sends an existing StaticObject to the Database for updating.

Parameters:
obj -

deleteEnemyNPC

public void deleteEnemyNPC(int npcId)
Sends EnemyNPCid to database for deletion.

Parameters:
npcId -

deleteFriendlyNPC

public void deleteFriendlyNPC(int npcId)
Sends FriendlyNPCid to database for deletion.

Parameters:
npcId -

deleteStaticObject

public void deleteStaticObject(int objId)
Sends StaticObjectid to database for deletion.

Parameters:
objId -

newQuestion

public void newQuestion(shared.models.Question question)
Sends a new Question to Database for insertion.

Parameters:
question -

updateQuestion

public void updateQuestion(shared.models.Question question)
Updates existing question in Database.

Parameters:
question -

deleteQuestion

public void deleteQuestion(int questionId)
Deletes question from database with questionId

Parameters:
questionId -

requestAllThemeTopics

public void requestAllThemeTopics()
Sends a request to the Database for all Theme topics.


requestAllEnemyNPC

public void requestAllEnemyNPC()
Sends a request to the Database for all EnemyNPCs.


requestAllFriendlyNPC

public void requestAllFriendlyNPC()
Sends a request to the Database for all FriendlyNPCs.


requestAllStaticObject

public void requestAllStaticObject()
Sends a request to the Database for all Static objects.


requestAllQuestions

public void requestAllQuestions()
Sends a request to the Database for all Questions.


requestAllKingdomNames

public void requestAllKingdomNames()
Sends a request to the Database for all Kingdom names.


requestAllPlayerNames

public void requestAllPlayerNames()
Sends a request to the Database for all Player names.


requestAllZoneTemplateNames

public void requestAllZoneTemplateNames()
Sends a request to the Database for all Zone Templates.


requestKingdom

public void requestKingdom(java.lang.String kingdomName)
Sends a request to the Database for a kingdom with the given name.

Parameters:
kingdomName -

loadZoneTemplate

public void loadZoneTemplate(java.lang.String templateName)
Sends a message to the database, requesting a Zone template with the given name.

Parameters:
templateName -

saveKingdom

public void saveKingdom(java.lang.String kingdomName,
                        java.lang.String subjectName,
                        int kingdomId,
                        java.util.HashMap<java.lang.String,shared.models.Zone> zoneList,
                        java.lang.String zoneName,
                        java.util.ArrayList<java.lang.String> playerAccessList)
Sends a message containing the kingdom for saving in the database.

Parameters:
kingdomName -
subjectName -
kingdomId -
zoneList -
zoneName -
playerAccessList -

saveTemplate

public void saveTemplate(java.lang.String templateName,
                         shared.models.Zone zone)
Sends a message with a Zone template and name for saving in database.

Parameters:
templateName -
zone -

getMessage

public void getMessage(shared.network.messages.Message msg)
Specified by:
getMessage in interface shared.network.MessageHandler

saveWorldToHarddrive

public boolean saveWorldToHarddrive(java.lang.String kingdomName,
                                    java.lang.String subjectName,
                                    int kingdomId,
                                    java.util.HashMap<java.lang.String,shared.models.Zone> zoneList,
                                    java.lang.String zoneName,
                                    java.util.ArrayList<java.lang.String> playerAccessList)
Stores a kingdom on the Harddrive as a serializable object.

Parameters:
kingdomName -
subjectName -
kingdomId -
zoneList -
zoneName -
playerAccessList -
Returns:

loadWorldFromHarddrive

public void loadWorldFromHarddrive(java.lang.String filePath)
Loads kingdom from a file.

Parameters:
filePath - Path to the kingdom file.

lostConnection

public void lostConnection()
Specified by:
lostConnection in interface shared.network.MessageHandler