edu.internet2.middleware.grouper.ddl
Class GrouperDdlUtils

java.lang.Object
  extended by edu.internet2.middleware.grouper.ddl.GrouperDdlUtils

public class GrouperDdlUtils
extends Object


Nested Class Summary
static class GrouperDdlUtils.DbMetadataBean
          bean
 
Field Summary
static boolean compareFromDbDllVersion
          true to compare ddl from db version to the current java version, false to start over and find all diffs (without deleting existing)
static boolean deepCheck
          if check from scratch
static boolean everythingRightVersion
          if everything is the right version
static boolean internal_printDdlUpdateMessage
          set this to false for testing
 
Constructor Summary
GrouperDdlUtils()
           
 
Method Summary
static boolean assertColumnThere(boolean expectTrue, String tableName, String columnName)
          see if tables are there (at least the grouper groups one)
static boolean assertTablesThere(DdlVersionBean ddlVersionBean, boolean expectRecords, boolean expectTrue)
          see if tables are there (at least the grouper groups one)
static boolean assertTablesThere(DdlVersionBean ddlVersionBean, boolean expectRecords, boolean expectTrue, String tableName, boolean falseIfDropBeforeCreate)
          see if tables are there (at least the grouper groups one)
static void bootstrap(boolean callFromCommandLine, boolean installDefaultGrouperData, boolean promptUser)
          startup the process, if the version table is not there, print out that ddl
static boolean bootstrapHelper(boolean callFromCommandLine, boolean fromUnitTest, boolean theCompareFromDbVersion, boolean theDropBeforeCreate, boolean theWriteAndRunScript, boolean dropOnly, boolean installDefaultGrouperData, Map<String,DdlVersionable> maxVersions, boolean promptUser)
          helper method which is more easily testable
static String changeDatabase(String objectName, DdlUtilsChangeDatabase ddlUtilsChangeDatabase)
           helper method to run custom db ddl, which is more easily testable TODO consolidate this code with the bootstrap code in the DdlVersionBean or somewhere Here is an example: GrouperDdlUtils.changeDatabase(GrouperDdl.V1.getObjectName(), new DdlUtilsChangeDatabase() { public void changeDatabase(DdlVersionBean ddlVersionBean) { Database database = ddlVersionBean.getDatabase(); { Table attributesTable = database.findTable(Attribute.TABLE_GROUPER_ATTRIBUTES); Column attributesFieldIdColumn = attributesTable.findColumn(Attribute.COLUMN_FIELD_ID); attributesTable.removeColumn(attributesFieldIdColumn); } { Table membershipsTable = database.findTable(Membership.TABLE_GROUPER_MEMBERSHIPS); Column membershipsFieldIdColumn = membershipsTable.findColumn(Membership.COLUMN_FIELD_ID); membershipsTable.removeColumn(membershipsFieldIdColumn); } } });
static String convertUrlToDriverClassIfNeeded(String connectionUrl, String driverClassName)
          if there is no driver class specified, then try to derive it from the URL
static String convertUrlToHibernateDialectIfNeeded(String connectionUrl, String hibernateDialect)
          if there is no driver class specified, then try to derive it from the URL
static String convertUrlToQuartzDriverDelegateClassIfNeeded(String connectionUrl, String driverClassName)
          if there is no quartz driver class specified, then try to derive it from the URL
static void ddlutilsBackupTable(DdlVersionBean ddlVersionBean, String tableName, String backupTableName)
          backup a table into another table (which should not exist)
static void ddlutilsColumnComment(DdlVersionBean ddlVersionBean, String objectName, String columnName, String comment)
           add a table or view column comment if the DB supports it COMMENT ON COLUMN zip_code.zip_code IS '5 Digit Zip Code';
static void ddlutilsCreateOrReplaceView(DdlVersionBean ddlVersionBean, String viewName, String viewComment, Set<String> aliases, Set<String> columnComments, String sql)
          add a view if the DB supports it
static void ddlutilsDropColumn(org.apache.ddlutils.model.Database database, String tableName, String columnName, DdlVersionBean ddlVersionBean)
          find and drop a column if it is there.
static void ddlutilsDropColumn(org.apache.ddlutils.model.Table table, String columnName, DdlVersionBean ddlVersionBean)
          find and drop a column if it is there also drop all related indexes
