Class GrouperDdlUtils
java.lang.Object
edu.internet2.middleware.grouper.ddl.GrouperDdlUtils
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleantrue to compare ddl from db version to the current java version, false to start over and find all diffs (without deleting existing)static booleanset this to false for testingstatic booleanif we are dropping tables then creating -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanassertColumnThere(boolean expectTrue, String tableName, String columnName) see if tables are there (at least the grouper groups one)static booleanassertForeignKeyExists(String tableName, String foreignKeyName) see if an foreign key with the given name existsstatic booleanassertIndexExists(String tableName, String indexName) see if an index has a column, if index isnt there its an exceptionstatic booleanassertIndexHasColumn(String tableName, String indexName, String columnName) see if an index has a column, if index isnt there its an exceptionstatic booleanassertPrimaryKeyExists(String tableName) See if table has a primary keystatic booleanassertTablesThere(DdlVersionBean ddlVersionBean, boolean expectRecords, boolean expectTrue) see if tables are there (at least the grouper groups one)static booleanassertTablesThere(DdlVersionBean ddlVersionBean, boolean expectRecords, boolean expectTrue, String tableName, boolean falseIfDropBeforeCreate) see if tables are there (at least the grouper groups one)static booleanassertTableThere(boolean expectTrue, String tableName) see if table is therestatic booleanstatic booleanautoDdlFor(GrouperVersion grouperVersion) static voidbootstrap(boolean callFromCommandLine, boolean installDefaultGrouperData, boolean promptUser, boolean fromStartup) startup the process, if the version table is not there, print out that ddlstatic StringcatalogName(Connection connection) static StringchangeDatabase(String objectName, boolean dropViewsConstraintsFirst, boolean runScript, 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 StringchangeDatabase(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 Object[]columnNamesWithoutMaxLength(String[] columnNamesWithMaxLength) input: col1, col2, col3(40), col4 output: object[] string[]: col1, col2, col3, col4 integer[]: null, null, 40, nullstatic StringconvertUrlToDriverClassIfNeeded(String connectionUrl, String driverClassName) if there is no driver class specified, then try to derive it from the URLstatic StringconvertUrlToHibernateDialectIfNeeded(String connectionUrl, String hibernateDialect) if there is no driver class specified, then try to derive it from the URLstatic Stringif there is no quartz driver class specified, then try to derive it from the URLstatic Stringreturns mysql, postgres, oracle, or exceptionstatic voidddlutilsBackupTable(DdlVersionBean ddlVersionBean, String tableName, String backupTableName) backup a table into another table (which should not exist)static voidddlutilsColumnComment(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 voidddlutilsCreateOrReplaceView(DdlVersionBean ddlVersionBean, String viewName, String viewComment, Set<String> aliases, Set<String> columnComments, String sql) add a view if the DB supports itstatic voidddlutilsDropColumn(Database database, String tableName, String columnName, DdlVersionBean ddlVersionBean) find and drop a column if it is there.static voidddlutilsDropColumn(Table table, String columnName, DdlVersionBean ddlVersionBean) find and drop a column if it is there also drop all related indexesstatic voidddlutilsDropIndexes(Table table, String columnName) drop all indexes by column name (e.g.static voidddlutilsDropTable(DdlVersionBean ddlVersionBean, String tableName, boolean falseIfDropBeforeCreate) find and drop a table if it is therestatic voidddlutilsDropViewIfExists(DdlVersionBean ddlVersionBean, String viewName, boolean falseIfDropBeforeCreate) drop a view if it is detected as existingstatic ColumnddlutilsFindColumn(Database database, String tableName, String columnName, boolean exceptionIfNotFound) find table, if not exist, throw exceptionstatic ColumnddlutilsFindColumn(Table table, String columnName, boolean exceptionOnNotFound) find column, if not exist, throw exceptionstatic IndexddlutilsFindIndex(Database database, String tableName, String indexName) add an index on a table.static ColumnddlutilsFindOrCreateColumn(Table table, String columnName, int typeCode, String size, boolean primaryKey, boolean required) find or create column with various propertiesstatic ColumnddlutilsFindOrCreateColumn(Table table, String columnName, int typeCode, String size, boolean primaryKey, boolean required, String defaultValue) find or create column with various propertiesstatic ForeignKeyddlutilsFindOrCreateForeignKey(Database database, String tableName, String foreignKeyName, String foreignTableName, String localColumnName, String foreignColumnName) add a foreign key on a table.static ForeignKeyddlutilsFindOrCreateForeignKey(Database database, String tableName, String foreignKeyName, String foreignTableName, List<String> localColumnNames, List<String> foreignColumnNames) add a foreign key on a table.static IndexddlutilsFindOrCreateIndex(Database database, DdlVersionBean ddlVersionBean, String tableName, String indexName, String customScript, boolean unique, String... columnNames) add an index on a table.static IndexddlutilsFindOrCreateIndex(Database database, String tableName, String indexName, boolean unique, String... columnNames) add an index on a table.static TableddlutilsFindOrCreateTable(Database database, String tableName) find or create tablestatic TableddlutilsFindTable(Database database, String tableName, boolean exceptionOnNotFound) find table, if not exist, throw exceptionstatic ColumnddlutilsFixSizeColumn(Table table, String columnName, int typeCode, String size, boolean primaryKey, boolean required) find or create column with various propertiesstatic ColumnddlutilsFixSizeColumn(Table table, String columnName, int typeCode, String size, boolean primaryKey, boolean required, String defaultValue) find or create column with various propertiesstatic ForeignKeyddlutilsForeignKeyExists(Database database, String tableName, String foreignKey) static voidddlutilsTableComment(DdlVersionBean ddlVersionBean, String tableName, String tableComment) add a table comment if the DB supports itstatic voidddlutilsViewComment(DdlVersionBean ddlVersionBean, String viewName, String tableComment) add a view comment if the DB supports itstatic DdlVersionBeanstatic voidddlVersionBeanThreadLocalAssign(DdlVersionBean ddlVersionBean) static voidstatic voiddeleteDdlById(String id) static voiddelete all utf ddlsstatic booleandoesConstraintExistOracle(String constraintName) static booleandoesFunctionExist(String functionName) static voiddropAllForeignKeys(Database database) drop all foreign keys from a ddlutils database objectstatic voiddropAllForeignKeysScript(GrouperDdlUtils.DbMetadataBean dbMetadataBean, DdlVersionBean ddlVersionBean) drop all foreign keys (database dependent), and generate the scriptfindDbMetadataBean(DdlVersionable ddlVersionable) find the correct metadata for the DBstatic StringfindScriptOverride(DdlVersionable dbObjectVersion, String dbname) File name must be objectName.V#.dbname.sql e.g.static StringfindScriptOverride(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 Stringstatic StringfindScriptOverrideDatabase(String connectionName) static intgetColumnType(String tableName, String columnName) Returns the java.sql.Types value for the column -5 is bigint.static intgetTableCount(String tableName, boolean exceptionIfTableDoesNotExist) Get the number of records in a tablestatic booleanisColumnNullable(String tableName, String columnName, String queryColumnName, long queryColumnValue) Checks if the columnName in the given tableName is allowed to be null.static booleanisColumnNullable(String tableName, String columnName, String queryColumnName, String queryColumnValue) Checks if the columnName in the given tableName is allowed to be null.static booleanisMysql()see if the config file seems to be mysqlstatic booleansee if the config file seems to be mysqlstatic booleanisOracle()see if the config file seems to be oraclestatic booleansee if the config file seems to be oraclestatic booleansee if the config file seems to be postgresstatic booleanisPostgres(String connectionUrl) see if the config file seems to be postgresstatic booleansee if the config file seems to be sql serverstatic booleanisSQLServer(String connectionUrl) see if the config file seems to be sql serverstatic intlastDelimiterPosition(StringBuffer buf, String currentLine) static voidkick off bootstrapstatic StringobjectName(Enum dbObjectVersion) find the object name from the db object versionstatic booleanif we are inside the bootstrap, or if everything is ok, we are good to gostatic voidremoveAllTables(Database database) remove all objects, the foreign keys, then the tablesstatic DdlVersionableretieveVersion(String objectName, int version) retrieve a version of a ddl object versionablestatic Hib3GrouperDdlstatic Hib3GrouperDdlretrieveDdlByNameFromDatabase(String objectName) retrieve a DDL by namestatic intretrieveDdlDbVersion(String objectName) get the version of a ddl object in the DBretrieveDdlEnum(String objectName) the relationship between object name and the enum is as follows.static intretrieveDdlJavaVersion(String objectName) get the version of a ddl object in the DBstatic List<Hib3GrouperDdl>get all the ddls, put grouper at the frontstatic StringBuilderretrieveHistory(String objectName) find history for a certain object nameget the object names from thestatic Platformretrieve the ddl utils platformstatic PlatformretrievePlatform(boolean useCache) retrieve the ddl utils platformstatic PlatformretrievePlatform(boolean useCache, String databaseName) retrieve the ddl utils platformstatic StringrunScriptFileIfShouldReturnString(String connectionName, File scriptFile, boolean runScript, boolean printOut) static StringrunScriptIfShouldReturnString(String connectionName, String script, boolean runScript, boolean deleteFileAfterwards, boolean printOut) static StringsqlConcatenation(String field1, String field2) Returns the sql to concatenate these two fields separated by the separatorstatic StringsqlConcatenation(String field1, String field2, String separator) Returns the sql to concatenate these two fields separated by the separatorstatic Stringget the first page of a query from the grouper databasestatic Stringrun a script file against the default databasestatic StringsqlRun(File scriptFile, GrouperLoaderDb grouperLoaderDb, boolean fromUnitTest, boolean printErrorToStdOut) run some sqlstatic Hib3GrouperDdlstoreAndReadUtfString(String someUtfString, String id, String name) store and read a utf string, but dont commit it so its doesnt stay in the databasestatic Hib3GrouperDdlstoreDdl(HibernateSession hibernateSession, String id, String name, String someUtfString) static booleansupportsComments(DdlVersionBean ddlVersionBean) if supports commentsstatic booleantableExists(String tableName) see if tables are there (at least the grouper groups one)static voidupgradeDatabaseVersion(Database baseVersion, Database oldVersion, int baseDatabaseVersion, String objectName, int upgradeToVersion, StringBuilder additionalScripts, StringBuilder fullScript, Platform platform, Connection connection, String schema, 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 voidupgradeDatabaseVersion(Database baseVersion, Database oldVersion, int baseDatabaseVersion, String objectName, int upgradeToVersion, StringBuilder additionalScripts, StringBuilder fullScript, Platform platform, Connection connection, String schema, SqlBuilder sqlBuilder, GrouperDdlCompareResult grouperDdlCompareResult) 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 intversionIntFromEnum(Enum ddlVersion) find a version from an enum version int
-
Field Details
-
isDropBeforeCreate
public static boolean isDropBeforeCreateif we are dropping tables then creating -
compareFromDbDllVersion
public static boolean compareFromDbDllVersiontrue to compare ddl from db version to the current java version, false to start over and find all diffs (without deleting existing) -
internal_printDdlUpdateMessage
public static boolean internal_printDdlUpdateMessageset this to false for testing
-
-
Constructor Details
-
GrouperDdlUtils
public GrouperDdlUtils()
-
-
Method Details
-
ddlVersionBeanThreadLocal
- Returns:
- the bean
-
ddlVersionBeanThreadLocalAssign
- Parameters:
ddlVersionBean-
-
ddlVersionBeanThreadLocalClear
public static void ddlVersionBeanThreadLocalClear() -
sqlPageFirstGrouper
get the first page of a query from the grouper database- Parameters:
sql-pageSize-- Returns:
- the new query, the page size will have a bind variable at end
-
databaseType
returns mysql, postgres, oracle, or exception- Returns:
- database type
-
isPostgres
public static boolean isPostgres()see if the config file seems to be postgres- Returns:
- see if postgres
-
isPostgres
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
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
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
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
retrieve the ddl utils platform- Returns:
- the platform object
-
retrievePlatform
retrieve the ddl utils platform- Parameters:
useCache- if we should get from cache if it is available- Returns:
- the platform object
-
retrievePlatform
retrieve the ddl utils platform- Parameters:
useCache- if we should get from cache if it is available- Returns:
- the platform object
-
main
kick off bootstrap- Parameters:
args-
-
bootstrap
public static void bootstrap(boolean callFromCommandLine, boolean installDefaultGrouperData, boolean promptUser, boolean fromStartup) 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
-
sqlRun
run a script file against the default database- Parameters:
scriptFile-fromUnitTest-printErrorToStdOut-- Returns:
- the output
-
convertUrlToDriverClassIfNeeded
if there is no driver class specified, then try to derive it from the URL- Parameters:
connectionUrl-driverClassName-- Returns:
- the driver class
-
convertUrlToQuartzDriverDelegateClass
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, GrouperLoaderDb grouperLoaderDb, 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
-
changeDatabase
public static String changeDatabase(String objectName, boolean dropViewsConstraintsFirst, boolean runScript, 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 databasedropViewsConstraintsFirst-runScript-- Returns:
- string
-
runScriptIfShouldReturnString
-
lastDelimiterPosition
-
runScriptFileIfShouldReturnString
-
dropAllForeignKeysScript
public static void dropAllForeignKeysScript(GrouperDdlUtils.DbMetadataBean dbMetadataBean, DdlVersionBean ddlVersionBean) drop all foreign keys (database dependent), and generate the script- Parameters:
dbMetadataBean-ddlVersionBean-
-
removeAllTables
remove all objects, the foreign keys, then the tables- Parameters:
database-
-
retrieveHistory
find history for a certain object name- Parameters:
objectName-- Returns:
- the history or new stringbuilder if none available
-
retieveVersion
retrieve a version of a ddl object versionable- Parameters:
objectName-version-- Returns:
- the ddl versionable
-
retrieveDdlJavaVersion
get the version of a ddl object in the DB- Parameters:
objectName-- Returns:
- the version or -1 if not in the DB
-
retrieveDdlEnum
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-
-
supportsComments
if supports comments- Parameters:
ddlVersionBean-- Returns:
- true if supports comments
-
retrieveObjectNames
get the object names from the- Returns:
- the list of object names
-
retrieveDdlDbVersion
get the version of a ddl object in the DB- Parameters:
objectName-- Returns:
- the version or -1 if not in the DB
-
retrieveDdlByIdFromDatabase
- Parameters:
id-- Returns:
- the ddl
-
deleteDdlById
- Parameters:
id-
-
deleteUtfDdls
public static void deleteUtfDdls()delete all utf ddls -
retrieveDdlByNameFromDatabase
retrieve a DDL by name- Parameters:
objectName-- Returns:
- the ddl or null
-
storeAndReadUtfString
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
get all the ddls, put grouper at the front- Returns:
- the ddls
-
findScriptOverrideDatabase
-
findScriptOverrideDatabase
-
findScriptOverride
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, 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 GrouperLoaderdbname- e.g. oracle10 or mysql5- Returns:
- the script or blank if it is not found
-
findScriptOverride
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
find a version from an enum version int- Parameters:
ddlVersion-- Returns:
- the version
-
objectName
find the object name from the db object version- Parameters:
dbObjectVersion-- Returns:
- the object name
-
upgradeDatabaseVersion
public static void upgradeDatabaseVersion(Database baseVersion, Database oldVersion, int baseDatabaseVersion, String objectName, int upgradeToVersion, StringBuilder additionalScripts, StringBuilder fullScript, Platform platform, Connection connection, String schema, 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 notbaseDatabaseVersion-objectName-upgradeToVersion- eventual upgrade versionadditionalScripts-fullScript- so farplatform-connection-schema-sqlBuilder-
-
upgradeDatabaseVersion
public static void upgradeDatabaseVersion(Database baseVersion, Database oldVersion, int baseDatabaseVersion, String objectName, int upgradeToVersion, StringBuilder additionalScripts, StringBuilder fullScript, Platform platform, Connection connection, String schema, SqlBuilder sqlBuilder, GrouperDdlCompareResult grouperDdlCompareResult) 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 notbaseDatabaseVersion-objectName-upgradeToVersion- eventual upgrade versionadditionalScripts-fullScript- so farplatform-connection-schema-sqlBuilder-
-
ddlutilsFindOrCreateTable
find or create table- Parameters:
database-tableName-- Returns:
- the table
-
autoDdl2_5orAbove
public static boolean autoDdl2_5orAbove() -
autoDdlFor
-
ddlutilsFindOrCreateIndex
public static Index ddlutilsFindOrCreateIndex(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
-
columnNamesWithoutMaxLength
input: col1, col2, col3(40), col4 output: object[] string[]: col1, col2, col3, col4 integer[]: null, null, 40, null
return the string array of column names and the Integer[] of max lengths- Parameters:
columnNamesWithMaxLength-- Returns:
- the array of arrays
-
assertIndexHasColumn
see if an index has a column, if index isnt there its an exception- Parameters:
tableName-indexName-columnName-- Returns:
- true or false
-
assertIndexExists
see if an index has a column, if index isnt there its an exception- Parameters:
tableName-indexName-columnName-- Returns:
- true or false
-
catalogName
-
assertForeignKeyExists
see if an foreign key with the given name exists- Parameters:
tableName-foreignKey-- Returns:
- true or false
-
assertPrimaryKeyExists
See if table has a primary key- Parameters:
tableName-- Returns:
- true or false
-
ddlutilsFindIndex
add an index on a table. drop a misnamed or a misuniqued index which is existing- Parameters:
database-ddlVersionBean- can be null unless custom scripttableName-indexName-customScript- use this script to create the index, not ddlutilsunique-columnNames- or column names with max length- Returns:
- the index which is the new one, or existing one if it already exists, or null if a custom index
-
ddlutilsForeignKeyExists
public static ForeignKey ddlutilsForeignKeyExists(Database database, String tableName, String foreignKey) -
ddlutilsFindOrCreateIndex
public static Index ddlutilsFindOrCreateIndex(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 scripttableName-indexName-customScript- use this script to create the index, not ddlutilsunique-columnNames- or column names with max length- Returns:
- the index which is the new one, or existing one if it already exists, or null if a custom index
-
ddlutilsFindOrCreateForeignKey
public static ForeignKey ddlutilsFindOrCreateForeignKey(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 ForeignKey ddlutilsFindOrCreateForeignKey(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
drop all foreign keys from a ddlutils database object- Parameters:
database-
-
ddlutilsFindTable
public static Table ddlutilsFindTable(Database database, String tableName, boolean exceptionOnNotFound) find table, if not exist, throw exception- Parameters:
database-tableName-exceptionOnNotFound-- Returns:
- the table
-
ddlutilsFindColumn
public static Column ddlutilsFindColumn(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 Column ddlutilsFindColumn(Table table, String columnName, boolean exceptionOnNotFound) find column, if not exist, throw exception- Parameters:
table- table to get column fromcolumnName- column name of column (case insensitive)exceptionOnNotFound-- Returns:
- the column
-
ddlutilsFindOrCreateColumn
public static Column ddlutilsFindOrCreateColumn(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.Typessize- string, can be a simple int, or comma separated, see ddlutils docsprimaryKey- this should only be true for new tablesrequired- this should probably only be true for new tables (since ddlutils will copy to temp table)- Returns:
- the column
-
ddlutilsFindOrCreateColumn
public static Column ddlutilsFindOrCreateColumn(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.Typessize- string, can be a simple int, or comma separated, see ddlutils docsprimaryKey- this should only be true for new tablesrequired- 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 Column ddlutilsFixSizeColumn(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.Typessize- string, can be a simple int, or comma separated, see ddlutils docsprimaryKey- this should only be true for new tablesrequired- this should probably only be true for new tables (since ddlutils will copy to temp table)- Returns:
- the column
-
ddlutilsFixSizeColumn
public static Column ddlutilsFixSizeColumn(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.Typessize- string, can be a simple int, or comma separated, see ddlutils docsprimaryKey- this should only be true for new tablesrequired- 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(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(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
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 truetableName-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
see if tables are there (at least the grouper groups one)- Parameters:
expectTrue- what the expected outcome istableName-columnName-- Returns:
- true if everything ok, false if not
-
assertTableThere
see if table is there- Parameters:
expectTrue- throw exception if expecting true and not there or vice versatableName-columnName-- Returns:
- true if everything ok, false if not
-
tableExists
see if tables are there (at least the grouper groups one)- Parameters:
tableName-- Returns:
- true if everything ok, false if not
-
findDbMetadataBean
find the correct metadata for the DB- Parameters:
ddlVersionable-- Returns:
- the metadatabean
-
sqlConcatenation
Returns the sql to concatenate these two fields separated by the separator- Parameters:
field1-field2-separator-- Returns:
- sql for concatenation
-
sqlConcatenation
Returns the sql to concatenate these two fields separated by the separator- Parameters:
field1-field2-- Returns:
- sql for concatenation
-
getTableCount
Get the number of records in a table- Parameters:
tableName-exceptionIfTableDoesNotExist-- Returns:
- count
-
isColumnNullable
public static boolean isColumnNullable(String tableName, String columnName, String queryColumnName, String queryColumnValue) Checks if the columnName in the given tableName is allowed to be null.- Parameters:
tableName-columnName-queryColumnName-queryColumnValue-- Returns:
-
isColumnNullable
public static boolean isColumnNullable(String tableName, String columnName, String queryColumnName, long queryColumnValue) Checks if the columnName in the given tableName is allowed to be null.- Parameters:
tableName-columnName-queryColumnName-queryColumnValue-- Returns:
-
getColumnType
Returns the java.sql.Types value for the column -5 is bigint. 93 is timestamp. 2 is numeric (number in Oracle).- Parameters:
tableName-columnName-- Returns:
-
doesConstraintExistOracle
-
doesFunctionExist
-