org.objectweb.cjdbc.controller.backup
Class Octopus

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.objectweb.cjdbc.controller.backup.Octopus
All Implemented Interfaces:
java.lang.Runnable

public class Octopus
extends java.lang.Thread

Octopus Hook Class. It has the necessary methods and fields to use octopus simply.

Author:
Nicolas Modrzyk
See Also:
OctopusConstants

Field Summary
private  boolean backupMode
           
private  java.lang.String checkpoint
           
(package private)  boolean cleanOctopus
           
(package private) static java.lang.String COPY_MODE
           
private  java.lang.String csvDir
           
private  DatabaseBackend database
           
(package private) static java.lang.String GENERATE_DOC
           
private  BackupListener listener
           
private  java.lang.String loaderJobXmlFile
           
(package private) static Trace logger
           
(package private) static java.lang.String mainDirectory
           
static int MODE_BACKUP
          Mode for backup using octopus
static int MODE_RECOVERY
          Mode for recovery using octopus
private static java.lang.String OCTOPUS_INCLUDE_HREF
           
(package private) static java.lang.String OCTOPUS_LOG_FILE
           
(package private) static int OCTOPUS_MODE_FROM_CSV
           
(package private) static int OCTOPUS_MODE_TO_CSV
           
private  java.lang.String octopusDir
           
(package private) static java.lang.String OVERRIDE_MODE
           
private  java.lang.String password
           
private  java.lang.Exception runException
           
private static java.io.PrintStream stream
           
private  java.util.ArrayList tables
           
(package private) static java.lang.String TYPE_CSV
           
private  java.lang.String user
           
(package private) static int ZIP_MODE_CREATE
           
(package private) static int ZIP_MODE_EXPAND
           
(package private)  boolean zipOctopus
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Octopus(DatabaseBackend database, java.lang.String checkpoint)
          Instanciate hook to octopus
Octopus(DatabaseBackend database, java.lang.String checkpoint, java.util.ArrayList tables)
          Use Octopus only for a set of tables
Octopus(DatabaseBackend database, java.lang.String checkpoint, java.util.ArrayList tables, boolean backupMode)
          Use Octopus only for a set of tables
Octopus(DatabaseBackend database, java.lang.String checkpoint, boolean backupMode)
          Creates a new Octopus object and sets the mode to use it as a thread
 
Method Summary
 void backup()
          Convert database to csv and zip the files
(package private)  void callOctopusLoader(java.lang.String sourceType, java.lang.String sourceUrl, java.lang.String sourceDriver, java.lang.String sourceUser, java.lang.String sourcePassword, java.lang.String targetType, java.lang.String targetDriver, java.lang.String targetUrl, java.lang.String targetUser, java.lang.String targetPassword, boolean backup, boolean generateAllVendors)
          Generate all the metadata
private  void cleanUp()
           
private  java.lang.String[] convertTablesToArray(java.util.ArrayList tablesList)
           
 boolean deleteDir(java.io.File dir)
          Delete a directory by deleting all sub files
(package private)  void generateMetadata(java.lang.String sourceType, java.lang.String sourceUrl, java.lang.String sourceDriver, java.lang.String sourceUser, java.lang.String sourcePassword, java.lang.String targetType, java.lang.String targetDriver, java.lang.String targetUrl, java.lang.String targetUser, java.lang.String targetPassword, boolean backup)
           
private  java.lang.String getDbType(java.lang.String url)
           
 java.lang.String getOctopusDirectory()
          Retrieve the path for the octopus directory
(package private)  java.util.Hashtable getOctopusStrings(DatabaseBackend database)
           
 java.lang.Exception getRunException()
          Returns the runException value.
private  void getUserLogin()
           
 boolean isCleanOctopus()
          Returns the cleanOctopus value.
 boolean isZipOctopus()
          Returns the zipOctopus value.
private  void launchOctopus()
          This start octopus with previously generated LoaderJob file
private  void prepareOctopus(int octopusMode)
           
(package private)  void prepareOctopus(java.lang.String sourceType, java.lang.String sourceUrl, java.lang.String sourceDriver, java.lang.String sourceUser, java.lang.String sourcePassword, java.lang.String targetType, java.lang.String targetDriver, java.lang.String targetUrl, java.lang.String targetUser, java.lang.String targetPassword, boolean backup)
          Prepare the loader job file for octopus
 void restore()
          Recover database from zipped csv the files
 void run()
           
 void sanityCheck()
          Check if backup can be executed.
 void setCleanOctopus(boolean cleanOctopus)
          Sets the cleanOctopus value.
 void setListener(BackupListener listener)
          Set the callback listener of this octopus process
 void setOctopusDirectory(java.lang.String path)
          Set the default path of octopus directory to a new one
