KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > enterprise > customer_cmp_ejb > persistence > Subscription


1 /*
2  * Subscription.java
3  *
4  * Created on November 25, 2005, 11:01 AM
5  *
6  * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
7  * Use is subject to license terms.
8  */

9
10 /**
11  *
12  * @author Rahul Biswas
13  */

14
15 package enterprise.customer_cmp_ejb.persistence;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collection JavaDoc;
19 import java.util.Iterator JavaDoc;
20
21 import javax.persistence.*;
22
23
24 @Entity
25 @NamedQuery(name="findAllSubscriptions", query="select s from Subscription s")
26
27 public class Subscription implements java.io.Serializable JavaDoc{
28
29     private String JavaDoc title;
30     private String JavaDoc type;
31     private Collection JavaDoc<Customer> customers;
32     
33     public Subscription(){
34         
35     }
36     
37     @Id
38     public String JavaDoc getTitle(){ //primary key
39
return title;
40     }
41     public void setTitle(String JavaDoc title){
42         this.title=title;
43     }
44     
45     public String JavaDoc getType(){
46         return type;
47     }
48     public void setType(String JavaDoc type){
49         this.type=type;
50     }
51
52     //access methods for cmr fields
53
@ManyToMany(mappedBy="subscriptions")
54     public Collection JavaDoc<Customer> getCustomers(){
55         return customers;
56     }
57     public void setCustomers(Collection JavaDoc<Customer> customers){
58         this.customers=customers;
59     }
60
61     public Subscription (
62             String JavaDoc title,
63             String JavaDoc type) {
64
65         if (type.equals(SubscriptionType.MAGAZINE)) {
66             _create(title,SubscriptionType.MAGAZINE);
67         }
68         else if (type.equals(SubscriptionType.JOURNAL)) {
69             _create(title,SubscriptionType.JOURNAL);
70         }
71         else if (type.equals(SubscriptionType.NEWS_PAPER)) {
72             _create(title,SubscriptionType.NEWS_PAPER);
73         }
74         else
75             _create(title,SubscriptionType.OTHER);
76
77     }
78     
79
80     private String JavaDoc _create (
81             String JavaDoc title,
82             String JavaDoc type) {
83         
84
85         setTitle(title);
86         setType(type);
87         return title;
88     }
89     
90 }
91
92
93     
94
Popular Tags