KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > rubis > beans > IDManagerBean


1 package edu.rice.rubis.beans;
2
3 import java.rmi.RemoteException JavaDoc;
4 import java.util.Properties JavaDoc;
5 import javax.ejb.*;
6 import java.io.Serializable JavaDoc;
7
8 /**
9  * IDManagerBean is used to generate id since the AUTO_INCREMENT
10  * feature of the database that automatically generate id on the primary key
11  * is not supported by JBoss.
12  * @author <a HREF="mailto:cecchet@rice.edu">Emmanuel Cecchet</a> and <a HREF="mailto:julie.marguerite@inrialpes.fr">Julie Marguerite</a>
13  * @version 1.1
14  */

15
16 public class IDManagerBean implements EntityBean
17 {
18   private EntityContext entityContext;
19   private transient boolean isDirty; // used for the isModified function
20

21   /* Class member variables */
22
23   public Integer JavaDoc id;
24
25   public Integer JavaDoc categoryCount;
26   public Integer JavaDoc regionCount;
27   public Integer JavaDoc userCount;
28   public Integer JavaDoc itemCount;
29   public Integer JavaDoc commentCount;
30   public Integer JavaDoc bidCount;
31   public Integer JavaDoc buyNowCount;
32
33   
34   /**
35    * Get IDManager id.
36    *
37    * @return IDManager id
38    * @exception RemoteException if an error occurs
39    * @since 1.0
40    */

41   public Integer JavaDoc getId() throws RemoteException JavaDoc
42   {
43     return id;
44   }
45
46   /**
47    * Generate the category id.
48    *
49    * @return Value of the ID
50    * @since 1.1
51    */

52   public Integer JavaDoc getNextCategoryID() throws RemoteException JavaDoc
53   {
54     categoryCount = new Integer JavaDoc(categoryCount.intValue()+1);
55     isDirty = true; // the bean content has been modified
56
return categoryCount;
57   }
58
59   /**
60    * Generate the region id.
61    *
62    * @return Value of the ID
63    * @since 1.1
64    */

65   public Integer JavaDoc getNextRegionID() throws RemoteException JavaDoc
66   {
67     regionCount = new Integer JavaDoc(regionCount.intValue()+1);
68     isDirty = true; // the bean content has been modified
69
return regionCount;
70   }
71
72   /**
73    * Generate the user id.
74    *
75    * @return Value of the ID
76    * @since 1.1
77    */

78   public Integer JavaDoc getNextUserID() throws RemoteException JavaDoc
79   {
80     userCount = new Integer JavaDoc(userCount.intValue()+1);
81     isDirty = true; // the bean content has been modified
82
return userCount;
83   }
84
85   /**
86    * Generate the item id.
87    *
88    * @return Value of the ID
89    * @since 1.1
90    */

91   public Integer JavaDoc getNextItemID() throws RemoteException JavaDoc
92   {
93     itemCount = new Integer JavaDoc(itemCount.intValue()+1);
94     isDirty = true; // the bean content has been modified
95
return itemCount;
96   }
97
98   /**
99    * Generate the comment id.
100    *
101    * @return Value of the ID
102    * @since 1.1
103    */

104   public Integer JavaDoc getNextCommentID() throws RemoteException JavaDoc
105   {
106     commentCount = new Integer JavaDoc(commentCount.intValue()+1);
107     isDirty = true; // the bean content has been modified
108
return commentCount;
109   }
110
111   /**
112    * Generate the bid id.
113    *
114    * @return Value of the ID
115    * @since 1.1
116    */

117   public Integer JavaDoc getNextBidID() throws RemoteException JavaDoc
118   {
119     bidCount = new Integer JavaDoc(bidCount.intValue()+1);
120     isDirty = true; // the bean content has been modified
121
return bidCount;
122   }
123
124   /**
125    * Generate the buyNow id.
126    *
127    * @return Value of the ID
128    * @since 1.1
129    */

130   public Integer JavaDoc getNextBuyNowID() throws RemoteException JavaDoc
131   {
132     buyNowCount = new Integer JavaDoc(buyNowCount.intValue()+1);
133     isDirty = true; // the bean content has been modified
134
return buyNowCount;
135   }
136
137
138   // ======================== EJB related methods ============================
139

140   /**
141    * This method is used to create a new IDManager Bean but should never be called.
142    *
143    * @return pk primary key set to null
144    * @exception CreateException if an error occurs
145    * @exception RemoteException if an error occurs
146    * @exception RemoveException if an error occurs
147    */

148   public IDManagerPK ejbCreate() throws CreateException, RemoteException JavaDoc, RemoveException
149   {
150     throw new CreateException();
151   }
152
153
154   /** This method does currently nothing */
155   public void ejbPostCreate() {}
156   /** This method is empty because persistence is managed by the container */
157   public void ejbActivate() throws RemoteException JavaDoc {}
158   /** This method is empty because persistence is managed by the container */
159   public void ejbPassivate() throws RemoteException JavaDoc {}
160   /** This method is empty because persistence is managed by the container */
161   public void ejbRemove() throws RemoteException JavaDoc, RemoveException {}
162
163   /** Persistence is managed by the container and the bean
164       becomes up to date */

165   public void ejbStore() throws RemoteException JavaDoc
166   {
167     isDirty = false;
168   }
169   /** Persistence is managed by the container and the bean
170       becomes up to date */

171   public void ejbLoad() throws RemoteException JavaDoc
172   {
173     isDirty = false;
174   }
175
176   /**
177    * Sets the associated entity context. The container invokes this method
178    * on an instance after the instance has been created.
179    *
180    * This method is called in an unspecified transaction context.
181    *
182    * @param context - An EntityContext interface for the instance. The instance should
183    * store the reference to the context in an instance variable.
184    * @exception EJBException Thrown by the method to indicate a failure
185    * caused by a system-level error.
186    * @exception RemoteException - This exception is defined in the method signature
187    * to provide backward compatibility for enterprise beans
188    * written for the EJB 1.0 specification.
189    * Enterprise beans written for the EJB 1.1 and
190    * higher specification should throw the javax.ejb.EJBException
191    * instead of this exception.
192    */

193   public void setEntityContext(EntityContext context) throws RemoteException JavaDoc
194   {
195     entityContext = context;
196   }
197
198   /**
199    * Unsets the associated entity context. The container calls this method
200    * before removing the instance. This is the last method that the container
201    * invokes on the instance. The Java garbage collector will eventually invoke
202    * the finalize() method on the instance.
203    *
204    * This method is called in an unspecified transaction context.
205    *
206    * @exception EJBException Thrown by the method to indicate a failure
207    * caused by a system-level error.
208    * @exception RemoteException - This exception is defined in the method signature
209    * to provide backward compatibility for enterprise beans
210    * written for the EJB 1.0 specification.
211    * Enterprise beans written for the EJB 1.1 and
212    * higher specification should throw the javax.ejb.EJBException
213    * instead of this exception.
214    */

215   public void unsetEntityContext() throws RemoteException JavaDoc
216   {
217     entityContext = null;
218   }
219
220   /**
221    * Returns true if the beans has been modified.
222    * It prevents the EJB server from reloading a bean
223    * that has not been modified.
224    *
225    * @return a <code>boolean</code> value
226    */

227   public boolean isModified()
228   {
229     return isDirty;
230   }
231
232
233 }
234
Popular Tags