001 package data.ooimpl;
002
003 import data.*;
004
005 import log.*;
006
007 /**
008 * DataBasketEntry describing operations with CountingStock's items. The fields
009 * of the <code>DataBasketEntry</code> are set as follows:
010 *
011 * <table border=1>
012 * <tr><td><strong>Field</strong></td><td><strong>Value</strong></td></tr>
013 * <tr><td>{@link DataBasketEntry#getMainKey main key}</td>
014 * <td>{@link DataBasketKeys#STOCK_ITEM_MAIN_KEY STOCK_ITEM_MAIN_KEY}
015 * </td>
016 * </tr>
017 * <tr><td>{@link DataBasketEntry#getSecondaryKey secondary key}</td>
018 * <td>{@link CatalogItem#getName name} of the StockItem in question</td>
019 * </tr>
020 * <tr><td>{@link DataBasketEntry#getSource source}</td>
021 * <td>{@link Stock source stock}<td>
022 * </tr>
023 * <tr><td>{@link DataBasketEntry#getDestination destination}</td>
024 * <td>{@link Stock destination stock}<td>
025 * </tr>
026 * <tr><td>{@link DataBasketEntry#getValue value}</td>
027 * <td>an {@link Integer} representing the number of StockItems that were
028 * moved.<td>
029 * </tr>
030 * </table>
031 *
032 * @author Steffen Zschaler
033 * @version 2.0 19/08/1999
034 * @since v2.0
035 */
036 public class CountingStockItemDBEntry extends StockItemDBEntry {
037
038 /**
039 * Create a new CountingStockItemDBEntry.
040 *
041 * @param sKey the affected key.
042 * @param stiSource the source Stock.
043 * @param stiDest the destination Stock.
044 * @param nCount the number of affected items. This will be stored as the
045 * {@link DataBasketEntry#getValue value attribute} of the DataBasketEntry.
046 */
047 public CountingStockItemDBEntry(String sKey, StockImpl stiSource, StockImpl stiDest, int nCount) {
048 super(sKey, stiSource, stiDest, new Integer(nCount));
049 }
050
051 /**
052 * Count the affected items.
053 *
054 * @return the number of affected items.
055 *
056 * @override Never
057 */
058 public int count() {
059 return ((Integer)getValue()).intValue();
060 }
061
062 /**
063 * Rollback the operation described by this {@link DataBasketEntry} for a given number of items.
064 *
065 * <p>The method will rollback the operation for the given number of items, updating the underlying
066 * DataBasket correctly.</p>
067 *
068 * <p><strong>Attention</strong>: The method is public as an implementation detail and should not be called
069 * directly.</p>
070 *
071 * @override Never
072 *
073 * @param nCount the number of items for which to rollback the operation.
074 *
075 * @exception IllegalArgumentException if <code>nCount >= {@link #count}</code>.
076 */
077 public void partialRollback(int nCount) {
078 if (nCount <= 0) {
079 return;
080 }
081
082 if (nCount >= ((Integer)getValue()).intValue()) {
083 throw new IllegalArgumentException();
084 }
085
086 DataBasketEntry dbe = new CountingStockItemDBEntry(getSecondaryKey(), (StockImpl)getSource(),
087 (StockImpl)getDestination(), nCount);
088 dbe.setOwner(m_dbiOwner);
089
090 m_oValue = new Integer(((Integer)getValue()).intValue() - nCount);
091
092 dbe.rollback();
093 }
094
095 /**
096 * LogEntry describing an operation on CountingStock StockItem's.
097 *
098 * @author Steffen Zschaler
099 * @version 2.0 19/09/1999
100 * @since v2.0
101 */
102 public static class CSDBELogEntry extends StockItemDBELogEntry {
103
104 /**
105 * The number of affected items.
106 *
107 * @serial
108 */
109 private int m_nCount;
110
111 /**
112 * Create a new CSDBELogEntry.
113 *
114 * @param sidbe the DataBasketEntry to be described.
115 */
116 public CSDBELogEntry(StockItemDBEntry sidbe) {
117 super(sidbe);
118
119 m_nCount = sidbe.count();
120 }
121
122 /**
123 * Get the number of affected items.
124 *
125 * @override Never
126 */
127 public int getCount() {
128 return m_nCount;
129 }
130
131 /**
132 * Get a String representation of the operation.
133 *
134 * @override Sometimes
135 */
136 public String toString() {
137 return "StockItem transfer: " + getCount() + " item(s) \"" + getKey() + "\" were transferred" +
138 ((getSource() != null) ? (" from Stock \"" + getSource() + "\"") :
139 ("")) + ((getDestination() != null) ? (" to Stock \"" + getDestination() + "\"") :
140 ("")) + " on " + getLogDate() + ".";
141 }
142 }
143
144 /**
145 * Create and return a LogEntry describing this DataBasketEntry.
146 *
147 * @override Sometimes
148 */
149 public LogEntry getLogData() {
150 return new CSDBELogEntry(this);
151 }
152 }