private  void setOctopusLoaderJob()
           
 void setOctopusMode(boolean backup)
          When used as a thread Octopus need the mode to run in
private  void setPaths()
           
 void setZipOctopus(boolean zipOctopus)
          Sets the zipOctopus value.
private  void zipOctopus(int zipMode)
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OCTOPUS_INCLUDE_HREF

private static final java.lang.String OCTOPUS_INCLUDE_HREF
See Also:
Constant Field Values

logger

static Trace logger

TYPE_CSV

static final java.lang.String TYPE_CSV
See Also:
Constant Field Values

COPY_MODE

static final java.lang.String COPY_MODE
See Also:
Constant Field Values

OVERRIDE_MODE

static final java.lang.String OVERRIDE_MODE
See Also:
Constant Field Values

GENERATE_DOC

static final java.lang.String GENERATE_DOC
See Also:
Constant Field Values

OCTOPUS_LOG_FILE

static final java.lang.String OCTOPUS_LOG_FILE
See Also:
Constant Field Values

cleanOctopus

boolean cleanOctopus

zipOctopus

boolean zipOctopus

ZIP_MODE_CREATE

static final int ZIP_MODE_CREATE
See Also:
Constant Field Values

ZIP_MODE_EXPAND

static final int ZIP_MODE_EXPAND
See Also:
Constant Field Values

OCTOPUS_MODE_FROM_CSV

static final int OCTOPUS_MODE_FROM_CSV
See Also:
Constant Field Values

OCTOPUS_MODE_TO_CSV

static final int OCTOPUS_MODE_TO_CSV
See Also:
Constant Field Values

MODE_BACKUP

public static final int MODE_BACKUP
Mode for backup using octopus

See Also:
Constant Field Values

MODE_RECOVERY

public static final int MODE_RECOVERY
Mode for recovery using octopus

See Also:
Constant Field Values

database

private DatabaseBackend database

user

private java.lang.String user

password

private java.lang.String password

checkpoint

private java.lang.String checkpoint

octopusDir

private java.lang.String octopusDir

csvDir

private java.lang.String csvDir

loaderJobXmlFile

private java.lang.String loaderJobXmlFile

tables

private java.util.ArrayList tables

stream

private static java.io.PrintStream stream

mainDirectory

static java.lang.String mainDirectory

backupMode

private boolean backupMode

runException

private java.lang.Exception runException

listener

private BackupListener listener
Constructor Detail

Octopus

public Octopus(DatabaseBackend database,
               java.lang.String checkpoint)
        throws BackupException
Instanciate hook to octopus

Parameters:
database - backend to manipulate with octopus
checkpoint - to name files
Throws:
BackupException - if fails

Octopus

public Octopus(DatabaseBackend database,
               java.lang.String checkpoint,
               boolean backupMode)
        throws BackupException
Creates a new Octopus object and sets the mode to use it as a thread

Parameters:
database - the DatabaseBackend object to process
checkpoint - the checkpoint to use for name of backup
backupMode - true if we should backup, false if we should restore
Throws:
BackupException - if fails (not due to Octopus)

Octopus

public Octopus(DatabaseBackend database,
               java.lang.String checkpoint,
               java.util.ArrayList tables,
               boolean backupMode)
        throws BackupException
Use Octopus only for a set of tables

Parameters:
database - backend to manipulate with octopus
checkpoint - to name files
tables - on which we should use Octopus
backupMode - true if we should backup, false if we should restore
Throws:
BackupException - if fails

Octopus

public Octopus(DatabaseBackend database,
               java.lang.String checkpoint,
               java.util.ArrayList tables)
        throws BackupException
Use Octopus only for a set of tables

Parameters:
database - backend to manipulate with octopus
checkpoint - to name files
tables - on which we should use Octopus
Throws:
BackupException - if fails
Method Detail

getRunException

public java.lang.Exception getRunException()
Returns the runException value.

Returns:
Returns the runException.

setOctopusDirectory

public final void setOctopusDirectory(java.lang.String path)
Set the default path of octopus directory to a new one

Parameters:
path - of the directory

getOctopusDirectory

