View Javadoc

1   // %3247860593:hoplugins.transfers.dao%
2   package hoplugins.transfers.dao;
3   
4   import hoplugins.Commons;
5   
6   import java.sql.ResultSet;
7   import java.sql.SQLException;
8   
9   
10  /***
11   * DAO to load from HO Database number of matches played by a player
12   *
13   * @author <a href=mailto:draghetto@users.sourceforge.net>Massimiliano Amato</a>
14   */
15  public final class PlayerMatchesDAO {
16      //~ Constructors -------------------------------------------------------------------------------
17  
18      /***
19       * Private default constuctor to prevent class instantiation.
20       */
21      private PlayerMatchesDAO() {
22      }
23  
24      //~ Methods ------------------------------------------------------------------------------------
25  
26      /***
27       * Method to load the number of matches player
28       *
29       * @param playerId Id of the Player to consider
30       * @param official true for official matches, false for friendly
31       *
32       * @return number of matches
33       */
34      public static int getAppearance(int playerId, boolean official) {
35          String sqlStmt = "select count(MATCHESKURZINFO.matchid) as MatchNumber FROM MATCHLINEUPPLAYER INNER JOIN MATCHESKURZINFO ON MATCHESKURZINFO.matchid = MATCHLINEUPPLAYER.matchid ";
36          sqlStmt = sqlStmt + "where spielerId = " + playerId + " and FIELDPOS>-1 ";
37  
38          if (official) {
39              sqlStmt = sqlStmt + "and matchtyp <8";
40          } else {
41              sqlStmt = sqlStmt + "and matchtyp >7";
42          }
43  
44          final ResultSet rs = Commons.getModel().getAdapter().executeQuery(sqlStmt.toString());
45  
46          if (rs == null) {
47              return 0;
48          }
49  
50          int count = 0;
51  
52          try {
53              while (rs.next()) {
54                  count = rs.getInt("MatchNumber");
55              }
56          } catch (SQLException e) {
57          }
58  
59          return count;
60      }
61  }