KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > repository > DjContext


1 /*
2  Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  Redistribution and use in source and binary forms, with or without modification, is permitted
4  provided that the following conditions are met:
5  - Redistributions of source code must retain the above copyright notice, this list of conditions
6  and the following disclaimer.
7  - Redistributions in binary form must reproduce the above copyright notice, this list of
8  conditions and the following disclaimer in the documentation and/or other materials
9  provided with the distribution.
10  - All advertising materials mentioning features or use of this software must display the
11  following acknowledgment: "This product includes Djeneric."
12  - Products derived from this software may not be called "Djeneric" nor may
13  "Djeneric" appear in their names without prior written permission of Genimen BV.
14  - Redistributions of any form whatsoever must retain the following acknowledgment: "This
15  product includes Djeneric."
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
17  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG,
20  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */

28 package com.genimen.djeneric.repository;
29
30 import com.genimen.djeneric.repository.exceptions.DjenericException;
31
32 /**
33  * A DjContext is an abstraction of the 'visible data'; everything a {@link
34  * DjSession} can 'see' is within the boundary of a context. Contexts can be
35  * used to separate data at a logical level. Only sessions that have a null
36  * context can see all data of all contexts that are present within the
37  * persistent store. The context is set at the persistence manager level;
38  *
39  *@author Wido Riezebos
40  *@created 24 mei 2002
41  *@see com.genimen.djeneric.repository.DjPersistenceManager#setCurrentContext(DjContext)
42  *@see com.genimen.djeneric.repository.DjPersistenceManager#getContextManager()
43  *@see com.genimen.djeneric.repository.DjPersistenceManager#getCurrentContext()
44  */

45 public abstract class DjContext
46 {
47   protected final static long NOT_YET_PERSISTED = -1;
48
49   /**
50    * Removes this context from the persistent store (unless there is data stored in it).
51    * No commit is done; this is left to the caller.
52    *
53    *@param session The session to use
54    *@exception DjenericException Description of the Exception
55    */

56   public abstract void delete(DjSession session) throws DjenericException;
57
58   /**
59    * Removes all data stored in the context from the persistent store.
60    * No commit is done; this is left to the caller.
61    *
62    *@param session The session to use
63    *@exception DjenericException Description of the Exception
64    */

65   public abstract void deleteContents(DjSession session) throws DjenericException;
66
67   /**
68    * Reloads the context from the persistent store.
69    *
70    *@param session The session to use
71    *@exception DjenericException Description of the Exception
72    */

73   public abstract void reload(DjSession session) throws DjenericException;
74
75   /**
76    * Applies changes to the persistent store. No commit is done; this is left
77    * to the caller.
78    *
79    *@param session The session to use
80    *@exception DjenericException Description of the Exception
81    */

82   public abstract void persist(DjSession session) throws DjenericException;
83
84   /**
85    * Removes the links between users and this context from the persistent
86    * store. No commit is done; this is left to the caller.
87    *
88    *@param session The session to use
89    *@exception DjenericException Description of the Exception
90    */

91   public abstract void removeAllUserAssociations(DjSession session) throws DjenericException;
92
93   /**
94    * Returns all users-context associations of users that have access to this
95    * context.
96    *
97    *@param session Description of the Parameter
98    *@return The users value
99    *@exception DjenericException Description of the Exception
100    */

101   public abstract DjUserContextAssociation[] getUsers(DjSession session) throws DjenericException;
102
103   /////////////////////////////////////////////////////////////////////
104

105   long _id;
106   String JavaDoc _code = "";
107   String JavaDoc _name = "";
108   DjPersistenceManager _mgr;
109
110   /**
111    * Constructor for the DjContext object; the ID is set to NOT_YET_PERSISTED
112    *
113    *@param mgr Description of the Parameter
114    */

115   protected DjContext(DjPersistenceManager mgr)
116
117   {
118     _id = NOT_YET_PERSISTED;
119     _mgr = mgr;
120   }
121
122   /**
123    * Constructor for the DjContext object
124    *
125    *@param id Unique id of the context in the persistent store
126    *@param code Unique code of the context in the persistent store
127    *@param name Description of the context in the persistent store
128    *@param mgr Description of the Parameter
129    */

130   protected DjContext(DjPersistenceManager mgr, long id, String JavaDoc code, String JavaDoc name)
131   {
132     _id = id;
133     _code = code;
134     _name = name;
135     _mgr = mgr;
136   }
137
138   public DjPersistenceManager getPersistenceManager()
139   {
140     return _mgr;
141   }
142
143   /**
144    * Gets the unique id of the context in the persistent store
145    *
146    *@return The Unique id of the context in the persistent store
147    */

148   public long getId()
149   {
150     return _id;
151   }
152
153   /**
154    * Sets the unique id of the context in the persistent store; you should not
155    * change the id after it is in use
156    *
157    *@param id The new id value
158    */

159   protected void setId(long id)
160   {
161     _id = id;
162   }
163
164   /**
165    * Gets the name of the DjContext object
166    *
167    *@return The name value
168    */

169   public String JavaDoc getName()
170   {
171     return _name;
172   }
173
174   /**
175    * Sets the name of the DjContext object
176    *
177    *@param name The new name value
178    */

179   public void setName(String JavaDoc name)
180   {
181     _name = name;
182   }
183
184   /**
185    * Gets the unique code of the DjContext object
186    *
187    *@return The code value
188    */

189   public String JavaDoc getCode()
190   {
191     return _code;
192   }
193
194   /**
195    * Sets the unique code of the DjContext object
196    *
197    *@param code The new code value
198    */

199   public void setCode(String JavaDoc code)
200   {
201     _code = code.toLowerCase();
202   }
203
204   /**
205    * Returns true if the ID's of the two DjContext objects match
206    *
207    *@param obj The object to compare with
208    *@return True if ID's match
209    */

210   public boolean equals(Object JavaDoc obj)
211   {
212     if (!(obj instanceof DjContext)) return false;
213     DjContext r = (DjContext) obj;
214
215     return getId() == r.getId();
216   }
217
218   public int hashCode()
219   {
220     return (int) getId();
221   }
222
223   /**
224    * Returns the name of the context
225    *
226    *@return The name of the context
227    */

228   public String JavaDoc toString()
229   {
230     return getName();
231   }
232
233 }
Popular Tags