public void update() {
    if (SpyMemCacheClient.getInstance().IsConnected())
      SpyMemCacheClient.getInstance()
          .delete(String.format(UserAccount.key_UserAccountByUserID, this.user_id));

    String query =
        String.format(
            UserSQL.sqlUpdateUserAccount,
            this.chips,
            this.gold,
            this.experience,
            this.level,
            this.lastlogin,
            this.invitebonus,
            this.id);
    System.out.println(query);
    Connection conn;
    try {
      conn = PoolFactory.getPooling().getConnection();
      Statement stm = conn.createStatement();
      stm.executeUpdate(query);
      conn.close();

    } catch (SQLException e) {
      System.out.println("SQL Exception Code : " + e.getErrorCode());
      System.out.println("SQL Exception Message : " + e.getLocalizedMessage());
      e.printStackTrace();
    }
  }
 public static UserAccount getUserAccountbyUserID(long userid) {
   UserAccount useraccount = null;
   if (SpyMemCacheClient.getInstance().IsConnected())
     useraccount =
         (UserAccount)
             SpyMemCacheClient.getInstance()
                 .get(String.format(UserAccount.key_UserAccountByUserID, userid));
   if (useraccount == null) {
     String query = String.format(UserSQL.sqlGetUserAccountByUserID, userid);
     System.out.println("User Acc Query : " + query);
     try {
       ResultSetHandler<UserAccount> h = new BeanHandler<UserAccount>(UserAccount.class);
       Connection conn = PoolFactory.getPooling().getConnection();
       QueryRunner run = new QueryRunner();
       useraccount = run.query(conn, query, h);
       System.out.println("User Account Details : " + useraccount.toString());
       conn.close();
       // System.out.println(useraccount.toString());
       return useraccount;
     } catch (SQLException e) {
       e.printStackTrace();
     }
   } else {
     System.out.println("Mem Cache used");
   }
   return useraccount;
 }
  public UserAccount(long user_id) {
    this.user_id = user_id;

    String query = String.format(UserSQL.sqlCreateUserAccountDefault, this.user_id);

    Connection conn;
    try {
      conn = PoolFactory.getPooling().getConnection();

      String autogenColumns[] = {"id"};
      Statement stm = conn.createStatement();

      stm.executeUpdate(query, autogenColumns);

      ResultSet result_set = stm.getGeneratedKeys();

      if (result_set.first()) {
        this.id = result_set.getLong(1);

        SpyMemCacheClient.getInstance()
            .add(String.format(UserAccount.key_UserAccountByUserID, this.user_id), this);
      }
      conn.close();

    } catch (SQLException e) {
      System.out.println("SQL Exception Code : " + e.getErrorCode());
      System.out.println("SQL Exception Message : " + e.getLocalizedMessage());
      e.printStackTrace();
    }
  }
  /**
   * DB Access methods
   *
   * @param chips
   * @param gold
   * @param experience
   * @param level
   * @param lastlogin
   * @param invitebonus
   * @param user_id
   */
  public UserAccount(
      int chips,
      int gold,
      int experience,
      int level,
      String lastlogin,
      int invitebonus,
      long user_id) {

    this.chips = chips;
    this.gold = gold;
    this.experience = experience;
    this.level = level;
    this.lastlogin = lastlogin;
    this.invitebonus = invitebonus;
    this.user_id = user_id;

    String query =
        String.format(
            UserSQL.sqlCreateUserAccount,
            this.chips,
            this.gold,
            this.experience,
            this.level,
            this.lastlogin,
            this.invitebonus,
            this.user_id);
    System.out.println(query);
    Connection conn;
    try {
      conn = PoolFactory.getPooling().getConnection();
      String autogenColumns[] = {"id"};
      Statement stm = conn.createStatement();

      stm.executeUpdate(query, autogenColumns);

      ResultSet result_set = stm.getGeneratedKeys();

      if (result_set.first()) {
        this.id = result_set.getInt("id");
        if (SpyMemCacheClient.getInstance().IsConnected())
          SpyMemCacheClient.getInstance()
              .add(String.format(UserAccount.key_UserAccountByUserID, this.user_id), this);
      }
      conn.close();

    } catch (SQLException e) {
      System.out.println("SQL Exception Code : " + e.getErrorCode());
      System.out.println("SQL Exception Message : " + e.getLocalizedMessage());
      e.printStackTrace();
    }
  }
Exemple #5
0
  public static Prize getPrizebyID(int id) {
    String query = String.format(UserSQL.sqlGetPrizeById, id);
    try {
      ResultSetHandler<Prize> h = new BeanHandler<Prize>(Prize.class);
      Connection conn = PoolFactory.getPooling().getConnection();
      QueryRunner run = new QueryRunner();
      Prize prize = run.query(conn, query, h);
      System.out.println(prize.toString());
      return prize;
    } catch (SQLException e) {
      e.printStackTrace();
    }

    return null;
  }
Exemple #6
0
  public Prize(String description, String sponsor, String img, String icon, String sponsor_logo) {

    this.description = description;
    this.sponsor = sponsor;
    this.img = img;
    this.icon = icon;
    this.sponsor_logo = sponsor_logo;

    String query =
        String.format(
            UserSQL.sqlGeneratePrize,
            this.description,
            this.sponsor,
            this.img,
            this.icon,
            this.sponsor_logo);
    System.out.println(query);
    Connection conn;
    try {
      conn = PoolFactory.getPooling().getConnection();
      String autogenColumns[] = {"id"};

      Statement stm = conn.createStatement();
      stm.executeUpdate(query, autogenColumns);
      ResultSet result_update = stm.getGeneratedKeys();

      if (result_update.first()) {
        this.id = result_update.getInt(1);
      }

    } catch (SQLException e) {
      System.out.println("SQL Exception Code : " + e.getErrorCode());
      System.out.println("SQL Exception Message : " + e.getLocalizedMessage());
      e.printStackTrace();
    }
  }