KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > backup > OnlineBackup


1 package com.daffodilwoods.daffodildb.server.backup;
2
3 import com.daffodilwoods.database.resource.DException;
4 import com.daffodilwoods.daffodildb.server.serversystem.ServerSystem;
5 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.PersistentSystem;
6 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.PersistentDatabase;
7 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.DatabaseConstants;
8 import com.daffodilwoods.daffodildb.server.datasystem.indexsystem.IndexDatabase;
9 import com.daffodilwoods.daffodildb.server.datasystem.mergesystem.MergeDatabase;
10 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.DRandomAccessFile;
11 import java.io.RandomAccessFile JavaDoc;
12 import java.io.File JavaDoc;
13 import java.util.HashMap JavaDoc;
14 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._DataTable;
15 import com.daffodilwoods.daffodildb.server.datadictionarysystem.SystemTables;
16 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.DatabaseUserTableIterator;
17 import com.daffodilwoods.daffodildb.utils.BufferRange;
18 import com.daffodilwoods.daffodildb.utils.byteconverter.CCzufDpowfsufs;
19 import com.daffodilwoods.daffodildb.utils.comparator.CTusjohJoTfotjujwfDpnqbsbups;
20 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._TableCharacteristics;
21 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Utility;
22 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._DatabaseUser;
23 import java.util.*;
24 import java.io.*;
25 import com.daffodilwoods.database.utility.P;
26 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._UserTableOperations;
27 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.DRandomAccessFileUpto3_2;
28 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.versioninfo.VersionHandler;
29
30 /**
31  * <p>Title: </p>
32  * <p>Description: </p>
33  * <p>Copyright: Copyright (c) 2003</p>
34  * <p>Company: </p>
35  * @author not attributable
36  * @version 1.0
37  */

