Source code: com/flexstor/common/gateway/RestrictiveWhereGateway.java
1 /*
2 * RestrictiveWhereGateway.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.where.RestrictiveWhereData;
16 import com.flexstor.common.gateway.debug.GatewayDebugOutput;
17 import com.flexstor.common.gateway.exceptions.TransactionFailedException;
18 import com.flexstor.common.keys.ejb.WhereCollectionKey;
19 import com.flexstor.common.keys.ejb.WhereKey;
20 import com.flexstor.ejb.EjbObject;
21 import com.flexstor.ejb.where.persist.WherePersist;
22 import com.flexstor.ejb.where.persist.WherePersistHome;
23
24 /**
25 * Retrieves and updates 'Where' information.
26 *
27 * @author Praveen Jani
28 * @since 3.0
29 */
30 public class RestrictiveWhereGateway
31 extends Gateway
32 {
33 // MKS macro expander
34 public final static String IDENTIFIER = "$Id: RestrictiveWhereGateway.java,v 1.3 2003/08/11 02:22:29 aleric Exp $";
35
36 /**
37 * Instance of WherePersist remote interface.
38 *
39 * @since 3.0
40 * @see com.flexstor.ejb.where.persist.WherePersist
41 */
42
43 private WherePersist where;
44
45 /**
46 * Returns the home name of the bean to be accessed.
47 *
48 * @return String - the home interface name
49 * @since 3.0
50 * @see com.flexstor.common.gateway.EjbHomeInterfacesI
51 */
52
53
54 protected String getHomeName ( )
55 {
56 return WHERE_PERSIST_HOME;
57 }
58
59 /**
60 * Returns the bean object (EjbObject)
61 *
62 * @return com.flexstor.ejb.EjbObject
63 * @since 3.0
64 * @see com.flexstor.ejb.EjbObject
65 */
66
67 protected EjbObject getBeanObject ( )
68 {
69 return (EjbObject)where;
70 }
71
72 /**
73 * Connects the EJB.
74 *
75 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
76 * @since 3.0
77 * @see com.flexstor.common.gateway.exceptions.TransactionFailedException
78 * @see com.flexstor.ejb.where.persist.GroupPersist
79 * @see com.flexstor.ejb.where.persist.GroupPersistHome
80 */
81
82 public void connect ()
83 throws TransactionFailedException
84 {
85 try
86 {
87 if ( canLoadObject() )
88 return;
89
90 WherePersistHome home = (WherePersistHome) getHome();
91 GatewayDebugOutput.println ( 3, "Getting WherePersist object" );
92 where = home.create();
93 }
94 catch ( Throwable e )
95 {
96 throw buildException(e, "Connecting to WherePersist", IDENTIFIER );
97 }
98 }
99
100 /**
101 * Updates a where data.
102 *
103 * @param data - the where's data.
104 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails
105 * @since 3.0
106 * @see com.flexstor.common.data.ejb.where.RestrictiveWhereData
107 */
108
109 public void update ( RestrictiveWhereData data )
110 throws TransactionFailedException
111 {
112 try
113 {
114 if ( canLoadObject() )
115 return;
116
117 GatewayDebugOutput.println ( 3, "Update where data" );
118
119 where.update ( data );
120 }
121 catch ( Throwable e )
122 {
123 throw buildException(e, "Updating", IDENTIFIER );
124 }
125 }
126
127 /**
128 * Removes a FLEXSTOR.db where data from the data base.
129 *
130 * @param roleId roleId - the role id
131 * @param disguiseId disguiseId - the disguise id
132 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
133 * @since 3.0
134 */
135
136 public void remove ( WhereKey key )
137 throws TransactionFailedException
138 {
139 try
140 {
141 if ( canLoadObject() )
142 return;
143
144 GatewayDebugOutput.println ( 3, "Remove where" );
145
146 where.remove ( key );
147 }
148 catch ( Throwable e )
149 {
150 throw buildException(e, "Removing", IDENTIFIER );
151 }
152 }
153
154 /**
155 * Inserts a FLEXSTOR.db where data to the data base.
156 *
157 * @param whereData - the where data object to be inserted
158 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
159 * @since 3.0
160 */
161
162 public WhereKey insert ( RestrictiveWhereData wData )
163 throws TransactionFailedException
164 {
165 try
166 {
167 if ( canLoadObject() )
168 return null;
169
170 GatewayDebugOutput.println ( 3, "Insert where" );
171
172 return where.insert ( wData );
173 }
174 catch ( Throwable e )
175 {
176 throw buildException(e, "Inserting", IDENTIFIER );
177 }
178 }
179
180
181 /**
182 * Returns a collection of FLEXSTOR.db where data objects for a disguise.
183 *
184 * @param disguiseId - the disguise ID.
185 * @return com.flexstor.common.data.ejb.where.WhereData
186 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
187 * @since 3.0
188 */
189
190 public Vector queryWhere ( int disguiseId )
191 throws TransactionFailedException
192 {
193 try
194 {
195 if ( canLoadObject() )
196 return ( Vector )retrieveObject ( "WherePersist_queryWhere( disguiseId )" );
197
198 GatewayDebugOutput.println ( 3, "Getting where provided a disguiseId" );
199 Vector wheres = where.queryWhere ( disguiseId );
200
201 if ( canSaveObject() )
202 storeObject ( "WherePersist_queryWhere( disguiseId )", wheres );
203
204 return wheres;
205 }
206 catch ( Throwable e )
207 {
208 throw buildException(e, "Querying Where", IDENTIFIER );
209 }
210 }
211 /**
212 * Returns a collection of FLEXSTOR.db where data objects for a disguise provided a where collection keys.
213 *
214 * @param whereKeys - the where collection keys.
215 * @param disguiseId - the disguise ID.
216 * @return Vector
217 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
218 * @since 3.0
219 */
220
221 public Vector getWheres ( WhereCollectionKey collectionKeys, int disguiseId )
222 throws TransactionFailedException
223 {
224 try
225 {
226 if ( canLoadObject() )
227 return ( Vector )retrieveObject ( "WherePersist_queryWhere( collectionKeys, disguiseId )" );
228
229 GatewayDebugOutput.println ( 3, "Getting where provided a disguiseId" );
230 Vector wheres = where.getWheres ( collectionKeys, disguiseId );
231
232 if ( canSaveObject() )
233 storeObject ( "WherePersist_queryWhere( collectionKeys, disguiseId )", wheres );
234
235 return wheres;
236 }
237 catch ( Throwable e )
238 {
239 throw buildException(e, "Getting Wheres", IDENTIFIER );
240 }
241 }
242
243 /**
244 * Returns a collection of FLEXSTOR.db where data objects for a disguise provided a where collection keys.
245 *
246 * @param whereKeys - the where collection keys.
247 * @param disguiseId - the disguise ID.
248 * @return Vector
249 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
250 * @since 3.0
251 */
252
253 public Vector getWheres ( Vector collectionKeys, int disguiseId )
254 throws TransactionFailedException
255 {
256 try
257 {
258 if ( canLoadObject() )
259 return ( Vector )retrieveObject ( "WherePersist_queryWhere( collectionKeys(vector), disguiseId )" );
260
261 GatewayDebugOutput.println ( 3, "Getting where provided a disguiseId and Vector of collection keys ");
262 Vector wheres = where.getWheres ( collectionKeys, disguiseId );
263
264 if ( canSaveObject() )
265 storeObject ( "WherePersist_queryWhere( collectionKeys(vector), disguiseId )", wheres );
266
267 return wheres;
268 }
269 catch ( Throwable e )
270 {
271 throw buildException(e, "Getting Wheres", IDENTIFIER );
272 }
273 }
274
275
276 }