// 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);
    }
  }
  // 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);
    }
  }