KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xpetstore > util > uidgen > ejb > Counter


1 package xpetstore.util.uidgen.ejb;
2
3 import javax.persistence.Entity;
4 import javax.persistence.Id;
5 import javax.persistence.PostLoad;
6 import javax.persistence.PostRemove;
7 import javax.persistence.PrePersist;
8 import javax.persistence.PreUpdate;
9 import javax.persistence.Table;
10
11 /**
12  *
13  * @ ejb.bean
14  * name="Counter"
15  * type="CMP"
16  * view-type="local"
17  * primkey-field="name"
18  * schema="Counter"
19  * cmp-version="${ejb.cmp.version}"
20  * @ ejb.transaction
21  * type="Required"
22  * @ ejb.persistence
23  * table-name="T_COUNTER"
24  *
25  * @ jboss.persistence
26  * create-table="${jboss.create.table}"
27  * remove-table="${jboss.remove.table}"
28  */

29 @Entity(name = "Counter")
30 @Table(name = "T_COUNTER")
31 public class Counter
32 {
33    private String JavaDoc name;
34
35    private int value;
36
37    public Counter(String JavaDoc name)
38    {
39       setName(name);
40       setValue(0);
41    }
42
43    /**
44     * @ ejb.interface-method
45     */

46    public int nextValue()
47    {
48       int value = getValue() + 1;
49       setValue(value);
50
51       return value;
52    }
53
54    @Id
55    protected java.lang.String JavaDoc getName()
56    {
57       return name;
58    }
59
60    protected void setName(java.lang.String JavaDoc name)
61    {
62       this.name = name;
63    }
64
65    protected int getValue()
66    {
67       return value;
68    }
69
70    protected void setValue(int value)
71    {
72       this.value = value;
73    }
74
75    @PostLoad
76    public void ejbLoad()
77    {
78    }
79
80    @PrePersist
81    @PreUpdate
82    public void ejbStore()
83    {
84    }
85
86    @PostRemove
87    public void ejbRemove() throws javax.ejb.RemoveException JavaDoc
88    {
89
90    }
91 }
92
Popular Tags