View Javadoc

1   package org.paneris.bibliomania;
2   
3   import java.sql.Timestamp;
4   import java.util.Enumeration;
5   
6   import org.melati.poem.AccessPoemException;
7   import org.paneris.bibliomania.generated.ShopOrderBase;
8   
9   public class ShopOrder extends ShopOrderBase {
10    public ShopOrder() {}
11  
12    // programmer's domain-specific code here
13    
14    public BibliomaniaDatabase getBibliomaniaDatabase () {
15        return (BibliomaniaDatabase)getDatabase();
16    }
17  
18    public Enumeration<ShopOrderItem> getItems() {
19      return getOrderShopOrderItems();
20      //return getBibliomaniaDatabase().getShopOrderItemTable().getOrderColumn().selectionWhereEq(troid());
21    }
22    
23   /**
24    * Get rid of any previously failed orders and purchases.
25    */
26    public void removeItems() {
27      if (troid() != null) {
28        for (ShopOrderItem i : getOrderShopOrderItemList()) {
29          i.deleteAndCommit();
30        }
31        /*
32        List toRemove = new ArrayList();
33        for (Enumeration en = getItems(); en.hasMoreElements();) {
34          toRemove.add(en.nextElement());
35        } 
36        for (Iterator it = toRemove.iterator(); it.hasNext();) {
37          ShopOrderItem item = (ShopOrderItem) it.next();
38          item.deleteAndCommit();
39        } 
40        */   
41     }
42   }
43    
44  
45   
46  
47    public void setStatus(OrderStatus cooked) throws AccessPoemException {
48      BibliomaniaDatabase db = (BibliomaniaDatabase)getDatabase();
49      if (getFufilleddate_unsafe() == null && 
50          cooked == db.getOrderStatusTable().getFufilled()) {
51        setFufilleddate_unsafe(now());
52      }      
53      super.setStatus(cooked);
54    }
55  
56    public void setFufilleddate_unsafe(Timestamp cooked) {
57      // avoid nulling it if the flag is set
58      BibliomaniaDatabase db = (BibliomaniaDatabase)getDatabase();
59      if (getStatus() != db.getOrderStatusTable().getFufilled() || cooked != null) {
60        super.setFufilleddate_unsafe(cooked);
61      }
62    }
63  
64    protected void writeLock() {
65      super.writeLock();
66      if (getDate_unsafe() == null) {
67        setDate_unsafe(now());
68      }
69    }
70    
71    private static java.sql.Timestamp now() {
72      return new java.sql.Timestamp(new java.util.Date().getTime());
73    }
74    
75  
76  }