package data.ooimpl;

import data.*; // This is to help javadoc...

/**
  * DataBasketEntry that describes operations with StoringStock's items. The
  * fields of the <code>DataBasketEntry</code> are set as follows:
  *
  * <table border=1>
  * <tr><td><strong>Field</strong></td><td><strong>Value</strong></td></tr>
  * <tr><td>{@link DataBasketEntry#getMainKey main key}</td>
  *     <td>{@link DataBasketKeys#STOCK_ITEM_MAIN_KEY STOCK_ITEM_MAIN_KEY}
  *     </td>
  * </tr>
  * <tr><td>{@link DataBasketEntry#getSecondaryKey secondary key}</td>
  *     <td>{@link StockItem#getName name} of the StockItem in question</td>
  * </tr>
  * <tr><td>{@link DataBasketEntry#getSource source}</td>
  *     <td>{@link Stock source stock}<td>
  * </tr>
  * <tr><td>{@link DataBasketEntry#getDestination destination}</td>
  *     <td>{@link Stock destination stock}<td>
  * </tr>
  * <tr><td>{@link DataBasketEntry#getValue value}</td>
  *     <td>{@link StockItem} that was moved.<td>
  * </tr>
  * </table>
  *
  * @author Steffen Zschaler
  * @version 2.0 19/09/1999
  * @since v2.0
  */
public class StoringStockItemDBEntry extends StockItemDBEntry {

  /**
    * Create a new StoringStockItemDBEntry.
    *
    * @param sstiSource the source Stock.
    * @param sstiDest the destination Stock.
    * @param siiItem the item that was operated on.
    */
  public StoringStockItemDBEntry (StoringStockImpl sstiSource,
                                  StoringStockImpl sstiDest,
                                  StockItemImpl siiItem) {
    super (siiItem.getName(), sstiSource, sstiDest, siiItem);
  }

  /**
    * Rollback the destination part of the operation described by this {@link data.DataBasketEntry}.
    *
    * <p>The method will correctly update the underlying DataBasket.</p>
    *
    * <p><strong>Attention</strong>: The method is public as an implementation detail and should not be called
    * directly.</p>
    *
    * @override Never
    */
  public void rollbackDestination() {
    DataBasketEntryImpl dbe = new StoringStockItemDBEntry (null,
                                                           (StoringStockImpl) getDestination(),
                                                           (StockItemImpl) getValue());

    dbe.setOwner (m_dbiOwner);

    m_dbedDest = null;

    dbe.rollback();
  }

  /**
    * Commit the source part of the operation described by this {@link data.DataBasketEntry}.
    *
    * <p>The method will correctly update the underlying DataBasket.</p>
    *
    * <p><strong>Attention</strong>: The method is public as an implementation detail and should not be called
    * directly.</p>
    *
    * @override Never
    */
  public void commitSource() {
    DataBasketEntryImpl dbe = new StoringStockItemDBEntry ((StoringStockImpl) getSource(),
                                                           null,
                                                           (StockItemImpl) getValue());
    dbe.setOwner (m_dbiOwner);

    m_dbesSource = null;

    dbe.commit();
  }
}