org.opengts.dbtools
Class DBAdmin

java.lang.Object
  extended by org.opengts.dbtools.DBAdmin

public class DBAdmin
extends java.lang.Object

DBAdmin provides database administrative functionality


Nested Class Summary
static class DBAdmin.DBAdminExec
          "DBAdmin.execCommands()" return status enumerated type
 
Field Summary
static java.lang.String[] ARG_BEAN
           
static java.lang.String[] ARG_COLUMNS
           
static java.lang.String[] ARG_CREATE_DB
           
static java.lang.String[] ARG_DB
           
static java.lang.String[] ARG_DIR
           
static java.lang.String[] ARG_DROP
           
static java.lang.String[] ARG_DUMP
           
static java.lang.String[] ARG_GRANT
           
static java.lang.String[] ARG_LAST
           
static java.lang.String[] ARG_LOAD
           
static java.lang.String[] ARG_NODROPWARN
           
static java.lang.String[] ARG_NOINSERT
           
static java.lang.String[] ARG_OVERWRITE
           
static java.lang.String[] ARG_ROOT_PASS
           
static java.lang.String[] ARG_ROOT_USER
           
static java.lang.String[] ARG_SCHEMA
           
static java.lang.String[] ARG_TABLENAME
           
static java.lang.String[] ARG_TABLES
           
static java.lang.String[] ARG_VALIDATE
           
static java.lang.String[] ARG_WHERE
           
static int VALIDATE_ACTUAL_RECORD_COUNT
           
static int VALIDATE_ADD_COLUMNS
           
static int VALIDATE_ALTER_COLUMNS
           
static int VALIDATE_CHECK_ENCODING
           
static int VALIDATE_CREATE_TABLE
           
static int VALIDATE_DISPLAY_DB_ENGINE
           
static int VALIDATE_DISPLAY_ERRORS
           
static int VALIDATE_DISPLAY_WARNINGS
           
static int VALIDATE_EXCLUDE_NAMED_TABLE
           
static int VALIDATE_NAMED_TABLE_ONLY
           
static int VALIDATE_REBUILD_KEYS
           
static int VALIDATE_SHOW_COLUMNS
           
 
Method Summary
protected static DBFactory<? extends DBRecord> _createDBRecordFactory(java.lang.String className, boolean isRequired)
          Returns the DBFactory instance for the specified class.
This assumes that the DBRecord subclass represented by the specified class name implements the static method "getFactory()".
static void addTableFactory(DBFactory<? extends DBRecord> factory)
          Adds the specified table to the table name/factory map
static boolean addTableFactory(java.lang.String className, boolean isRequired)
          Loads the DBFactory for the specified DBRecord classname, and adds it to the table name/factory map This assumes that the DBRecord subclass represented by the specified class name implements the static method "getFactory()".
static DBAdmin.DBAdminExec execCommands()
          Execute command defined in the runtime-config properties (RTConfig)
static DBFactory<? extends DBRecord>[] getChildTableFactories(DBFactory<? extends DBRecord> parentFactory)
          Gets all child/dependent table factories for the specified table factory
static java.io.File getDumpDirectory()
          Creates and returns the default dump file directory
static DBFactory<? extends DBRecord> getTableFactory(java.lang.String utableName)
          Returns the table factory for the specified table name
static int getTableFactoryCount()
          Returns the number of registered DBFactory classes
static OrderedMap<java.lang.String,DBFactory<? extends DBRecord>> getTableFactoryMap()
          Returns a map of all defined table names to their table DBFactory
static java.lang.String getTableNameProperCase(java.lang.String utableName)
          Returns the proper case of the specified table name.
static boolean hasTableFactory(java.lang.String utableName)
          Returns true if the spcified table name has been defined
static boolean includeFieldInFactory(DBFactory fact, DBField field)
          Provides the opportunity for the DBAdmin to decide whether or not the specified DBField should be added/included in the DBFactory.
static void main(java.lang.String[] argv)
          Main entry point
