KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.backup;
2
3 import java.io.File JavaDoc;
4 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.
5
    DatabaseConstants;
6 import java.io.RandomAccessFile JavaDoc;
7 import com.daffodilwoods.database.resource.DException;
8 import java.io.*;
9 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.
10
    DatabaseProperties;
11 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.
12
    DRandomAccessFile;
13 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.
14
    PersistentDatabase;
15 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.
16
    FileGenerator;
17 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.
18
    PersistentSystem;
19 import java.util.Properties JavaDoc;
20 import com.daffodilwoods.daffodildb.server.serversystem.ServerSystem;
21 import com.daffodilwoods.daffodildb.server.datadictionarysystem.SystemTables;
22 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._DataTable;
23 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.
24
    DatabaseUserTableIterator;
25 import com.daffodilwoods.daffodildb.utils.BufferRange;
26 import com.daffodilwoods.daffodildb.utils.byteconverter.CCzufDpowfsufs;
27 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.
28
    _TableCharacteristics;
29 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Utility;
30 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._DatabaseUser;
31 import com.daffodilwoods.daffodildb.utils.comparator.CTusjohJoTfotjujwfDpnqbsbups;
32 import java.util.ArrayList JavaDoc;
33 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._UserTableOperations;
34
35 /**
36  *
37  * <p>Title:Backup</p>
38  * <p>Description:Class came into Picture as a result of the Backup Facility provided
39  * in DaffodilDB </p>
40  * <p>Copyright: Copyright (c) 2003</p>
41  * <p>Company: </p>
42  * @author not attributable
43  * @version 1.0
44  */

