/** @see com.g4g.services.GameOptionService#getList() */
 @SuppressWarnings(UNCHECKED)
 public List<GameoptionsDTO> getList() throws HibernateException {
   AuditUtil.getInstance()
       .writeLog(
           AuditUtil.FILE_TYPE_G4G,
           new StringBuffer(this.getClass().getName())
               .append(COLON_WITH_SPACES)
               .append(CALLINGMETHOD)
               .append(DataUtil.getCallingMethod())
               .append(CURRENTMETHOD)
               .append(DataUtil.getCurrentMethod())
               .append(DASHES)
               .append(STARTED)
               .append(DASHES)
               .append(PARAMETERS)
               .append(GAMEID_DB)
               .toString(),
           Level.INFO);
   Session session = HibernateUtil.getSession();
   Query query =
       session.createQuery(
           new StringBuffer(G4GConstants.FROM)
               .append(G4GConstants.BLANK)
               .append(G4GConstants.GAME_OPTION_DTO)
               .toString());
   Transaction transaction = session.beginTransaction();
   List<GameoptionsDTO> list = query.list();
   transaction.commit();
   HibernateUtil.closeSession();
   AuditUtil.getInstance()
       .writeLog(
           AuditUtil.FILE_TYPE_G4G,
           new StringBuffer(this.getClass().getName())
               .append(COLON_WITH_SPACES)
               .append(CALLINGMETHOD)
               .append(DataUtil.getCallingMethod())
               .append(CURRENTMETHOD)
               .append(DataUtil.getCurrentMethod())
               .append(DASHES)
               .append(GAME_OPTIONS_LIST_SIZE)
               .append(list.size())
               .toString(),
           Level.INFO);
   AuditUtil.getInstance()
       .writeLog(
           AuditUtil.FILE_TYPE_G4G,
           new StringBuffer(this.getClass().getName())
               .append(COLON_WITH_SPACES)
               .append(CALLINGMETHOD)
               .append(DataUtil.getCallingMethod())
               .append(CURRENTMETHOD)
               .append(DataUtil.getCurrentMethod())
               .append(DASHES)
               .append(ENDED)
               .toString(),
           Level.INFO);
   return list;
 }
  /**
   * Move to house account.
   *
   * @param betId the bet id
   * @param siteId the site id
   * @param money the money
   */
  public void moveToHouseAccount(String betId, String siteId, Money money) {
    try {
      statement = connection.createStatement();
      resultSet = statement.executeQuery("SELECT amount FROM bet WHERE id='" + betId + "'");

      if (resultSet.next()) {
        preparedStatement =
            connection.prepareStatement("UPDATE bet SET amount=amount - ? WHERE id=?");

        preparedStatement.setLong(1, money.getAmount());
        preparedStatement.setString(2, betId);

        preparedStatement.executeUpdate();
      }
    } catch (SQLException sqlException) {
      AuditUtil.getInstance().writeLog(AuditUtil.FILE_TYPE_G4G_FINANCIAL, sqlException);
    } finally {
      try {
        if (resultSet != null) {
          resultSet.close();
        }
      } catch (SQLException sqlException) {
        AuditUtil.getInstance().writeLog(AuditUtil.FILE_TYPE_G4G_FINANCIAL, sqlException);
      }

      try {
        if (preparedStatement != null) {
          preparedStatement.close();
        }
      } catch (SQLException sqlException) {
        AuditUtil.getInstance().writeLog(AuditUtil.FILE_TYPE_G4G_FINANCIAL, sqlException);
      }

      try {
        if (statement != null) {
          statement.close();
        }
      } catch (SQLException sqlException) {
        AuditUtil.getInstance().writeLog(AuditUtil.FILE_TYPE_G4G_FINANCIAL, sqlException);
      }

      try {
        if (connection != null) {
          connection.close();
        }
      } catch (SQLException sqlException) {
        AuditUtil.getInstance().writeLog(AuditUtil.FILE_TYPE_G4G_FINANCIAL, sqlException);
      }
    }
  }
 /**
  * Instantiates a new move to house account.
  *
  * @param url the url
  * @param username the username
  * @param password the password
  */
 public MoveToHouseAccount(String url, String username, String password) {
   try {
     this.connection = DriverManager.getConnection(url, username, password);
   } catch (SQLException e) {
     AuditUtil.getInstance()
         .writeLog(AuditUtil.FILE_TYPE_G4G, this.getClass().getName() + G4GConstants.NONE);
   }
 }
  /** @see com.g4g.services.GameOptionService#getGame(com.g4g.dto.GameoptionsDTO) */
  public GameoptionsDTO getGame(GameoptionsDTO dto) throws HibernateException {
    AuditUtil.getInstance()
        .writeLog(
            AuditUtil.FILE_TYPE_G4G,
            new StringBuffer(this.getClass().getName())
                .append(COLON_WITH_SPACES)
                .append(CALLINGMETHOD)
                .append(DataUtil.getCallingMethod())
                .append(CURRENTMETHOD)
                .append(DataUtil.getCurrentMethod())
                .append(DASHES)
                .append(STARTED)
                .append(DASHES)
                .append(PARAMETERS)
                .append(GAME_OPTION_DTO)
                .toString(),
            Level.INFO);
    Session session = HibernateUtil.getSession();
    Transaction transaction = session.beginTransaction();
    dto = (GameoptionsDTO) session.get(GameoptionsDTO.class, dto);
    transaction.commit();
    HibernateUtil.closeSession();
    AuditUtil.getInstance()
        .writeLog(
            AuditUtil.FILE_TYPE_G4G,
            new StringBuffer(this.getClass().getName())
                .append(DASHES)
                .append(GET_GAME_OF_ID)
                .toString(),
            Level.INFO);
    AuditUtil.getInstance()
        .writeLog(
            AuditUtil.FILE_TYPE_G4G,
            new StringBuffer(this.getClass().getName())
                .append(COLON_WITH_SPACES)
                .append(CALLINGMETHOD)
                .append(DataUtil.getCallingMethod())
                .append(CURRENTMETHOD)
                .append(DataUtil.getCurrentMethod())
                .append(DASHES)
                .append(ENDED)
                .toString(),
            Level.INFO);

    return dto;
  }
 /** @see com.g4g.services.GameOptionService#add(com.g4g.dto.GameoptionsDTO) */
 public GameoptionsDTO add(GameoptionsDTO dto) throws HibernateException {
   AuditUtil.getInstance()
       .writeLog(
           AuditUtil.FILE_TYPE_G4G,
           new StringBuffer(this.getClass().getName())
               .append(COLON_WITH_SPACES)
               .append(CALLINGMETHOD)
               .append(DataUtil.getCallingMethod())
               .append(CURRENTMETHOD)
               .append(DataUtil.getCurrentMethod())
               .append(DASHES)
               .append(STARTED)
               .toString(),
           Level.INFO);
   Session session = HibernateUtil.getSession();
   Transaction transaction = session.beginTransaction();
   try {
     session.save(dto);
     transaction.commit();
     session.flush();
     HibernateUtil.closeSession();
     AuditUtil.getInstance()
         .writeLog(
             AuditUtil.FILE_TYPE_G4G,
             new StringBuffer(this.getClass().getName())
                 .append(COLON_WITH_SPACES)
                 .append(CALLINGMETHOD)
                 .append(DataUtil.getCallingMethod())
                 .append(CURRENTMETHOD)
                 .append(DataUtil.getCurrentMethod())
                 .append(DASHES)
                 .append(RECORD_ADDED)
                 .toString(),
             Level.INFO);
   } catch (HibernateException e) {
     transaction.rollback();
     HibernateUtil.closeSession();
     AuditUtil.getInstance()
         .writeLog(
             AuditUtil.FILE_TYPE_HIBERNATE,
             new StringBuffer(this.getClass().getName())
                 .append(COLON_WITH_SPACES)
                 .append(CALLINGMETHOD)
                 .append(DataUtil.getCallingMethod())
                 .append(CURRENTMETHOD)
                 .append(DataUtil.getCurrentMethod())
                 .append(DASHES)
                 .append(RECORD_NOT_ADDED)
                 .toString(),
             Level.ERROR);
     AuditUtil.getInstance()
         .writeLog(
             AuditUtil.FILE_TYPE_HIBERNATE,
             new StringBuffer(this.getClass().getName())
                 .append(COLON_WITH_SPACES)
                 .append(CALLINGMETHOD)
                 .append(DataUtil.getCallingMethod())
                 .append(CURRENTMETHOD)
                 .append(DataUtil.getCurrentMethod())
                 .append(DASHES)
                 .append(e.getMessage())
                 .toString(),
             Level.ERROR);
     throw e;
   }
   AuditUtil.getInstance()
       .writeLog(
           AuditUtil.FILE_TYPE_G4G,
           new StringBuffer(this.getClass().getName())
               .append(COLON_WITH_SPACES)
               .append(CALLINGMETHOD)
               .append(DataUtil.getCallingMethod())
               .append(CURRENTMETHOD)
               .append(DataUtil.getCurrentMethod())
               .append(DASHES)
               .append(ENDED)
               .toString(),
           Level.INFO);
   return dto;
 }
 /**
  * @see com.g4g.services.GameOptionService#getGameOptions(int, int, com.g4g.dto.SearchCriteria)
  */
 public List<GameoptionsDTO> getGameOptions(
     int gameid, int optionsequenceid, SearchCriteria searchCriteria) throws HibernateException {
   AuditUtil.getInstance()
       .writeLog(
           AuditUtil.FILE_TYPE_G4G,
           new StringBuffer(this.getClass().getName())
               .append(COLON_WITH_SPACES)
               .append(CALLINGMETHOD)
               .append(DataUtil.getCallingMethod())
               .append(CURRENTMETHOD)
               .append(DataUtil.getCurrentMethod())
               .append(DASHES)
               .append(STARTED)
               .toString(),
           Level.INFO);
   StringBuffer query =
       new StringBuffer(GameIdConstants.gameoptionquery).append(gameid).append(G4GConstants.BLANK);
   Set<String> keys = searchCriteria.getAttributeNames();
   Iterator<String> it = keys.iterator();
   String key = null;
   Object value = null;
   if (keys.size() > 0) {
     query.append(GameIdConstants.gameoptionqueryapp);
   }
   while (it.hasNext()) {
     key = it.next();
     value = searchCriteria.getAttribute(key);
     query.append(key).append(SQLConstants.EQUAL).append(value).append(G4GConstants.BLANK);
   }
   if (keys.size() > 0) {
     query.append(SQLConstants.CLOSE_PAREN);
   }
   query
       .append(GameIdConstants.middelquery)
       .append((optionsequenceid + G4GConstants.ONE_NUMBER))
       .append(GameIdConstants.gameoptionquerylast);
   Session session = HibernateUtil.getSession();
   Query q = session.createQuery(query.toString());
   Transaction transaction = session.beginTransaction();
   List<GameoptionsDTO> list = null;
   try {
     list = q.list();
     transaction.commit();
   } catch (HibernateException e) {
     throw e;
   } finally {
     session.flush();
     HibernateUtil.closeSession();
   }
   AuditUtil.getInstance()
       .writeLog(
           AuditUtil.FILE_TYPE_G4G,
           new StringBuffer(this.getClass().getName())
               .append(COLON_WITH_SPACES)
               .append(CALLINGMETHOD)
               .append(DataUtil.getCallingMethod())
               .append(CURRENTMETHOD)
               .append(DataUtil.getCurrentMethod())
               .append(DASHES)
               .append(GAME_OPTIONS_LIST_SIZE_CRITERIA)
               .append(list.size())
               .toString(),
           Level.INFO);
   return list;
 }
  /** @see com.g4g.services.GameOptionService#getList(com.g4g.dto.SearchCriteria) */
  @SuppressWarnings(UNCHECKED)
  public List<GameoptionsDTO> getList(SearchCriteria searchCriteria) throws HibernateException {
    AuditUtil.getInstance()
        .writeLog(
            AuditUtil.FILE_TYPE_G4G,
            new StringBuffer(this.getClass().getName())
                .append(COLON_WITH_SPACES)
                .append(CALLINGMETHOD)
                .append(DataUtil.getCallingMethod())
                .append(CURRENTMETHOD)
                .append(DataUtil.getCurrentMethod())
                .append(DASHES)
                .append(STARTED)
                .toString(),
            Level.INFO);
    Session session = HibernateUtil.getSession();
    Criteria criteria = session.createCriteria(GameoptionsDTO.class);
    String orderBY = searchCriteria.getOrderBy();
    if (orderBY != null) {
      if (searchCriteria.isAsc()) {
        criteria.addOrder(Order.asc(orderBY));
      } else {
        criteria.addOrder(Order.desc(orderBY));
      }
    }
    Set<String> keys = searchCriteria.getAttributeNames();
    Iterator<String> it = keys.iterator();
    String key = null;
    Object value = null;
    while (it.hasNext()) {
      key = it.next();
      value = searchCriteria.getAttribute(key);
      criteria.add(Restrictions.eq(key, value));
      AuditUtil.getInstance()
          .writeLog(
              AuditUtil.FILE_TYPE_G4G,
              new StringBuffer(this.getClass().getName())
                  .append(DASHES)
                  .append(key)
                  .append(COLON)
                  .append(value)
                  .toString(),
              Level.INFO);
    }
    Transaction transaction = session.beginTransaction();
    List<GameoptionsDTO> list = new ArrayList<GameoptionsDTO>();

    try {
      list = criteria.list();
      transaction.commit();
    } catch (HibernateException e) {
      for (String keyexception : keys) {
        AuditUtil.getInstance()
            .writeLog(
                AuditUtil.FILE_TYPE_HIBERNATE,
                new StringBuffer(this.getClass().getName()).append(keyexception).toString(),
                Level.ERROR);
      }
      throw e;
    } finally {
      session.flush();
      HibernateUtil.closeSession();
    }
    AuditUtil.getInstance()
        .writeLog(
            AuditUtil.FILE_TYPE_G4G,
            new StringBuffer(this.getClass().getName())
                .append(COLON_WITH_SPACES)
                .append(CALLINGMETHOD)
                .append(DataUtil.getCallingMethod())
                .append(CURRENTMETHOD)
                .append(DataUtil.getCurrentMethod())
                .append(DASHES)
                .append(GAME_OPTIONS_LIST_SIZE_CRITERIA)
                .append(list.size())
                .toString(),
            Level.INFO);
    AuditUtil.getInstance()
        .writeLog(
            AuditUtil.FILE_TYPE_G4G,
            new StringBuffer(this.getClass().getName())
                .append(COLON_WITH_SPACES)
                .append(CALLINGMETHOD)
                .append(DataUtil.getCallingMethod())
                .append(CURRENTMETHOD)
                .append(DataUtil.getCurrentMethod())
                .append(DASHES)
                .append(ENDED)
                .toString(),
            Level.INFO);
    return list;
  }
  public static String getAlert(int playerId) {
    AuditUtil.getInstance()
        .writeLog(
            AuditUtil.FILE_TYPE_G4G,
            new StringBuffer(UserAlertAjaxImpl.class.getName())
                .append(COLON_WITH_SPACES)
                .append(CALLINGMETHOD)
                .append(DataUtil.getCallingMethod())
                .append(CURRENTMETHOD)
                .append(DataUtil.getCurrentMethod())
                .append(DASHES)
                .append(STARTED)
                .toString(),
            Level.INFO);

    String message = NONE;

    SearchListCriteria searchListCriteria = new SearchListCriteria();
    PlayerDTO playerDTO = PlayerServiceDelegator.getPlayer(playerId);
    if (playerDTO == null) {
      playerDTO = new PlayerDTO(playerId);
    }
    searchListCriteria.setAttribute(
        RECIPIENT_PLAYER, new Object[] {playerDTO, SearchListCriteria.EQ});
    searchListCriteria.setAttribute(
        EXPIRE_DATE, new Object[] {DataUtil.todayGMT(), SearchListCriteria.GE});
    searchListCriteria.setAttribute(VIEW_DATE, new Object[] {null, SearchListCriteria.ISNULL});
    List<NotificationqueueDTO> notificationqueueList =
        NotificationQueueServiceDelegator.getList(searchListCriteria);
    AuditUtil.getInstance()
        .writeLog(
            AuditUtil.FILE_TYPE_G4G,
            new StringBuffer(UserAlertAjaxImpl.class.getName())
                .append(COLON_WITH_SPACES)
                .append(CALLINGMETHOD)
                .append(DataUtil.getCallingMethod())
                .append(CURRENTMETHOD)
                .append(DataUtil.getCurrentMethod())
                .append(DASHES)
                .append(NOTIFICATIONQUEUEDTO_LIST_SEARCH_CRITERIA)
                .append(notificationqueueList.size())
                .toString(),
            Level.INFO);
    if (notificationqueueList.size() > ZERO) {
      NotificationqueueDTO notificationqueueDTO = notificationqueueList.get(ZERO);
      message = notificationqueueDTO.getBody();

      notificationqueueDTO.setViewdate(DataUtil.todayGMT());
      try {
        NotificationQueueServiceDelegator.update(notificationqueueDTO);
      } catch (Exception exception) {
        AuditUtil.getInstance()
            .writeLog(
                AuditUtil.FILE_TYPE_G4G,
                new StringBuffer(UserAlertAjaxImpl.class.getName())
                    .append(COLON_WITH_SPACES)
                    .append(CALLINGMETHOD)
                    .append(DataUtil.getCallingMethod())
                    .append(CURRENTMETHOD)
                    .append(DataUtil.getCurrentMethod())
                    .append(DASHES)
                    .append(exception)
                    .toString(),
                Level.ERROR);
      }
    }
    AuditUtil.getInstance()
        .writeLog(
            AuditUtil.FILE_TYPE_G4G,
            new StringBuffer(UserAlertAjaxImpl.class.getName())
                .append(COLON_WITH_SPACES)
                .append(CALLINGMETHOD)
                .append(DataUtil.getCallingMethod())
                .append(CURRENTMETHOD)
                .append(DataUtil.getCurrentMethod())
                .append(DASHES)
                .append(ENDED)
                .toString(),
            Level.INFO);
    return message;
  }