View Javadoc

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.LoadTestSummary;
7   
8   public class LoadTestSummaryDetachableModel extends LoadableDetachableModel {
9   	private transient LoadTestSummary summary;
10  
11  	private Long id;
12  
13  	public LoadTestSummaryDetachableModel(LoadTestSummary s) {
14  		this(s.getId());
15  		this.summary = s;
16  	}
17  
18  	public LoadTestSummaryDetachableModel(Long id) {
19  		this.id = id;
20  	}
21  
22  	@Override
23  	protected Object load() {
24  		summary = ResourceFactory.getLoadTestSummaryDAO()
25  				.getLoadTestSummary(id);
26  		return summary;
27  	}
28  
29  	@Override
30  	public Object getObject() {
31  		return summary;
32  	}
33  
34  	@Override
35  	protected void onAttach() {
36  		if (summary == null) {
37  			summary = ResourceFactory.getLoadTestSummaryDAO()
38  					.getLoadTestSummary(id);
39  		}
40  	}
41  
42  	@Override
43  	protected void onDetach() {
44  		summary = null;
45  	}
46  
47  	/**
48  	 * @see java.lang.Object#hashCode()
49  	 */
50  	public int hashCode() {
51  		return id.hashCode();
52  	}
53  
54  	/**
55  	 * used for dataview with ReuseIfModelsEqualStrategy item reuse strategy
56  	 * 
57  	 * @see wicket.extensions.markup.html.repeater.pageable.AbstractPageableView#setItemReuseStrategy(IItemReuseStrategy)
58  	 * @see wicket.extensions.markup.html.repeater.refreshing.ReuseIfModelsEqualStrategy
59  	 * @see java.lang.Object#equals(java.lang.Object)
60  	 */
61  	public boolean equals(Object obj) {
62  		if (obj instanceof LoadTestSummaryDetachableModel) {
63  			LoadTestSummaryDetachableModel other = (LoadTestSummaryDetachableModel) obj;
64  			return other.id.equals(this.id);
65  		}
66  		return false;
67  	}
68  
69  }