Source code: com/flexstor/common/gateway/FileStorageGateway.java
1 /*
2 * FileStorageGateway.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.ActionData;
14 import com.flexstor.common.exceptions.ejb.NotFoundException;
15 import com.flexstor.common.gateway.debug.GatewayDebugOutput;
16 import com.flexstor.common.gateway.exceptions.TransactionFailedException;
17 import com.flexstor.ejb.EjbObject;
18 import com.flexstor.ejb.filestorage.persist.FileStoragePersist;
19 import com.flexstor.ejb.filestorage.persist.FileStoragePersistHome;
20
21 //import java.util.Hashtable;
22
23 /**
24 * To do the update into the database
25 * @author David Cardozo
26 * @version 3.0
27 */
28 public class FileStorageGateway
29 extends Gateway
30 {
31 // MKS macro expander
32 public final static String IDENTIFIER = "$Id: FileStorageGateway.java,v 1.3 2003/08/11 02:22:29 aleric Exp $";
33
34 private FileStoragePersist fileStorage = null;
35
36 protected String getHomeName ( )
37 {
38 return FILE_STORAGE_HOME;
39 }
40
41 protected EjbObject getBeanObject ( )
42 {
43 return fileStorage;
44 }
45
46 /**
47 * Sends the request for the fileStorage data to the server.
48 * @throws TransactionFailedException Throws if this transaction fails.
49 */
50 public void connect ()
51 throws TransactionFailedException
52 {
53 try
54 {
55 if ( canLoadObject() )
56 return;
57
58 FileStoragePersistHome home = (FileStoragePersistHome) getHome ( );
59
60 GatewayDebugOutput.println ( 3, "Getting FileStoragePersist object" );
61 fileStorage = home.create();
62 }
63 catch ( NotFoundException e )
64 {
65 throw new TransactionFailedException ( e );
66 }
67 catch ( Throwable e )
68 {
69 throw buildException(e, "Connecting to FileStoragePersist", IDENTIFIER );
70 }
71 }
72
73 // public Hashtable assetsArchived( ArchiveInformation[] assetsInfo )
74 public ActionData assetsArchived(ActionData storageData)
75 throws TransactionFailedException
76 {
77 try
78 {
79 GatewayDebugOutput.println ( 3, "Changing status to ARCHIVED in database" );
80
81 if ( canLoadObject() )
82 return (ActionData) retrieveObject( "FileStoragePersist_assetsArchived" );
83
84 ActionData data = fileStorage.assetsArchived( storageData );
85
86 if ( canSaveObject() )
87 storeObject( "FileStoragePersist_assetsArchived", data );
88
89 return data;
90 }
91 catch ( Throwable e )
92 {
93 throw buildException(e, "Setting status to Archived", IDENTIFIER );
94 }
95 }
96
97 /**
98 * Change instances of the asset to Restored
99 */
100 public ActionData assetsRestored(ActionData storageData)
101 throws TransactionFailedException
102 {
103 try
104 {
105 GatewayDebugOutput.println ( 3, "Changing status to RESTORED in database" );
106
107 if ( canLoadObject() )
108 return (ActionData) retrieveObject( "FileStoragePersist_assetsRestored" );
109
110 ActionData data = fileStorage.assetsRestored( storageData );
111
112 if ( canSaveObject() )
113 storeObject( "FileStoragePersist_assetsRestored", data );
114
115 return data;
116 }
117 catch ( Throwable e )
118 {
119 throw buildException(e, "Setting status to Restored", IDENTIFIER );
120 }
121 }
122
123 /**
124 * Change instances of the asset to In Process to Archive
125 * All Files are sent to the DB where they are updated.
126 * Before sending them back, the status field is set.
127 */
128 //public Hashtable assetsInProcessArchive( AssetInstanceId[] assetInstance )
129 public ActionData assetsInProcessArchive( ActionData storageData )
130 throws TransactionFailedException
131 {
132 try
133 {
134 GatewayDebugOutput.println ( 3, "Changing status to IN_PROGRESS_ARCHIVE in database" );
135
136 if ( canLoadObject() )
137 return (ActionData) retrieveObject( "FileStoragePersist_assetsInProcessArchive" );
138
139 ActionData data = fileStorage.assetsInProcessArchive( storageData );
140
141
142 if ( canSaveObject() )
143 storeObject( "FileStoragePersist_assetsInProcessArchive", data );
144
145 return data;
146 }
147 catch ( Throwable e )
148 {
149 throw buildException(e, "Setting status to In Process Archive", IDENTIFIER );
150 }
151 }
152
153 /**
154 * Change instances of the asset to In Process to Restore
155 * bUpdateDB true will update the Database, false will not update the database
156 * All assets are returned (to get archiveId's etc...). When restoring to new
157 * location database is not updated. But archiveId's are still needed.
158 */
159 public ActionData assetsInProcessRestore( ActionData storageData, boolean bUpdateDB )
160 throws TransactionFailedException
161 {
162 try
163 {
164 GatewayDebugOutput.println ( 3, "Changing status to IN_PROGRESS_RESTORE in database" );
165
166 if ( canLoadObject() )
167 return (ActionData) retrieveObject( "FileStoragePersist_assetsInProcessRestore" );
168
169 ActionData data = fileStorage.assetsInProcessRestore( storageData, bUpdateDB );
170
171 if ( canSaveObject() )
172 storeObject( "FileStoragePersist_assetsInProcessRestore", data );
173
174 return data;
175 }
176 catch ( Throwable e )
177 {
178 throw buildException(e, "Setting status to In Process Restore", IDENTIFIER );
179 }
180 }
181
182 /**
183 * Change instances of the asset to File Not Found
184 */
185 public ActionData assetsFileNotFound( ActionData storageData )
186 throws TransactionFailedException
187 {
188 try
189 {
190 GatewayDebugOutput.println ( 3, "Checking for files not found in database" );
191
192 if ( canLoadObject() )
193 return (ActionData) retrieveObject( "FileStoragePersist_assetsFileNotFound" );
194
195 ActionData data = fileStorage.assetsFileNotFound( storageData );
196
197
198 if ( canSaveObject() )
199 storeObject( "FileStoragePersist_assetsFileNotFound", data );
200
201 return data;
202 }
203 catch ( Throwable e )
204 {
205 throw buildException(e, "Getting File Not Found Assets", IDENTIFIER );
206 }
207 }
208 }