コード例 #1
0
  // 73
  public SmTbProductBean decodeRow(ResultSet rs, int[] fieldList) throws SQLException {
    SmTbProductBean pObject = createSmTbProductBean();
    int pos = 0;
    for (int i = 0; i < fieldList.length; i++) {
      switch (fieldList[i]) {
        case ID_PRD_ID:
          ++pos;
          pObject.setPrdId(Manager.getLong(rs, pos));
          break;
        case ID_PRD_TYPE_ID:
          ++pos;
          pObject.setPrdTypeId(Manager.getLong(rs, pos));
          break;
        case ID_NAME:
          ++pos;
          pObject.setName(rs.getString(pos));
          break;
        case ID_PRICE:
          ++pos;
          pObject.setPrice(Manager.getLong(rs, pos));
          break;
        case ID_PRICE_VIP:
          ++pos;
          pObject.setPriceVip(Manager.getLong(rs, pos));
          break;
        case ID_SUPLY_STATUS:
          ++pos;
          pObject.setSuplyStatus(rs.getString(pos));
          break;
        case ID_FORMAT_DESC:
          ++pos;
          pObject.setFormatDesc(rs.getString(pos));
          break;
        case ID_DETAIL_DESC:
          ++pos;
          pObject.setDetailDesc(rs.getString(pos));
          break;
        case ID_SEND_AREA:
          ++pos;
          pObject.setSendArea(rs.getString(pos));
          break;
        case ID_SEND_DESC:
          ++pos;
          pObject.setSendDesc(rs.getString(pos));
          break;
        case ID_PRD_PIC_FILE:
          ++pos;
          pObject.setPrdPicFile(rs.getString(pos));
          break;
        case ID_OWNER:
          ++pos;
          pObject.setOwner(Manager.getLong(rs, pos));
          break;
      }
    }
    pObject.isNew(false);
    pObject.resetIsModified();

    return pObject;
  }
コード例 #2
0
  // 72
  public SmTbProductBean decodeRow(ResultSet rs) throws SQLException {
    SmTbProductBean pObject = createSmTbProductBean();
    pObject.setPrdId(Manager.getLong(rs, 1));
    pObject.setPrdTypeId(Manager.getLong(rs, 2));
    pObject.setName(rs.getString(3));
    pObject.setPrice(Manager.getLong(rs, 4));
    pObject.setPriceVip(Manager.getLong(rs, 5));
    pObject.setSuplyStatus(rs.getString(6));
    pObject.setFormatDesc(rs.getString(7));
    pObject.setDetailDesc(rs.getString(8));
    pObject.setSendArea(rs.getString(9));
    pObject.setSendDesc(rs.getString(10));
    pObject.setPrdPicFile(rs.getString(11));
    pObject.setOwner(Manager.getLong(rs, 12));

    pObject.isNew(false);
    pObject.resetIsModified();

    return pObject;
  }