static void printTableColumns(int docWidth, java.lang.String[] header, java.lang.String utableName)
          Print the database schema for the managed tables
static void printTableSchema(int docWidth, java.lang.String[] header, java.lang.String utableName)
          Print the database schema for the managed tables
static boolean verifyTablesExist()
          Verify that all defined tables actually exist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALIDATE_CREATE_TABLE

public static final int VALIDATE_CREATE_TABLE
See Also:
Constant Field Values

VALIDATE_ADD_COLUMNS

public static final int VALIDATE_ADD_COLUMNS
See Also:
Constant Field Values

VALIDATE_ALTER_COLUMNS

public static final int VALIDATE_ALTER_COLUMNS
See Also:
Constant Field Values

VALIDATE_REBUILD_KEYS

public static final int VALIDATE_REBUILD_KEYS
See Also:
Constant Field Values

VALIDATE_CHECK_ENCODING

public static final int VALIDATE_CHECK_ENCODING
See Also:
Constant Field Values

VALIDATE_DISPLAY_ERRORS

public static final int VALIDATE_DISPLAY_ERRORS
See Also:
Constant Field Values

VALIDATE_DISPLAY_WARNINGS

public static final int VALIDATE_DISPLAY_WARNINGS
See Also:
Constant Field Values

VALIDATE_SHOW_COLUMNS

public static final int VALIDATE_SHOW_COLUMNS
See Also:
Constant Field Values

VALIDATE_NAMED_TABLE_ONLY

public static final int VALIDATE_NAMED_TABLE_ONLY
See Also:
Constant Field Values

VALIDATE_EXCLUDE_NAMED_TABLE

public static final int VALIDATE_EXCLUDE_NAMED_TABLE
See Also:
Constant Field Values

VALIDATE_DISPLAY_DB_ENGINE

public static final int VALIDATE_DISPLAY_DB_ENGINE
See Also:
Constant Field Values

VALIDATE_ACTUAL_RECORD_COUNT

public static final int VALIDATE_ACTUAL_RECORD_COUNT
See Also:
Constant Field Values

ARG_ROOT_USER

public static final java.lang.String[] ARG_ROOT_USER

ARG_ROOT_PASS

public static final java.lang.String[] ARG_ROOT_PASS

ARG_CREATE_DB

public static final java.lang.String[] ARG_CREATE_DB

ARG_GRANT

public static final java.lang.String[] ARG_GRANT

ARG_DB

public static final java.lang.String[] ARG_DB

ARG_DIR

public static final java.lang.String[] ARG_DIR

ARG_LOAD

public static final java.lang.String[] ARG_LOAD

ARG_DROP

public static final java.lang.String[] ARG_DROP

ARG_TABLES

public static final java.lang.String[] ARG_TABLES

ARG_TABLENAME

public static final java.lang.String[] ARG_TABLENAME

ARG_SCHEMA

public static final java.lang.String[] ARG_SCHEMA

ARG_COLUMNS

public static final java.lang.String[] ARG_COLUMNS

ARG_DUMP

public static final java.lang.String[] ARG_DUMP

ARG_WHERE

public static final java.lang.String[] ARG_WHERE

ARG_VALIDATE

public static final java.lang.String[] ARG_VALIDATE

ARG_LAST

public static final java.lang.String[] ARG_LAST

ARG_NOINSERT

public static final java.lang.String[] ARG_NOINSERT

ARG_OVERWRITE

public static final java.lang.String[] ARG_OVERWRITE

ARG_NODROPWARN

public static final java.lang.String[] ARG_NODROPWARN

ARG_BEAN

public static final java.lang.String[] ARG_BEAN
Method Detail

_createDBRecordFactory

protected static DBFactory<? extends DBRecord> _createDBRecordFactory(java.lang.String className,
                                                                      boolean isRequired)
Returns the DBFactory instance for the specified class.
This assumes that the DBRecord subclass represented by the specified class name implements the static method "getFactory()".

