KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > odmg > shared > Article


1 package org.apache.ojb.odmg.shared;
2
3 import org.apache.ojb.odmg.shared.ProductGroup;
4 import org.apache.commons.lang.builder.ToStringBuilder;
5 import org.apache.commons.lang.builder.EqualsBuilder;
6
7
8 /** Simple Article class is not derived from any base class nor does it implement any Interface,
9  * but still it can be made persistent by the PersistenceBroker.
10  * Has a lot of private members to be mapped to rdbms columns, but only few business methods
11  */

12 public class Article implements org.apache.ojb.odmg.TransactionAware
13 {
14     /** return a string representaion of an article*/
15     public String JavaDoc toString()
16     {
17         return new ToStringBuilder(this)
18                 .append("articleId", articleId)
19                 .append("articleName", articleName)
20                 .append("productGroup", (productGroup != null ? productGroup.getName() : null))
21                 .append("productGroupId", productGroupId)
22                 .append("isSelloutArticle", isSelloutArticle)
23                 .append("minimumStock", minimumStock)
24                 .append("orderedUnits", orderedUnits)
25                 .append("price", price)
26                 .append("orderedUnits", orderedUnits)
27                 .append("stock", stock)
28                 .append("supplierId", supplierId)
29                 .append("unit", unit)
30                 .toString();
31     }
32
33     /** maps to db-column "Artikel-Nr";INT;PrimaryKey*/
34     private int articleId;
35     /** maps to db-column Artikelname;CHAR*/
36     private String JavaDoc articleName;
37     /** maps to db-column Auslaufartikel;SMALL INT*/
38     private boolean isSelloutArticle;
39     /** maps to db-column Mindestbestand;INT*/
40     private int minimumStock;
41     /** maps to db-column BestellteEinheiten;INT*/
42     private int orderedUnits;
43     /** maps to db-column Einzelpreis;DECIMAL*/
44     private double price;
45     /** reference to the articles category*/
46     private ProductGroup productGroup;
47     /** maps to db-column Kategorie-Nr;INT*/
48     private int productGroupId;
49     /** maps to db-column Lagerbestand;INT*/
50     private int stock;
51     /** maps to db-column Lieferanten-Nr;INT*/
52     private int supplierId;
53     /** maps to db-column Liefereinheit;CHAR*/
54     private String JavaDoc unit;
55
56     public Article(int pArticleId, String JavaDoc pArticleName,
57                    int pSupplierId, int pProcuctGroupId,
58                    String JavaDoc pUnit, double pPrice, int pStock,
59                    int pOrderedUnits, int pMinimumStock,
60                    boolean pIsSelloutArticle)
61     {
62         articleId = pArticleId;
63         articleName = pArticleName;
64         supplierId = pSupplierId;
65         productGroupId = pProcuctGroupId;
66         unit = pUnit;
67         price = pPrice;
68         stock = pStock;
69         orderedUnits = pOrderedUnits;
70         minimumStock = pMinimumStock;
71         isSelloutArticle = pIsSelloutArticle;
72
73     }
74
75     public Article()
76     {
77     }
78
79     public static Article createInstance()
80     {
81         return new Article();
82     }
83
84
85     /** increase the amount of articles in stock by diff
86      * mark the object as modified only if value changes (i.e. diff != 0 )
87      */

88     public void addToStock(int diff)
89     {
90         stock += diff;
91     }
92
93     /**
94      * return an articles unique id.
95      * @return int the articles unique id
96      */

97     public int getArticleId()
98     {
99         return articleId;
100     }
101
102     /**
103      * return an articles name.
104      * @return java.lang.String
105      */

106     public String JavaDoc getArticleName()
107     {
108         return articleName;
109     }
110
111     /** return an articles ProductGroup*/
112     public ProductGroup getProductGroup()
113     {
114         return productGroup;
115     }
116
117     /**
118      * return stock of Article.
119      * @return int
120      */

121     public int getStock()
122     {
123         return stock;
124     }
125
126     /** compute the total value of an articles stock*/
127     public double getStockValue()
128     {
129         return price * stock;
130     }
131
132     /**
133      * Sets the articleId.
134      * @param articleId The articleId to set
135      */

136     public void setArticleId(int articleId)
137     {
138         this.articleId = articleId;
139     }
140
141     /**
142      * Sets the articleName.
143      * @param articleName The articleName to set
144      */

145     public void setArticleName(String JavaDoc articleName)
146     {
147         this.articleName = articleName;
148     }
149
150     /**
151      * Sets the stock.
152      * @param stock The stock to set
153      */

154     public void setStock(int stock)
155     {
156         this.stock = stock;
157     }
158
159     /**
160      * afterAbort will be called after a transaction has been aborted.
161      * The values of fields which get persisted will have changed to
162      * what they were at the begining of the transaction. This method
163      * should be overridden to reset any transient or non-persistent
164      * fields.
165      */

166     public void afterAbort()
167     {
168         //System.out.println("afterAbort: " + new Identity(this));
169
}
170
171     /**
172      * afterCommit is called only after a successful commit has taken
173      * place.
174      */

175     public void afterCommit()
176     {
177         //System.out.println("afterCommit: " + new Identity(this));
178
}
179
180     /**
181      * beforeAbort is called before a transaction is aborted.
182      */

183     public void beforeAbort()
184     {
185         //System.out.println("beforeAbort: " + new Identity(this));
186
}
187
188     /**
189      * beforeCommit will give an object a chance to kill a
190      * transaction before it is committed.
191      *
192      * To kill a transaction, throw a new TransactionAbortedException.
193      */

194     public void beforeCommit() throws org.odmg.TransactionAbortedException
195     {
196         //System.out.println("beforeCommit: " + new Identity(this));
197
}
198
199
200     public boolean equals(Object JavaDoc obj)
201     {
202         if (obj instanceof Article)
203         {
204             Article other = ((Article) obj);
205             return new EqualsBuilder()
206                 .append(articleId, other.articleId)
207                 .append(articleName, other.articleName)
208                 .append(productGroupId, other.productGroupId)
209                 .append(isSelloutArticle, other.isSelloutArticle)
210                 .append(minimumStock, other.minimumStock)
211                 .append(orderedUnits, other.orderedUnits)
212                 .append(price, other.price)
213                 .append(orderedUnits, other.orderedUnits)
214                 .append(stock, other.stock)
215                 .append(supplierId, other.supplierId)
216                 .append(unit, other.unit)
217                 .isEquals();
218         }
219         else
220             return false;
221     }
222
223
224     /* (non-Javadoc)
225      * @see java.lang.Object#hashCode()
226      */

227     public int hashCode()
228     {
229         // Since we redefined equals, we have to redefine hashCode as well
230
return articleId;
231     }
232
233     /**
234      * Gets the isSelloutArticle.
235      * @return Returns a boolean
236      */

237     public boolean getIsSelloutArticle()
238     {
239         return isSelloutArticle;
240     }
241
242     /**
243      * Sets the isSelloutArticle.
244      * @param isSelloutArticle The isSelloutArticle to set
245      */

246     public void setIsSelloutArticle(boolean isSelloutArticle)
247     {
248         this.isSelloutArticle = isSelloutArticle;
249     }
250
251     /**
252      * Gets the minimumStock.
253      * @return Returns a int
254      */

255     public int getMinimumStock()
256     {
257         return minimumStock;
258     }
259
260     /**
261      * Sets the minimumStock.
262      * @param minimumStock The minimumStock to set
263      */

264     public void setMinimumStock(int minimumStock)
265     {
266         this.minimumStock = minimumStock;
267     }
268
269     /**
270      * Gets the orderedUnits.
271      * @return Returns a int
272      */

273     public int getOrderedUnits()
274     {
275         return orderedUnits;
276     }
277
278     /**
279      * Sets the orderedUnits.
280      * @param orderedUnits The orderedUnits to set
281      */

282     public void setOrderedUnits(int orderedUnits)
283     {
284         this.orderedUnits = orderedUnits;
285     }
286
287     /**
288      * Gets the price.
289      * @return Returns a double
290      */

291     public double getPrice()
292     {
293         return price;
294     }
295
296     /**
297      * Sets the price.
298      * @param price The price to set
299      */

300     public void setPrice(double price)
301     {
302         this.price = price;
303     }
304
305     /**
306      * Sets the productGroup.
307      * @param productGroup The productGroup to set
308      */

309     public void setProductGroup(ProductGroup productGroup)
310     {
311         this.productGroup = productGroup;
312     }
313
314     /**
315      * Gets the productGroupId.
316      * @return Returns a int
317      */

318     public int getProductGroupId()
319     {
320         return productGroupId;
321     }
322
323     /**
324      * Sets the productGroupId.
325      * @param productGroupId The productGroupId to set
326      */

327     public void setProductGroupId(int productGroupId)
328     {
329         this.productGroupId = productGroupId;
330     }
331
332     /**
333      * Gets the supplierId.
334      * @return Returns a int
335      */

336     public int getSupplierId()
337     {
338         return supplierId;
339     }
340
341     /**
342      * Sets the supplierId.
343      * @param supplierId The supplierId to set
344      */

345     public void setSupplierId(int supplierId)
346     {
347         this.supplierId = supplierId;
348     }
349
350     /**
351      * Gets the unit.
352      * @return Returns a String
353      */

354     public String JavaDoc getUnit()
355     {
356         return unit;
357     }
358
359     /**
360      * Sets the unit.
361      * @param unit The unit to set
362      */

363     public void setUnit(String JavaDoc unit)
364     {
365         this.unit = unit;
366     }
367
368 }
369
Popular Tags