1 package org.whatsitcalled.webflange.webapp.model;
2
3 import org.apache.wicket.markup.repeater.IItemReuseStrategy;
4 import org.apache.wicket.model.LoadableDetachableModel;
5 import org.whatsitcalled.webflange.ResourceFactory;
6 import org.whatsitcalled.webflange.model.LoadTest;
7 import org.whatsitcalled.webflange.model.LoadTestDAO;
8
9 public class LoadTestDetachableModel extends LoadableDetachableModel {
10 private transient LoadTest test;
11 private Long id;
12 public LoadTestDetachableModel(LoadTest t) {
13 this(t.getId());
14 this.test = t;
15 }
16
17 public LoadTestDetachableModel(Long id) {
18 this.id = id;
19 }
20
21 protected LoadTestDAO getDAO() {
22 return ResourceFactory.getLoadTestDAO();
23 }
24
25 @Override
26 protected Object load() {
27 test = getDAO().getLoadTest(id);
28 return test;
29 }
30
31 @Override
32 public Object getObject() {
33 return test;
34 }
35
36 @Override
37 protected void onAttach() {
38 if (test == null) {
39 test = getDAO().getLoadTest(id);
40 }
41 }
42
43 @Override
44 protected void onDetach() {
45 test=null;
46 }
47
48
49
50
51 public int hashCode()
52 {
53 return id.hashCode();
54 }
55
56
57
58
59
60
61
62
63 public boolean equals(Object obj)
64 {
65 if (obj instanceof LoadTestDetachableModel)
66 {
67 LoadTestDetachableModel other = (LoadTestDetachableModel)obj;
68 return other.id.equals(this.id);
69 }
70 return false;
71 }
72
73
74 }