示例#1
0
  // Based on our latest design, we default to today's date in every case. One record per day per
  // user is expected
  // The Save method doesn't refresh the data. Need to re-query in factory
  public void Save() {
    String sqlStatement = "";

    if (!IsLoaded) {
      sqlStatement =
          "INSERT INTO `java`.`WeekDay` "
              + "( "
              + "`DateCreated`,"
              + "`AppUserId`)"
              + "VALUES"
              + "("
              + " Now()," // "'" + dateCreated + "',"
              + ""
              + appUserId
              + ")";
    } else {
      sqlStatement =
          "UPDATE `java`.`Weekday` SET "
              + "`DateCreated` = Now(), " // '" + dateCreated + "',"
              + "`AppUserId` = "
              + appUserId
              + "WHERE `WeekDayID` = "
              + weekDayId;
    }

    try {
      super.executeInsertUpdateDeleteQuery(sqlStatement);

      super.closeConnection();
    } catch (SQLException ex) {
      Logger.getLogger(MealModel.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
示例#2
0
  public int getCurrentIdByUserId(Integer userId) throws SQLException {
    int result = 0;

    String sqlStatement =
        "select * from WeekDay where Date(DateCreated) = Date(Now()) And AppUserId = "
            + userId.toString()
            + " Limit 1";
    setData(super.executeSelectQuery(sqlStatement));

    if (getData().isBeforeFirst()) {
      getData().next();
      result = getData().getInt("WeekDayId");
      weekDayId = getData().getInt("WeekDayId");
      dateCreated = getData().getDate("DateCreated");
      appUserId = getData().getInt("AppUserId");

      IsLoaded = true;
    } else {
      IsLoaded = false;
    }

    super.closeConnection();

    return result;
  }
示例#3
0
  public List<Integer> getLastSevenIdsByUserId(Integer userId) throws SQLException {
    String sqlStatement =
        "select WeekDayId from WeekDay where AppUserId = "
            + userId.toString()
            + " order by datecreated desc Limit 7";
    setData(super.executeSelectQuery(sqlStatement));

    List<Integer> itemIdList = new ArrayList<>();

    if (getData().isBeforeFirst()) {
      while (data.next()) {
        itemIdList.add(getData().getInt("WeekDayId"));
      }
    }

    super.closeConnection();

    return itemIdList;
  }
示例#4
0
  @Override
  public void loadRowByPrimaryKey(Object id) throws SQLException {
    String sqlStatement = "select * from WeekDay where WeekDayId = " + id.toString();
    setData(super.executeSelectQuery(sqlStatement));

    if (getData().isBeforeFirst()) {
      getData().next();

      weekDayId = getData().getInt("WeekDayId");
      dateCreated = getData().getDate("DateCreated");
      appUserId = getData().getInt("AppUserId");

      IsLoaded = true;
    } else {
      IsLoaded = false;
    }

    super.closeConnection();
  }