Source code: com/flexstor/common/gateway/ImportSettingGateway.java
1 /*
2 * ImportSettingGateway.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.Vector;
14
15 import com.flexstor.common.data.ejb.setting.ImportSettingData;
16 import com.flexstor.common.gateway.debug.GatewayDebugOutput;
17 import com.flexstor.common.gateway.exceptions.TransactionFailedException;
18 import com.flexstor.common.keys.ejb.ImportSettingCollectionKey;
19 import com.flexstor.common.keys.ejb.ImportSettingKey;
20 import com.flexstor.common.keys.ejb.RoleKey;
21 import com.flexstor.ejb.EjbObject;
22 import com.flexstor.ejb.setting.persist.ImportSettingPersist;
23 import com.flexstor.ejb.setting.persist.ImportSettingPersistHome;
24
25 /**
26 * Gateway class to perform operations on import setting related information.
27 *
28 * @author Praveen Jani
29 * @since 3.0
30 * @see com.flexstor.common.gateway.Gateway
31 */
32
33
34 public class ImportSettingGateway
35 extends Gateway
36 {
37 // MKS macro expander
38 public final static String IDENTIFIER = "$Id: ImportSettingGateway.java,v 1.3 2003/08/11 02:22:29 aleric Exp $";
39
40 /**
41 * Instance of ImportSettingPersist remote interface.
42 *
43 * @since 3.0
44 * @see com.flexstor.ejb.setting.persist.ImportSettungPersist
45 */
46
47 private ImportSettingPersist importSetting;
48
49
50 /**
51 * Returns the home name of the bean to be accessed.
52 *
53 * @return String - the bean's published name
54 * @since 3.0
55 * @see com.flexstor.common.constants.EjbHomeInterfacesI
56 */
57
58 protected String getHomeName ( )
59 {
60 return IMPORT_SETTING_HOME;
61 }
62
63 /**
64 * Returns the bean object (EjbObject)
65 *
66 * @return EjbObject - the bean object
67 * @since 3.0
68 * @see com.flexstor.ejb.EjbObject
69 */
70
71 protected EjbObject getBeanObject ( )
72 {
73 return (EjbObject)importSetting;
74 }
75
76 /**
77 * Connects to the import setting persist EJB.
78 *
79 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
80 * @since 3.0
81 */
82
83 public void connect ()
84 throws TransactionFailedException
85 {
86 try
87 {
88 if ( canLoadObject() )
89 return;
90
91 ImportSettingPersistHome home = (ImportSettingPersistHome)getHome();
92 GatewayDebugOutput.println ( 3, "Getting ImportSettingPersist object" );
93 importSetting = home.create();
94 }
95 catch ( Throwable e )
96 {
97 throw buildException(e, "Connecting to ImportSettingPersist", IDENTIFIER );
98 }
99 }
100
101 /**
102 * Retrieves a list of all available import settings contained by FLEXSTOR.db.
103 *
104 * @return Vector - collection of ImportSettingData objects.
105 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
106 * @since 3.0
107 * @see com.flexstor.ejb.address.persist.ImportSettingPersist
108 * @see com.flexstor.common.data.ejb.settings.ImportSettingData
109 */
110 public Vector getImportSettingList ( )
111 throws TransactionFailedException
112 {
113 try
114 {
115 if ( canLoadObject() )
116 return (Vector)retrieveObject ( "ImportSettingPersist_getImportSettingList" );
117
118 GatewayDebugOutput.println ( 3, "Getting Import Setting list" );
119 Vector vector = importSetting.getAllImportSettings();
120
121 if ( canSaveObject() )
122 storeObject ( "ImportSettingPersist_getImportSettingList", vector );
123
124 return vector;
125 }
126 catch ( Throwable e )
127 {
128 throw buildException(e, "Getting Import Setting List", IDENTIFIER );
129 }
130 }
131
132 /**
133 * Retrieves a list of all import settings contained by FLEXSTOR.db provided a list of import
134 * setting keys.
135 *
136 * @param keyCollection - Collection of import setting keys.
137 * @return Vector - Collection of ImportSettingData objects.
138 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
139 * @since 3.0
140 * @see com.flexstor.ejb.address.setting.persist.ImportSettingPersist
141 */
142 public Vector getImportSettings (Vector keyCollection)
143 throws TransactionFailedException
144 {
145 try
146 {
147 if ( canLoadObject() )
148 return (Vector)retrieveObject ( "ImportSettingPersist_getImportSettings(Vector)" );
149
150 GatewayDebugOutput.println ( 3, "Getting Import Setting list" );
151 Vector addresses = importSetting.getImportSetting( keyCollection );
152
153 if ( canSaveObject() )
154 storeObject ( "ImportSettingPersist_getImportSettings(Vector)", addresses );
155
156 return addresses;
157 }
158 catch ( Throwable e )
159 {
160 throw buildException(e, "Getting Import Settings", IDENTIFIER );
161 }
162 }
163 /**
164 * Retrieves a list of all import settings contained by FLEXSTOR.db provided
165 * a import setting collection key.
166 *
167 * @param collectionKey collectionKey - Instance of ImportSettingCollectionKey.
168 * @return Vector - Collection of ImportSettingData objects.
169 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
170 * @since 3.0
171 * @see com.flexstor.ejb.address.setting.persist.ImportSettingPersist
172 */
173 public Vector getImportSettings (ImportSettingCollectionKey collectionKey)
174 throws TransactionFailedException
175 {
176 try
177 {
178 if ( canLoadObject() )
179 return (Vector)retrieveObject ( "ImportSettingPersist_getImportSettings(collectionKey)" );
180
181 GatewayDebugOutput.println ( 3, "Getting Import Setting list" );
182 Vector addresses = importSetting.getImportSetting ( collectionKey );
183
184 if ( canSaveObject() )
185 storeObject ( "ImportSettingPersist_getImportSettings(collectionKey)", addresses );
186
187 return addresses;
188 }
189 catch ( Throwable e )
190 {
191 throw buildException(e, "Getting Import Settings", IDENTIFIER );
192 }
193 }
194
195 /**
196 * Retrieves a import setting contained by FLEXSTOR.db provided a import setting name.
197 *
198 * @param name name - Name of the import setting.
199 * @return ImportSettingData data object.
200 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
201 * @since 3.0
202 * @see com.flexstor.ejb.address.setting.persist.ImportSettingPersist
203 */
204 public ImportSettingData getImportSetting ( String name )
205 throws TransactionFailedException
206 {
207 try
208 {
209 if ( canLoadObject() )
210 return (ImportSettingData)retrieveObject ( "ImportSettingPersist_getImportSetting(name)" );
211
212 GatewayDebugOutput.println ( 3, "Getting a Import Setting" );
213 ImportSettingData iSetting = importSetting.getImportSetting ( name );
214
215 if ( canSaveObject() )
216 storeObject ( "ImportSettingPersist_getImportSetting(name)", iSetting);
217
218 return iSetting;
219 }
220 catch ( Throwable e )
221 {
222 throw buildException(e, "Getting Import Setting", IDENTIFIER );
223 }
224 }
225
226
227
228 /**
229 * Retrieves a Import Setting contained by FLEXSTOR.db provided a import
230 * setting key.
231 *
232 * @param key key - The import setting key.
233 * @return ImportSettingData data object.
234 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
235 * @since 3.0
236 * @see com.flexstor.ejb.address.persist.ImportSettingPersist
237 * @see com.flexstor.common.address.persist.ImportSettingData
238 * @see com.flexstor.common.keys.ejb.ImportSettingKey
239 */
240 public ImportSettingData getImportSetting(ImportSettingKey key)
241 throws TransactionFailedException
242 {
243 try
244 {
245 if ( canLoadObject() )
246 return (ImportSettingData)retrieveObject ( "ImportSettingPersist_getImportSetting(key)" );
247
248 GatewayDebugOutput.println ( 3, "Getting Import Setting list" );
249 ImportSettingData iSetting = importSetting.getImportSetting(key);
250
251 if ( canSaveObject() )
252 storeObject ( "ImportSettingPersist_getImportSetting(key)", iSetting );
253
254 return iSetting;
255 }
256 catch ( Throwable e )
257 {
258 throw buildException(e, "Getting Import Setting", IDENTIFIER );
259 }
260 }
261
262 /**
263 * Inserts a Import Settings to the FLEXSTOR.db Import Setting database.
264 *
265 * @param importSettingData - ImportSettingData, import setting data object
266 * @return ImportSettingData data object.
267 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
268 * @since 3.0
269 * @see com.flexstor.ejb.address.persist.ImportSettingPersist
270 * @see com.flexstor.common.address.persist.ImportSettingData
271 */
272
273
274 public ImportSettingData insert( ImportSettingData importSettingData )
275 throws TransactionFailedException
276 {
277 try
278 {
279 if ( canLoadObject() )
280 return (ImportSettingData)retrieveObject( "ImportSettingPersist_insert" );
281
282 GatewayDebugOutput.println ( 3, "Inserting Import Setting." );
283 ImportSettingData eAddressData = importSetting.insert( importSettingData );
284
285 if ( canSaveObject() )
286 storeObject( "ImportSettingPersist_insert", eAddressData );
287
288 return eAddressData;
289 }
290 catch ( Throwable e )
291 {
292 throw buildException( e, "Inserting", IDENTIFIER );
293 }
294 }
295
296 /**
297 * Adds a Import Setting to a role.
298 *
299 * @param importSettingData - ImportSettingData - data object
300 * @param key - key represents the role this setting is assigned to
301 * @return ImportSettingData - import setting data object.
302 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
303 * @since 3.0
304 * @see com.flexstor.ejb.address.persist.ImportSettingPersist
305 * @see com.flexstor.common.address.persist.ImportSettingData
306 */
307
308
309 public ImportSettingData insert( ImportSettingData importSettingData, RoleKey key )
310 throws TransactionFailedException
311 {
312 try
313 {
314 if ( canLoadObject() )
315 return (ImportSettingData)retrieveObject( "ImportSettingPersist_insert" );
316
317 GatewayDebugOutput.println ( 3, "Inserting Import Setting." );
318 ImportSettingData iSetting = importSetting.insert( importSettingData, key );
319
320 if ( canSaveObject() )
321 storeObject( "ImportSettingPersist_insert", iSetting );
322
323 return iSetting;
324 }
325 catch ( Throwable e )
326 {
327 throw buildException( e, "Inserting", IDENTIFIER );
328 }
329 }
330
331
332 /**
333 * Deletes ( removes ) a Import Setting from the FLEXSTOR.db Import Setting database.
334 *
335 * @param importSettingKey - key represents the import setting to be removed from the database.
336 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
337 * @since 3.0
338 * @see com.flexstor.ejb.address.persist.ImportSettingPersist
339 * @see com.flexstor.common.address.persist.ImportSettingData
340 * @see com.flexstor.common.address.persist.ImportSettingKey
341 */
342
343
344 public void remove( ImportSettingKey importSettingKey )
345 throws TransactionFailedException
346 {
347 try
348 {
349 if ( canLoadObject() )
350 return;
351 GatewayDebugOutput.println ( 3, "Removing Import Setting." );
352 importSetting.remove( importSettingKey );
353 }
354 catch ( Throwable e )
355 {
356 throw buildException( e, "Removing", IDENTIFIER );
357 }
358 }
359 /**
360 * Deletes ( removes ) a Import Setting from the FLEXSTOR.db Import Setting database provided
361 * name of the setting.
362 *
363 * @param String - key represents name of the import setting to be removed from the database.
364 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
365 * @since 3.0
366 * @see com.flexstor.ejb.address.persist.ImportSettingPersist
367 * @see com.flexstor.common.address.persist.ImportSettingData
368 * @see com.flexstor.common.address.persist.ImportSettingKey
369 */
370
371
372 public void remove( String strImportSettingName )
373 throws TransactionFailedException
374 {
375 try
376 {
377 if ( canLoadObject() )
378 return;
379 GatewayDebugOutput.println ( 3, "Removing Import Setting provided name." );
380 importSetting.remove( strImportSettingName );
381 }
382 catch ( Throwable e )
383 {
384 throw buildException( e, "Removing setting "+strImportSettingName, IDENTIFIER );
385 }
386 }
387
388
389 /**
390 * Updates Import Setting to the FLEXSTOR.db Import Setting database.
391 *
392 * @param importSettingData - ImportSettingData - data object
393 * @return ImportSettingData - updated data object
394 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
395 * @since 3.0
396 * @see com.flexstor.ejb.address.persist.ImportSettingPersist
397 * @see com.flexstor.common.address.persist.ImportSettingData
398 * @see com.flexstor.common.address.persist.ImportSettingKey
399 */
400
401
402 public ImportSettingData update( ImportSettingData importSettingData )
403 throws TransactionFailedException
404 {
405 try
406 {
407 if ( canLoadObject() )
408 return (ImportSettingData)retrieveObject( "ImportSettingPersist_update" );
409
410 GatewayDebugOutput.println ( 3, "Updating Import Setting." );
411 ImportSettingData iSetting = importSetting.update( importSettingData );
412
413 if ( canSaveObject() )
414 storeObject( "ImportSettingPersist_update", iSetting );
415
416 return iSetting;
417
418 }
419 catch ( Throwable e )
420 {
421 throw buildException( e, "Updating", IDENTIFIER );
422 }
423 }
424
425
426 }