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