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 * ID for serialization.
040 */
041 private static final long serialVersionUID = 353809479798505256L;
042
043 /**
044 * Create a new CountingStockItemDBEntry.
045 *
046 * @param sKey the affected key.
047 * @param stiSource the source Stock.
048 * @param stiDest the destination Stock.
049 * @param nCount the number of affected items. This will be stored as the
050 * {@link DataBasketEntry#getValue value attribute} of the DataBasketEntry.
051 */
052 public CountingStockItemDBEntry(String sKey, StockImpl stiSource, StockImpl stiDest, int nCount) {
053 super(sKey, stiSource, stiDest, new Integer(nCount));
054 }
055
056 /**
057 * Count the affected items.
058 *
059 * @return the number of affected items.
060 *
061 * @override Never
062 */
063 public int count() {
064 return ((Integer)getValue()).intValue();
065 }
066
067 /**
068 * Rollback the operation described by this {@link DataBasketEntry} for a given number of items.
069 *
070 * <p>The method will rollback the operation for the given number of items, updating the underlying
071 * DataBasket correctly.</p>
072 *
073 * <p><strong>Attention</strong>: The method is public as an implementation detail and should not be called
074 * directly.</p>
075 *
076 * @override Never
077 *
078 * @param nCount the number of items for which to rollback the operation.
079 *
080 * @exception IllegalArgumentException if <code>nCount >= {@link #count}</code>.
081 */
082 public void partialRollback(int nCount) {
083 if (nCount <= 0) {
084 return;
085 }
086
087 if (nCount >= ((Integer)getValue()).intValue()) {
088 throw new IllegalArgumentException();
089 }
090
091 DataBasketEntry dbe = new CountingStockItemDBEntry(getSecondaryKey(), (StockImpl)getSource(),
092 (StockImpl)getDestination(), nCount);
093 dbe.setOwner(m_dbiOwner);
094
095 m_oValue = new Integer(((Integer)getValue()).intValue() - nCount);
096
097 dbe.rollback();
098 }
099
100 /**
101 * LogEntry describing an operation on CountingStock StockItem's.
102 *
103 * @author Steffen Zschaler
104 * @version 2.0 19/09/1999
105 * @since v2.0
106 */
107 public static class CSDBELogEntry extends StockItemDBELogEntry {
108
109 /**
110 * ID for serialization.
111 */
112 private static final long serialVersionUID = 7449568409286181324L;
113
114 /**
115 * The number of affected items.
116 *
117 * @serial
118 */
119 private int m_nCount;
120
121 /**
122 * Create a new CSDBELogEntry.
123 *
124 * @param sidbe the DataBasketEntry to be described.
125 */
126 public CSDBELogEntry(StockItemDBEntry sidbe) {
127 super(sidbe);
128
129 m_nCount = sidbe.count();
130 }
131
132 /**
133 * Get the number of affected items.
134 *
135 * @override Never
136 */
137 public int getCount() {
138 return m_nCount;
139 }
140
141 /**
142 * Get a String representation of the operation.
143 *
144 * @override Sometimes
145 */
146 public String toString() {
147 return "StockItem transfer: " + getCount() + " item(s) \"" + getKey() + "\" were transferred" +
148 ((getSource() != null) ? (" from Stock \"" + getSource() + "\"") :
149 ("")) + ((getDestination() != null) ? (" to Stock \"" + getDestination() + "\"") :
150 ("")) + " on " + getLogDate() + ".";
151 }
152 }
153
154 /**
155 * Create and return a LogEntry describing this DataBasketEntry.
156 *
157 * @override Sometimes
158 */
159 public LogEntry getLogData() {
160 return new CSDBELogEntry(this);
161 }
162 }