45
46   public class Backup {
47 private boolean isReadOnlyMode = false;
48   public Backup() throws DException {
49   }
50
51   /**
52    * takes backup of the database from the source to destination
53    * if SystemDatabase doesn't exist on the destination path
54    * then it simple copies SystemDatabase and for copying userDatabase
55        * it checks if the database is to be restored with same name then simply copies
56    * files form source path to the destination path
57    * else it first removes the entry from the system database for the sourceDatabaseName
58    * and then calls createDatabase with the new name.
59    * else it checks if userDatabase already exists at the destination
60    * if it exists there there then first we remove the existing database and then give call to create database
61    * -> if overwrite option is true
62    * -> else throw exception that Database already exists on the given path
63    * else it simply gives call to createDatabase method
64    *
65    * @param path source path from which the database is to be taken
66    * @param destination path at which backup is taken
67    * @param databaseNameSource name of the source database for taking backup
68    * @param databaseNameDestination name of the destination database for taking backup
69    * @param overwrite boolean whether to overwrite if the databse already exists.
70    * @throws DException DSE5564 if database to be backed up is in use at source path
71    */

72
73   public void offlineBackup(String JavaDoc sourcePath, String JavaDoc destination,String JavaDoc databaseNameSource,
74                              String JavaDoc databaseNameDestination, boolean overwrite) throws DException {
75      if (sourcePath.equalsIgnoreCase(destination))
76        throw new DException("DSE5574", null);
77      checkDatabase(sourcePath,databaseNameSource);
78      if (databaseNameSource.equalsIgnoreCase(DatabaseConstants.SYSTEMDATABASE))
79        throw new DException("DSE5570", new Object JavaDoc[] {databaseNameSource});
80      if (databaseNameDestination.equalsIgnoreCase(DatabaseConstants.SYSTEMDATABASE))
81        throw new DException("DSE5571", new Object JavaDoc[] {databaseNameDestination});
82
83   RandomAccessFile JavaDoc raf = null;
84   ServerSystem ss = null;
85    try {
86      raf = checkDatabaseInUse(sourcePath);
87      String JavaDoc systemDatabaseSourcePath = sourcePath + File.separator +
88          DatabaseConstants.SYSTEMDATABASE + File.separator +
89          DatabaseConstants.SYSTEMDATABASE + ".ddb";
90      String JavaDoc systemDatabaseDestinationPath = destination + File.separator +
91          DatabaseConstants.SYSTEMDATABASE + File.separator +
92          DatabaseConstants.SYSTEMDATABASE + ".ddb";
93      File JavaDoc ff = new File JavaDoc(systemDatabaseSourcePath);
94      File JavaDoc df = new File JavaDoc(systemDatabaseDestinationPath);
95      if (!df.exists()) {
96        copyDatabase(systemDatabaseSourcePath, systemDatabaseDestinationPath,
97                     destination, databaseNameDestination);
98        ss = new ServerSystem(destination);
99        PersistentSystem ps = new PersistentSystem(destination,isReadOnlyMode);
100        PersistentDatabase pd = (PersistentDatabase) ps.getDatabase(DatabaseConstants.SYSTEMDATABASE);
101        _DataTable databaseInfoTable = (_DataTable) pd.getTable(SystemTables.DATABASEINFO);
102        DatabaseUserTableIterator databaseTableIteartor = (DatabaseUserTableIterator) databaseInfoTable.getIterator();
103        ArrayList JavaDoc list = new ArrayList JavaDoc();
104        list.add(SystemTables.DATABASEINFO);
105        _DatabaseUser user = pd.getDatabaseUser(list);
106
107        if (databaseTableIteartor.first()) {
108          do {
109            databaseTableIteartor.delete(user);
110          }
111          while (databaseTableIteartor.next());
112        }
113        user.writeToFile();
114        createDatabase(sourcePath, destination, databaseNameSource,
115                         databaseNameDestination);
116      }
117      else {
118        ss = new ServerSystem(destination);
119        PersistentSystem ps = new PersistentSystem(destination,isReadOnlyMode);
120        PersistentDatabase pd = (PersistentDatabase) ps.getDatabase(
121            DatabaseConstants.SYSTEMDATABASE);
122        checkDatabase(pd);
123        try {
124          pd = (PersistentDatabase) ps.getDatabase(databaseNameDestination);
125          if (pd != null && overwrite) {
126            ps.removeDatabase(databaseNameDestination);
127            ps.dropDatabase(databaseNameDestination);
128            createDatabase(sourcePath, destination, databaseNameSource,
129                           databaseNameDestination);
130          }
131          else {
132            throw new DException("DSE5567", new Object JavaDoc[]{databaseNameDestination});
133          }
134        }
135        catch (DException ex) {
136          if (ex.getDseCode().equalsIgnoreCase("DSE316"))
137            createDatabase(sourcePath, destination, databaseNameSource,
138                           databaseNameDestination);
139          else
140            throw ex;
141        }
142      }
143    }
144    finally {
145      try {
146        if (raf != null)
147          raf.close();
148      }
149      catch (Exception JavaDoc e) {
150        throw new DException("DSE5564", new Object JavaDoc[] {e.getMessage()});
151      }
152    }
153 }
154
155   /**
156    * if userDatabse exists at the destination then first drop the database and then give call for create database
157    * if overwrite option is true else throws exception that database to be backed up
158    * already exists on the destination path
159    * else it just copies the file from source path to destination path
160    *
161    * @param path source path from which the database is to be taken
162    * @param destination path at which backup is taken
163    * @param databaseNameSource name of the database in the source
164    * @param databaseNameDestination name of the database with which it is to be restored or backed up
165    * @param ifExists is true if the userDatabse already exists at the path
166    */

167
168   private void offLineBackupUserDatabase(String JavaDoc sourcePath, String JavaDoc destination,
169                                          String JavaDoc databaseNameSource,
170                                          String JavaDoc databaseNameDestination,
171                                          boolean ifExists, boolean overwrite) throws
172       DException {
173
174     if (!ifExists) {
175       String JavaDoc userDatabaseSourcePath = sourcePath + File.separator + databaseNameSource +
176           File.separator + databaseNameSource + ".ddb";
177       String JavaDoc userDatabaseDestinationPath = destination + File.separator +
178           databaseNameDestination + File.separator + databaseNameDestination +
179           ".ddb";
180       copyDatabase(userDatabaseSourcePath, userDatabaseDestinationPath, destination,
181                              databaseNameDestination);
182     }
183     else {
184       ServerSystem ss = new ServerSystem(destination);
185       PersistentSystem ps = new PersistentSystem(destination,isReadOnlyMode);
186       PersistentDatabase pd = null;
187       try {
188         pd = (PersistentDatabase) ps.getDatabase(databaseNameDestination);
189         if (pd != null && overwrite) {
190           ps.removeDatabase(databaseNameDestination);
191           ps.dropDatabase(databaseNameDestination);
192           createDatabase(sourcePath, destination, databaseNameSource,
193                          databaseNameDestination);
194         }
195         else
196           throw new DException("DSE5567", new Object JavaDoc[]{databaseNameDestination});
197       }
198       catch (DException ex) {
199         if (ex.getDseCode().equalsIgnoreCase("DSE316"))
200           createDatabase(sourcePath, destination, databaseNameSource,
201                          databaseNameDestination);
202         else
203           throw ex;
204       }
205     }
206   }
207
208   /**
209    * Creates database at the destination it takes properties of the database from the
210    * source SystemDatabase and then creates Database with these properties it also modifies
211    * the SystemTable DATABASEFILEINFO.
212    * Gives call for creation of database and then delete the files on the path and then just copy the files from source to destination.
213    * by giving call to offlineBackupUserDatabase.
214    *
215    * @param path source path from which the database is to be taken
216    * @param destination path at which backup is taken
217    * @param databaseNameSource name of the database in the source
218    * @param databaseNameDestination name of the database with which it is to be restored or backed up
219    *
220    */

221   private void createDatabase(String JavaDoc sourcePath, String JavaDoc destination,
222                               String JavaDoc databaseNameSource,
223                               String JavaDoc databaseNameDestination) throws DException {
224     int index = 0;
225     ServerSystem ss = new ServerSystem(sourcePath);
226     PersistentSystem ps = new PersistentSystem(sourcePath,isReadOnlyMode);
227     PersistentDatabase systemDatabaseSourcePath = (PersistentDatabase)ps.getDatabase(DatabaseConstants.SYSTEMDATABASE);
228     _DataTable databaseInfoTable = (_DataTable) systemDatabaseSourcePath.getTable(SystemTables.
229         DATABASEINFO);
230     DatabaseUserTableIterator databaseTableIteartor = (
231         DatabaseUserTableIterator) databaseInfoTable.getIterator();
232     Object JavaDoc[] databaseProperties = null;
233     BufferRange bytesOfDestinationDatabaseName = new BufferRange(CCzufDpowfsufs.
234         getBytes(databaseNameDestination, databaseNameDestination.length(), false));
235     BufferRange bytesOfSourceDatabaseName = new BufferRange(CCzufDpowfsufs.
236         getBytes(databaseNameSource, databaseNameSource.length(), false));
237    CTusjohJoTfotjujwfDpnqbsbups stringComparator = new CTusjohJoTfotjujwfDpnqbsbups();
238
239    if (databaseTableIteartor.first())
240       do {
241         BufferRange[] bytesGot = (BufferRange[]) databaseTableIteartor.
242             getColumnValues();
243         if (stringComparator.compare(bytesGot[0], bytesOfSourceDatabaseName) ==
244             0) {
245           _TableCharacteristics tableCharacteristics = databaseInfoTable.
246               getTableCharacteristics();
247           databaseProperties = (Object JavaDoc[]) tableCharacteristics.getObject(
248               bytesGot);
249           break;
250         }
251       }
252       while (databaseTableIteartor.next());
253     Object JavaDoc[] databaseProps = Utility.convertIntoFieldBase(databaseProperties);
254     String JavaDoc initialSize = (String JavaDoc) databaseProps[1];
255     int incrementFactor = databaseProps[4].hashCode();
256     boolean unicodeSupport = ( (Boolean JavaDoc) databaseProps[5]).booleanValue();
257     boolean multiFilesSupport = ( (Boolean JavaDoc) databaseProps[6]).booleanValue();
258     boolean encryptionSupport = ( (Boolean JavaDoc) databaseProps[7]).booleanValue();
259     String JavaDoc encrytpionAlgo = (String JavaDoc) databaseProps[8];
260     String JavaDoc encryptionKey = (String JavaDoc) databaseProps[9];
261     String JavaDoc clusterSize = (String JavaDoc) databaseProps[10];
262     if (multiFilesSupport) {
263       DatabaseUserTableIterator databaseFileInfoIterator = (
264           DatabaseUserTableIterator) ( (_DataTable) systemDatabaseSourcePath.getTable(
265           SystemTables.DATABASEFILEINFO)).getIterator();
266       if (databaseFileInfoIterator.first())
267         do {
268           BufferRange[] bytesGot = (BufferRange[]) databaseFileInfoIterator.
269               getColumnValues();
270           if (stringComparator.compare(bytesGot[0],
271                                           bytesOfSourceDatabaseName) == 0) {
272             index = CCzufDpowfsufs.getInt(bytesGot[1].getBytes()).hashCode();
273             break;
274           }
275         }
276         while (databaseTableIteartor.next());
277     }
278
279          _DataTable table = (_DataTable) systemDatabaseSourcePath.getTable(SystemTables.SCHEDULEINFO);
280          DatabaseUserTableIterator scheduleInfoTableIteartor = (DatabaseUserTableIterator) table.getIterator();
281          ArrayList JavaDoc scheduleEntries = new ArrayList JavaDoc();
282          if (scheduleInfoTableIteartor.first())
283            do {
284              BufferRange[] bytesGot = (BufferRange[])scheduleInfoTableIteartor.getColumnValues();
285              if (stringComparator.compare(bytesGot[0],bytesOfSourceDatabaseName) == 0) {
286                scheduleEntries.add(bytesGot);
287              }
288            }
289            while (scheduleInfoTableIteartor.next());
290          ss = new ServerSystem(destination);
291          ps = new PersistentSystem(destination,isReadOnlyMode);
292          ps.createDatabase(databaseNameDestination, initialSize, incrementFactor,
293                       unicodeSupport, multiFilesSupport, encryptionSupport,
294                       encrytpionAlgo, encryptionKey, clusterSize);
295
296   if (multiFilesSupport) {
297     PersistentDatabase systemDatabaseDestinationPath = (PersistentDatabase) ps.getDatabase(
298       DatabaseConstants.SYSTEMDATABASE);
299     DatabaseUserTableIterator databaseFileInfoIterator = (
300         DatabaseUserTableIterator) ( (_DataTable) systemDatabaseDestinationPath.getTable(
301         SystemTables.DATABASEFILEINFO)).getIterator();
302     if (databaseFileInfoIterator.first())
303       do {
304         BufferRange[] bytesGot = (BufferRange[]) databaseFileInfoIterator.getColumnValues();
305         if (stringComparator.compare(bytesGot[0],bytesOfDestinationDatabaseName) == 0) {
306           _DatabaseUser user = systemDatabaseDestinationPath.getDatabaseUser();
307           databaseFileInfoIterator.update(user,
308                                           new BufferRange[] {bytesOfDestinationDatabaseName,
309                                           new
310                                           BufferRange(CCzufDpowfsufs.
311               getBytes(new Integer JavaDoc(index)))});
312           user.writeToFile();
313           break;
314         }
315       }
316       while (databaseTableIteartor.next());
317   }
318
319  if (scheduleEntries.size() > 0) {
320       PersistentDatabase systemDatabaseDestination = (PersistentDatabase) ps.getDatabase(DatabaseConstants.SYSTEMDATABASE);
321       _DataTable scheduleInfoTable = (_DataTable)systemDatabaseDestination.getTable(SystemTables.SCHEDULEINFO);
322       DatabaseUserTableIterator scheduleInfoTableIteartorDestination = (DatabaseUserTableIterator) scheduleInfoTable.getIterator();
323       ArrayList JavaDoc list = new ArrayList JavaDoc();
324       list.add(SystemTables.SCHEDULEINFO);
325       _DatabaseUser user = systemDatabaseDestination.getDatabaseUser(list);
326       for (int i = 0; i < scheduleEntries.size(); i++) {
327         BufferRange[] entry = (BufferRange[]) scheduleEntries.get(i);
328         entry[0] = bytesOfDestinationDatabaseName;
329         ( (_UserTableOperations) scheduleInfoTableIteartorDestination).insert(user,entry);
330       }
331       user.writeToFile();
332     }
333
334     deleteFiles(databaseNameDestination, destination);
335     offLineBackupUserDatabase(sourcePath, destination, databaseNameSource,
336                               databaseNameDestination, false, true);
337   }
338
339   /**
340    * Method to delete .ddb file and database folder created through create databse method before
341    * giving call to the copy file methof from source to destination
342    * @param databaseName
343    * @param destination
344    * @throws DException
345    */

346   private void deleteFiles(String JavaDoc databaseName, String JavaDoc destination) throws
347       DException {
348     String JavaDoc path = destination + File.separator + databaseName + File.separator +
349         databaseName + ".ddb";
350     File JavaDoc f = new File JavaDoc(path);
351     f.delete();
352     File JavaDoc ff1 = f.getParentFile();
353     path = destination + File.separator + databaseName + File.separator +
354         DatabaseConstants.TEMPDATABASE + ".ddb";
355     File JavaDoc f1 = new File JavaDoc(path);
356     f1.delete();
357     ff1.delete();
358   }
359
360   /**
361    * restores the database from the backup place to destination.
362    * first of all it checks that database to be restored is not in use.
363    * if SystemDatabase doesn't exist on the destination path
364    * then it simple copies SystemDatabase and for copying userDatabase
365        * it checks if the database is to be restored with same name then simply copies
366    * files form source path to the destination path
367    * else it first removes the entry from the system database for the sourceDatabaseName
368    * and then calls createDatabase with the new name.
369    * else it checks if userDatabase already exists at the destination
370    * if it exists there there then first we remove the existing database and then give call to create database
371    * -> if overwrite option is true
372    * -> else throw exception that Database already exists on the given path
373    * else it simply gives call to createDatabase method
374    *
375    * @param path source path from which the database is to be taken
376    * @param destination path at which backup is taken
377    * @param databaseNameSource name of the source database for taking backup
378    * @param databaseNameDestination name of the destination database for taking backup
379    * @param overwrite boolean whether to overwrite if the databse already exists.
380    * @throws DException DSE5566 if database to be restored alredy exists at destination path
381    */

382
383   public void RestoreBackup(String JavaDoc path, String JavaDoc destination,String JavaDoc databaseNameSource,
384                              String JavaDoc databaseNameDestination, boolean overwrite) throws DException {
385      if (databaseNameSource.equalsIgnoreCase(DatabaseConstants.SYSTEMDATABASE))
386        throw new DException("DSE5568", new Object JavaDoc[] {databaseNameSource});
387      if (databaseNameDestination.equalsIgnoreCase(DatabaseConstants.SYSTEMDATABASE))
388        throw new DException("DSE5569", new Object JavaDoc[] {databaseNameDestination});
389      try {
390       offlineBackup(path, destination, databaseNameSource,
391                     databaseNameDestination, overwrite);
392     }
393     catch (DException ex) {
394       if (ex.getDseCode().equalsIgnoreCase("DSE5567"))
395         throw new DException("DSE5566", new Object JavaDoc[]{databaseNameDestination});
396       else
397         throw ex;
398     }
399   }
400
401   /**
402    * private method to check if SystemDatabase is Complete
403    * @throws DException DSE5543 if system database is corrupt
404    */

405   private void checkDatabase(PersistentDatabase pd) throws DException {
406     byte[] bytes = pd.readBytes(pd.getDatabaseProperties().
407                                 ISCOMPLETE_BIT_IN_DATABASE, 1);
408     Boolean JavaDoc isComplete = CCzufDpowfsufs.getBoolean(bytes);
409     if (!isComplete.booleanValue()) {
410       throw new DException("DSE5543", null);
411     }
412   }
413
414   /**
415    * checks if database is in use at the source path
416    * @return arndom accessfile created on the log.lg file
417    * @throws DException DSE5564 that databse is in use if it doesn't allow to delete the log.lg file
418    * at the source path
419    */

420   private RandomAccessFile JavaDoc checkDatabaseInUse(String JavaDoc sourcePath) throws DException {
421     String JavaDoc logFile = sourcePath + File.separator + "log.lg";
422     File JavaDoc ff = new File JavaDoc(logFile);
423     boolean isDelete = false;
424     if (ff.exists()) {
425       isDelete = ff.delete();
426       if (!isDelete) {
427          ;//// Removed By Program ** System.out.println(" log file path " + logFile);
428
throw new DException("DSE5564", new Object JavaDoc[] {});
429       }
430     }
431     RandomAccessFile JavaDoc raf = null;
432     try {
433       raf = new RandomAccessFile JavaDoc(ff, "rw");
434     }
435     catch (FileNotFoundException ex) {
436     }
437     return raf;
438   }
439
440   /**
441    * Copies database files from source path to the destination path
442    * If power files exists then copies all the power files also to the destination path
443    * If multiFileSupport exists and multiple files (.dat) exists at the source path then
444    * copies all the multipleFiles to the destination with the databaseNameDestination
445    *
446    * @param sourcePath
447    * @param destinationPath
448    * @param destination
449    * @param databaseNameDestination
450    * @throws DException
451    */

452   private void copyDatabase(String JavaDoc sourcePath, String JavaDoc destinationPath, String JavaDoc destination,String JavaDoc databaseNameDestination) throws DException{
453            File JavaDoc ff = new File JavaDoc(sourcePath);
454            File JavaDoc df = new File JavaDoc(destinationPath);
455            try {
456                  File JavaDoc ff1 = ff.getParentFile();
457                  ff1.mkdirs();
458                  File JavaDoc df1 = df.getParentFile();
459                  df1.mkdirs();
460                  FileInputStream file = new FileInputStream(ff);
461                  FileOutputStream DestinationFile = new FileOutputStream(df);
462                  CopyFile cf = new CopyFile();
463                  cf.copyFile(file,DestinationFile);
464                  destinationPath = destinationPath.substring(0,destinationPath.lastIndexOf(File.separator));
465                  File JavaDoc [] files = ff1.listFiles(new PowerFileFilter());
466                  for (int i = 0; i < files.length; i++) {
467                    FileInputStream powerFile = new FileInputStream(files[i]);
468                    String JavaDoc name = files[i].getName();
469                    if(!name.startsWith("_"))
470                      name = databaseNameDestination+"_" + i +"_PowerFile.log";
471                    String JavaDoc destinationPath1 = destinationPath + File.separator + name;
472                    DestinationFile = new FileOutputStream(new File JavaDoc(destinationPath1));
473                    cf.copyFile(powerFile,DestinationFile);
474                  }
475                   files = ff1.listFiles(new MultiFileFilter());
476                  for (int i = 0; i < files.length; i++) {
477                    FileInputStream multiFile = new FileInputStream(files[i]);
478                  String JavaDoc name = files[i].getName();
479                  if(!name.startsWith("_"))
480                    name = databaseNameDestination+(i+1)+".dat";
481                  String JavaDoc destinationPath1 = destinationPath + File.separator + name;
482                  DestinationFile = new FileOutputStream(new File JavaDoc(destinationPath1));
483                  cf.copyFile(multiFile,DestinationFile);
484                  }
485                }
486                catch (Exception JavaDoc ex) {
487                  throw new DException("DSE0",new Object JavaDoc[] {ex.getMessage()});
488                }
489
490          }
491
492  /**
493   * Checks if database to be backed up exists on the source Path
494   * @param sourcePath path from which backup is taken
495   * @param databaseName database to be backed up
496   * @throws DException if Database doesn't exists on the path
497   */

498   private void checkDatabase(String JavaDoc sourcePath,String JavaDoc databaseName) throws DException {
499    String JavaDoc databaseURLSystemDatabase = sourcePath + File.separator +DatabaseConstants.SYSTEMDATABASE;
500    String JavaDoc databaseURL = sourcePath + File.separator + databaseName;
501   File JavaDoc fs = new File JavaDoc(databaseURLSystemDatabase);
502
503   if (!fs.exists())
504        throw new DException("DSE5572", new Object JavaDoc[]{sourcePath});
505   File JavaDoc f = new File JavaDoc(databaseURL);
506   if(!f.exists())
507        throw new DException("DSE5563", new Object JavaDoc[]{databaseName});
508   checkDatabaseEntryInSystemDatabase(sourcePath,databaseName);
509  }
510
511  /**
512   * checks if entry of user database exists in systemDatabase else
513   * throws exception that databases are incompatible
514   * @param sourcePath
515   * @param userDatabase
516   * @throws DException DSE5573 that databases are incompatible
517   */

518 private void checkDatabaseEntryInSystemDatabase(String JavaDoc sourcePath,String JavaDoc userDatabase) throws DException{
519    ServerSystem ss1 = new ServerSystem(sourcePath);
520    PersistentSystem ps = new PersistentSystem(sourcePath,isReadOnlyMode);
521   try {
522     PersistentDatabase pd = (PersistentDatabase) ps.getDatabase(userDatabase);
523   }
524   catch (DException ex) {
525     if (ex.getDseCode().equalsIgnoreCase("DSE316"))
526       throw new DException("DSE5573",new Object JavaDoc[]{userDatabase});
527   }
528  }
529
530
531  class PowerFileFilter
532      implements FilenameFilter {
533    public boolean accept(File JavaDoc dir, String JavaDoc name) {
534      return name.endsWith("PowerFile.log") ? true
535          : false;
536    }
537  }
538
539  class MultiFileFilter
540      implements FilenameFilter {
541    public boolean accept(File JavaDoc dir, String JavaDoc name) {
542      return name.endsWith(".dat") ? true
543          : false;
544    }
545  }
546
547 }
548
Popular Tags