Source code: com/flexstor/common/gateway/LookupGateway.java
1 /*
2 * LookupGateway.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.lookup.LookupData;
16 import com.flexstor.common.exceptions.ejb.NotFoundException;
17 import com.flexstor.common.gateway.debug.GatewayDebugOutput;
18 import com.flexstor.common.gateway.exceptions.TransactionFailedException;
19 import com.flexstor.common.keys.ejb.LookupKey;
20 import com.flexstor.ejb.EjbObject;
21 import com.flexstor.ejb.lookup.persist.LookupPersist;
22 import com.flexstor.ejb.lookup.persist.LookupPersistHome;
23
24 /**
25 * Retrieves lookup lists.
26 * @author Dan Schroeder
27 * @version 3.0
28 */
29 public class LookupGateway
30 extends Gateway
31 {
32 // MKS macro expander
33 public final static String IDENTIFIER = "$Id: LookupGateway.java,v 1.3 2003/08/11 02:22:29 aleric Exp $";
34
35 private LookupPersist lookup;
36
37 protected String getHomeName ( )
38 {
39 return LOOKUP_HOME;
40 }
41
42 protected EjbObject getBeanObject ( )
43 {
44 return lookup;
45 }
46
47 public void connect ( )
48 throws TransactionFailedException
49 {
50 try
51 {
52 if ( canLoadObject() )
53 return;
54
55 LookupPersistHome home = (LookupPersistHome)getHome();
56 GatewayDebugOutput.println ( 3, "Getting LookupPersist object" );
57 lookup = home.create();
58 }
59 catch ( Throwable e )
60 {
61 throw buildException(e, "Connecting to LookupPersist", IDENTIFIER );
62 }
63 }
64
65 public String[] getLookupList ( LookupKey key )
66 throws TransactionFailedException, NotFoundException
67 {
68 try
69 {
70 if ( canLoadObject() )
71 return (String[])retrieveObject ( "LookupPersist_getLookupData_" + key );
72
73 GatewayDebugOutput.println ( 3, "Getting list for " + key );
74
75 String[] data = lookup.getColumnData ( key );
76
77 if ( canSaveObject() )
78 storeObject ( "LookupPersist_getLookupData_" + key, data );
79
80 return data;
81 }
82 // A not found exception is thrown when there are no items in a lookup list.
83 catch ( NotFoundException e )
84 {
85 // Log and Display the exception, but rethrow the orginal one.
86 buildException(e, "Getting Lookup List", IDENTIFIER );
87 throw e;
88 }
89 catch ( Throwable e )
90 {
91 throw buildException(e);
92 }
93 }
94
95 public String[] getLookupList ( String sQuery )
96 throws TransactionFailedException, NotFoundException
97 {
98 try
99 {
100 if ( canLoadObject() )
101 return (String[])retrieveObject ( "LookupPersist_getLookupList" );
102
103 GatewayDebugOutput.println ( 3, "Getting list for query" );
104
105 String[] data = lookup.getColumnData ( sQuery );
106
107 if ( canSaveObject() )
108 storeObject ( "LookupPersist_getLookupList", data );
109
110 return data;
111 }
112 // A not found exception is thrown when there are no items in a lookup list.
113 catch ( NotFoundException e )
114 {
115 // Log and Display the exception, but rethrow the orginal one.
116 buildException(e, "Getting Lookup List", IDENTIFIER );
117 throw e;
118 }
119 catch ( Throwable e )
120 {
121 throw buildException(e);
122 }
123 }
124
125 public LookupData getLookup( LookupKey key )
126 throws TransactionFailedException
127 {
128 try
129 {
130 if ( canLoadObject() )
131 return (LookupData) retrieveObject ( "LookupPersist_getLookup" );
132
133 GatewayDebugOutput.println ( 3, "Getting lookup" );
134
135 LookupData data = lookup.getDataObject( key );
136
137 if ( canSaveObject() )
138 storeObject ( "LookupPersist_getLookup", data );
139
140 return data;
141 }
142 catch ( Throwable e )
143 {
144 throw buildException(e);
145 }
146 }
147
148 /*
149 * Retrieves a list of LookupData objects representing all lookup lists in the database
150 */
151 public Vector getLookups()
152 throws TransactionFailedException
153 {
154 try
155 {
156 if ( canLoadObject() )
157 return (Vector) retrieveObject ( "LookupPersist_getLookups" );
158
159 GatewayDebugOutput.println ( 3, "Getting lookups" );
160
161 Vector data = lookup.getDataObjects();
162
163 if ( canSaveObject() )
164 storeObject ( "LookupPersist_getLookups", data );
165
166 return data;
167 }
168 catch ( Throwable e )
169 {
170 throw buildException(e);
171 }
172 }
173
174 /**
175 * Insert a new lookup column in the lookup table. This will
176 * insert a new table, column combo and return a Lookup Key.
177 * Transaction Attribute: Required
178 *
179 * @param lookDat LookupData Object
180 * @return LookupKey
181 *
182 * @exception EjbException If there is a problem while inserting info in the database
183 * @exception RemoteException If there is an internal problem in the EJB Server
184 */
185 public LookupKey insert( LookupData data )
186 throws TransactionFailedException
187 {
188 try
189 {
190 if ( canLoadObject() )
191 return (LookupKey)retrieveObject ( "Lookup_insert" );
192
193 GatewayDebugOutput.println ( 3, "Inserting Lookup" );
194
195 LookupKey key = lookup.insert( data );
196
197 if ( canSaveObject() )
198 storeObject ( "Lookup_insert", key );
199
200 return key;
201 }
202 catch ( Throwable e )
203 {
204 throw buildException(e);
205 }
206 }
207
208 /**
209 * Remove a Lookup From database Based upon key. Throws exception if error removing row.
210 * Transaction Attribute: Required
211 *
212 * @param key LookupKey Object
213 *
214 * @exception EjbException If there is a problem while removing info from the database
215 * @exception RemoteException If there is an internal problem in the EJB Server
216 * @exception NotFoundException If no info is returned from the database
217 */
218 public void remove( LookupKey key )
219 throws TransactionFailedException
220 {
221 try
222 {
223 GatewayDebugOutput.println ( 3, "remove Lookup" );
224 lookup.remove( key );
225 }
226 catch ( Throwable e )
227 {
228 throw buildException( e, "Removing Lookup", IDENTIFIER );
229 }
230 }
231
232 /**
233 * This will get the LookupKey associated with a table, column String
234 * Transaction Attribute: Not Supported
235 *
236 * @param nLuDisguiseId the id of the Lookup Disguise
237 * @param nLuBucketStructId the structure id of the Lookup Bucket
238 * @param nLuFieldId the id of the Lookup Field
239 * @return A lookup key object
240 *
241 * @exception EjbException If there is a problem while getting info from the database
242 * @exception RemoteException If there is an internal problem in the EJB Server
243 * @exception NotFoundException If no info is returned from the database
244 */
245 public LookupKey getLookupKey( int nLuDisguiseId, int nLuBucketStructId, int nLuFieldId )
246 throws TransactionFailedException
247 {
248 try
249 {
250 if ( canLoadObject() )
251 return (LookupKey) retrieveObject ( "LookupPersist_getLookupKey" );
252
253 GatewayDebugOutput.println ( 3, "Getting Looku Key" );
254
255 LookupKey data = lookup.getDataObjectKey( nLuDisguiseId, nLuBucketStructId, nLuFieldId );
256
257 if ( canSaveObject() )
258 storeObject ( "LookupPersist_getLookupKey", data );
259
260 return data;
261 }
262 catch ( Throwable e )
263 {
264 throw buildException(e);
265 }
266 }
267 }