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

Quick Search    Search Deep

Source code: com/flexstor/ejb/machine/MachineBean.java


1   /*
2    * MachineBean.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:43 $ 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.ejb.machine;
12  
13  import java.rmi.RemoteException;
14  
15  import javax.ejb.CreateException;
16  import javax.ejb.RemoveException;
17  
18  import com.flexstor.common.constants.EjbHomeInterfacesI;
19  import com.flexstor.common.data.ejb.machine.MachineData;
20  import com.flexstor.common.exceptions.ejb.DuplicateRecordException;
21  import com.flexstor.common.exceptions.ejb.EjbException;
22  import com.flexstor.ejb.machine.persist.MachinePersist;
23  import com.flexstor.ejb.machine.persist.MachinePersistHome;
24  
25  /**
26   *
27   * <P>
28   * Machine <BR>
29   * <BLOCKQUOTE>
30   *    This interface defines a machine that connects to FLEXSTOR.db. <BR>
31   *    At this point, there is no dirty write checking for updates.  This bean functions under <BR>
32   *    the assumption that there should only one client updating a Machine. <BR>
33   *    Right now, this bean is configured for updating a small number of machine settings (<10). <BR>
34   *    Later, the bean may be needed to be changed because a larger number of machine settings are actually used. <BR>
35   * </BLOCKQUOTE>
36   * </P>
37   *
38   * <P>
39   * Uses cache: no
40   *
41   * State Management Type: Stateless
42   * </P>
43   *
44   * Configurable properties in flexdm.properties: <BR>
45   * <BLOCKQUOTE>
46   * <P>
47   *    NONE <BR>
48   * </P>
49   * </BLOCKQUOTE>
50   *
51   */
52  public class MachineBean
53      extends com.flexstor.ejb.BusinessObjectSessionBean 
54  {
55    // MKS macro expander
56    public final static String IDENTIFIER = "$Id: MachineBean.java,v 1.4 2003/08/11 02:22:43 aleric Exp $";
57    
58      /**
59      * EJB container calls ejbCreate in order to create an instance of the object. ejbCreate initalizes the state of <br>
60      * the EJB object.
61      *
62      * This method corresponds to the create method in the home interface <code>MachineHome</code>.
63      *
64      * @exception javax.ejb.CreateException                 - The EJB server could not create an instance of this bean
65      * @exception java.rmi.RemoteException                  - Some problem occured with the EJB server 
66      *
67      * @see com.flexstor.ejb.machine.MachineHome
68      */
69       
70      public void ejbCreate() 
71          throws CreateException, RemoteException 
72      {
73        // create an initial Context object
74        buildInitialContext("Machine");
75      }
76  
77     /**
78      * Retrieve Machine's state data object
79      * Transaction Attribute: Not Supported
80      *
81      * @param aMachineName  a machine name (or host name)
82      * @return - a machine data object
83      *
84      * @exception EjbException - A problem occured obtaining the Machine data object from the MachinePersist bean
85      * @exception RemoteException - Some problem occured with the EJB server
86      */
87      public MachineData getDataObject(String aMachineName)
88          throws EjbException, RemoteException 
89      {
90        //check to see that the name is not null or empty
91        if (assertNull(aMachineName)) 
92        {
93          throw new EjbException("MachineBean", "getDataObject", 5410);
94        }
95        if (assertEmptyString(aMachineName)) 
96        {
97          throw new EjbException("MachineBean", "getDataObject", 5411);    
98        }  
99          
100        MachinePersist machinePersist = getMachinePersist();
101       try
102       {
103         return machinePersist.getMachine(aMachineName);
104       }
105       catch(RemoteException aRemoteException)
106       {
107         throw new EjbException("MachineBean", "getDataObject", aRemoteException.getMessage(), 5419);
108       }
109        finally
110        {
111          try { machinePersist.remove(); }
112          catch( RemoveException re ) {}
113        }
114     }
115 
116     /**
117     * Retrieve the MachinePersist persistence bean associated with this business bean
118     *
119     * @return com.flexstor.ejb.machine.persist.MachinePerist
120     *
121     * @exception com.flexstor.common.exceptions.ejb   -  A problem occured creating a MachinePersist bean
122     */
123      
124     private MachinePersist getMachinePersist()
125         throws EjbException 
126     {
127       try
128       {
129         return ((MachinePersistHome)getBeanHome(EjbHomeInterfacesI.MACHINE_HOME, MachinePersistHome.class)).create();
130       }
131       catch (javax.ejb.CreateException aCreateException)
132       {
133         throw new EjbException("MachineBean", "getMachinePersist", aCreateException.getMessage(), 5417);
134       }
135       catch (RemoteException aRemoteException)
136       {
137         throw new EjbException("MachineBean", "getMachinePersist", aRemoteException.getMessage(), 5419);
138       }
139     }
140 
141    /**
142     * Save the current state of the object to the database.
143     * Transaction Attribute: Required
144     *
145     * @param aDataObject an Machine data object
146     *
147     * @exception DuplicateRecordException - a row already exists within the database with the given key
148     * @exception EjbException - A problem update a data object to the database
149     * @exception RemoteException - Some problem occured with the EJB server
150     */
151     public void update(MachineData aDataObject) 
152         throws DuplicateRecordException, EjbException, RemoteException 
153     {
154       //check to see if parameter is null
155       if (assertNull(aDataObject)) 
156       {
157         throw new EjbException("MachineBean", "update", 5410);
158       }
159 
160        MachinePersist machinePersist = getMachinePersist();
161       try
162       {
163         machinePersist.update(aDataObject);
164       }
165       catch (RemoteException aRemoteException)
166       {
167         throw new EjbException("MachineBean", "update", aRemoteException.getMessage(), 5419);
168       }
169        finally
170        {
171            try { machinePersist.remove(); }
172            catch ( RemoveException re ) {}
173        }
174     }
175 }