Expresso 5-6

com.jcorporate.expresso.core.utility
Class DBTool

java.lang.Object
  extended byjava.lang.Thread
      extended bycom.jcorporate.expresso.core.utility.DBTool
All Implemented Interfaces:
Runnable

public class DBTool
extends Thread

DBTool is a multi-purpose tool for working with database objects. It can:

  1. Verify data in the database with respect to referential integrity
  2. Generate the code for a Database Object by reading the data in a database
  3. Export data in a database object to an external XML file
  4. Import data from an external XML file into a database object

Command Line Parameters

Required Command Line Arguments

configDir - <Directory that contains your config files>

webbAppDir -<The Expresso webapp directory>

db=<The database to create>

Optional Command Line Argumments

These arguments define the role to use as well as some arguments are specific for a given task.

Author:
Michael Nash

Modify by Yves Henri AMAIZO


Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
DBTool()
          Constructor
 
Method Summary
static List compareTables(InstallLog theLog, Vector allSchemas, String dbName)
          Reverse engineer the table for each db object for every known schema, then compare the fields in the database to the fields in the db object and report on the differences to the the log and to System.err

todo why isn't this log passed in used?

static void createTables(InstallLog theLog, Vector allSchemas, String dataContext)
          Create the tables required by the database objects in the list of schemas.
static void deleteSchema(Page myPage, String dbName, String schemaName)
          Method to remove an installed schema.
static void deleteSchema(Page myPage, String dbName, Vector schemas)
          Method wipes out more than one installed schema.
static void deleteTable(String dbName, String tableName)
          Delete Table - Deletes a table from the specified db
static void main(String[] args)
          Main method so that DBTool can be launched from a command line
static void otherSetups(InstallLog theLog, Vector allSchemas, String dbName)
          Method to perform any other additonal setup required by each schema
static void populateTables(InstallLog installLog, Vector allSchemas, String dbName)
          This method goes through the schemas and populates tables with default values if they do not exist.
static void setupConfig(InstallLog installLog, Vector allSchemas, String dbName)
          Method to set up the default Setup values for each schema.
static void setupSecurity(InstallLog theLog, Vector allSchemas, String dbName)
          This method creates default security entries for all of the database objects and controller objects for the known schemas.
 
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, run, 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
 

Constructor Detail

DBTool

public DBTool()
Constructor

Method Detail

deleteTable

public static void deleteTable(String dbName,
                               String tableName)
                        throws DBException
Delete Table - Deletes a table from the specified db

Parameters:
dbName - - the name of the db that contains this table
tableName - - The name of the table to delete.
Throws:
DBException

deleteSchema

public static void deleteSchema(Page myPage,
                                String dbName,
                                Vector schemas)
                         throws DBException,
                                HtmlException,
                                IllegalArgumentException
Method wipes out more than one installed schema.

Parameters:
myPage - an HTML page to render output to (optional)
dbName - The database context to create the database in.
schemas - List of the schema objects to delete
Throws:
HtmlException - if an error occurs constructing the HTML code
DBException
IllegalArgumentException

deleteSchema

public static void deleteSchema(Page myPage,
                                String dbName,
                                String schemaName)
                         throws DBException,
                                HtmlException,
                                IllegalArgumentException
Method to remove an installed schema. Deletes all the tables associated with the schema

Parameters:
myPage - - The page to output the 'log' to.
dbName - - the name of the database to perform this operation
schemaName - - the full classname of the schema to delete.
Throws:
IllegalArgumentException - if the schema doesn't exist.
DBException - If there is a database problem creating the new default values
HtmlException - If there is a problem building the confirmation page

Modify by Yves Henri AMAIZO

Since:
$DatabaseSchema $Date: 2004/11/20 20:11:53 $

compareTables

public static List compareTables(InstallLog theLog,
                                 Vector allSchemas,
                                 String dbName)
                          throws DBException,
                                 ConfigurationException
Reverse engineer the table for each db object for every known schema, then compare the fields in the database to the fields in the db object and report on the differences to the the log and to System.err

todo why isn't this log passed in used?

Parameters:
theLog - the Install log to output to
allSchemas - a vector of all the schemas to compare
dbName - the data context to use
Returns:
list of string error messages
Throws:
DBException
ConfigurationException

main

public static void main(String[] args)
Main method so that DBTool can be launched from a command line

Parameters:
args - Command line arguments to supply the information to connect to the database

createTables

public static void createTables(InstallLog theLog,
                                Vector allSchemas,
                                String dataContext)
                         throws DBException
Create the tables required by the database objects in the list of schemas. Each database object knows how to create the database table it requires - this method goes through the list of registered schemas and calls the create method for all of the database objects in the schema. If the table is already there, nothing is done.

Parameters:
theLog - The installLog object. Use ConsoleInstallLog if you don't know what this does.
allSchemas - List of the schema objects
dataContext - The database context to create the database in.
Throws:
DBException - If there is a problem creating the tables

otherSetups

public static void otherSetups(InstallLog theLog,
                               Vector allSchemas,
                               String dbName)
                        throws DBException
Method to perform any other additonal setup required by each schema

Parameters:
theLog - InstallLog object to save the data to
allSchemas - List of the schema objects
dbName - The database context to create the database in.
Throws:
DBException - If there is a database problem creating the new default values

populateTables

public static void populateTables(InstallLog installLog,
                                  Vector allSchemas,
                                  String dbName)
                           throws DBException
This method goes through the schemas and populates tables with default values if they do not exist. Works closely with

Parameters:
installLog - The InstallLog to save the output traces to
allSchemas - List of the schema objects
dbName - The database context to create the database in.
Throws:
DBException - If a problem occurrs putting the default records in the database

setupConfig

public static void setupConfig(InstallLog installLog,
                               Vector allSchemas,
                               String dbName)
                        throws DBException
Method to set up the default Setup values for each schema. Every schema object has a list of the Setup values and default values for them that are required by the application that the schema applies to. The default schema is done first, then any other registered schema objects

Parameters:
installLog - - The installation log to log output to
allSchemas - A list of all of the schema objects
dbName - The database context to setup the config in.
Throws:
DBException - If there is a database problem creating the new default values

setupSecurity

public static void setupSecurity(InstallLog theLog,
                                 Vector allSchemas,
                                 String dbName)
                          throws DBException
This method creates default security entries for all of the database objects and controller objects for the known schemas. This includes full access for a group and user called User.ADMIN_USER

Parameters:
theLog - Installation Log
allSchemas - List of the schema objects
dbName - The database context to create the database in.
Throws:
DBException - If a problem occurrs putting the security info in the database

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.