38
39 public class OnlineBackup {
40   ServerSystem ss;
41   VersionHandler versionHandler;
42   public OnlineBackup(ServerSystem serverSystem) throws DException{
43     ss = serverSystem;
44   }
45
46   /**
47    * takes online backup of the database from the source to destination.
48    * First of all it gets the SystemDatabase and userDatabase from the online source
49    * gets the DRandomAccesFile and synchronize this DRandomAccesFile object
50    * and also takes user on the SystemDatabase and hence locks it.
51    * if SystemDatabase doesn't exist on the destination path
52    * then it simple copies SystemDatabase and for copying userDatabase
53    * -> it checks if the database is to be backed up with same name then simply copies
54    * files form source path to the destination path
55    * ->else it first removes the entry from the system database for the sourceDatabaseName
56    * and then calls createDatabase with the new name.
57    * else it checks if userDatabase already exists at the destination
58    * if it exists there there then first we remove the existing database and then give call to create database
59    * -> if overwrite option is true
60    * -> else throw exception that Database already exists on the given path
61    * else it simply gives call to createDatabase method
62    *
63    * @param ss server system object of the source database for which backup is to be taken
64    * @param destination path at which backup is taken
65    * @param databaseNameSource name of the source database for taking backup
66    * @param databaseNameDestination name of the destination database for taking backup
67    * @param overwrite boolean whether to overwrite if the databse already exists.
68    */

69
70   public void onlineBackup(String JavaDoc destination,String JavaDoc databaseNameSource, String JavaDoc databaseNameDestination,boolean overwrite) throws DException{
71
72     if (databaseNameSource.equalsIgnoreCase(DatabaseConstants.SYSTEMDATABASE))
73       throw new DException("DSE5570", new Object JavaDoc[] {databaseNameSource});
74     if (databaseNameDestination.equalsIgnoreCase(DatabaseConstants.SYSTEMDATABASE))
75       throw new DException("DSE5571", new Object JavaDoc[] {databaseNameDestination});
76
77     PersistentDatabase systemDatabaseSourcePath = (PersistentDatabase) ( (IndexDatabase) ( (
78         MergeDatabase) ss.getMergeDatabase(DatabaseConstants.SYSTEMDATABASE)).getFileDatabase()).
79         getUnderLyingDatabase();
80     PersistentDatabase userDatabaseSourcePath = (PersistentDatabase) ( (IndexDatabase) ( (
81         MergeDatabase) ss.getMergeDatabase(databaseNameSource)).
82         getFileDatabase()).getUnderLyingDatabase();
83     versionHandler = userDatabaseSourcePath.getVersionHandler();
84     _DatabaseUser user = systemDatabaseSourcePath.getDatabaseUser();
85     try {
86       DRandomAccessFileUpto3_2 dRAM = systemDatabaseSourcePath.getDrandomAccessFile();
87       synchronized (dRAM) {
88
89         boolean ifExists = BackupHelper.backupSystemDatabase(dRAM,
90             destination, databaseNameSource);
91         if (!ifExists) {
92           BackupPersistentSystem ps = new BackupPersistentSystem(destination);
93           PersistentDatabase pd = (PersistentDatabase) ps.getDatabase(
94               DatabaseConstants.SYSTEMDATABASE+"_Bk");
95           BackupHelper.removingEntriesForSchedules(pd);
96           _DataTable databaseInfoTable = (_DataTable) pd.getTable(SystemTables.
97               DATABASEINFO);
98           DatabaseUserTableIterator databaseTableIteartor = (
99               DatabaseUserTableIterator) databaseInfoTable.getIterator();
100           ArrayList list = new ArrayList();
101           list.add(SystemTables.DATABASEINFO);
102           _DatabaseUser user1 = null;
103           try {
104             user1 = pd.getDatabaseUser(list);
105             if (databaseTableIteartor.first()) {
106               do {
107                 databaseTableIteartor.delete(user1); //deleting all entries of databases from SystemDatabase
108
}
109               while (databaseTableIteartor.next());
110             }
111           }
112           finally {
113             user1.writeToFile();
114           }
115
116           BackupHelper.createDatabase(user,systemDatabaseSourcePath,destination, databaseNameSource,
117                                       databaseNameDestination);
118
119           onlineBackupUserDatabase(systemDatabaseSourcePath,
120                                    userDatabaseSourcePath, destination,
121                                    databaseNameSource,
122                                    databaseNameDestination);
123         }
124
125         else {
126
127           BackupPersistentSystem ps = new BackupPersistentSystem(destination);
128           PersistentDatabase pd = (PersistentDatabase) ps.getDatabase(
129               DatabaseConstants.SYSTEMDATABASE + "_Bk");
130           checkDatabase(pd);
131           _DataTable databaseInfoTable = (_DataTable) systemDatabaseSourcePath.
132               getTable(SystemTables.DATABASEINFO);
133           try {
134             pd = (PersistentDatabase) ps.getDatabase(databaseNameDestination);
135             if (pd != null && overwrite) {
136               ps.removeDatabase(databaseNameDestination);
137               ps.dropDatabase(databaseNameDestination);
138               BackupHelper.createDatabase(user,systemDatabaseSourcePath, destination,
139                   databaseNameSource,
140                   databaseNameDestination);
141               onlineBackupUserDatabase(systemDatabaseSourcePath,
142                                        userDatabaseSourcePath, destination,
143                                        databaseNameSource,
144                                        databaseNameDestination);
145
146             }
147             else {
148               throw new DException("DSE5567",
149                                    new Object JavaDoc[] {databaseNameDestination});
150             }
151           }
152           catch (DException ex) {
153             if (ex.getDseCode().equalsIgnoreCase("DSE316")) {
154               BackupHelper.createDatabase(user,systemDatabaseSourcePath, destination,
155                   databaseNameSource,
156                   databaseNameDestination);
157               onlineBackupUserDatabase(systemDatabaseSourcePath,
158                                        userDatabaseSourcePath, destination,
159                                        databaseNameSource,
160                                        databaseNameDestination);
161
162             }
163             else {
164               throw ex;
165             }
166           }finally{
167             user.releaseCluster();
168           }
169         }
170       }
171     }
172     finally {
173       user.releaseCluster();
174     }
175   }
176
177
178   public void onlineBackup1(String JavaDoc destination,String JavaDoc databaseNameSource, String JavaDoc databaseNameDestination,boolean overwrite) throws DException{
179
180     if (databaseNameSource.equalsIgnoreCase(DatabaseConstants.SYSTEMDATABASE))
181       throw new DException("DSE5570", new Object JavaDoc[] {databaseNameSource});
182     if (databaseNameDestination.equalsIgnoreCase(DatabaseConstants.SYSTEMDATABASE))
183       throw new DException("DSE5571", new Object JavaDoc[] {databaseNameDestination});
184
185     PersistentDatabase systemDatabaseSourcePath = (PersistentDatabase) ( (IndexDatabase) ( (
186         MergeDatabase) ss.getMergeDatabase(DatabaseConstants.SYSTEMDATABASE)).getFileDatabase()).
187         getUnderLyingDatabase();
188     PersistentDatabase userDatabaseSourcePath = (PersistentDatabase) ( (IndexDatabase) ( (
189         MergeDatabase) ss.getMergeDatabase(databaseNameSource)).
190         getFileDatabase()).getUnderLyingDatabase();
191     _DatabaseUser user = systemDatabaseSourcePath.getDatabaseUser();
192     try {
193       DRandomAccessFileUpto3_2 dRAM = systemDatabaseSourcePath.getDrandomAccessFile();
194       synchronized (dRAM) {
195         RandomAccessFile raf = dRAM.getRandomAccessFile();
196         String JavaDoc destinationPath = destination + File.separator +
197                                  DatabaseConstants.SYSTEMDATABASE+"_Bk"+ File.separator +
198                                  DatabaseConstants.SYSTEMDATABASE + ".ddb";
199         File df = new File(destinationPath);
200         if (!df.exists()) {
201           boolean isMultiFileSupport = dRAM.isMultiFileSupport();
202           HashMap JavaDoc multiFileMap = dRAM.getMultiFileMap();
203           int multiFileIndex = dRAM.getIndexMultipleFiles(/*DatabaseConstants.SYSTEMDATABASE*/);
204           copyDatabase(raf,destinationPath, destination,databaseNameSource,
205                        databaseNameDestination, isMultiFileSupport,
206                        multiFileMap,multiFileIndex);
207           if (databaseNameSource.equalsIgnoreCase(databaseNameDestination)) {
208             onlineBackupUserDatabase(systemDatabaseSourcePath, userDatabaseSourcePath,
209                                      destination,
210                                      databaseNameSource,
211                                      databaseNameDestination);
212           }
213           else {
214             BackupPersistentSystem ps = new BackupPersistentSystem(destination);
215             ps.dropDatabase(databaseNameSource);
216             createDatabase(systemDatabaseSourcePath, userDatabaseSourcePath, destination,
217                            databaseNameSource, databaseNameDestination);
218           }
219         }
220         else {
221           BackupPersistentSystem ps = new BackupPersistentSystem(destination);
222           PersistentDatabase pd = (PersistentDatabase) ps.getDatabase(
223               DatabaseConstants.SYSTEMDATABASE);
224           checkDatabase(pd);
225           _DataTable databaseInfoTable = (_DataTable) systemDatabaseSourcePath.getTable(SystemTables.DATABASEINFO);
226           try {
227             pd = (PersistentDatabase) ps.getDatabase(databaseNameDestination);
228             if (pd != null && overwrite) {
229               ps.removeDatabase(databaseNameDestination);
230               ps.dropDatabase(databaseNameDestination);
231               createDatabase(systemDatabaseSourcePath, userDatabaseSourcePath, destination,databaseNameSource, databaseNameDestination);
232             }
233             else {
234               throw new DException("DSE5567", new Object JavaDoc[]{databaseNameDestination});
235             }
236           }
237           catch (DException ex) {
238             if (ex.getDseCode().equalsIgnoreCase("DSE316")) {
239               createDatabase(systemDatabaseSourcePath, userDatabaseSourcePath, destination,
240                              databaseNameSource, databaseNameDestination);
241             }
242             else {
243               throw ex;
244             }
245           }
246         }
247       }
248     }finally {
249       user.releaseCluster();
250     }
251   }
252
253   /**
254    * takes online backup of the userDatabase from the source to destination.
255    * gets the DRandomAccesFile of the source userDatabase and synchronize this DRandomAccesFile object
256    * and also takes user on the SystemDatabase and hence locks it.
257    * if userDatabse exists at the destination then first drop the database and then give call for create database
258    * if overwrite option is true else throws exception that database to be backed up
259    * already exists on the destination path
260    * else it just copies the file from source path to destination path
261    *
262    * @param SystemDatabase persistentDatabase object of systemDatabse present in the source
263    * @param sourceDatabase persistentDatabase object of userDatabase present in the source
264    * @param destination path at which backup is taken
265    * @param databaseNameSource name of the database in the source
266    * @param databaseNameDestination name of the database with which it is to be restored or backed up
267    * @param ifExists is true if the userDatabse already exists at the path
268    * @param overwrite boolean whether to overwrite if the databse already exists.
269    */

270
271   private void onlineBackupUserDatabase(PersistentDatabase systemDatabaseSourcePath,PersistentDatabase userDatabaseSourcePath,String JavaDoc destination, String JavaDoc databaseNameSource, String JavaDoc databaseNameDestination) throws DException{
272     String JavaDoc destinationPath = destination + File.separator + databaseNameDestination +"_Bk"+ File.separator + databaseNameDestination + ".ddb";
273     _DatabaseUser user = userDatabaseSourcePath.getDatabaseUser();
274     try {
275       DRandomAccessFileUpto3_2 dRAM = userDatabaseSourcePath.getDrandomAccessFile();
276       synchronized (dRAM) {
277
278         RandomAccessFile raf = dRAM.getRandomAccessFile();
279         File df = new File(destinationPath);
280         boolean isMultiFileSupport = dRAM.isMultiFileSupport();
281         HashMap JavaDoc multiFileMap = dRAM.getMultiFileMap();
282         int multiFileIndex = dRAM.getIndexMultipleFiles(
283             /*databaseNameDestination*/);
284              copyDatabase(raf, destinationPath, destination, databaseNameSource,
285                           databaseNameDestination, isMultiFileSupport,
286                           multiFileMap, multiFileIndex);
287       }
288     }catch(Exception JavaDoc ex){
289
290     }finally{
291       user.releaseCluster();
292     }
293   }
294
295   /**
296    * Creates database at the destination it takes properties of the databse from the
297    * source SystemDatabase and then creates Database with these properties it also modifies
298    * the SystemTable DATABASEFILEINFO.
299    * Gives call for creation of database and then delete the files on the path and then just copy the files from source to destination.
300    *
301    * @param SystemDatabase persistentDatabase object of systemDatabse present in the source
302    * @param sourceDatabase persistentDatabase object of userDatabase present in the source
303    * @param destination path at which backup is taken
304    * @param databaseNameSource name of the database in the source
305    * @param databaseNameDestination name of the database with which it is to be restored or backed up
306    */

307
308   private void createDatabase(PersistentDatabase systemDatabaseSourcePath,PersistentDatabase userDatabaseSourcePath, String JavaDoc destination,String JavaDoc databaseNameSource,
309                               String JavaDoc databaseNameDestination) throws DException {
310     int index = 0;
311     _DataTable databaseInfoTable = (_DataTable) systemDatabaseSourcePath.getTable(SystemTables.DATABASEINFO);
312     DatabaseUserTableIterator databaseTableIteartor = (DatabaseUserTableIterator) databaseInfoTable.getIterator();
313     Object JavaDoc[] databaseProperties = null;
314     BufferRange bytesOfDestinationDatabaseName = new BufferRange(CCzufDpowfsufs.getBytes(databaseNameDestination, databaseNameDestination.length(), false));
315     BufferRange bytesOfSourceDatabaseName = new BufferRange(CCzufDpowfsufs.getBytes(databaseNameSource, databaseNameSource.length(), false));
316     CTusjohJoTfotjujwfDpnqbsbups stringComparator = new CTusjohJoTfotjujwfDpnqbsbups();
317
318     if (databaseTableIteartor.first())
319       do {
320       BufferRange[] bytesGot = (BufferRange[]) databaseTableIteartor.getColumnValues();
321       if (stringComparator.compare(bytesGot[0], bytesOfSourceDatabaseName) == 0) {
322         _TableCharacteristics tableCharacteristics = databaseInfoTable.getTableCharacteristics();
323         databaseProperties = (Object JavaDoc[]) tableCharacteristics.getObject(bytesGot);
324         break;
325       }
326     }
327     while (databaseTableIteartor.next());
328     Object JavaDoc[] databaseProps = Utility.convertIntoFieldBase(databaseProperties);
329     String JavaDoc initialSize = (String JavaDoc) databaseProps[1];
330     int incrementFactor = databaseProps[4].hashCode();
331     boolean unicodeSupport = ( (Boolean JavaDoc) databaseProps[5]).booleanValue();
332     boolean multiFilesSupport = ( (Boolean JavaDoc) databaseProps[6]).booleanValue();
333     boolean encryptionSupport = ( (Boolean JavaDoc) databaseProps[7]).booleanValue();
334     String JavaDoc encrytpionAlgo = (String JavaDoc) databaseProps[8];
335     String JavaDoc encryptionKey = (String JavaDoc) databaseProps[9];
336     String JavaDoc clusterSize = (String JavaDoc) databaseProps[10];
337     if (multiFilesSupport) {
338       DatabaseUserTableIterator databaseFileInfoIterator = (DatabaseUserTableIterator) ( (_DataTable) systemDatabaseSourcePath.getTable(SystemTables.DATABASEFILEINFO)).getIterator();
339       if (databaseFileInfoIterator.first())
340         do {
341         BufferRange[] bytesGot = (BufferRange[]) databaseFileInfoIterator.getColumnValues();
342         if (stringComparator.compare(bytesGot[0],bytesOfSourceDatabaseName) == 0) {
343           index = CCzufDpowfsufs.getInt(bytesGot[1].getBytes()).hashCode();
344           break;
345         }
346       }
347       while (databaseTableIteartor.next());
348     }
349
350     ArrayList scheduleEntries = null;
351     try {
352       _DataTable table = (_DataTable) systemDatabaseSourcePath.getTable(
353           SystemTables.SCHEDULEINFO);
354       DatabaseUserTableIterator scheduleInfoTableIteartor = (
355           DatabaseUserTableIterator) table.getIterator();
356       scheduleEntries = new ArrayList();
357       if (scheduleInfoTableIteartor.first()) {
358         do {
359           BufferRange[] bytesGot = (BufferRange[])
360                                    scheduleInfoTableIteartor.getColumnValues();
361           if (stringComparator.compare(bytesGot[0],
362                                        bytesOfSourceDatabaseName) == 0) {
363             scheduleEntries.add(bytesGot);
364           }
365         }
366         while (scheduleInfoTableIteartor.next());
367       }
368     }
369     catch (DException ex) {
370       if (!ex.getDseCode().equalsIgnoreCase("DSE959"))
371         throw ex;
372     }
373
374
375     BackupPersistentSystem ps = new BackupPersistentSystem(destination);
376     ps.createDatabase(databaseNameDestination, initialSize, incrementFactor,
377                       unicodeSupport, multiFilesSupport, encryptionSupport,
378                       encrytpionAlgo, encryptionKey, clusterSize);
379
380     if (multiFilesSupport) {
381       PersistentDatabase systemDatabaseDestinationPath = (PersistentDatabase) ps.getDatabase(
382           DatabaseConstants.SYSTEMDATABASE);
383       DatabaseUserTableIterator databaseFileInfoIterator = (DatabaseUserTableIterator) ( (_DataTable) systemDatabaseDestinationPath.getTable(
384           SystemTables.DATABASEFILEINFO)).getIterator();
385       if (databaseFileInfoIterator.first())
386         do {
387         BufferRange[] bytesGot = (BufferRange[]) databaseFileInfoIterator.getColumnValues();
388         if (stringComparator.compare(bytesGot[0],bytesOfDestinationDatabaseName) == 0) {
389           _DatabaseUser user = systemDatabaseSourcePath.getDatabaseUser();
390           databaseFileInfoIterator.update(user,new BufferRange[] {bytesOfDestinationDatabaseName,new BufferRange(CCzufDpowfsufs.getBytes(new Integer JavaDoc(index)))});
391           user.writeToFile();
392           break;
393         }
394       }
395       while (databaseTableIteartor.next());
396     }
397
398     if (scheduleEntries!= null && scheduleEntries.size() > 0) {
399       PersistentDatabase systemDatabaseDestination = (PersistentDatabase) ps.getDatabase(DatabaseConstants.SYSTEMDATABASE);
400       DatabaseUserTableIterator scheduleInfoTableIteartorDestination = null;
401       _DatabaseUser user = null;
402       try {
403         _DataTable scheduleInfoTable = (_DataTable) systemDatabaseDestination.
404                                        getTable(SystemTables.SCHEDULEINFO);
405         scheduleInfoTableIteartorDestination = (DatabaseUserTableIterator)
406             scheduleInfoTable.getIterator();
407         ArrayList list = new ArrayList();
408         list.add(SystemTables.SCHEDULEINFO);
409         user = systemDatabaseDestination.getDatabaseUser(list);
410       }
411       catch (DException ex1) {
412         if (!ex1.getDseCode().equalsIgnoreCase("DSE959"))
413           throw ex1;
414       }
415       for (int i = 0; i < scheduleEntries.size(); i++) {
416         BufferRange[] entry = (BufferRange[]) scheduleEntries.get(i);
417         entry[0] = bytesOfDestinationDatabaseName;
418         ( (_UserTableOperations) scheduleInfoTableIteartorDestination).insert(user,entry);
419       }
420       user.writeToFile();
421     }
422
423     deleteFiles(databaseNameDestination, destination);
424     onlineBackupUserDatabase(systemDatabaseSourcePath,userDatabaseSourcePath,destination, databaseNameSource,databaseNameDestination);
425   }
426
427   /**
428    * Method to delete .ddb file and database folder created through create databse method before
429    * giving caonlineBackupUserDatabasell to the copy file methof from source to destination
430    * @param databaseName
431    * @param destination
432    * @throws DException
433    */

434
435   private void deleteFiles(String JavaDoc databaseName,String JavaDoc destination)throws DException{
436     String JavaDoc path = destination + File.separator +databaseName + File.separator + databaseName + ".ddb";
437     File f = new File(path);
438     f.delete();
439     File ff1 = f.getParentFile();
440     path = destination+File.separator +databaseName + File.separator + DatabaseConstants.TEMPDATABASE+".ddb";
441     File f1 = new File(path);
442     f1.delete();
443     ff1.delete();
444   }
445
446   /**
447    * private method to check if SystemDatabase is Complete
448    * @throws DException DSE5543 if system database is corrupt
449    */

450
451   private void checkDatabase(PersistentDatabase pd) throws DException{
452     byte[] bytes = pd.readBytes(pd.getDatabaseProperties().ISCOMPLETE_BIT_IN_DATABASE, 1);
453     Boolean JavaDoc isComplete = CCzufDpowfsufs.getBoolean(bytes);
454     if (!isComplete.booleanValue()) {
455       throw new DException("DSE5543", null);
456     }
457   }
458
459   /**
460    * Copies database files from source path to the destination path
461    * If multiFileSupport exists and multiple files (.dat) exists at the source path then
462    * copies all the multipleFiles to the destination with the databaseNameDestination
463    * takes the randomaccessFile from the map present in DRandomAccessFile of the source
464    * and copies this file
465    * else copies only .ddb file
466    *
467    * @param sourceFile randomaccessfile of the source to be copied
468    * @param multiFileMap map of the loaded multile files present in the DRandom access file of the source
469    * @param multiFileIndex no of multiple files present in the database including .ddb file
470    * @throws DException
471    */

472
473   private void copyDatabase(RandomAccessFile sourceFile ,String JavaDoc destinationPath, String JavaDoc destination,String JavaDoc databaseNameSource,String JavaDoc databaseNameDestination,boolean isMultiFileSupport,HashMap JavaDoc multiFileMap,int multiFileIndex ) throws DException {
474     ArrayList multiFilesCopied = new ArrayList();
475     File df = new File(destinationPath,databaseNameDestination);
476     if(!df.getName().equals(databaseNameDestination))
477       throw new DException("DSE2049",new Object JavaDoc[] {databaseNameDestination});
478     df = new File(destinationPath);
479     File df1 = df.getParentFile();
480     df1.mkdirs();
481     try {
482       CopyFile cf = new CopyFile();
483       if(!isMultiFileSupport){
484         RandomAccessFile DestinationFile = new RandomAccessFile(df, "rw");
485         cf.copyFile(sourceFile, DestinationFile);
486       }
487       else{
488         Set set = multiFileMap.entrySet();
489         Iterator i = set.iterator();
490         destinationPath = destinationPath.substring(0,destinationPath.lastIndexOf(File.separator));
491         while(i.hasNext()){
492           Map.Entry JavaDoc m=(Map.Entry JavaDoc)i.next();
493           String JavaDoc multiFileName = (String JavaDoc) m.getKey();
494           RandomAccessFile multiFile = (RandomAccessFile) m.getValue();
495           if(multiFile != null){
496             multiFilesCopied.add(multiFileName);
497             String JavaDoc indexOfMultiFile ;
498             String JavaDoc name = "";
499
500             if (multiFileName.equalsIgnoreCase(databaseNameSource)) {
501               name = databaseNameDestination + ".ddb";
502             }
503             else{
504               if(versionHandler.getDbVersion() > 3.2)
505                 name = multiFileName+".dat";
506               else{
507                 indexOfMultiFile = multiFileName.substring( databaseNameSource.length(), multiFileName.length());
508                 name = databaseNameDestination + indexOfMultiFile + ".dat";
509               }
510             }
511             String JavaDoc destinationPath1 = destinationPath + File.separator + name;
512             RandomAccessFile DestinationFile1 = new RandomAccessFile(new File(
513                 destinationPath1), "rw");
514             cf.copyFile(multiFile, DestinationFile1);
515           }
516         }
517         for (int j =1; j < multiFileIndex; j++) {
518           String JavaDoc multiFileName;
519           if(versionHandler.getDbVersion() > 3.2)
520             multiFileName = "_"+j;
521           else
522            multiFileName = databaseNameSource+j;
523           if(multiFilesCopied.contains(multiFileName)){
524             continue;
525           }
526           File multiFileSource = new File(ss.getDaffodilHome()+File.separator+databaseNameSource+File.separator+ multiFileName+".dat");
527           RandomAccessFile multiFile = new RandomAccessFile(multiFileSource,"rw");
528           String JavaDoc name;
529          if(versionHandler.getDbVersion() > 3.2)
530            name = "_"+j+".dat";
531          else
532            name = databaseNameDestination+j+".dat";
533
534           String JavaDoc destinationPath1 = destinationPath + File.separator + name;
535           RandomAccessFile DestinationFile1 = new RandomAccessFile(new File(destinationPath1),"rw");
536           cf.copyFile(multiFile,DestinationFile1);
537           DestinationFile1.close();
538         }
539       }
540
541     }
542     catch (Exception JavaDoc ex) {
543       throw new DException("DSE0",new Object JavaDoc[] {ex.getMessage()});
544     }
545   }
546 }
547
Popular Tags