static void ddlutilsDropIndexes(org.apache.ddlutils.model.Table table, String columnName)
          drop all indexes by column name (e.g.
static void ddlutilsDropTable(DdlVersionBean ddlVersionBean, String tableName, boolean falseIfDropBeforeCreate)
          find and drop a table if it is there
static void ddlutilsDropViewIfExists(DdlVersionBean ddlVersionBean, String viewName, boolean falseIfDropBeforeCreate)
          drop a view if it is detected as existing
static org.apache.ddlutils.model.Column ddlutilsFindColumn(org.apache.ddlutils.model.Database database, String tableName, String columnName, boolean exceptionIfNotFound)
          find table, if not exist, throw exception
static org.apache.ddlutils.model.Column ddlutilsFindColumn(org.apache.ddlutils.model.Table table, String columnName, boolean exceptionOnNotFound)
          find column, if not exist, throw exception
static org.apache.ddlutils.model.Column ddlutilsFindOrCreateColumn(org.apache.ddlutils.model.Table table, String columnName, int typeCode, String size, boolean primaryKey, boolean required)
          find or create column with various properties
static org.apache.ddlutils.model.Column ddlutilsFindOrCreateColumn(org.apache.ddlutils.model.Table table, String columnName, int typeCode, String size, boolean primaryKey, boolean required, String defaultValue)
          find or create column with various properties
static org.apache.ddlutils.model.ForeignKey ddlutilsFindOrCreateForeignKey(org.apache.ddlutils.model.Database database, String tableName, String foreignKeyName, String foreignTableName, List<String> localColumnNames, List<String> foreignColumnNames)
          add a foreign key on a table.
static org.apache.ddlutils.model.ForeignKey ddlutilsFindOrCreateForeignKey(org.apache.ddlutils.model.Database database, String tableName, String foreignKeyName, String foreignTableName, String localColumnName, String foreignColumnName)
          add a foreign key on a table.
static org.apache.ddlutils.model.Index ddlutilsFindOrCreateIndex(org.apache.ddlutils.model.Database database, DdlVersionBean ddlVersionBean, String tableName, String indexName, String customScript, boolean unique, String... columnNames)
          add an index on a table.
static org.apache.ddlutils.model.Index ddlutilsFindOrCreateIndex(org.apache.ddlutils.model.Database database, String tableName, String indexName, boolean unique, String... columnNames)
          add an index on a table.
static org.apache.ddlutils.model.Table ddlutilsFindOrCreateTable(org.apache.ddlutils.model.Database database, String tableName)
          find or create table
static org.apache.ddlutils.model.Table ddlutilsFindTable(org.apache.ddlutils.model.Database database, String tableName, boolean exceptionOnNotFound)
          find table, if not exist, throw exception
static org.apache.ddlutils.model.Column ddlutilsFixSizeColumn(org.apache.ddlutils.model.Table table, String columnName, int typeCode, String size, boolean primaryKey, boolean required)
          find or create column with various properties
static org.apache.ddlutils.model.Column ddlutilsFixSizeColumn(org.apache.ddlutils.model.Table table, String columnName, int typeCode, String size, boolean primaryKey, boolean required, String defaultValue)
          find or create column with various properties
static void ddlutilsTableComment(DdlVersionBean ddlVersionBean, String tableName, String tableComment)
          add a table comment if the DB supports it
static void ddlutilsViewComment(DdlVersionBean ddlVersionBean, String viewName, String tableComment)
          add a view comment if the DB supports it
static void deleteDdlById(String id)
           
static void deleteUtfDdls()
          delete all utf ddls
static void dropAllForeignKeys(org.apache.ddlutils.model.Database database)
          drop all foreign keys from a ddlutils database object
static void dropAllForeignKeysScript(GrouperDdlUtils.DbMetadataBean dbMetadataBean, DdlVersionBean ddlVersionBean)
          drop all foreign keys (database dependent), and generate the script
static GrouperDdlUtils.DbMetadataBean findDbMetadataBean(DdlVersionable ddlVersionable)
          find the correct metadata for the DB
static String findScriptOverride(DdlVersionable dbObjectVersion, String dbname)
           File name must be objectName.V#.dbname.sql e.g.
static String findScriptOverride(String objectName, int version, String dbNameExact)
           get an override file (exact, dont look for the all ones like oracleall) File name must be objectName.V#.dbname.sql e.g.
static int getTableCount(String tableName, boolean exceptionIfTableDoesNotExist)
          Get the number of records in a table
static boolean isHsql()
          see if the config file seems to be hsql
static boolean isHsql(String connectionUrl)
          see if the config file seems to be hsql
static boolean isMysql()
          see if the config file seems to be mysql
static boolean isMysql(String connectionUrl)
          see if the config file seems to be mysql
static boolean isOracle()
          see if the config file seems to be oracle
static boolean isOracle(String connectionUrl)
          see if the config file seems to be oracle
static boolean isPostgres()
          see if the config file seems to be postgres
static boolean isPostgres(String connectionUrl)
          see if the config file seems to be postgres
static boolean isSQLServer()
          see if the config file seems to be sql server
static boolean isSQLServer(String connectionUrl)
          see if the config file seems to be sql server
static void main(String[] args)
          kick off bootstrap
static String objectName(Enum dbObjectVersion)
          find the object name from the db object version
static boolean okToUseHibernate()
          if we are inside the bootstrap, or if everything is ok, we are good to go
static void removeAllTables(org.apache.ddlutils.model.Database database)
          remove all objects, the foreign keys, then the tables
static DdlVersionable retieveVersion(String objectName, int version)
          retrieve a version of a ddl object versionable
static Hib3GrouperDdl retrieveDdlByIdFromDatabase(String id)
           
static Hib3GrouperDdl retrieveDdlByNameFromDatabase(String objectName)
          retrieve a DDL by name
static int retrieveDdlDbVersion(String objectName)
          get the version of a ddl object in the DB
static Class<Enum> retrieveDdlEnum(String objectName)
          the relationship between object name and the enum is as follows.
static int retrieveDdlJavaVersion(String objectName)
          get the version of a ddl object in the DB
static List<Hib3GrouperDdl> retrieveDdlsFromDb()
          get all the ddls, put grouper at the front
static StringBuilder retrieveHistory(String objectName)
          find history for a certain object name
static List<String> retrieveObjectNames()
          get the object names from the
static org.apache.ddlutils.Platform retrievePlatform()
          retrieve the ddl utils platform
static org.apache.ddlutils.Platform retrievePlatform(boolean useCache)
          retrieve the ddl utils platform
static String sqlConcatenation(String field1, String field2)
          Returns the sql to concatenate these two fields separated by the separator
static String sqlConcatenation(String field1, String field2, String separator)
          Returns the sql to concatenate these two fields separated by the separator
static String sqlRun(File scriptFile, boolean fromUnitTest, boolean printErrorToStdOut)
          run a script file against the default database
static String sqlRun(File scriptFile, String driver, String url, String user, String pass, boolean fromUnitTest, boolean printErrorToStdOut)
          run some sql
static Hib3GrouperDdl storeAndReadUtfString(String someUtfString, String id, String name)
          store and read a utf string, but dont commit it so its doesnt stay in the database
static Hib3GrouperDdl storeDdl(HibernateSession hibernateSession, String id, String name, String someUtfString)
           
static boolean tableExists(String tableName)
          see if tables are there (at least the grouper groups one)
static void upgradeDatabaseVersion(org.apache.ddlutils.model.Database baseVersion, org.apache.ddlutils.model.Database oldVersion, int baseDatabaseVersion, String objectName, int requestedVersion, int upgradeToVersion, StringBuilder additionalScripts, StringBuilder fullScript, org.apache.ddlutils.Platform platform, Connection connection, String schema, org.apache.ddlutils.platform.SqlBuilder sqlBuilder)
          get a database object of a certain version based on the existing database, and tack on all the enums up to the version we want (if any)
static int versionIntFromEnum(Enum ddlVersion)
          find a version from an enum version int
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

compareFromDbDllVersion

public static boolean compareFromDbDllVersion
true to compare ddl from db version to the current java version, false to start over and find all diffs (without deleting existing)


everythingRightVersion

public static boolean everythingRightVersion
if everything is the right version


internal_printDdlUpdateMessage

public static boolean internal_printDdlUpdateMessage
set this to false for testing


deepCheck

public static boolean deepCheck
if check from scratch

Constructor Detail

GrouperDdlUtils

public GrouperDdlUtils()
Method Detail

isHsql

public static boolean isHsql()
see if the config file seems to be hsql

Returns:
see if hsql

isHsql

public static boolean isHsql(String connectionUrl)
see if the config file seems to be hsql

Parameters:
connectionUrl - url to check against
Returns:
see if hsql

isPostgres

public static boolean isPostgres()
see if the config file seems to be postgres

Returns:
see if postgres

isPostgres

public static boolean isPostgres(String connectionUrl)
see if the config file seems to be postgres

Parameters:
connectionUrl -
Returns:
see if postgres

isOracle

public static boolean isOracle()
see if the config file seems to be oracle

Returns:
see if oracle

isOracle

public static boolean isOracle(String connectionUrl)
see if the config file seems to be oracle

Parameters:
connectionUrl -
Returns:
see if oracle

isMysql

public static boolean isMysql()
see if the config file seems to be mysql

Returns:
see if mysql

isMysql

public static boolean isMysql(String connectionUrl)
see if the config file seems to be mysql

Parameters:
connectionUrl -
Returns:
see if mysql

isSQLServer

public static boolean isSQLServer()
see if the config file seems to be sql server

Returns:
see if sql server

isSQLServer

public static boolean isSQLServer(String connectionUrl)
see if the config file seems to be sql server

Parameters:
connectionUrl -
Returns:
see if sql server

okToUseHibernate

public static boolean okToUseHibernate()
if we are inside the bootstrap, or if everything is ok, we are good to go

Returns:
true if ok

retrievePlatform

public static org.apache.ddlutils.Platform retrievePlatform()
retrieve the ddl utils platform

Returns:
the platform object

retrievePlatform

public static org.apache.ddlutils.Platform retrievePlatform(boolean useCache)
retrieve the ddl utils platform

Parameters:
useCache - if we should get from cache if it is available
Returns:
the platform object

main

public static void main(String[] args)
kick off bootstrap

Parameters:
args -

bootstrap

public static void bootstrap(boolean callFromCommandLine,
                             boolean installDefaultGrouperData,
                             boolean promptUser)
startup the process, if the version table is not there, print out that ddl

Parameters:
callFromCommandLine -
installDefaultGrouperData -
promptUser - prompt user to see if they really want to do this

bootstrapHelper

public static boolean bootstrapHelper(boolean callFromCommandLine,
                                      boolean fromUnitTest,
                                      boolean theCompareFromDbVersion,
                                      boolean theDropBeforeCreate,
                                      boolean theWriteAndRunScript,
                                      boolean dropOnly,
                                      boolean installDefaultGrouperData,
                                      Map<String,DdlVersionable> maxVersions,
                                      boolean promptUser)
helper method which is more easily testable

Parameters:
callFromCommandLine -
fromUnitTest - true if just testing this method
theCompareFromDbVersion -
theDropBeforeCreate -
theWriteAndRunScript -
dropOnly - just drop stuff, e.g. for unit test
installDefaultGrouperData - if registry install should be called afterwards
maxVersions - if unit testing, and not going to max, then associate object name with max version
promptUser - promptUser to see if they want to do this...
Returns:
true if up to date, false if needs to run a script

sqlRun

public static String sqlRun(File scriptFile,
                            boolean fromUnitTest,
                            boolean printErrorToStdOut)
run a script file against the default database

Parameters:
scriptFile -
fromUnitTest -
printErrorToStdOut -
Returns:
the output

convertUrlToDriverClassIfNeeded

public static String convertUrlToDriverClassIfNeeded(String connectionUrl,
                                                     String driverClassName)
if there is no driver class specified, then try to derive it from the URL

Parameters:
connectionUrl -
driverClassName -
Returns:
the driver class

convertUrlToQuartzDriverDelegateClassIfNeeded

public static String convertUrlToQuartzDriverDelegateClassIfNeeded(String connectionUrl,
                                                                   String driverClassName)
if there is no quartz driver class specified, then try to derive it from the URL

Parameters:
connectionUrl -
driverClassName -
Returns:
the driver class

convertUrlToHibernateDialectIfNeeded

public static String convertUrlToHibernateDialectIfNeeded(String connectionUrl,
                                                          String hibernateDialect)
if there is no driver class specified, then try to derive it from the URL

Parameters:
connectionUrl -
hibernateDialect -
Returns:
the driver class

sqlRun

public static String sqlRun(File scriptFile,
                            String driver,
                            String url,
                            String user,
                            String pass,
                            boolean fromUnitTest,
                            boolean printErrorToStdOut)
run some sql

Parameters:
scriptFile -
driver -
url -
user -
pass -
fromUnitTest -
printErrorToStdOut -
Returns:
the output

changeDatabase

public static String changeDatabase(String objectName,
                                    DdlUtilsChangeDatabase ddlUtilsChangeDatabase)
 helper method to run custom db ddl, which is more easily testable
 TODO consolidate this code with the bootstrap code in the DdlVersionBean or somewhere
 Here is an example:
 
     GrouperDdlUtils.changeDatabase(GrouperDdl.V1.getObjectName(), new DdlUtilsChangeDatabase() {
 
       public void changeDatabase(DdlVersionBean ddlVersionBean) {
         
         Database database = ddlVersionBean.getDatabase();
         {
           Table attributesTable = database.findTable(Attribute.TABLE_GROUPER_ATTRIBUTES);
           Column attributesFieldIdColumn = attributesTable.findColumn(Attribute.COLUMN_FIELD_ID);
           attributesTable.removeColumn(attributesFieldIdColumn);
         }
         
         {
           Table membershipsTable = database.findTable(Membership.TABLE_GROUPER_MEMBERSHIPS);
           Column membershipsFieldIdColumn = membershipsTable.findColumn(Membership.COLUMN_FIELD_ID);
           membershipsTable.removeColumn(membershipsFieldIdColumn);
         }
         
       }
       
     });
 
 
 

Parameters:
objectName - (from enum of ddl utils type)
ddlUtilsChangeDatabase - is the callback to change the database
Returns:
string

dropAllForeignKeysScript

public static void dropAllForeignKeysScript(GrouperDdlUtils.DbMetadataBean dbMetadataBean,
                                            DdlVersionBean ddlVersionBean)
drop all foreign keys (database dependent), and generate the script

Parameters:
dbMetadataBean -
ddlVersionBean -

removeAllTables

public static void removeAllTables(org.apache.ddlutils.model.Database database)
remove all objects, the foreign keys, then the tables

Parameters:
database -

retrieveHistory

public static StringBuilder retrieveHistory(String objectName)
find history for a certain object name

Parameters:
objectName -
Returns:
the history or new stringbuilder if none available

retieveVersion

public static DdlVersionable retieveVersion(String objectName,
                                            int version)
retrieve a version of a ddl object versionable

Parameters:
objectName -
version -
Returns:
the ddl versionable

retrieveDdlJavaVersion

public static int retrieveDdlJavaVersion(String objectName)
get the version of a ddl object in the DB

Parameters:
objectName -
Returns:
the version or -1 if not in the DB

retrieveDdlEnum

public static Class<Enum> retrieveDdlEnum(String objectName)
the relationship between object name and the enum is as follows. If the object name is "Grouper", then the enum is edu.internet2.middleware.grouper.ddl.GrouperDdl

Parameters:
objectName -
Returns:
the enum

ddlutilsDropViewIfExists

public static void ddlutilsDropViewIfExists(DdlVersionBean ddlVersionBean,
                                            String viewName,
                                            boolean falseIfDropBeforeCreate)
drop a view if it is detected as existing

Parameters:
ddlVersionBean -
viewName -
falseIfDropBeforeCreate -

ddlutilsBackupTable

public static void ddlutilsBackupTable(DdlVersionBean ddlVersionBean,
                                       String tableName,
                                       String backupTableName)
backup a table into another table (which should not exist)

Parameters:
ddlVersionBean -
tableName -
backupTableName -

ddlutilsCreateOrReplaceView

public static void ddlutilsCreateOrReplaceView(DdlVersionBean ddlVersionBean,
                                               String viewName,
                                               String viewComment,
                                               Set<String> aliases,
                                               Set<String> columnComments,
                                               String sql)
add a view if the DB supports it

Parameters:
ddlVersionBean -
viewName -
viewComment -
aliases -
columnComments -
sql - should not have a semicolon at end

ddlutilsTableComment

public static void ddlutilsTableComment(DdlVersionBean ddlVersionBean,
                                        String tableName,
                                        String tableComment)
add a table comment if the DB supports it

Parameters:
ddlVersionBean -
tableName -
tableComment -

ddlutilsViewComment

public static void ddlutilsViewComment(DdlVersionBean ddlVersionBean,
                                       String viewName,
                                       String tableComment)
add a view comment if the DB supports it

Parameters:
ddlVersionBean -
viewName -
tableComment -

ddlutilsColumnComment

public static void ddlutilsColumnComment(DdlVersionBean ddlVersionBean,
                                         String objectName,
                                         String columnName,
                                         String comment)
 add a table or view column comment if the DB supports it
   COMMENT ON COLUMN zip_code.zip_code IS '5 Digit Zip Code';
 

Parameters:
ddlVersionBean -
objectName -
comment -
columnName -

retrieveObjectNames

public static List<String> retrieveObjectNames()
get the object names from the

Returns:
the list of object names

retrieveDdlDbVersion

public static int retrieveDdlDbVersion(String objectName)
get the version of a ddl object in the DB

Parameters:
objectName -
Returns:
the version or -1 if not in the DB

retrieveDdlByIdFromDatabase

public static Hib3GrouperDdl retrieveDdlByIdFromDatabase(String id)
Parameters:
id -
Returns:
the ddl

deleteDdlById

public static void deleteDdlById(String id)
Parameters:
id -

deleteUtfDdls

public static void deleteUtfDdls()
delete all utf ddls


retrieveDdlByNameFromDatabase

public static Hib3GrouperDdl retrieveDdlByNameFromDatabase(String objectName)
retrieve a DDL by name

Parameters:
objectName -
Returns:
the ddl or null

storeAndReadUtfString

public static Hib3GrouperDdl storeAndReadUtfString(String someUtfString,
                                                   String id,
                                                   String name)
store and read a utf string, but dont commit it so its doesnt stay in the database

Parameters:
someUtfString -
id -
name -
Returns:
the ddl if it is found

storeDdl

public static Hib3GrouperDdl storeDdl(HibernateSession hibernateSession,
                                      String id,
                                      String name,
                                      String someUtfString)
Parameters:
someUtfString -
id -
name -
hibernateSession -
Returns:
the object

retrieveDdlsFromDb

public static List<Hib3GrouperDdl> retrieveDdlsFromDb()
get all the ddls, put grouper at the front

Returns:
the ddls

findScriptOverride

public static String findScriptOverride(DdlVersionable dbObjectVersion,
                                        String dbname)
 File name must be objectName.V#.dbname.sql
 e.g. Grouper.5.oracle10.sql
 
 The dbname must be a valid ddlutils dbname:
 axion, cloudscape, db2, db2v8, derby, firebird, hsqldb, interbase, maxdb, mckoi, 
 mssql, mysql, mysql5, oracle, oracle10, oracle9, postgresql, sapdb, sybase, sybasease15

 Also the following catchalls are acceptable: oracleall, mysqlall, db2all, sybaseall
 

Parameters:
dbObjectVersion - e.g. Grouper or GrouperLoader
dbname - e.g. oracle10 or mysql5
Returns:
the script or blank if it is not found

findScriptOverride

public static String findScriptOverride(String objectName,
                                        int version,
                                        String dbNameExact)
 get an override file (exact, dont look for the all ones like oracleall)
 File name must be objectName.V#.dbname.sql
 e.g. Grouper.5.oracle10.sql
 
 

Parameters:
objectName -
version -
dbNameExact -
Returns:
the script or null if none found

versionIntFromEnum

public static int versionIntFromEnum(Enum ddlVersion)
find a version from an enum version int

Parameters:
ddlVersion -
Returns:
the version

objectName

public static String objectName(Enum dbObjectVersion)
find the object name from the db object version

Parameters:
dbObjectVersion -
Returns:
the object name

upgradeDatabaseVersion

public static void upgradeDatabaseVersion(org.apache.ddlutils.model.Database baseVersion,
                                          org.apache.ddlutils.model.Database oldVersion,
                                          int baseDatabaseVersion,
                                          String objectName,
                                          int requestedVersion,
                                          int upgradeToVersion,
                                          StringBuilder additionalScripts,
                                          StringBuilder fullScript,
                                          org.apache.ddlutils.Platform platform,
                                          Connection connection,
                                          String schema,
                                          org.apache.ddlutils.platform.SqlBuilder sqlBuilder)
get a database object of a certain version based on the existing database, and tack on all the enums up to the version we want (if any)

Parameters:
baseVersion -
oldVersion - old version if there is one, null if not
baseDatabaseVersion -
objectName -
requestedVersion -
upgradeToVersion - eventual upgrade version
additionalScripts -
fullScript - so far
platform -
connection -
schema -
sqlBuilder -

ddlutilsFindOrCreateTable

public static org.apache.ddlutils.model.Table ddlutilsFindOrCreateTable(org.apache.ddlutils.model.Database database,
                                                                        String tableName)
find or create table

Parameters:
database -
tableName -
Returns:
the table

ddlutilsFindOrCreateIndex

public static org.apache.ddlutils.model.Index ddlutilsFindOrCreateIndex(org.apache.ddlutils.model.Database database,
                                                                        String tableName,
                                                                        String indexName,
                                                                        boolean unique,
                                                                        String... columnNames)
add an index on a table. drop a misnamed or a misuniqued index which is existing

Parameters:
database -
tableName -
indexName -
unique -
columnNames -
Returns:
the index which is the new one, or existing one if it already exists, or null if a custom index

ddlutilsFindOrCreateIndex

public static org.apache.ddlutils.model.Index ddlutilsFindOrCreateIndex(org.apache.ddlutils.model.Database database,
                                                                        DdlVersionBean ddlVersionBean,
                                                                        String tableName,
                                                                        String indexName,
                                                                        String customScript,
                                                                        boolean unique,
                                                                        String... columnNames)
add an index on a table. drop a misnamed or a misuniqued index which is existing

Parameters:
database -
ddlVersionBean - can be null unless custom script
tableName -
indexName -
customScript - use this script to create the index, not ddlutils
unique -
columnNames -
Returns:
the index which is the new one, or existing one if it already exists, or null if a custom index

ddlutilsFindOrCreateForeignKey

public static org.apache.ddlutils.model.ForeignKey ddlutilsFindOrCreateForeignKey(org.apache.ddlutils.model.Database database,
                                                                                  String tableName,
                                                                                  String foreignKeyName,
                                                                                  String foreignTableName,
                                                                                  String localColumnName,
                                                                                  String foreignColumnName)
add a foreign key on a table. drop a misnamed foreign key which is existing

Parameters:
database -
tableName -
foreignKeyName -
foreignTableName -
localColumnName -
foreignColumnName -
Returns:
the foreign key which is the new one, or existing one if it already exists

ddlutilsFindOrCreateForeignKey

public static org.apache.ddlutils.model.ForeignKey ddlutilsFindOrCreateForeignKey(org.apache.ddlutils.model.Database database,
                                                                                  String tableName,
                                                                                  String foreignKeyName,
                                                                                  String foreignTableName,
                                                                                  List<String> localColumnNames,
                                                                                  List<String> foreignColumnNames)
add a foreign key on a table. drop a misnamed foreign key which is existing

Parameters:
database -
tableName -
foreignKeyName -
foreignTableName -
localColumnNames -
foreignColumnNames -
Returns:
the foreign key which is the new one, or existing one if it already exists

dropAllForeignKeys

public static void dropAllForeignKeys(org.apache.ddlutils.model.Database database)
drop all foreign keys from a ddlutils database object

Parameters:
database -

ddlutilsFindTable

public static org.apache.ddlutils.model.Table ddlutilsFindTable(org.apache.ddlutils.model.Database database,
                                                                String tableName,
                                                                boolean exceptionOnNotFound)
find table, if not exist, throw exception

Parameters:
database -
tableName -
exceptionOnNotFound -
Returns:
the table

ddlutilsFindColumn

public static org.apache.ddlutils.model.Column ddlutilsFindColumn(org.apache.ddlutils.model.Database database,
                                                                  String tableName,
                                                                  String columnName,
                                                                  boolean exceptionIfNotFound)
find table, if not exist, throw exception

Parameters:
database -
tableName -
columnName -
exceptionIfNotFound -
Returns:
the table

ddlutilsFindColumn

public static org.apache.ddlutils.model.Column ddlutilsFindColumn(org.apache.ddlutils.model.Table table,
                                                                  String columnName,
                                                                  boolean exceptionOnNotFound)
find column, if not exist, throw exception

Parameters:
table - table to get column from
columnName - column name of column (case insensitive)
exceptionOnNotFound -
Returns:
the column

ddlutilsFindOrCreateColumn

public static org.apache.ddlutils.model.Column ddlutilsFindOrCreateColumn(org.apache.ddlutils.model.Table table,
                                                                          String columnName,
                                                                          int typeCode,
                                                                          String size,
                                                                          boolean primaryKey,
                                                                          boolean required)
find or create column with various properties

Parameters:
table -
columnName -
typeCode - from java.sql.Types
size - string, can be a simple int, or comma separated, see ddlutils docs
primaryKey - this should only be true for new tables
required - this should probably only be true for new tables (since ddlutils will copy to temp table)
Returns:
the column

ddlutilsFindOrCreateColumn

public static org.apache.ddlutils.model.Column ddlutilsFindOrCreateColumn(org.apache.ddlutils.model.Table table,
                                                                          String columnName,
                                                                          int typeCode,
                                                                          String size,
                                                                          boolean primaryKey,
                                                                          boolean required,
                                                                          String defaultValue)
find or create column with various properties

Parameters:
table -
columnName -
typeCode - from java.sql.Types
size - string, can be a simple int, or comma separated, see ddlutils docs
primaryKey - this should only be true for new tables
required - this should probably only be true for new tables (since ddlutils will copy to temp table)
defaultValue - is null for none, or something for default value
Returns:
the column

ddlutilsFixSizeColumn

public static org.apache.ddlutils.model.Column ddlutilsFixSizeColumn(org.apache.ddlutils.model.Table table,
                                                                     String columnName,
                                                                     int typeCode,
                                                                     String size,
                                                                     boolean primaryKey,
                                                                     boolean required)
find or create column with various properties

Parameters:
table -
columnName -
typeCode - from java.sql.Types
size - string, can be a simple int, or comma separated, see ddlutils docs
primaryKey - this should only be true for new tables
required - this should probably only be true for new tables (since ddlutils will copy to temp table)
Returns:
the column

ddlutilsFixSizeColumn

public static org.apache.ddlutils.model.Column ddlutilsFixSizeColumn(org.apache.ddlutils.model.Table table,
                                                                     String columnName,
                                                                     int typeCode,
                                                                     String size,
                                                                     boolean primaryKey,
                                                                     boolean required,
                                                                     String defaultValue)
find or create column with various properties

Parameters:
table -
columnName -
typeCode - from java.sql.Types
size - string, can be a simple int, or comma separated, see ddlutils docs
primaryKey - this should only be true for new tables
required - this should probably only be true for new tables (since ddlutils will copy to temp table)
defaultValue - is null for none, or something for default value
Returns:
the column

ddlutilsDropColumn

public static void ddlutilsDropColumn(org.apache.ddlutils.model.Database database,
                                      String tableName,
                                      String columnName,
                                      DdlVersionBean ddlVersionBean)
find and drop a column if it is there. If table not there, thats ok also drop all related indexes

Parameters:
database -
tableName -
ddlVersionBean -
columnName -

ddlutilsDropTable

public static void ddlutilsDropTable(DdlVersionBean ddlVersionBean,
                                     String tableName,
                                     boolean falseIfDropBeforeCreate)
find and drop a table if it is there

Parameters:
ddlVersionBean -
tableName -
falseIfDropBeforeCreate -

ddlutilsDropColumn

public static void ddlutilsDropColumn(org.apache.ddlutils.model.Table table,
                                      String columnName,
                                      DdlVersionBean ddlVersionBean)
find and drop a column if it is there also drop all related indexes

Parameters:
table -
columnName -
ddlVersionBean -

ddlutilsDropIndexes

public static void ddlutilsDropIndexes(org.apache.ddlutils.model.Table table,
                                       String columnName)
drop all indexes by column name (e.g. if removing column)

Parameters:
table -
columnName -

assertTablesThere

public static boolean assertTablesThere(DdlVersionBean ddlVersionBean,
                                        boolean expectRecords,
                                        boolean expectTrue)
see if tables are there (at least the grouper groups one)

Parameters:
ddlVersionBean -
expectRecords -
expectTrue - pritn exception if expecting true
Returns:
true if expect records, and records there. false if records not there. exception if exception is thrown and expect true.false if exception and not expect true

assertTablesThere

public static boolean assertTablesThere(DdlVersionBean ddlVersionBean,
                                        boolean expectRecords,
                                        boolean expectTrue,
                                        String tableName,
                                        boolean falseIfDropBeforeCreate)
see if tables are there (at least the grouper groups one)

Parameters:
ddlVersionBean -
expectRecords -
expectTrue - pritn exception if expecting true
tableName -
falseIfDropBeforeCreate -
Returns:
true if expect records, and records there. false if records not there. exception if exception is thrown and expect true.false if exception and not expect true

assertColumnThere

public static boolean assertColumnThere(boolean expectTrue,
                                        String tableName,
                                        String columnName)
see if tables are there (at least the grouper groups one)

Parameters:
expectTrue - throw exception if expecting true and not there or vice versa
tableName -
columnName -
Returns:
true if everything ok, false if not

tableExists

public static boolean tableExists(String tableName)
see if tables are there (at least the grouper groups one)

Parameters:
tableName -
Returns:
true if everything ok, false if not

findDbMetadataBean

public static GrouperDdlUtils.DbMetadataBean findDbMetadataBean(DdlVersionable ddlVersionable)
find the correct metadata for the DB

Parameters:
ddlVersionable -
Returns:
the metadatabean

sqlConcatenation

public static String sqlConcatenation(String field1,
                                      String field2,
                                      String separator)
Returns the sql to concatenate these two fields separated by the separator

Parameters:
field1 -
field2 -
separator -
Returns:
sql for concatenation

sqlConcatenation

public static String sqlConcatenation(String field1,
                                      String field2)
Returns the sql to concatenate these two fields separated by the separator

Parameters:
field1 -
field2 -
Returns:
sql for concatenation

getTableCount

public static int getTableCount(String tableName,
                                boolean exceptionIfTableDoesNotExist)
Get the number of records in a table

Parameters:
tableName -
exceptionIfTableDoesNotExist -
Returns:
count