Esempio n. 1
0
  @Override
  public void read(SGuiSession session, int[] pk) throws SQLException, Exception {
    ResultSet resultSet = null;

    initRegistry();
    initQueryMembers();
    mnQueryResultId = SDbConsts.READ_ERROR;

    msSql = "SELECT * " + getSqlFromWhere(pk);
    resultSet = session.getStatement().executeQuery(msSql);
    if (!resultSet.next()) {
      throw new Exception(SDbConsts.ERR_MSG_REG_NOT_FOUND);
    } else {
      mnPkSpotId = resultSet.getInt("id_spot");
      msCode = resultSet.getString("code");
      msName = resultSet.getString("name");
      mbDeleted = resultSet.getBoolean("b_del");
      mnFkDeliveryTypeId = resultSet.getInt("fk_tp_dly");
      mnFkSpotTypeId = resultSet.getInt("fk_tp_spot");
      mnFkUserInsertId = resultSet.getInt("fk_usr_ins");
      mnFkUserUpdateId = resultSet.getInt("fk_usr_upd");
      mtTsUserInsert = resultSet.getTimestamp("ts_usr_ins");
      mtTsUserUpdate = resultSet.getTimestamp("ts_usr_upd");

      mbRegistryNew = false;
    }

    mnQueryResultId = SDbConsts.READ_OK;
  }
Esempio n. 2
0
  @Override
  public void computePrimaryKey(SGuiSession session) throws SQLException, Exception {
    ResultSet resultSet = null;

    mnPkSpotId = 0;

    msSql = "SELECT COALESCE(MAX(id_spot), 0) + 1 FROM " + getSqlTable();
    resultSet = session.getStatement().executeQuery(msSql);
    if (resultSet.next()) {
      mnPkSpotId = resultSet.getInt(1);
    }
  }
Esempio n. 3
0
  @Override
  public void save(SGuiSession session) throws SQLException, Exception {
    initQueryMembers();
    mnQueryResultId = SDbConsts.SAVE_ERROR;

    if (mbRegistryNew) {
      verifyRegistryNew(session);
    }

    if (mbRegistryNew) {
      computePrimaryKey(session);
      mbDeleted = false;
      mnFkUserInsertId = session.getUser().getPkUserId();
      mnFkUserUpdateId = SUtilConsts.USR_NA_ID;

      msSql =
          "INSERT INTO "
              + getSqlTable()
              + " VALUES ("
              + mnPkSpotId
              + ", "
              + "'"
              + msCode
              + "', "
              + "'"
              + msName
              + "', "
              + (mbDeleted ? 1 : 0)
              + ", "
              + mnFkSpotTypeId
              + ", "
              + mnFkDeliveryTypeId
              + ", "
              + mnFkUserInsertId
              + ", "
              + mnFkUserUpdateId
              + ", "
              + "NOW()"
              + ", "
              + "NOW()"
              + " "
              + ")";
    } else {
      mnFkUserUpdateId = session.getUser().getPkUserId();

      msSql =
          "UPDATE "
              + getSqlTable()
              + " SET "
              +
              // "id_spot = " + mnPkSpotId + ", " +
              "code = '"
              + msCode
              + "', "
              + "name = '"
              + msName
              + "', "
              + "b_del = "
              + (mbDeleted ? 1 : 0)
              + ", "
              + "fk_tp_spot = "
              + mnFkSpotTypeId
              + ", "
              + "fk_tp_dly = "
              + mnFkDeliveryTypeId
              + ", "
              +
              // "fk_usr_ins = " + mnFkUserInsertId + ", " +
              "fk_usr_upd = "
              + mnFkUserUpdateId
              + ", "
              +
              // "ts_usr_ins = " + "NOW()" + ", " +
              "ts_usr_upd = "
              + "NOW()"
              + " "
              + getSqlWhere();
    }

    session.getStatement().execute(msSql);
    mbRegistryNew = false;
    mnQueryResultId = SDbConsts.SAVE_OK;
  }