KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > entitycallback > Customer


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.test.entitycallback;
23
24 import javax.persistence.Entity;
25 import javax.persistence.CascadeType;
26 import javax.persistence.FetchType;
27 import javax.persistence.GeneratedValue; import javax.persistence.GenerationType;
28 import javax.persistence.Id;
29 import javax.persistence.OneToMany;
30 import javax.persistence.PostLoad;
31 import javax.persistence.PostPersist;
32 import javax.persistence.PostRemove;
33 import javax.persistence.PostUpdate;
34 import javax.persistence.PrePersist;
35 import javax.persistence.PreRemove;
36 import javax.persistence.PreUpdate;
37 import java.util.HashSet JavaDoc;
38 import java.util.Set JavaDoc;
39
40 /**
41  * @author <a HREF="mailto:kabir.khan@jboss.org">Kabir Khan</a>
42  * @version $Revision: 39429 $
43  */

44 @Entity
45 public class Customer
46 {
47    Long JavaDoc id;
48    String JavaDoc name;
49    Set JavaDoc<Journey> journeys = new HashSet JavaDoc<Journey>();
50
51    public Customer()
52    {
53
54    }
55
56    public Customer(String JavaDoc name)
57    {
58       this.name = name;
59    }
60
61    @Id @GeneratedValue(strategy=GenerationType.AUTO)
62    public Long JavaDoc getId()
63    {
64       return id;
65    }
66
67    public void setId(Long JavaDoc id)
68    {
69       this.id = id;
70    }
71
72    public String JavaDoc getName()
73    {
74       return name;
75    }
76
77    public void setName(String JavaDoc name)
78    {
79       this.name = name;
80    }
81
82    @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER, mappedBy="customer")
83    public Set JavaDoc<Journey> getJourneys()
84    {
85       return journeys;
86    }
87
88    public void setJourneys(Set JavaDoc<Journey> journeys)
89    {
90       this.journeys = journeys;
91    }
92
93    public void addJourney(Journey journey)
94    {
95       journeys.add(journey);
96       journey.setCustomer(this);
97    }
98
99    @PrePersist
100    public void doPreCreate()
101    {
102       System.out.println("Customer doPreCreate");
103       CallbackCounterBean.addCallback("Customer", PrePersist.class);
104    }
105
106    @PostPersist
107    public void doPostCreate()
108    {
109       System.out.println("Customer doPostCreate");
110       CallbackCounterBean.addCallback("Customer", PostPersist.class);
111    }
112
113    @PreRemove
114    public void doPreRemove()
115    {
116       System.out.println("Customer doPreRemove");
117       CallbackCounterBean.addCallback("Customer", PreRemove.class);
118    }
119
120    @PostRemove
121    public void doPostRemove()
122    {
123       System.out.println("Customer doPostRemove");
124       CallbackCounterBean.addCallback("Customer", PostRemove.class);
125    }
126
127    @PreUpdate
128    public void doPreUpdate()
129    {
130       System.out.println("Customer doPreUpdate");
131       CallbackCounterBean.addCallback("Customer", PreUpdate.class);
132    }
133
134    @PostUpdate
135    public void doPostUpdate()
136    {
137       System.out.println("Customer doPostUpdate");
138       CallbackCounterBean.addCallback("Customer", PostUpdate.class);
139    }
140
141    @PostLoad
142    public void doPostLoad()
143    {
144       System.out.println("Customer doPostLoad");
145       CallbackCounterBean.addCallback("Customer", PostLoad.class);
146    }
147 }
148
Popular Tags