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
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 }