View Javadoc

1   /*
2    * Copyright 2007 The International Moth Class Association (IMCA)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.imca.model.entities;
17  
18  import java.util.Collection;
19  
20  import javax.persistence.Entity;
21  import javax.persistence.GeneratedValue;
22  import javax.persistence.GenerationType;
23  import javax.persistence.Id;
24  import javax.persistence.NamedQueries;
25  import javax.persistence.NamedQuery;
26  import javax.persistence.OneToMany;
27  import javax.persistence.ManyToOne;
28  import javax.persistence.ManyToMany;
29  
30  /**
31   * An persistence entity description. There is no logic just getter and setters,
32   * for the properties. This Object represents a table in the database and the
33   * properties are fields.
34   *
35   * @author dougculnane
36   */
37  @Entity
38  @NamedQueries( { 
39      @NamedQuery(name = "findBoatByIsafId",
40              query = "SELECT b FROM BoatEntity b WHERE b.icfPlaqueNo = :icfPlaqueNo"),
41      @NamedQuery(name = "BoatBasicSearch",
42              query = "SELECT b FROM BoatEntity b WHERE description like :search")
43  })
44  public class BoatEntity {
45      
46      /**
47       * Object Identifier.
48       */
49      @Id
50      @GeneratedValue(strategy=GenerationType.TABLE)
51      private long id;
52  
53      /**
54       * Long description of the boat.
55       */
56      private String description = "";
57      
58      /**
59       * Current name of the boat.  Note the event entries store other
60       * names of the boat.
61       */
62      private String name = "";
63      
64      @ManyToMany
65      private Collection<EventEntryEntity> eventEntries;
66  
67      private int yearBuilt = -1;
68  
69      private Integer icfPlaqueNo = -1;
70  
71      @ManyToOne
72      private DesignEntity design;
73  
74      @OneToMany
75      private Collection<FoilEntity> foils;
76  
77      @ManyToMany
78      private Collection<SailNumberEntity> sailNumbers;
79  
80      @OneToMany
81      private Collection<SailEntity> sails;
82  
83      @ManyToOne
84      private EquipmentSupplierEntity builder;
85  
86      public EquipmentSupplierEntity getBuilder() {
87          return builder;
88      }
89  
90      public void setBuilder(EquipmentSupplierEntity builder) {
91          this.builder = builder;
92      }
93  
94      public DesignEntity getDesign() {
95          return design;
96      }
97  
98      public void setDesign(DesignEntity design) {
99          this.design = design;
100     }
101 
102     public long getId() {
103         return id;
104     }
105 
106     public void setId(long id) {
107         this.id = id;
108     }
109 
110     public int getYearBuilt() {
111         return yearBuilt;
112     }
113 
114     public void setYearBuilt(int yearBuilt) {
115         this.yearBuilt = yearBuilt;
116     }
117 
118     public int getIcfPlaqueNo() {
119         return icfPlaqueNo;
120     }
121 
122     public void setIcfPlaqueNo(int icfPlaqueNo) {
123         this.icfPlaqueNo = icfPlaqueNo;
124     }
125 
126     public Collection<EventEntryEntity> getEventEntries() {
127         return eventEntries;
128     }
129 
130     public void setEventEntries(Collection<EventEntryEntity> eventEntries) {
131         this.eventEntries = eventEntries;
132     }
133 
134     public Collection<FoilEntity> getFoils() {
135         return foils;
136     }
137 
138     public void setFoils(Collection<FoilEntity> foils) {
139         this.foils = foils;
140     }
141 
142     public Collection<SailEntity> getSails() {
143         return sails;
144     }
145 
146     public void setSails(Collection<SailEntity> sails) {
147         this.sails = sails;
148     }
149 
150     public Collection<SailNumberEntity> getSailNumbers() {
151         return sailNumbers;
152     }
153 
154     public void setSailNumbers(Collection<SailNumberEntity> sailNumbers) {
155         this.sailNumbers = sailNumbers;
156     }
157 
158     /**
159      * Override the Object method to give a usable human readable 
160      * representation of the Object.
161      */
162     public String toString(){
163         StringBuffer buf = new StringBuffer();
164         
165         if (icfPlaqueNo != null) {
166             buf.append(icfPlaqueNo + ": ");
167         }
168         if (getSailNumbers() != null) {
169         java.util.Iterator<SailNumberEntity> iter = getSailNumbers().iterator();
170             while (iter.hasNext()) {
171                 buf.append(iter.next().toString() + ", ");
172             }
173         }
174         if (buf.toString().endsWith(", ")) {
175             return buf.toString().substring(0, buf.length() - 2) + ".";
176         } else {
177             return buf.toString() + ".";
178         }
179     }
180 
181     public String getDescription() {
182         return description;
183     }
184 
185     public void setDescription(String description) {
186         this.description = description;
187     }
188 
189     public String getName() {
190         return name;
191     }
192 
193     public void setName(String name) {
194         this.name = name;
195     }
196 
197     
198 
199 }