Source code: com/flexstor/common/gateway/ApplicationGateway.java
1 /*
2 * ApplicationGateway.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.application.ApplicationData;
16 import com.flexstor.common.gateway.debug.GatewayDebugOutput;
17 import com.flexstor.common.gateway.exceptions.TransactionFailedException;
18 import com.flexstor.common.keys.ejb.ApplicationKey;
19 import com.flexstor.ejb.EjbObject;
20 import com.flexstor.ejb.application.persist.ApplicationPersist;
21 import com.flexstor.ejb.application.persist.ApplicationPersistHome;
22
23 /**
24 * Gateway class to perform operations related to applications.
25 *
26 * @author Praveen Jani
27 * @since 3.0
28 * @see com.flexstor.common.gateway.Gateway
29 */
30
31
32 public class ApplicationGateway
33 extends Gateway
34 {
35 // MKS macro expander
36 public final static String IDENTIFIER = "$Id: ApplicationGateway.java,v 1.3 2003/08/11 02:22:29 aleric Exp $";
37
38 /**
39 * Instance of ApplicationPersist remote interface.
40 *
41 * @since 3.0
42 * @see com.flexstor.ejb.application.persist.ApplicationPersist
43 */
44
45 private ApplicationPersist application;
46
47
48 /**
49 * Returns the home name of the bean to be accessed.
50 *
51 * @return String - the published home interface name
52 * @since 3.0
53 * @see com.flexstor.common.constants.EjbHomeInterfacesI
54 */
55
56 protected String getHomeName ( )
57 {
58 return APPLICATION_HOME;
59 }
60
61 /**
62 * Returns the bean object (EjbObject)
63 *
64 * @return EjbObject - the bean object
65 * @since 3.0
66 * @see com.flexstor.ejb.EjbObject
67 */
68
69 protected EjbObject getBeanObject ( )
70 {
71 return (EjbObject)application;
72 }
73
74 /**
75 * Connects to the EJB.
76 *
77 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
78 * @since 3.0
79 */
80
81 public void connect ()
82 throws TransactionFailedException
83 {
84 try
85 {
86 if ( canLoadObject() )
87 return;
88
89 ApplicationPersistHome home = (ApplicationPersistHome)getHome();
90 GatewayDebugOutput.println ( 3, "Getting ApplicationPersist object" );
91 application = home.create();
92 }
93 catch ( Throwable e )
94 {
95 throw buildException(e, "Connecting to ApplicationPersist", IDENTIFIER );
96 }
97 }
98
99 /**
100 * Retrieves an application contained by FLEXSTOR.db based on the id passed
101 *
102 * @param nApplicationId The id of the application to be retrieved
103 * @return ApplicationData
104 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
105 * @since 3.0
106 */
107 public ApplicationData getApplication( int nApplicationId )
108 throws TransactionFailedException
109 {
110 try
111 {
112 if ( canLoadObject() )
113 return (ApplicationData)retrieveObject ( "ApplicationPersist_getDataObject" );
114
115 GatewayDebugOutput.println ( 3, "Getting Application" );
116 ApplicationData disguiseData = application.getDataObject( nApplicationId );
117
118 if ( canSaveObject() )
119 storeObject ( "ApplicationPersist_getDataObject", disguiseData );
120
121
122 return disguiseData;
123 }
124 catch ( Throwable e )
125 {
126 throw buildException(e, "Getting Application", IDENTIFIER );
127 }
128 }
129
130 /**
131 * Retrieves a list of applications contained by FLEXSTOR.db based on the name passed
132 *
133 * @param sAppName The name of the application for which return some matches
134 * @return ApplicationData
135 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
136 * @since 3.0
137 */
138 public Vector getApplications( String sAppName )
139 throws TransactionFailedException
140 {
141 try
142 {
143 if ( canLoadObject() )
144 return (Vector)retrieveObject ( "ApplicationPersist_queryDataObjects" );
145
146 GatewayDebugOutput.println ( 3, "Getting Application" );
147 Vector data = application.queryDataObjects( sAppName );
148
149 if ( canSaveObject() )
150 storeObject ( "ApplicationPersist_queryDataObjects", data );
151
152
153 return data;
154 }
155 catch ( Throwable e )
156 {
157 throw buildException(e, "Getting Application", IDENTIFIER );
158 }
159 }
160
161 /**
162 * Insert a new application column in the application table. This will
163 * insert a new field and return a Application key.
164 *
165 * @param fieldDat ApplicationData Object
166 *
167 * @return com.flexstor.ejb.key.ApplicationKey
168 *
169 * @exception com.flexstor.ejb.exceptions.ServerException
170 * @exception java.rmi.RemoteException
171 */
172 public ApplicationKey insert( ApplicationData fieldDat )
173 throws TransactionFailedException
174 {
175 try
176 {
177 if ( canLoadObject() )
178 return (ApplicationKey)retrieveObject ( "ApplicationPersist_insert" );
179
180 GatewayDebugOutput.println ( 3, "Inserting Application" );
181 ApplicationKey data = application.insert( fieldDat );
182
183 if ( canSaveObject() )
184 storeObject ( "ApplicationPersist_insert", data );
185
186
187 return data;
188 }
189 catch ( Throwable e )
190 {
191 throw buildException(e, "Getting Application", IDENTIFIER );
192 }
193 }
194
195 /**
196 * Remove a application From database Based upon key. Throws
197 * exception if error removing row.
198 *
199 * @param key ApplicationKey Object
200 * @exception com.flexstor.ejb.exceptions.EjbException
201 * @exception java.rmi.RemoteException
202 */
203 public void remove( ApplicationKey key )
204 throws TransactionFailedException
205 {
206 try
207 {
208 GatewayDebugOutput.println ( 3, "remove Application" );
209 application.remove( key );
210 }
211 catch ( Throwable e )
212 {
213 throw buildException( e, "Removing Application", IDENTIFIER );
214 }
215 }
216 }