Exemplo n.º 1
0
  /**
   * Adds a game to be saved.
   *
   * @param sgm The server game manager to add.
   * @throws PersistenceException Thrown if issues occur adding the game.
   */
  public void AddGame(ServerGameManager sgm) throws PersistenceException {
    IPersistenceProvider provider = handler.GetPlugin();

    try {
      provider.StartTransaction();

      int gameID = sgm.GetGameID();

      String blob = Serialize(sgm);
      provider.GetGameDAO().AddGame(gameID, blob);

      provider.EndTransaction(true);
    } catch (PersistenceException | IOException e) {
      provider.EndTransaction(false);
      throw new PersistenceException("Error saving game", e);
    }
  }
Exemplo n.º 2
0
  /**
   * Updates the currently saved game.
   *
   * @param sgm The server game manager to update.
   * @throws PersistenceException Thron if errors occur updating.
   */
  public void UpdateGame(ServerGameManager sgm) throws PersistenceException {
    IPersistenceProvider provider = handler.GetPlugin();

    try {
      provider.StartTransaction();

      int gameID = sgm.GetGameID();
      provider.GetCommandDAO().DeleteCommands(gameID);

      String blob = Serialize(sgm);
      provider.GetGameDAO().UpdateGame(gameID, blob);

      provider.EndTransaction(true);
    } catch (PersistenceException e) {
      provider.EndTransaction(false);
      throw e;
    } catch (IOException e) {
      // TODO Auto-generated catch block
      provider.EndTransaction(false);
      throw new PersistenceException("Unable to serialize");
    }
  }