1   import org.wcb.model.bd.LogbookDelegate;
2   import org.wcb.model.vo.hibernate.Logbook;
3   
4   import java.util.Date;
5   import java.util.List;
6   import java.util.Iterator;
7   import java.text.SimpleDateFormat;
8   import java.text.ParseException;
9   
10  /**
11   * <small>
12   * Copyright (c)  2006  wbogaardt.
13   * Permission is granted to copy, distribute and/or modify this document
14   * under the terms of the GNU Free Documentation License, Version 1.2
15   * or any later version published by the Free Software Foundation;
16   * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
17   * Texts.  A copy of the license is included in the section entitled "GNU
18   * Free Documentation License".
19   * <p/>
20   * $File:  $ <br>
21   * $Change:  $ submitted by $Author: wbogaardt $ at $DateTime: Mar 24, 2006 1:58:14 PM $ <br>
22   * </small>
23   *
24   * @author wbogaardt
25   * @version 1
26   *          Date: Mar 24, 2006
27   *          Time: 1:58:14 PM
28   */
29  public class TestAddEntry {
30  
31      public void init() {
32          LogbookDelegate delegate = new LogbookDelegate();
33          Logbook entry = new Logbook();
34          try {
35              SimpleDateFormat sdf = new SimpleDateFormat("yyyy, MM, dd");
36              Date date = sdf.parse("2005, 03, 11");
37              entry.setEntryDate(date);
38          }
39          catch (ParseException pe) {
40              System.err.println("Unable to parse date");
41          }
42          entry.setRegistration("N704SL");
43          entry.setFlightDuration(1.9);
44          entry.setFaaFrom("OXR");
45          entry.setFaaTo("EMT");
46          entry.setFaaVia("direct");
47          entry.setPic(1.9);
48          entry.setConditionNight(.5);
49          entry.setCrossCountry(1.9);
50          entry.setNightLandings(1);
51          entry.setSafetyPilot(1.8);
52          delegate.saveLogEntry(entry);
53      }
54  
55      public void delete(Logbook item) {
56          if (item != null) {
57              LogbookDelegate delegate = new LogbookDelegate();
58              delegate.deleteLogEntry(item);
59          }
60          else {
61              System.out.println("Nothing to delete");
62          }
63      }
64  
65      public void findSingleEntry() {
66          LogbookDelegate delegate = new LogbookDelegate();
67          Logbook lineitem = delegate.findLogEntry(1);
68          if (lineitem != null) {
69              System.out.println("Found entry for a " + lineitem.getRegistration() + " at hours " + lineitem.getFlightDuration());
70          }
71      }
72  
73      public void all() {
74          LogbookDelegate delegate = new LogbookDelegate();
75          List items = delegate.getAllLogbookEntries();
76          Iterator iterate = items.iterator();
77          Logbook lineitem = null;
78          while (iterate.hasNext()) {
79              lineitem = (Logbook) iterate.next();
80              System.out.println("Found entry for a " + lineitem.getRegistration() + " at hours " + lineitem.getFlightDuration());
81          }
82          this.delete(lineitem);
83      }
84  
85      public static void main(String[] args) {
86          TestAddEntry test = new TestAddEntry();
87          test.init();
88          test.findSingleEntry();
89          test.all();
90      }
91  }