コード例 #1
0
  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();
    }
  }
コード例 #2
0
 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;
 }
コード例 #3
0
  /**
   * 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();
    }
  }
コード例 #4
0
  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();
    }
  }