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.Date;
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.OneToOne;
27  
28  import net.sf.imca.model.ImcaUtils;
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 dc
36   */
37  @Entity
38  @NamedQueries( {
39      @NamedQuery(name = "findMembershipTypes",
40              query = "SELECT m FROM MembershipTypeEntity m WHERE " +
41              		"m.association = :association"),
42      @NamedQuery(name = "MembershipTypeBasicSearch",
43              query = "SELECT m FROM MembershipTypeEntity m WHERE " +
44                                      "m.name LIKE :search")                 
45  })
46  
47  public class MembershipTypeEntity {
48  
49      /**
50       * Object Identifier.
51       */
52      @Id
53      @GeneratedValue(strategy=GenerationType.TABLE)
54      private long id;
55  
56      @OneToOne
57      private AssociationEntity association;
58  
59      private String name = "";
60  
61      @OneToOne
62      private FeeEntity currentFee;
63  
64      private Date validFrom;
65  
66      private Date validTo;
67  
68      public Date getValidFrom() {
69          return validFrom;
70      }
71  
72      public void setValidFrom(Date validFrom) {
73          this.validFrom = validFrom;
74      }
75  
76      public Date getValidTo() {
77          return validTo;
78      }
79  
80      public void setValidTo(Date validTo) {
81          this.validTo = validTo;
82      }
83  
84      public FeeEntity getCurrentFee() {
85          return currentFee;
86      }
87  
88      /**
89       * @param currentFee
90       */
91      public void setCurrentFee(FeeEntity currentFee) {
92          this.currentFee = currentFee;
93      }
94  
95      public long getId() {
96          return id;
97      }
98  
99      public void setId(long id) {
100         this.id = id;
101     }
102 
103     public String getName() {
104         return name;
105     }
106 
107     public void setName(String name) {
108         this.name = name;
109     }
110 
111     public AssociationEntity getAssociation() {
112         return association;
113     }
114 
115     public void setAssociation(AssociationEntity association) {
116         this.association = association;
117     }
118 
119     /**
120      * Override the Object method to give a usable human readable 
121      * representation of the Object.
122      */
123     public String toString(){
124         return name + " - " + association.toString() + " ( " + 
125                 ImcaUtils.formatDate(validFrom) + " - " + 
126                 ImcaUtils.formatDate(validTo) + " ).";
127     }
128 }