コード例 #1
0
  // 63
  public int deleteUsingTemplate(SmTbProductBean pObject) throws SQLException {
    if (pObject.isPrdIdInitialized()) return deleteByPrimaryKey(pObject.getPrdId());

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

    try {
      sql = new StringBuffer("DELETE FROM sm_tb_product WHERE ");
      int _dirtyAnd = 0;
      if (pObject.isPrdIdInitialized()) {
        if (_dirtyAnd > 0) sql.append(" AND ");
        sql.append("prd_id").append("=?");
        _dirtyAnd++;
      }

      if (pObject.isPrdTypeIdInitialized()) {
        if (_dirtyAnd > 0) sql.append(" AND ");
        sql.append("prd_type_id").append("=?");
        _dirtyAnd++;
      }

      if (pObject.isNameInitialized()) {
        if (_dirtyAnd > 0) sql.append(" AND ");
        sql.append("name").append("=?");
        _dirtyAnd++;
      }

      if (pObject.isPriceInitialized()) {
        if (_dirtyAnd > 0) sql.append(" AND ");
        sql.append("price").append("=?");
        _dirtyAnd++;
      }

      if (pObject.isPriceVipInitialized()) {
        if (_dirtyAnd > 0) sql.append(" AND ");
        sql.append("price_vip").append("=?");
        _dirtyAnd++;
      }

      if (pObject.isSuplyStatusInitialized()) {
        if (_dirtyAnd > 0) sql.append(" AND ");
        sql.append("suply_status").append("=?");
        _dirtyAnd++;
      }

      if (pObject.isFormatDescInitialized()) {
        if (_dirtyAnd > 0) sql.append(" AND ");
        sql.append("format_desc").append("=?");
        _dirtyAnd++;
      }

      if (pObject.isDetailDescInitialized()) {
        if (_dirtyAnd > 0) sql.append(" AND ");
        sql.append("detail_desc").append("=?");
        _dirtyAnd++;
      }

      if (pObject.isSendAreaInitialized()) {
        if (_dirtyAnd > 0) sql.append(" AND ");
        sql.append("send_area").append("=?");
        _dirtyAnd++;
      }

      if (pObject.isSendDescInitialized()) {
        if (_dirtyAnd > 0) sql.append(" AND ");
        sql.append("send_desc").append("=?");
        _dirtyAnd++;
      }

      if (pObject.isPrdPicFileInitialized()) {
        if (_dirtyAnd > 0) sql.append(" AND ");
        sql.append("prd_pic_file").append("=?");
        _dirtyAnd++;
      }

      if (pObject.isOwnerInitialized()) {
        if (_dirtyAnd > 0) sql.append(" AND ");
        sql.append("owner").append("=?");
        _dirtyAnd++;
      }

      c = getConnection();
      ps =
          c.prepareStatement(
              sql.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      int _dirtyCount = 0;

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

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

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

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

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

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

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

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

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

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

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

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

      int _rows = ps.executeUpdate();
      return _rows;
    } finally {
      getManager().close(ps);
      freeConnection(c);
    }
  }
コード例 #2
0
  // 88.5
  public SmTbProductBean[] loadUsingTemplate(SmTbProductBean pObject, int startRow, int numRows)
      throws SQLException {
    Connection c = null;
    PreparedStatement ps = null;
    StringBuffer where = new StringBuffer("");
    StringBuffer _sql = new StringBuffer("SELECT " + ALL_FIELDS + " from sm_tb_product WHERE ");
    StringBuffer _sqlWhere = new StringBuffer("");
    try {
      int _dirtyCount = 0;

      if (pObject.isPrdIdModified()) {
        _dirtyCount++;
        _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("prd_id= ?");
      }

      if (pObject.isPrdTypeIdModified()) {
        _dirtyCount++;
        _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("prd_type_id= ?");
      }

      if (pObject.isNameModified()) {
        _dirtyCount++;
        _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("name= ?");
      }

      if (pObject.isPriceModified()) {
        _dirtyCount++;
        _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("price= ?");
      }

      if (pObject.isPriceVipModified()) {
        _dirtyCount++;
        _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("price_vip= ?");
      }

      if (pObject.isSuplyStatusModified()) {
        _dirtyCount++;
        _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("suply_status= ?");
      }

      if (pObject.isFormatDescModified()) {
        _dirtyCount++;
        _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("format_desc= ?");
      }

      if (pObject.isDetailDescModified()) {
        _dirtyCount++;
        _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("detail_desc= ?");
      }

      if (pObject.isSendAreaModified()) {
        _dirtyCount++;
        _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("send_area= ?");
      }

      if (pObject.isSendDescModified()) {
        _dirtyCount++;
        _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("send_desc= ?");
      }

      if (pObject.isPrdPicFileModified()) {
        _dirtyCount++;
        _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("prd_pic_file= ?");
      }

      if (pObject.isOwnerModified()) {
        _dirtyCount++;
        _sqlWhere.append((_sqlWhere.length() == 0) ? " " : " AND ").append("owner= ?");
      }

      if (_dirtyCount == 0) {
        throw new SQLException("The pObject to look for is invalid : not initialized !");
      }
      _sql.append(_sqlWhere);
      c = getConnection();
      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.executeQuery();
      return loadByPreparedStatement(ps, null, startRow, numRows);
    } finally {
      getManager().close(ps);
      freeConnection(c);
    }
  }
コード例 #3
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;
  }
コード例 #4
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);
    }
  }
コード例 #5
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;
  }