예제 #1
0
  /**
   * Gets the saved games.
   *
   * @return A list of the saved games.
   * @throws PersistenceException Thrown if issues occur getting the games.
   */
  public List<ServerGameManager> GetAllGames() throws PersistenceException {
    IPersistenceProvider provider = handler.GetPlugin();

    List<String> games;
    try {
      provider.StartTransaction();
      games = provider.GetGameDAO().GetAllGames();
      provider.EndTransaction(true);
    } catch (PersistenceException e) {
      provider.EndTransaction(false);
      throw e;
    }

    List<ServerGameManager> convertedGames = new ArrayList<ServerGameManager>(games.size());
    for (String game : games) {
      try {
        ServerGameManager convertedGame = Deserialize(game, RealServerGameManager.class);
        convertedGames.add(convertedGame);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    return convertedGames;
  }
예제 #2
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);
    }
  }
예제 #3
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");
    }
  }