net.sourceforge.jdbdump.dump
Interface DumpFileManager

All Known Implementing Classes:
BinaryFileManager, PlainTextFileManager

public interface DumpFileManager

A class that can save dumps into a file and then load them back again into memory.

After a Dump object is created using DatabaseConnection.dump(), it can be saved into a file using a DumpFileManager. A Dump only contains database structure, not data, because the amount of data may be so big that it will not fit into the memory. So when a Dump is exported using exportDump(), first all information contained in it is saved, and then the Dump is used to download the rest of the data from the database.

The same is with loading a dump - first its structure is loaded into a Dump object using importDump(), and then in restore() all data is read from the same file after the structure is created in the database.

Usage example:

 DatabaseConnectorFactory fac = DatabaseConnectorFactory.getInstance();
 DatabaseConnector conn = fac.createConnector("net.sourceforge.connect.connectors.MysqlConnector");
 DumpFileManager fman = new BinaryFileManager();
 try {
     // dump base1 into dump.zip 
     conn.connect("jdbc:mysql://database.myserver.com/base1", "admin", "AdMiNpAsS");
     Dump dump = conn.dump();
     fman.exportDump(dump, new File("dump.zip"), DumpFileManager.CompressionMethod.ZIP);
     conn.disconnect();
     
     // restore dump.zip into base2
     conn.connect("jdbc:mysql://database.myserver.com/base2", "admin", "AdMiNpAsS");
     Dump dump2 = fman.importDump(new File("dump.zip"), DumpFileManager.CompressionMethod.ZIP);
     conn.restore(dump2);
     dump2.closeFileReader();
     conn.disconnect();
 } catch (SQLException e) {
     e.printStackTrace();
 }
 

Author:
jsuder

Nested Class Summary
static class DumpFileManager.CompressionMethod
           
 
Method Summary
 void exportDump(Dump dump, java.io.File file, DumpFileManager.CompressionMethod compress)
          Saves a backup of the database represented in the dump object into the specified file.
 Dump importDump(java.io.File file, DumpFileManager.CompressionMethod compress)
          Loads the database structure as a Dump object from the specified file.
 

Method Detail

exportDump

void exportDump(Dump dump,
                java.io.File file,
                DumpFileManager.CompressionMethod compress)
Saves a backup of the database represented in the dump object into the specified file. First it saves the database structure which is already contained in the Dump, then uses the Dump to download all the data, table by table, record by record, and saves it into the file as soon as it's downloaded.

Parameters:
dump - a database dump created using DatabaseConnector.dump() method
file - a file in which the backup will be stored
compress - compression method used to compress the file (zip, gzip or none)

importDump

Dump importDump(java.io.File file,
                DumpFileManager.CompressionMethod compress)
Loads the database structure as a Dump object from the specified file.
This method doesn't load any data (i.e. table records) from the file yet. Data should be loaded by DatabaseConnector.restore() when the dump returned by this function is passed to it. The dump stores a reference to the input stream from this file to be able to read the data later; when it is no longer needed, it should be closed by calling closeFileReader() on the Dump (but that shouldn't be called until all data is read in DatabaseConnector.restore()).

Parameters:
file - a file from which the backup should be read
compress - compression method used to decompress the file (zip, gzip or none)
Returns:
a database dump that can be uploaded using DatabaseConnector.restore() method


Copyright © 2005-2006 AGH International University of Science and Technology. All Rights Reserved.