コード例 #3
0
  // 100
  public SmTbProductBean save(SmTbProductBean pObject) throws SQLException {
    if (!pObject.isModified()) {
      return pObject; // should not we log something ?
    }

    Connection c = null;
    PreparedStatement ps = null;
    StringBuffer _sql = null;

    try {
      c = getConnection();
      if (pObject.isNew()) { // SAVE
        beforeInsert(pObject); // listener callback
        int _dirtyCount = 0;
        _sql = new StringBuffer("INSERT into sm_tb_product (");

        if (pObject.isPrdIdModified()) {
          if (_dirtyCount > 0) {
            _sql.append(",");
          }
          _sql.append("prd_id");
          _dirtyCount++;
        }

        if (pObject.isPrdTypeIdModified()) {
          if (_dirtyCount > 0) {
            _sql.append(",");
          }
          _sql.append("prd_type_id");
          _dirtyCount++;
        }

        if (pObject.isNameModified()) {
          if (_dirtyCount > 0) {
            _sql.append(",");
          }
          _sql.append("name");
          _dirtyCount++;
        }

        if (pObject.isPriceModified()) {
          if (_dirtyCount > 0) {
            _sql.append(",");
          }
          _sql.append("price");
          _dirtyCount++;
        }

        if (pObject.isPriceVipModified()) {
          if (_dirtyCount > 0) {
            _sql.append(",");
          }
          _sql.append("price_vip");
          _dirtyCount++;
        }

        if (pObject.isSuplyStatusModified()) {
          if (_dirtyCount > 0) {
            _sql.append(",");
          }
          _sql.append("suply_status");
          _dirtyCount++;
        }

        if (pObject.isFormatDescModified()) {
          if (_dirtyCount > 0) {
            _sql.append(",");
          }
          _sql.append("format_desc");
          _dirtyCount++;
        }

        if (pObject.isDetailDescModified()) {
          if (_dirtyCount > 0) {
            _sql.append(",");
          }
          _sql.append("detail_desc");
          _dirtyCount++;
        }

        if (pObject.isSendAreaModified()) {
          if (_dirtyCount > 0) {
            _sql.append(",");
          }
          _sql.append("send_area");
          _dirtyCount++;
        }

        if (pObject.isSendDescModified()) {
          if (_dirtyCount > 0) {
            _sql.append(",");
          }
          _sql.append("send_desc");
          _dirtyCount++;
        }

        if (pObject.isPrdPicFileModified()) {
          if (_dirtyCount > 0) {
            _sql.append(",");
          }
          _sql.append("prd_pic_file");
          _dirtyCount++;
        }

        if (pObject.isOwnerModified()) {
          if (_dirtyCount > 0) {
            _sql.append(",");
          }
          _sql.append("owner");
          _dirtyCount++;
        }

        _sql.append(") values (");
        if (_dirtyCount > 0) {
          _sql.append("?");
          for (int i = 1; i < _dirtyCount; i++) {
            _sql.append(",?");
          }
        }
        _sql.append(")");

        ps =
            c.prepareStatement(
                _sql.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        _dirtyCount = 0;

        if (pObject.isPrdIdModified()) {
          Manager.setLong(ps, ++_dirtyCount, pObject.getPrdId());
        }

        if (pObject.isPrdTypeIdModified()) {
          Manager.setLong(ps, ++_dirtyCount, pObject.getPrdTypeId());
        }

        if (pObject.isNameModified()) {
          ps.setString(++_dirtyCount, pObject.getName());
        }

        if (pObject.isPriceModified()) {
          Manager.setLong(ps, ++_dirtyCount, pObject.getPrice());
        }

        if (pObject.isPriceVipModified()) {
          Manager.setLong(ps, ++_dirtyCount, pObject.getPriceVip());
        }

        if (pObject.isSuplyStatusModified()) {
          ps.setString(++_dirtyCount, pObject.getSuplyStatus());
        }

        if (pObject.isFormatDescModified()) {
          ps.setString(++_dirtyCount, pObject.getFormatDesc());
        }

        if (pObject.isDetailDescModified()) {
          ps.setString(++_dirtyCount, pObject.getDetailDesc());
        }

        if (pObject.isSendAreaModified()) {
          ps.setString(++_dirtyCount, pObject.getSendArea());
        }

        if (pObject.isSendDescModified()) {
          ps.setString(++_dirtyCount, pObject.getSendDesc());
        }

        if (pObject.isPrdPicFileModified()) {
          ps.setString(++_dirtyCount, pObject.getPrdPicFile());
        }

        if (pObject.isOwnerModified()) {
          Manager.setLong(ps, ++_dirtyCount, pObject.getOwner());
        }

        ps.executeUpdate();

        if (!pObject.isPrdIdModified()) {
          PreparedStatement ps2 = null;
          ResultSet rs = null;
          try {
            ps2 = c.prepareStatement("SELECT last_insert_id()");
            rs = ps2.executeQuery();
            if (rs.next()) {
              pObject.setPrdId(Manager.getLong(rs, 1));
            } else {
              getManager().log("ATTENTION: Could not retrieve generated key!");
            }
          } finally {
            getManager().close(ps2, rs);
          }
        }

        pObject.isNew(false);
        pObject.resetIsModified();
        afterInsert(pObject); // listener callback
      } else { // UPDATE
        beforeUpdate(pObject); // listener callback
        _sql = new StringBuffer("UPDATE sm_tb_product SET ");
        boolean useComma = false;

        if (pObject.isPrdIdModified()) {
          if (useComma) {
            _sql.append(",");
          } else {
            useComma = true;
          }
          _sql.append("prd_id").append("=?");
        }

        if (pObject.isPrdTypeIdModified()) {
          if (useComma) {
            _sql.append(",");
          } else {
            useComma = true;
          }
          _sql.append("prd_type_id").append("=?");
        }

        if (pObject.isNameModified()) {
          if (useComma) {
            _sql.append(",");
          } else {
            useComma = true;
          }
          _sql.append("name").append("=?");
        }

        if (pObject.isPriceModified()) {
          if (useComma) {
            _sql.append(",");
          } else {
            useComma = true;
          }
          _sql.append("price").append("=?");
        }

        if (pObject.isPriceVipModified()) {
          if (useComma) {
            _sql.append(",");
          } else {
            useComma = true;
          }
          _sql.append("price_vip").append("=?");
        }

        if (pObject.isSuplyStatusModified()) {
          if (useComma) {
            _sql.append(",");
          } else {
            useComma = true;
          }
          _sql.append("suply_status").append("=?");
        }

        if (pObject.isFormatDescModified()) {
          if (useComma) {
            _sql.append(",");
          } else {
            useComma = true;
          }
          _sql.append("format_desc").append("=?");
        }

        if (pObject.isDetailDescModified()) {
          if (useComma) {
            _sql.append(",");
          } else {
            useComma = true;
          }
          _sql.append("detail_desc").append("=?");
        }

        if (pObject.isSendAreaModified()) {
          if (useComma) {
            _sql.append(",");
          } else {
            useComma = true;
          }
          _sql.append("send_area").append("=?");
        }

        if (pObject.isSendDescModified()) {
          if (useComma) {
            _sql.append(",");
          } else {
            useComma = true;
          }
          _sql.append("send_desc").append("=?");
        }

        if (pObject.isPrdPicFileModified()) {
          if (useComma) {
            _sql.append(",");
          } else {
            useComma = true;
          }
          _sql.append("prd_pic_file").append("=?");
        }

        if (pObject.isOwnerModified()) {
          if (useComma) {
            _sql.append(",");
          } else {
            useComma = true;
          }
          _sql.append("owner").append("=?");
        }
        _sql.append(" WHERE ");
        _sql.append("sm_tb_product.prd_id=?");
        ps =
            c.prepareStatement(
                _sql.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        int _dirtyCount = 0;

        if (pObject.isPrdIdModified()) {
          Manager.setLong(ps, ++_dirtyCount, pObject.getPrdId());
        }

        if (pObject.isPrdTypeIdModified()) {
          Manager.setLong(ps, ++_dirtyCount, pObject.getPrdTypeId());
        }

        if (pObject.isNameModified()) {
          ps.setString(++_dirtyCount, pObject.getName());
        }

        if (pObject.isPriceModified()) {
          Manager.setLong(ps, ++_dirtyCount, pObject.getPrice());
        }

        if (pObject.isPriceVipModified()) {
          Manager.setLong(ps, ++_dirtyCount, pObject.getPriceVip());
        }

        if (pObject.isSuplyStatusModified()) {
          ps.setString(++_dirtyCount, pObject.getSuplyStatus());
        }

        if (pObject.isFormatDescModified()) {
          ps.setString(++_dirtyCount, pObject.getFormatDesc());
        }

        if (pObject.isDetailDescModified()) {
          ps.setString(++_dirtyCount, pObject.getDetailDesc());
        }

        if (pObject.isSendAreaModified()) {
          ps.setString(++_dirtyCount, pObject.getSendArea());
        }

        if (pObject.isSendDescModified()) {
          ps.setString(++_dirtyCount, pObject.getSendDesc());
        }

        if (pObject.isPrdPicFileModified()) {
          ps.setString(++_dirtyCount, pObject.getPrdPicFile());
        }

        if (pObject.isOwnerModified()) {
          Manager.setLong(ps, ++_dirtyCount, pObject.getOwner());
        }

        if (_dirtyCount == 0) {
          return pObject;
        }

        Manager.setLong(ps, ++_dirtyCount, pObject.getPrdId());
        ps.executeUpdate();
        pObject.resetIsModified();
        afterUpdate(pObject); // listener callback
      }

      return pObject;
    } finally {
      getManager().close(ps);
      freeConnection(c);
    }
  }