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

Quick Search    Search Deep

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


1   /*
2    * PropertyGateway.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 com.flexstor.common.data.ejb.property.PropertyData;
14  import com.flexstor.common.gateway.debug.GatewayDebugOutput;
15  import com.flexstor.common.gateway.exceptions.TransactionFailedException;
16  import com.flexstor.common.keys.ejb.PropertyKey;
17  import com.flexstor.ejb.EjbObject;
18  import com.flexstor.ejb.property.persist.PropertyPersist;
19  import com.flexstor.ejb.property.persist.PropertyPersistHome;
20  
21  /**
22   * A gateway for interacting with the PropertyPersistGateway.
23   */
24  public class PropertyGateway
25     extends Gateway
26  {
27     // MKS macro expander
28     public final static String IDENTIFIER = "$Id: PropertyGateway.java,v 1.3 2003/08/11 02:22:29 aleric Exp $";
29  
30     private PropertyPersist property;
31  
32     protected String getHomeName()
33     {
34        return PROPERTY_PERSIST_HOME;
35     }
36  
37     protected EjbObject getBeanObject()
38     {
39        return property;
40     }
41  
42     public void connect()
43        throws TransactionFailedException
44     {
45        try
46        {
47           if ( canLoadObject() )
48              return;
49  
50           PropertyPersistHome home = (PropertyPersistHome)getHome();
51           GatewayDebugOutput.println ( 3, "Getting PropertyPersist object" );
52           property = home.create();
53        }
54        catch ( Throwable e )
55        {
56           throw buildException(e, "Connecting to PropertyPersist", IDENTIFIER );
57        }
58     }
59  
60     /**
61      * Insert a new  Property column in the  Property table. This will
62      * insert a new field and return a Property key.
63      *
64      * @param fieldDat PropertyData Object
65      *
66      * @return updated PropertyData
67      *
68      * @exception com.flexstor.ejb.exceptions.ServerException
69      * @exception java.rmi.RemoteException
70      */
71     public PropertyData insert( PropertyData data )
72        throws TransactionFailedException
73     {
74        try
75        {
76           if ( canLoadObject() )
77              return (PropertyData)retrieveObject ( "Property_insert" );
78  
79           GatewayDebugOutput.println ( 3, "Inserting Property" );
80  
81           PropertyData key = property.insert( data );
82  
83           if ( canSaveObject() )
84              storeObject ( "Property_insert", key );
85  
86           return key;
87        }
88        catch ( Throwable e )
89        {
90           throw buildException(e);
91        }
92     }
93  
94      /**
95       * This will update a  Property row. There MUST
96       * contain a Database key! If key is null in the
97       * dataobject then a RemoteException is thrown!
98       * <br><br>
99       * Also the id needs to be set to the valid id or
100      * id will become null.
101      *
102      * @param disDat com.flexstor.ejb.dataobject.PropertyData
103      * @exception java.rmi.RemoteException
104      * @since FlexDB 3.0
105      */
106 
107    public void update( PropertyData data )
108       throws TransactionFailedException
109    {
110       try
111       {
112          GatewayDebugOutput.println ( 3, "Update Property" );
113          property.update( data );
114       }
115       catch ( Throwable e )
116       {
117          throw buildException( e, "Updating Property", IDENTIFIER );
118       }
119    }
120 
121    /**
122     * Remove a Property From database Based upon key. Throws
123     * exception if error removing row.
124     *
125     * @param key PropertyKey Object
126     * @exception com.flexstor.ejb.exceptions.EjbException
127     * @exception java.rmi.RemoteException
128     */
129    public void remove( PropertyKey key )
130       throws TransactionFailedException
131    {
132       try
133       {
134          GatewayDebugOutput.println ( 3, "remove Property" );
135          property.remove( key );
136       }
137       catch ( Throwable e )
138       {
139          throw buildException( e, "Removing Property", IDENTIFIER );
140       }
141    }
142 }