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 javax.persistence.Entity;
19  import javax.persistence.GeneratedValue;
20  import javax.persistence.GenerationType;
21  import javax.persistence.Id;
22  import javax.persistence.NamedQueries;
23  import javax.persistence.NamedQuery;
24  import javax.persistence.OneToOne;
25  
26  /**
27   * An persistence entity description. There is no logic just getter and setters,
28   * for the properties. This Object represents a table in the database and the
29   * properties are fields.
30   *
31   * @author dougculnane
32   */
33  @Entity
34  @NamedQueries ({
35      @NamedQuery(name = "MembershipBasicSearch",
36              query = "SELECT m FROM MembershipEntity m WHERE " +
37              		"m.note LIKE :search"),
38      @NamedQuery(name = "findActiveMembersOnDate",
39              query = "SELECT m FROM MembershipEntity m WHERE " +
40                      "m.type.validFrom <= :date AND m.type.validTo >= :date " +
41                      "AND m.paid = true " +
42                      "ORDER BY m.person.firstName, m.person.lastName"),
43      @NamedQuery(name = "findMembersForMembershipType",
44              query = "SELECT m FROM MembershipEntity m WHERE " +
45                      "m.type = :membershipType"),
46      @NamedQuery(name = "findMembershipsForPerson",
47              query = "SELECT m FROM MembershipEntity m WHERE " +
48                      "m.person = :person")
49  })
50  public class MembershipEntity {
51  
52      /**
53       * Object Identifier.
54       */
55      @Id
56      @GeneratedValue(strategy=GenerationType.TABLE)
57      private long id;
58  
59      @OneToOne
60      private MembershipTypeEntity type;
61  
62      @OneToOne
63      private FeeEntity fee;
64  
65      @OneToOne
66      private PersonEntity person;
67      
68      private String note = "";
69  
70      private boolean paid = false;
71  
72      public FeeEntity getFee() {
73          return fee;
74      }
75  
76      public void setFee(FeeEntity fee) {
77          this.fee = fee;
78      }
79  
80      public long getId() {
81          return id;
82      }
83  
84      public void setId(long id) {
85          this.id = id;
86      }
87  
88      public boolean getPaid() {
89          return paid;
90      }
91  
92      public void setPaid(boolean paid) {
93          this.paid = paid;
94      }
95  
96      public PersonEntity getPerson() {
97          return person;
98      }
99      
100     public void setPerson(PersonEntity person) {
101         this.person = person;
102     }
103 
104     public MembershipTypeEntity getType() {
105         return type;
106     }
107 
108     public void setType(MembershipTypeEntity type) {
109         this.type = type;
110     }
111 
112     /**
113      * Override the Object method to give a usable human readable 
114      * representation of the Object.
115      */
116     public String toString(){
117         if (person == null || type == null) {
118             return this.getId() + "";
119         }
120         return person.getFirstName() + " " + person.getLastName() + " - " + 
121                 type.toString();
122     }
123 
124     public String getNote() {
125         return note;
126     }
127 
128     public void setNote(String note) {
129         this.note = note;
130     }
131 }