/**
   * @see net.metaship.generic.Manager#deleteSpecialRate(PrimaryKey)
   * @ejb.interface-method
   * @ejb.transaction type="Required"
   */
  public void delete(PrimaryKey primaryKey) throws LocalException {
    checkPrimaryKeyInstance(primaryKey);

    try {
      Collection col =
          SpecialRateLineUtil.getLocalHome()
              .findBySpecialRateId(((SpecialRatePK) primaryKey).getId().longValue());
      for (Iterator iter = col.iterator(); iter.hasNext(); ) {
        SpecialRateLineLocal element = (SpecialRateLineLocal) iter.next();

        Collection col2 =
            RateServiceAreaUtil.getLocalHome().findBySpecialRateLineId(element.getId().longValue());
        for (Iterator iterator = col2.iterator(); iterator.hasNext(); ) {
          RateServiceAreaLocal element2 = (RateServiceAreaLocal) iterator.next();
          element2.remove();
        }

        element.remove();
      }

      SpecialRateLocalHome home = SpecialRateUtil.getLocalHome();
      SpecialRateLocal local = home.findByPrimaryKey((SpecialRatePK) primaryKey);
      local.remove();
    } catch (Exception e) {
      throw new LocalException(
          "An Error occured while deleting object with primary key: " + primaryKey + "!!", e);
    }
  }
  /**
   * @see net.metaship.generic.Manager#update(ValueObject)
   * @ejb.interface-method
   * @ejb.transaction type="Required"
   */
  public void update(ValueObject valueObject) throws LocalException {
    checkValueObjectInstance(valueObject);

    SpecialRateValue value = (SpecialRateValue) valueObject;
    SpecialRateLocal local = null;
    try {
      SpecialRateLocalHome home = SpecialRateUtil.getLocalHome();
      local = home.findByPrimaryKey(value.getPrimaryKey());
      local.setSpecialRateValue(value);

    } catch (Exception e) {
      throw new LocalException("An Error occured while updating object: " + valueObject + "!!", e);
    }
  }
  /**
   * @see net.metaship.generic.Manager#findByPrimaryKey(PrimaryKey)
   * @ejb.interface-method
   * @ejb.transaction type="Required"
   */
  public ValueObject findByPrimaryKey(PrimaryKey primaryKey) throws LocalException {
    checkPrimaryKeyInstance(primaryKey);

    SpecialRateLocal local = null;
    try {
      SpecialRateLocalHome home = SpecialRateUtil.getLocalHome();
      local = home.findByPrimaryKey((SpecialRatePK) primaryKey);
    } catch (Exception e) {
      throw new LocalException(
          "An Error occured while finding object with primary key: " + primaryKey + "!!", e);
    }

    return local.getSpecialRateValue();
  }
 /**
  * @ejb.interface-method
  * @ejb.transaction type="Supports"
  */
 public Collection findAll() throws LocalException {
   try {
     SpecialRateLocalHome home = SpecialRateUtil.getLocalHome();
     Collection col = home.findAll();
     List list = new CompressedSerializedList();
     for (Iterator iter = col.iterator(); iter.hasNext(); ) {
       SpecialRateLocal element = (SpecialRateLocal) iter.next();
       list.add(fill(element.getSpecialRateValue()));
     }
     return list;
   } catch (Exception e) {
     log.warn(StackTraceUtil.getStackTrace(e));
     throw new LocalException("An Error occured while findAll()!", e);
   }
 }
 /**
  * @see net.metaship.generic.Manager#add(ValueObject)
  * @ejb.interface-method
  * @ejb.transaction type="Required"
  */
 public ValueObject add(ValueObject valueObject) throws LocalException {
   checkValueObjectInstance(valueObject);
   if (isDuplicate(
       "SpecialRate",
       ((SpecialRateValue) valueObject).getIsImport() ? Boolean.TRUE : Boolean.FALSE,
       new Long(((SpecialRateValue) valueObject).getFacilityId()),
       new Long(((SpecialRateValue) valueObject).getVendorId()),
       ((SpecialRateValue) valueObject).getDurationFrom(),
       ((SpecialRateValue) valueObject).getDurationTo())) {
     throw new LocalException("<USER>A tariff with these setting does exist already</USER>");
   }
   try {
     SpecialRateLocalHome home = SpecialRateUtil.getLocalHome();
     return home.create((SpecialRateValue) valueObject).getSpecialRateValue();
   } catch (Exception e) {
     throw new LocalException(
         "An Error occured while adding valueObject: " + valueObject + "!!", e);
   }
 }
  /**
   * @ejb.interface-method
   * @ejb.transaction type="Required"
   */
  public void modifyValidity(
      java.util.List tariffPKs, java.util.Date durationFrom, java.util.Date durationTo)
      throws LocalException, FinderException, NamingException {
    if (log.isInfoEnabled())
      log.info(
          ">modifyValidity "
              + " List"
              + tariffPKs
              + " Date "
              + durationFrom
              + " Date "
              + durationTo);

    if (tariffPKs.size() < 1) return;

    SpecialRateLocalHome ttlh = SpecialRateUtil.getLocalHome();
    for (int i = 0, n = tariffPKs.size(); i < n; i++) {
      SpecialRateLocal ttl = ttlh.findByPrimaryKey((SpecialRatePK) tariffPKs.get(i));
      if (durationFrom != null) ttl.setDurationFrom(durationFrom);
      if (durationTo != null) ttl.setDurationTo(durationTo);
    }
  }
  /**
   * Copy the specified tariff with all line items to a new tariff. if a parameter is null, the
   * original value will be taken.
   *
   * @param tariffToCopyFrom, the tariff which should be copied
   * @param newIsImport, specifies whether the new tariff is an import tariff
   * @param newSeaterminalId, the facility id of the seaterminal for the new tariff
   * @param newVendorId, the id of the vendor for the new tariff
   * @param durationFrom, duration from for the new tariff
   * @param durationTo, duration to for the new tariff
   * @ejb.interface-method
   * @ejb.transaction type="Required"
   */
  public SpecialRateValue copy(
      SpecialRatePK tariffToCopyFrom,
      Boolean newIsImport,
      Long newSeaterminalId,
      Long newVendorId,
      Date newDurationFrom,
      Date newDurationTo)
      throws LocalException {

    SpecialRateLocal local;
    try {

      //
      // if tariff exists, throw exception
      //
      if (isDuplicate(
          "SpecialRate",
          newIsImport,
          newSeaterminalId,
          newVendorId,
          newDurationFrom,
          newDurationTo)) {
        throw new LocalException("<USER>A tariff with these setting does exist already</USER>");
      }

      //
      // get original tariff
      //
      local = SpecialRateUtil.getLocalHome().findByPrimaryKey(tariffToCopyFrom);

      //
      // copy and return new tariff
      //
      return local.copy(newIsImport, newSeaterminalId, newVendorId, newDurationFrom, newDurationTo);

    } catch (Exception e) {
      throw new LocalException(e);
    }
  }
  /**
   * Copy the specified tariffPK's with all line items to new tariffs with the given validity Can
   * handle Tariff PK's or TariffLine PK's if TariffLinePK's are handed over onlly the handed ones
   * are copied
   *
   * @param tariffPKs
   * @param newDurationFrom
   * @param newDurationTo
   * @return
   * @throws LocalException
   * @throws NamingException
   * @throws FinderException
   * @ejb.interface-method
   * @ejb.transaction type="Required"
   */
  public List copy(java.util.List tariffPKs, java.util.Date durationFrom, java.util.Date durationTo)
      throws LocalException, FinderException, NamingException {
    if (log.isInfoEnabled())
      log.info(">copy " + " List" + tariffPKs + " Date " + durationFrom + " Date " + durationTo);

    if (tariffPKs.size() < 1) return new ArrayList();

    List pks = null;
    List copiedTariffs = new ArrayList();
    Hashtable pKs = new Hashtable();
    if (tariffPKs.get(0) instanceof SpecialRateLinePK) {
      for (int i = 0, n = tariffPKs.size(); i < n; i++) {
        SpecialRateLineLocal ttll =
            ((SpecialRateLineLocal)
                SpecialRateLineUtil.getLocalHome()
                    .findByPrimaryKey((SpecialRateLinePK) tariffPKs.get(i)));
        SpecialRatePK ttpk = new SpecialRatePK(new Long(ttll.getSpecialRateId()));
        SpecialRateValue ttl = null;
        if (!pKs.contains(ttpk)) {
          ttl =
              SpecialRateUtil.getLocalHome()
                  .findByPrimaryKey(ttpk)
                  .plainCopy(false, durationFrom, durationTo);
          pKs.put(ttpk, ttl);
          copiedTariffs.add(ttl);
        }
        ttl = (SpecialRateValue) pKs.get(ttpk);
        ttll.copyInto(ttl.getPrimaryKey());
      }

    } else {
      pks = tariffPKs;
      copiedTariffs = copyTariffPK(pks, durationFrom, durationTo);
    }
    return copiedTariffs;
  }