Holger's
Java API

com.antelmann.sql
Class JDBCBackup

java.lang.Object
  extended by com.antelmann.sql.JDBCBackup

public class JDBCBackup
extends Object

allows to perform a backup/restore operation on a JDBC connection. Only the data will be backed up (in form of serialized Map instances). A restore will only work on already existing table structures. In case of foreign key constrains, be careful to use the right order of tables for backup operations. This implementation uses serialized objects, so that even BLOBs are supported.

Since:
02.10.2008, 15:53:31
Author:
Holger Antelmann
See Also:
ConnectionHelper, ObjectOutputStream, ObjectInputStream

Nested Class Summary
protected static class JDBCBackup.TableBegin
          used to store the table name uniquely recognizable into the backup stream
protected static class JDBCBackup.TableEnd
          used to mark the end of a table for the backup stream
 
Constructor Summary
JDBCBackup(Connection con)
           
 
Method Summary
 void backup(File file, String... tables)
           
 void backup(OutputStream out, Logger logger, Monitor mon, String... tables)
          performs a backup of the table rows for the given table names to the given stream
 void backup(OutputStream out, String... tables)
           
 void copyTo(Connection target, Logger logger, Monitor backupMonitor, Monitor restoreMonitor, String... tables)
          instead of just making a backup, the data is directly transferred to the target.
 void deleteRowsInOppositeOrder(String... tableNames)
          deletes all tables in opposite order, so that the deletion logic is consistent to the table names provided with backup(File, String...).
 void restore(File file)
           
 void restore(InputStream in)
           
 void restore(InputStream in, Monitor mon, Logger logger, boolean continueOnInsertionError)
          note that before you run the restore, the relevant tables should ideally be made empty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCBackup

public JDBCBackup(Connection con)
Method Detail

copyTo

public void copyTo(Connection target,
                   Logger logger,
                   Monitor backupMonitor,
                   Monitor restoreMonitor,
                   String... tables)
            throws SQLException,
                   IOException
instead of just making a backup, the data is directly transferred to the target. Before the tables are restored in the target connection, the given tables are emptied. The method returns only after the restore operation finished.

Parameters:
target - the target connection the data is to be written to
logger - for logging purposes
backupMonitor - allows to monitor/cancel the backup operation
restoreMonitor - allows to monitor/cancel the restore operation
tables - if null, all existing tables are copied; otherwise only the specified one in the given order
Throws:
SQLException
IOException

backup

public void backup(File file,
                   String... tables)
            throws SQLException,
                   IOException
Throws:
SQLException
IOException

backup

public void backup(OutputStream out,
                   String... tables)
            throws SQLException,
                   IOException
Throws:
SQLException
IOException

backup

public void backup(OutputStream out,
                   Logger logger,
                   Monitor mon,
                   String... tables)
            throws SQLException,
                   IOException
performs a backup of the table rows for the given table names to the given stream

Parameters:
out - the stream the data is to be written to
logger - for logging purposes
mon - allows to monitor and cancel the operation
tables - if null or empty, all tables of the given connection will be backed up in the order returned by ConnectionHelper.getTableNames()
Throws:
SQLException - when accessing the database fails
IOException - when writing to the stream fails

restore

public void restore(File file)
             throws SQLException,
                    IOException
Throws:
SQLException
IOException

restore

public void restore(InputStream in)
             throws SQLException,
                    IOException
Throws:
SQLException
IOException

deleteRowsInOppositeOrder

public void deleteRowsInOppositeOrder(String... tableNames)
                               throws SQLException
deletes all tables in opposite order, so that the deletion logic is consistent to the table names provided with backup(File, String...). Normally, this method would be used before restoring an already filled database.

Parameters:
tableNames - if null, all tables will be deleted according to ConnectionHelper.getTableNames()
Throws:
SQLException

restore

public void restore(InputStream in,
                    Monitor mon,
                    Logger logger,
                    boolean continueOnInsertionError)
             throws SQLException,
                    IOException
note that before you run the restore, the relevant tables should ideally be made empty

Throws:
SQLException
IOException
See Also:
deleteRowsInOppositeOrder(String...)


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads