net.sourceforge.jdbdump.dump
Class Dump

java.lang.Object
  extended by net.sourceforge.jdbdump.dump.Dump
All Implemented Interfaces:
java.io.Serializable

public class Dump
extends java.lang.Object
implements java.io.Serializable

Represents the entire database structure downloaded into memory.

A typical process of dumping a database looks like the following:

  1. gui class creates a DatabaseConnector and connects it using connect()
  2. gui calls DatabaseConnector.dump(), which creates a Dump
  3. then it calls DumpFileManager.exportDump(dump), which saves it and its data to a file
  4. finally, it disconnects DatabaseConnector using disconnect()
And a process of restoring a database looks like the following:
  1. gui class creates a DatabaseConnector and connects it using connect()
  2. then it calls DumpFileManager.importDump() which reads the dump back from a file
  3. then it calls DatabaseConnector.restore(dump), which uploads the dump and its data into a database
  4. finally, it disconnects DatabaseConnector using disconnect(), and closes the input file using Dump.closeFileReader()

It is important to know that when the dump object is constructed, either by dump() or importDump(), it doesn't mean that it already contains all the data it needs. To minimize memory usage, Dump stores only database structure, but not its data. The data is read from a file or database later, in exportDump() or restore(), and copied on the fly to the destination place. So, when a Dump is created by dump(), the Connection object which was used to create is must be available until all the data is downloaded in exportDump(); and when a Dump is created by importDump(), the file input stream used to load it must not be closed until the data is downloaded in restore().

In both cases, the data is read by the same methods initializeData() and getDataLine() (see Table class). A Table knows where to get the data from by checking the "mode" in which its parent Dump is, which can be either "database read mode" or "file read mode". It can be set by calling setDatabaseReader(Connection c) or setFileReader(ObjectInputStream s) respectively, and can be checked by isReadingFromDatabase() method.

Author:
jsuder
See Also:
Table, DatabaseConnector, DumpFileManager, Serialized Form

Constructor Summary
Dump()
          Creates a new empty dump, which will be later filled with tables, views and other stuff...
 
Method Summary
 void closeFileReader()
          Closes the file from which dump data has been read.
 DatabaseConnector getDatabaseReader()
          Returns a DatabaseConnector used to download table data after the dump is created, if the dump is set in "read from database" mode (by calling setDatabaseReader()).
 java.io.ObjectInputStream getFileReader()
          Returns a stream which can be used to read records of table data from a backup file, if the dump is set in "read from file" mode (by calling setFileReader()).
 java.util.Vector<Table> getTables()
          Returns a list of all tables stored in the dump object.
 boolean isReadingFromDatabase()
          Tells if the dump is currently in "database read mode" or "file read mode".
 void setDatabaseReader(DatabaseConnector connection)
          Sets the dump in "database read mode", and sets the used DatabaseConnector to the one given in argument.
 void setFileReader(java.io.ObjectInputStream stream)
          Sets the dump in "file read mode", and sets the used file input stream the one given in argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Dump

public Dump()
Creates a new empty dump, which will be later filled with tables, views and other stuff...

Method Detail

getTables

public java.util.Vector<Table> getTables()
Returns a list of all tables stored in the dump object.

Returns:
a list of tables

getDatabaseReader

public DatabaseConnector getDatabaseReader()
Returns a DatabaseConnector used to download table data after the dump is created, if the dump is set in "read from database" mode (by calling setDatabaseReader()). Otherwise, returns null.

Returns:
a DatabaseConnector which created this dump

getFileReader

public java.io.ObjectInputStream getFileReader()
Returns a stream which can be used to read records of table data from a backup file, if the dump is set in "read from file" mode (by calling setFileReader()). Otherwise, returns null.

Returns:
an input stream reading records from a backup file

setDatabaseReader

public void setDatabaseReader(DatabaseConnector connection)
Sets the dump in "database read mode", and sets the used DatabaseConnector to the one given in argument.

Parameters:
connection - a DatabaseConnector which should be used to read data later

setFileReader

public void setFileReader(java.io.ObjectInputStream stream)
Sets the dump in "file read mode", and sets the used file input stream the one given in argument.

Parameters:
stream - an open file input stream which should be used to read data later

closeFileReader

public void closeFileReader()
Closes the file from which dump data has been read. Should be done after all the data is read in DatabaseConnector.restore(), but not earlier.


isReadingFromDatabase

public boolean isReadingFromDatabase()
Tells if the dump is currently in "database read mode" or "file read mode".

Returns:
true if it is in "database read mode"


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