public final java.lang.String getOctopusDirectory()
Retrieve the path for the octopus directory

Returns:
string

backup

public void backup()
            throws BackupException,
                   OctopusException
Convert database to csv and zip the files

Throws:
BackupException - if failure is not due to octopus
OctopusException - if failure is due to octopus

restore

public void restore()
             throws BackupException,
                    OctopusException
Recover database from zipped csv the files

Throws:
BackupException - if failure is not due to octopus
OctopusException - if failure is due to octopus

setOctopusMode

public void setOctopusMode(boolean backup)
When used as a thread Octopus need the mode to run in

Parameters:
backup - if true, when run will start a backup process, otherwise will start a restore process

run

public void run()
See Also:
Runnable.run()

getUserLogin

private void getUserLogin()

setPaths

private void setPaths()
               throws BackupException
Throws:
BackupException

sanityCheck

public void sanityCheck()
                 throws BackupException
Check if backup can be executed.

Throws:
BackupException - if backend cannot be used for backup

setOctopusLoaderJob

private void setOctopusLoaderJob()
                          throws OctopusException,
                                 BackupException
Throws:
OctopusException
BackupException

launchOctopus

private void launchOctopus()
                    throws OctopusException
This start octopus with previously generated LoaderJob file

Throws:
OctopusException - if octopus fails

cleanUp

private void cleanUp()

deleteDir

public boolean deleteDir(java.io.File dir)
Delete a directory by deleting all sub files

Parameters:
dir - to delete
Returns:
true if success, false otherwise

zipOctopus

private void zipOctopus(int zipMode)
                 throws BackupException
Throws:
BackupException

getDbType

private java.lang.String getDbType(java.lang.String url)
                            throws BackupException
Throws:
BackupException

prepareOctopus

private void prepareOctopus(int octopusMode)
                     throws BackupException,
                            OctopusException
Throws:
BackupException
OctopusException

getOctopusStrings

final java.util.Hashtable getOctopusStrings(DatabaseBackend database)
                                     throws BackupException
Throws:
BackupException

generateMetadata

final void generateMetadata(java.lang.String sourceType,
                            java.lang.String sourceUrl,
                            java.lang.String sourceDriver,
                            java.lang.String sourceUser,
                            java.lang.String sourcePassword,
                            java.lang.String targetType,
                            java.lang.String targetDriver,
                            java.lang.String targetUrl,
                            java.lang.String targetUser,
                            java.lang.String targetPassword,
                            boolean backup)
                     throws OctopusException
Throws:
OctopusException

prepareOctopus

final void prepareOctopus(java.lang.String sourceType,
                          java.lang.String sourceUrl,
                          java.lang.String sourceDriver,
                          java.lang.String sourceUser,
                          java.lang.String sourcePassword,
                          java.lang.String targetType,
                          java.lang.String targetDriver,
                          java.lang.String targetUrl,
                          java.lang.String targetUser,
                          java.lang.String targetPassword,
                          boolean backup)
                   throws OctopusException
Prepare the loader job file for octopus

Throws:
OctopusException

callOctopusLoader

final void callOctopusLoader(java.lang.String sourceType,
                             java.lang.String sourceUrl,
                             java.lang.String sourceDriver,
                             java.lang.String sourceUser,
                             java.lang.String sourcePassword,
                             java.lang.String targetType,
                             java.lang.String targetDriver,
                             java.lang.String targetUrl,
                             java.lang.String targetUser,
                             java.lang.String targetPassword,
                             boolean backup,
                             boolean generateAllVendors)
                      throws OctopusException
Generate all the metadata

Throws:
OctopusException

convertTablesToArray

private java.lang.String[] convertTablesToArray(java.util.ArrayList tablesList)

isCleanOctopus

public boolean isCleanOctopus()
Returns the cleanOctopus value.

Returns:
Returns the cleanOctopus.

setCleanOctopus

public void setCleanOctopus(boolean cleanOctopus)
Sets the cleanOctopus value.

Parameters:
cleanOctopus - The cleanOctopus to set.

isZipOctopus

public boolean isZipOctopus()
Returns the zipOctopus value.

Returns:
Returns the zipOctopus.

setZipOctopus

public void setZipOctopus(boolean zipOctopus)
Sets the zipOctopus value.

Parameters:
zipOctopus - The zipOctopus to set.

setListener

public void setListener(BackupListener listener)
Set the callback listener of this octopus process

Parameters:
listener - this thread will call the callback method on this object


Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.