Source code: com/flexstor/common/gateway/AdmGroupPersistGateway.java
1 /*
2 * AdmGroupPersistGateway.java
3 *
4 * Copyright $Date: 2003/08/11 02:22:29 $ FLEXSTOR.net Inc.
5 *
6 * This work is licensed for use and distribution under license terms found at
7 * http://www.flexstor.org/license.html
8 *
9 */
10
11 package com.flexstor.common.gateway;
12
13 import java.util.Hashtable;
14 import java.util.Vector;
15
16 import com.flexstor.common.data.ejb.user.GroupData;
17 import com.flexstor.common.gateway.debug.GatewayDebugOutput;
18 import com.flexstor.common.gateway.exceptions.TransactionFailedException;
19 import com.flexstor.common.keys.ejb.GroupCollectionKey;
20 import com.flexstor.common.keys.ejb.GroupKey;
21 import com.flexstor.ejb.EjbObject;
22 import com.flexstor.ejb.user.persist.GroupPersist;
23 import com.flexstor.ejb.user.persist.GroupPersistHome;
24
25
26
27 /**
28 * Retrieves Group information.
29 *
30 * @author Praveen Jani
31 * @version 3.0
32 * @since 3.0
33 * @see com.flexstor.ejb.user.persist.GroupPersist
34 * @see com.flexstor.ejb.user.persist.GroupPersistHome
35 */
36
37 public class AdmGroupPersistGateway
38 extends Gateway
39 {
40 // MKS macro expander
41 public final static String IDENTIFIER = "$Id: AdmGroupPersistGateway.java,v 1.3 2003/08/11 02:22:29 aleric Exp $";
42
43 /**
44 * Instance of GroupPersist remote interface.
45 *
46 * @since 3.0
47 */
48 private GroupPersist group;
49
50 /**
51 * Returns the home name of the bean to be accessed.
52 *
53 * @return String
54 * @since 3.0
55 * @see com.flexstor.common.constants.EjbHomeInterfacesI
56 */
57 protected String getHomeName ( )
58 {
59 return GROUP_PERSIST_HOME;
60 }
61
62 /**
63 * Returns the bean object (EjbObject)
64 *
65 * @since 3.0
66 * @see com.flexstor.ejb.EjbObject
67 */
68 protected EjbObject getBeanObject ( )
69 {
70 return (EjbObject)group;
71 }
72
73 /**
74 * Connects to the EJB with the group name provided. Rest all the functions
75 * would then be called for this group only.
76 *
77 * @param groupName The name of the group.
78 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
79 * @since 3.0
80 * @see com.flexstor.common.gateway.exceptions.TransactionFailedException
81 * @see com.flexstor.ejb.user.persist.GroupPersist
82 * @see com.flexstor.ejb.user.persist.GroupPersistHome
83 */
84 public void connect ( String groupName )
85 throws TransactionFailedException
86 {
87 try
88 {
89 if ( canLoadObject() )
90 return;
91
92 GroupPersistHome home = (GroupPersistHome)getHome();
93 GatewayDebugOutput.println ( 3, "Getting GroupPersist object" );
94 group = home.create( groupName );
95 }
96 catch ( Throwable e )
97 {
98 throw buildException(e, "Connecting to GroupPersist", IDENTIFIER );
99 }
100 }
101
102 /**
103 * Connects the EJB for general purpose functionalities.
104 *
105 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
106 * @since 3.0
107 * @see com.flexstor.common.gateway.exceptions.TransactionFailedException
108 * @see com.flexstor.ejb.user.persist.GroupPersist
109 * @see com.flexstor.ejb.user.persist.GroupPersistHome
110 */
111 public void connect ()
112 throws TransactionFailedException
113 {
114 try
115 {
116 if ( canLoadObject() )
117 return;
118
119 GroupPersistHome home = ( GroupPersistHome ) getHome();
120 GatewayDebugOutput.println ( 3, "Getting GroupPersist object" );
121 group = home.create();
122 }
123 catch ( Throwable e )
124 {
125 throw buildException(e, "Connecting to GroupPersist", IDENTIFIER );
126 }
127 }
128
129
130
131 /**
132 * Retrieves a list of all groups registered in FLEXSTOR.db.
133 *
134 * @return a hashtable of GroupData objects.
135 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
136 * @since 3.0
137 */
138 public Hashtable getGroupList ()
139 throws TransactionFailedException
140 {
141 try
142 {
143 if ( canLoadObject() )
144 return (Hashtable)retrieveObject ( "GroupPersist_getGroupList" );
145
146 GatewayDebugOutput.println ( 3, "Getting Group list" );
147 Hashtable h = group.getGroupList();
148
149 if ( canSaveObject() )
150 storeObject ( "GroupPersist_getGroupList", h );
151
152 return h;
153 }
154 catch ( Throwable e )
155 {
156 throw buildException(e, "Getting Group List", IDENTIFIER );
157 }
158 }
159
160 /**
161 * Retrieves a group provided the group key.
162 *
163 * @param key The group key
164 * @return a UserData objects.
165 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
166 * @since 3.0
167 * @see com.flexstor.common.exceptions.TransactionFailedException
168 * @see com.flexstor.common.keys.ejb.GroupKey
169 */
170 public GroupData getGroup(GroupKey key)
171 throws TransactionFailedException
172 {
173 try
174 {
175 if ( canLoadObject() )
176 return (GroupData)retrieveObject ( "GroupPersist_getGroup(key)" );
177
178 GatewayDebugOutput.println ( 3, "Getting Group for a key" );
179 GroupData data = group.getGroup(key);
180
181 if ( canSaveObject() )
182 storeObject ( "GroupPersist_getGroup(key)", data);
183
184 return data;
185 }
186 catch ( Throwable e )
187 {
188 throw buildException(e, "Getting Group", IDENTIFIER );
189 }
190 }
191
192 /**
193 * Retrieves a group with the name specified as a parameter.
194 *
195 * @param gName The name of the group.
196 * @return GroupData
197 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
198 * @since 3.0
199 * @see com.flexstor.common.data.ejb.user.GroupData
200 */
201 public GroupData getGroup( String gName )
202 throws TransactionFailedException
203 {
204 try
205 {
206 if ( canLoadObject() )
207 return (GroupData)retrieveObject ( "GroupPersist_getGroup(String)" );
208
209 GatewayDebugOutput.println ( 3, "Getting Group for a Group Name" );
210 GroupData data = group.getGroup(gName);
211
212 if ( canSaveObject() )
213 storeObject ( "GroupPersist_getGroup(String)", data );
214
215 return data;
216 }
217 catch ( Throwable e )
218 {
219 throw buildException(e, "Getting Group", IDENTIFIER );
220 }
221 }
222 public GroupData getGroup()
223 throws TransactionFailedException
224 {
225 try
226 {
227 if ( canLoadObject() )
228 return (GroupData)retrieveObject ( "GroupPersist_getGroup()" );
229
230 GatewayDebugOutput.println ( 3, "Getting Group Data" );
231 GroupData data = group.getGroup();
232
233 if ( canSaveObject() )
234 storeObject ( "GroupPersist_getGroup()", data );
235
236 return data;
237 }
238 catch ( Throwable e )
239 {
240 throw buildException(e, "Getting Group", IDENTIFIER );
241 }
242 }
243
244 /**
245 * Retrieves a group based on the group collection key.
246 *
247 * @param keys Group cCollection key
248 * @return a GroupData object.
249 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException
250 */
251 public Vector getGroups(GroupCollectionKey keys)
252 throws TransactionFailedException
253 {
254 try
255 {
256 if ( canLoadObject() )
257 return (Vector)retrieveObject ( "GroupPersist_getGroup(GroupCollectionKey)" );
258
259 GatewayDebugOutput.println ( 3, "Getting Group for GroupCollectionKey" );
260 Vector h = group.getGroups(keys);
261
262 if ( canSaveObject() )
263 storeObject ( "GroupPersist_getGroup(GroupCollectionKey)", h );
264
265 return h;
266 }
267 catch ( Throwable e )
268 {
269 throw buildException(e, "Getting Groups", IDENTIFIER );
270 }
271 }
272
273 /**
274 * Insert a new FLEXSTOR.db group to the database.
275 *
276 * @param data new Group's data.
277 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
278 * @since 3.0
279 */
280 public GroupData insert ( GroupData data )
281 throws TransactionFailedException
282 {
283 GroupData gData = null;
284 try
285 {
286 if ( canLoadObject() )
287 return ( GroupData )retrieveObject( "AdmGroupPersistPersist_insert(data)" );
288
289
290 GatewayDebugOutput.println ( 3, "Insert group" );
291 gData = group.insert ( data );
292
293 if ( canSaveObject() )
294 storeObject( "AdmGroupPersistPersist_insert(data)", data);
295 }
296 catch ( Throwable e )
297 {
298 throw buildException(e, "Inserting", IDENTIFIER );
299 }
300 return gData;
301 }
302 /**
303 * Removes a group from the database.
304 *
305 * @param key the group key.
306 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
307 * @since 3.0
308 */
309 public void remove ( GroupKey key )
310 throws TransactionFailedException
311 {
312 try
313 {
314 if ( canLoadObject() )
315 return;
316
317 GatewayDebugOutput.println ( 3, "Remove group" );
318
319 group.remove ( key );
320 }
321 catch ( Throwable e )
322 {
323 throw buildException(e, "Removing", IDENTIFIER );
324 }
325 }
326
327 /**
328 * Updates the Group data for this group.
329 *
330 * @param data the group's data.
331 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException
332 * @since 3.0
333 * @see com.flexstor.common.data.ejb.user.GroupData
334 */
335 public GroupData update ( GroupData data )
336 throws TransactionFailedException
337 {
338 GroupData gData = null;
339 try
340 {
341 if ( canLoadObject() )
342 return ( GroupData )retrieveObject( "AdmGroupPersistPersist_update(data)" );
343
344
345 GatewayDebugOutput.println ( 3, "Update group data" );
346 gData = group.update ( data );
347
348 if ( canSaveObject() )
349 storeObject( "AdmGroupPersistPersist_update(data)", data);
350 }
351 catch ( Throwable e )
352 {
353 throw buildException(e, "Updating", IDENTIFIER );
354 }
355 return gData;
356 }
357 }