Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.jcorporate.expresso.core.utility
Class DBTool  view DBTool download DBTool.java

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

public class DBTool
extends java.lang.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.


Nested Class Summary
 
Nested classes inherited from class java.lang.Thread
java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private static java.lang.String dbName
           
private static org.apache.log4j.Logger log
           
private static java.lang.String thisClass
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
DBTool()
          Constructor
 
Method Summary
private static void chooseConfig(java.lang.String dbName)
          Choose a schema to enter Setup values for
static java.util.List compareTables(com.jcorporate.expresso.kernel.InstallLog theLog, java.util.Vector allSchemas, java.lang.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(com.jcorporate.expresso.kernel.InstallLog theLog, java.util.Vector allSchemas, java.lang.String dataContext)
          Create the tables required by the database objects in the list of schemas.
static void deleteSchema(com.jcorporate.expresso.services.html.Page myPage, java.lang.String dbName, java.lang.String schemaName)
          Method to remove an installed schema.
static void deleteSchema(com.jcorporate.expresso.services.html.Page myPage, java.lang.String dbName, java.util.Vector schemas)
          Method wipes out more than one installed schema.
static void deleteTable(java.lang.String dbName, java.lang.String tableName)
          Delete Table - Deletes a table from the specified db
private static void doBenchMarks()
          Benchmark the data connection
private static void enterConfig(java.lang.String dbName, java.lang.String schemaClass)
           
private static void exportFile(java.lang.String exportCmd, java.lang.String fileName, java.lang.String format)
          Export data from the named dbobject to the specified filename
private static void exportTabFile(com.jcorporate.expresso.core.dbobj.DBObject myObj, java.lang.String fileName)
          Export the named database object into the given file, where the file is tab delimited, and the fields are in the order of the database object's fields
private static void genAllDBObject(com.jcorporate.expresso.core.db.DBConnection myConnection, java.lang.String schemaPattern, java.lang.String tableNamePattern, java.lang.String dbKey, java.lang.String packageName)
          Recursively generate a Java DBObject file for every table in the specified database.
private static void genDBObject(com.jcorporate.expresso.core.db.DBConnection myConnection, java.lang.String generate, java.lang.String dbKey, java.lang.String packageName)
          Generate a Java file as a database object for the given table
private static java.lang.String getJavaClassName(java.lang.String tableName)
          Creates a Java Class name from a database table name.
private static void importExportAll(com.jcorporate.expresso.core.db.DBConnection myConnection, java.lang.String choice, java.lang.String format)
          Instantiate & load all Schema objects that we know about, get a list of their DBObjects, and call the import or export for each DBObject as appropriate
private static void importFile(java.lang.String importCmd, java.lang.String fileName, java.lang.String format, com.jcorporate.expresso.core.db.DBConnection myConnection)
          Import data into the named dbobject from the specified filename
private static void importTabFile(com.jcorporate.expresso.core.dbobj.DBObject myObj, java.lang.String fileName)
          Import the named file into the given database object, where the file is tab delimited, and the fields are in the order of the database object's fields
private static void importTabLine(java.lang.String oneLine, com.jcorporate.expresso.core.dbobj.DBObject myObj, int lineNumber)
          Process a single line of tab-delimited data into a record for the given database object, and add the object to the database
private static boolean isMixedCase(java.lang.String stringToCheck)
          This method returns true if the string contains both upper and lowercase letters, false otherwise.
static void main(java.lang.String[] args)
          Main method so that DBTool can be launched from a command line
private static void nameChange(java.lang.String dbName)
          Performs the Expresso 3 to Expresso 4 name changes
static void otherSetups(com.jcorporate.expresso.kernel.InstallLog theLog, java.util.Vector allSchemas, java.lang.String dbName)
          Method to perform any other additonal setup required by each schema
private static void poolTest()
           
static void populateTables(com.jcorporate.expresso.kernel.InstallLog installLog, java.util.Vector allSchemas, java.lang.String dbName)
          This method goes through the schemas and populates tables with default values if they do not exist.
private static java.lang.String prepareWord(java.lang.String wordToPrepare)
          prepareWord prepares a single word for use in a Java class name by capitalizing the first letter and lowecasing the rest.
private static void setup(java.lang.String dbName)
          Command line setup
static void setupConfig(com.jcorporate.expresso.kernel.InstallLog installLog, java.util.Vector allSchemas, java.lang.String dbName)
          Method to set up the default Setup values for each schema.
static void setupSecurity(com.jcorporate.expresso.kernel.InstallLog theLog, java.util.Vector allSchemas, java.lang.String dbName)
          This method creates default security entries for all of the database objects and controller objects for the known schemas.
private static void testAllSchemas()
          Instantiate & load all Schema objects that we know about, get a list of their DBObjects, and call the verify() method of each DBObject
private static void usage()
          Show the user a usage message
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, 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

thisClass

private static final java.lang.String thisClass

dbName

private static java.lang.String dbName

log

private static org.apache.log4j.Logger log
Constructor Detail

DBTool

public DBTool()
Constructor

Method Detail

chooseConfig

private static void chooseConfig(java.lang.String dbName)
                          throws com.jcorporate.expresso.core.db.DBException,
                                 java.io.IOException
Choose a schema to enter Setup values for


doBenchMarks

private static void doBenchMarks()
                          throws com.jcorporate.expresso.core.db.DBException,
                                 java.sql.SQLException,
                                 com.jcorporate.expresso.core.misc.ConfigurationException
Benchmark the data connection


deleteTable

public static void deleteTable(java.lang.String dbName,
                               java.lang.String tableName)
                        throws com.jcorporate.expresso.core.db.DBException
Delete Table - Deletes a table from the specified db


deleteSchema

public static void deleteSchema(com.jcorporate.expresso.services.html.Page myPage,
                                java.lang.String dbName,
                                java.util.Vector schemas)
                         throws com.jcorporate.expresso.core.db.DBException,
                                com.jcorporate.expresso.services.html.HtmlException,
                                java.lang.IllegalArgumentException
Method wipes out more than one installed schema.


deleteSchema

public static void deleteSchema(com.jcorporate.expresso.services.html.Page myPage,
                                java.lang.String dbName,
                                java.lang.String schemaName)
                         throws com.jcorporate.expresso.core.db.DBException,
                                com.jcorporate.expresso.services.html.HtmlException,
                                java.lang.IllegalArgumentException
Method to remove an installed schema. Deletes all the tables associated with the schema

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

enterConfig

private static void enterConfig(java.lang.String dbName,
                                java.lang.String schemaClass)
                         throws com.jcorporate.expresso.core.db.DBException,
                                java.io.IOException

exportFile

private static void exportFile(java.lang.String exportCmd,
                               java.lang.String fileName,
                               java.lang.String format)
                        throws com.jcorporate.expresso.core.db.DBException,
                               java.io.IOException,
                               java.lang.IllegalAccessException,
                               java.lang.InstantiationException,
                               java.lang.ClassNotFoundException
Export data from the named dbobject to the specified filename


exportTabFile

private static void exportTabFile(com.jcorporate.expresso.core.dbobj.DBObject myObj,
                                  java.lang.String fileName)
                           throws java.io.IOException,
                                  com.jcorporate.expresso.core.db.DBException
Export the named database object into the given file, where the file is tab delimited, and the fields are in the order of the database object's fields


genAllDBObject

private static void genAllDBObject(com.jcorporate.expresso.core.db.DBConnection myConnection,
                                   java.lang.String schemaPattern,
                                   java.lang.String tableNamePattern,
                                   java.lang.String dbKey,
                                   java.lang.String packageName)
                            throws java.io.IOException,
                                   com.jcorporate.expresso.core.db.DBException,
                                   java.sql.SQLException
Recursively generate a Java DBObject file for every table in the specified database.

The schemaPattern and tableNamePattern attributes take a String that can match the JDBC pattern-matching format. A percent ("%") character will match 0 or more characters in a String, while an underscore ("_") character will match any single character. So, if you wanted to retrieve information on all tables in schemas containing the string "Employee", you could use "%Employee%" for the schemaPattern parameter.

Both schemaPattern and tableNamePattern may be null, in which case all tables will be returned.


genDBObject

private static void genDBObject(com.jcorporate.expresso.core.db.DBConnection myConnection,
                                java.lang.String generate,
                                java.lang.String dbKey,
                                java.lang.String packageName)
                         throws java.io.IOException,
                                com.jcorporate.expresso.core.db.DBException,
                                java.sql.SQLException
Generate a Java file as a database object for the given table


compareTables

public static java.util.List compareTables(com.jcorporate.expresso.kernel.InstallLog theLog,
                                           java.util.Vector allSchemas,
                                           java.lang.String dbName)
                                    throws com.jcorporate.expresso.core.db.DBException,
                                           com.jcorporate.expresso.core.misc.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?


importExportAll

private static void importExportAll(com.jcorporate.expresso.core.db.DBConnection myConnection,
                                    java.lang.String choice,
                                    java.lang.String format)
                             throws com.jcorporate.expresso.core.db.DBException,
                                    java.lang.IllegalAccessException,
                                    java.lang.InstantiationException,
                                    java.lang.ClassNotFoundException,
                                    java.io.IOException,
                                    com.jcorporate.expresso.core.job.ServerException
Instantiate & load all Schema objects that we know about, get a list of their DBObjects, and call the import or export for each DBObject as appropriate

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

importFile

private static void importFile(java.lang.String importCmd,
                               java.lang.String fileName,
                               java.lang.String format,
                               com.jcorporate.expresso.core.db.DBConnection myConnection)
                        throws com.jcorporate.expresso.core.db.DBException,
                               java.io.IOException,
                               java.lang.IllegalAccessException,
                               java.lang.InstantiationException,
                               java.lang.ClassNotFoundException,
                               com.jcorporate.expresso.core.job.ServerException
Import data into the named dbobject from the specified filename

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

importTabFile

private static void importTabFile(com.jcorporate.expresso.core.dbobj.DBObject myObj,
                                  java.lang.String fileName)
                           throws java.io.IOException,
                                  com.jcorporate.expresso.core.db.DBException,
                                  com.jcorporate.expresso.core.job.ServerException
Import the named file into the given database object, where the file is tab delimited, and the fields are in the order of the database object's fields


importTabLine

private static void importTabLine(java.lang.String oneLine,
                                  com.jcorporate.expresso.core.dbobj.DBObject myObj,
                                  int lineNumber)
                           throws com.jcorporate.expresso.core.db.DBException,
                                  com.jcorporate.expresso.core.job.ServerException
Process a single line of tab-delimited data into a record for the given database object, and add the object to the database


main

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


isMixedCase

private static boolean isMixedCase(java.lang.String stringToCheck)
This method returns true if the string contains both upper and lowercase letters, false otherwise.


getJavaClassName

private static java.lang.String getJavaClassName(java.lang.String tableName)
Creates a Java Class name from a database table name. Removes underscore characters and spaces, capitalizes the first letter of each word.


prepareWord

private static java.lang.String prepareWord(java.lang.String wordToPrepare)
prepareWord prepares a single word for use in a Java class name by capitalizing the first letter and lowecasing the rest.


nameChange

private static void nameChange(java.lang.String dbName)
                        throws com.jcorporate.expresso.core.db.DBException
Performs the Expresso 3 to Expresso 4 name changes


poolTest

private static void poolTest()

setup

private static void setup(java.lang.String dbName)
                   throws com.jcorporate.expresso.core.db.DBException,
                          com.jcorporate.expresso.core.misc.ConfigurationException
Command line setup


testAllSchemas

private static void testAllSchemas()
                            throws com.jcorporate.expresso.core.db.DBException
Instantiate & load all Schema objects that we know about, get a list of their DBObjects, and call the verify() method of each DBObject


usage

private static void usage()
Show the user a usage message


createTables

public static void createTables(com.jcorporate.expresso.kernel.InstallLog theLog,
                                java.util.Vector allSchemas,
                                java.lang.String dataContext)
                         throws com.jcorporate.expresso.core.db.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.


otherSetups

public static void otherSetups(com.jcorporate.expresso.kernel.InstallLog theLog,
                               java.util.Vector allSchemas,
                               java.lang.String dbName)
                        throws com.jcorporate.expresso.core.db.DBException
Method to perform any other additonal setup required by each schema


populateTables

public static void populateTables(com.jcorporate.expresso.kernel.InstallLog installLog,
                                  java.util.Vector allSchemas,
                                  java.lang.String dbName)
                           throws com.jcorporate.expresso.core.db.DBException
This method goes through the schemas and populates tables with default values if they do not exist. Works closely with


setupConfig

public static void setupConfig(com.jcorporate.expresso.kernel.InstallLog installLog,
                               java.util.Vector allSchemas,
                               java.lang.String dbName)
                        throws com.jcorporate.expresso.core.db.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


setupSecurity

public static void setupSecurity(com.jcorporate.expresso.kernel.InstallLog theLog,
                                 java.util.Vector allSchemas,
                                 java.lang.String dbName)
                          throws com.jcorporate.expresso.core.db.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