Parameters:
className - The class name of the DBRecord subclass
isRequired - True if this class must be resolved (any errors will be displayed), false if it is optional (errors may be quietly ignored).
Returns:
The returned DBFactory instance, or null if unable to load the specifid DBFactory

addTableFactory

public static boolean addTableFactory(java.lang.String className,
                                      boolean isRequired)
Loads the DBFactory for the specified DBRecord classname, and adds it to the table name/factory map This assumes that the DBRecord subclass represented by the specified class name implements the static method "getFactory()".

Parameters:
className - The class name of the DBRecord subclass
isRequired - True if this class must be resolved, false if it is optional
Returns:
True if the DBFactory was succesfully loaded/added.

addTableFactory

public static void addTableFactory(DBFactory<? extends DBRecord> factory)
Adds the specified table to the table name/factory map

Parameters:
factory - The table factory

includeFieldInFactory

public static boolean includeFieldInFactory(DBFactory fact,
                                            DBField field)
Provides the opportunity for the DBAdmin to decide whether or not the specified DBField should be added/included in the DBFactory. Typically, an external configuration manager will provide the actual decision.

Parameters:
fact - The DBFactory
field - The DBField which is to be added to the DBFactory
Returns:
True if the DBField should be added to the DBFactory

getTableFactoryCount

public static int getTableFactoryCount()
Returns the number of registered DBFactory classes

Returns:
The number of registered DBFactory classes

getTableFactoryMap

public static OrderedMap<java.lang.String,DBFactory<? extends DBRecord>> getTableFactoryMap()
Returns a map of all defined table names to their table DBFactory

Returns:
The table name/factory map

getChildTableFactories

public static DBFactory<? extends DBRecord>[] getChildTableFactories(DBFactory<? extends DBRecord> parentFactory)
Gets all child/dependent table factories for the specified table factory

Parameters:
parentFactory - The parent table factory
Returns:
The child/dependent table factories of the specified parent factory

getTableFactory

public static DBFactory<? extends DBRecord> getTableFactory(java.lang.String utableName)
Returns the table factory for the specified table name

Parameters:
utableName - The untranslated table name
Returns:
The table factory

hasTableFactory

public static boolean hasTableFactory(java.lang.String utableName)
Returns true if the spcified table name has been defined

Parameters:
utableName - The untranslated table name
Returns:
True if the table has been defined, false otherwise

getTableNameProperCase

public static java.lang.String getTableNameProperCase(java.lang.String utableName)
Returns the proper case of the specified table name. For example, assuming that "Account" is a defined table name, passing "accounT" to this method will return "Account".

Parameters:
utableName - The untranslated table name
Returns:
The table name with the proper 'case'

printTableSchema

public static void printTableSchema(int docWidth,
                                    java.lang.String[] header,
                                    java.lang.String utableName)
Print the database schema for the managed tables

Parameters:
utableName - The specific untranslated table name for which the schema will be printed. If null, the schema for all tables will be printed.

printTableColumns

public static void printTableColumns(int docWidth,
                                     java.lang.String[] header,
                                     java.lang.String utableName)
Print the database schema for the managed tables

Parameters:
utableName - The specific untranslated table name for which the schema will be printed. If null, the schema for all tables will be printed.

verifyTablesExist

public static boolean verifyTablesExist()
Verify that all defined tables actually exist

Returns:
True if all tables exist

getDumpDirectory

public static java.io.File getDumpDirectory()
Creates and returns the default dump file directory

Returns:
The default dump file directory

execCommands

public static DBAdmin.DBAdminExec execCommands()
Execute command defined in the runtime-config properties (RTConfig)

Returns:
One of the following DBAdminExec status codes: ERROR to represent an error condition, NONE to represent that no command was executed, EXIT to represent that a command was executed and that the caller of this method should exit, OK to represent that a command was executed, but the caller should continue.

main

public static void main(java.lang.String[] argv)
Main entry point

Parameters:
argv - The command-line arguments