Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/common/gateway/ServerListGateway.java


1   /*
2    * ServerListGateway.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.server.ServerData;
17  import com.flexstor.common.gateway.debug.GatewayDebugOutput;
18  import com.flexstor.common.gateway.exceptions.TransactionFailedException;
19  import com.flexstor.common.keys.ejb.ServerKey;
20  import com.flexstor.ejb.EjbObject;
21  import com.flexstor.ejb.server.persist.ServerPersist;
22  import com.flexstor.ejb.server.persist.ServerPersistHome;
23  
24  /**
25   * Revision 1.8 2001/03/01 : 15.03.00 Visesh
26   * Added a remove method to delete a server
27   *
28   * Retrieves server information.
29   * @author Dan Schroeder
30   * @version 3.0
31   */
32  public class ServerListGateway
33     extends Gateway
34  {
35     // MKS macro expander
36     public final static String IDENTIFIER = "$Id: ServerListGateway.java,v 1.3 2003/08/11 02:22:29 aleric Exp $";
37  
38     private ServerPersist server;
39     
40     protected String getHomeName ( )
41     {
42        return SERVER_LIST_HOME;
43     }
44  
45     protected EjbObject getBeanObject ( )
46     {
47        return server;
48     }
49  
50     public void connect ( )
51        throws TransactionFailedException
52     {
53        try
54        {
55           if ( canLoadObject() )
56              return;
57           
58           ServerPersistHome home = (ServerPersistHome)getHome();
59           GatewayDebugOutput.println ( 3, "Getting ServerPersist object" );
60           server = home.create();
61  
62        }
63        catch ( Throwable e )
64        {         
65           throw buildException(e, "Connecting to ServerPersist", IDENTIFIER );
66        }
67     }
68     
69     
70     /**
71      * Retrieves a list of all servers used by FLEXSTOR.db.
72      * @return a hashtable of ServerData objects.
73      */  
74     public Hashtable getServerList ( )
75        throws TransactionFailedException
76     {
77        try
78        {
79           if ( canLoadObject() )
80              return (Hashtable)retrieveObject ( "ServerPersist_getServerList" );
81  
82           GatewayDebugOutput.println ( 3, "Getting server list" );
83           Hashtable h = server.getServerList();
84                 
85           if ( canSaveObject() )
86              storeObject ( "ServerPersist_getServerList", h );
87                 
88           return h;
89        }
90        catch ( Throwable e )
91        {         
92           throw buildException(e, "Getting Server List", IDENTIFIER );
93        }
94     }
95     
96     
97     /**
98      * Gets a list of servers for the specified server keys.
99      * @param vKeys a Vector of ServerCollectionKey objects.
100     * @return a hashtable of ServerData objects.
101     */  
102    public Hashtable getServerList ( Vector vKeys )
103       throws TransactionFailedException
104    {
105       try
106       {
107          if ( canLoadObject() )
108             return (Hashtable)retrieveObject ( "ServerPersist_getServers" );
109 
110          GatewayDebugOutput.println ( 3, "Getting server list" );
111          Hashtable h = server.getServers ( vKeys );
112                
113          if ( canSaveObject() )
114             storeObject ( "ServerPersist_getServers", h );
115                
116          return h;
117       }
118       catch ( Throwable e )
119       {
120          throw buildException(e, "Getting Server List", IDENTIFIER );
121       }
122    }
123    
124    /**
125     * Inserts a new server.
126     * 
127     * @param serverData - ServerData, server data obejct
128     * @return ServerKey - server key
129     * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown if the tramsaction fails.
130     * @since 3.0
131     * @see com.flexstor.common.data.ejb.server.Server
132     */
133    public ServerKey insert( ServerData serverData ) 
134       throws TransactionFailedException   
135    {
136       try
137       {
138          if ( canLoadObject() )
139             return (ServerKey)retrieveObject( "ServerPersist_insert" );
140 
141          GatewayDebugOutput.println ( 3, "Inserting server" );
142          ServerKey serverKey = server.insert( serverData );
143 
144          if ( canSaveObject() )
145             storeObject( "ServerPersist_insert", serverKey );
146                
147          return serverKey;
148       }
149       catch ( Throwable e )
150       {         
151          throw buildException( e, "Inserting", IDENTIFIER );
152       }
153    }   
154    /**
155     * Updates server.
156     * 
157     * @param serverData - ServerData, server data obejct
158     * @return ServerKey - server key
159     * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown if the tramsaction fails.
160     * @since 3.0
161     * @see com.flexstor.common.data.ejb.server.Server
162     */
163    public void update( ServerData serverData ) 
164       throws TransactionFailedException   
165    {
166       try
167       {
168          if ( canLoadObject() )
169             return;
170 
171          GatewayDebugOutput.println ( 3, "Updating server" );
172          server.update( serverData );                     
173          
174       }
175       catch ( Throwable e )
176       {         
177          throw buildException( e, "Updating", IDENTIFIER );
178       }
179    }      
180    /**
181     * Removes server.
182     * 
183     * @param serverData - ServerData, server data obejct
184     * @return ServerKey - server key
185     * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown if the tramsaction fails.
186     * @since 3.0
187     * @see com.flexstor.common.data.ejb.server.Server
188     */
189    public void remove( ServerData serverData ) 
190       throws TransactionFailedException   
191    {
192       try
193       {
194          if ( canLoadObject() )
195             return;
196          server.remove( serverData.getKey() );   
197       }
198       catch( Throwable e )
199       {
200         throw buildException( e, "Removing", IDENTIFIER );
201       }
202    }
203    
204    
205 }