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

Quick Search    Search Deep

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


1   /*
2    * FieldGateway.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.field.FieldData;
14  import com.flexstor.common.gateway.debug.GatewayDebugOutput;
15  import com.flexstor.common.gateway.exceptions.TransactionFailedException;
16  import com.flexstor.common.keys.ejb.FieldKey;
17  import com.flexstor.ejb.EjbObject;
18  import com.flexstor.ejb.field.persist.FieldPersist;
19  import com.flexstor.ejb.field.persist.FieldPersistHome;
20  
21  /**
22   * A gateway for interacting with the FieldPersistBean.
23   */
24  public class FieldGateway
25     extends Gateway
26  {
27     // MKS macro expander
28     public final static String IDENTIFIER = "$Id: FieldGateway.java,v 1.3 2003/08/11 02:22:29 aleric Exp $";
29  
30     private FieldPersist field;
31  
32     protected String getHomeName()
33     {
34        return FIELD_PERSIST_HOME;
35     }
36  
37     protected EjbObject getBeanObject()
38     {
39        return field;
40     }
41  
42     public void connect()
43        throws TransactionFailedException
44     {
45        try
46        {
47           if ( canLoadObject() )
48              return;
49  
50           FieldPersistHome home = (FieldPersistHome)getHome();
51           GatewayDebugOutput.println ( 3, "Getting FieldPersist object" );
52           field = home.create();
53        }
54        catch ( Throwable e )
55        {
56           throw buildException(e, "Connecting to FieldPersist", IDENTIFIER );
57        }
58     }
59  
60     /**
61      * Insert a new field column in the lookup table. This will
62      * insert a new field and return a Field key.
63      *
64      * @param fieldDat FieldData Object
65      *
66      * @return com.flexstor.ejb.key.FieldKey
67      *
68      * @exception com.flexstor.ejb.exceptions.ServerException
69      * @exception java.rmi.RemoteException
70      */
71     public FieldKey insert( FieldData data )
72        throws TransactionFailedException
73     {
74        try
75        {
76           if ( canLoadObject() )
77              return (FieldKey)retrieveObject ( "Field_insert" );
78  
79           GatewayDebugOutput.println ( 3, "Inserting field" );
80  
81           FieldKey key = field.insert( data );
82  
83           if ( canSaveObject() )
84              storeObject ( "Field_insert", key );
85  
86           return key;
87        }
88        catch ( Throwable e )
89        {
90           throw buildException(e);
91        }
92     }
93  
94      /**
95      * Remove a Field From database Based upon key. Throws
96      * exception if error removing row.
97      *
98      * @param key FieldKey Object
99      * @exception com.flexstor.ejb.exceptions.ServerException
100     * @exception java.rmi.RemoteException
101     */
102    public void remove( FieldKey key )
103       throws TransactionFailedException
104    {
105       try
106       {
107          GatewayDebugOutput.println ( 3, "remove Field" );
108          field.remove( key );
109          return;
110       }
111       catch ( Throwable e )
112       {
113          throw buildException( e, "Removing Field", IDENTIFIER );
114       }
115    }
116 }