Exemplo n.º 1
0
  public void select(Castle castle) {
    Connection con = null;
    PreparedStatement statement = null;
    ResultSet rset = null;

    try {
      con = DatabaseFactory.getInstance().getConnection();
      statement = con.prepareStatement(SELECT_SQL_QUERY);
      statement.setInt(1, castle.getId());
      rset = statement.executeQuery();
      if (rset.next()) {
        castle.setTaxPercent(rset.getInt("tax_percent"));
        castle.setTreasury(rset.getLong("treasury"));
        castle.setRewardCount(rset.getInt("reward_count"));
        castle.getSiegeDate().setTimeInMillis(rset.getLong("siege_date") * 1000L);
        castle.getLastSiegeDate().setTimeInMillis(rset.getLong("last_siege_date") * 1000L);
        castle.getOwnDate().setTimeInMillis(rset.getLong("own_date") * 1000L);
        castle.setResidenceSide(ResidenceSide.VALUES[rset.getInt("side")], true);
      }
    } catch (Exception e) {
      _log.error("CastleDAO.select(Castle):" + e, e);
    } finally {
      DbUtils.closeQuietly(con, statement, rset);
    }
  }
Exemplo n.º 2
0
 private void update0(Castle castle) {
   Connection con = null;
   PreparedStatement statement = null;
   try {
     con = DatabaseFactory.getInstance().getConnection();
     statement = con.prepareStatement(UPDATE_SQL_QUERY);
     statement.setInt(1, castle.getTaxPercent0());
     statement.setLong(2, castle.getTreasury());
     statement.setInt(3, castle.getRewardCount());
     statement.setInt(4, (int) (castle.getSiegeDate().getTimeInMillis() / 1000L));
     statement.setInt(5, (int) (castle.getLastSiegeDate().getTimeInMillis() / 1000L));
     statement.setInt(6, (int) (castle.getOwnDate().getTimeInMillis() / 1000L));
     statement.setInt(7, castle.getResidenceSide().ordinal());
     statement.setInt(8, castle.getId());
     statement.execute();
   } catch (Exception e) {
     _log.warn("CastleDAO#update0(Castle): " + e, e);
   } finally {
     DbUtils.closeQuietly(con, statement);
   }
 }