Class GrouperDdlUtils
java.lang.Object
edu.internet2.middleware.grouper.ddl.GrouperDdlUtils
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic boolean
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
set this to false for testingstatic boolean
if we are dropping tables then creating -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
assertColumnThere
(boolean expectTrue, String tableName, String columnName) see if tables are there (at least the grouper groups one)static boolean
assertForeignKeyExists
(String tableName, String foreignKeyName) see if an foreign key with the given name existsstatic boolean
assertIndexExists
(String tableName, String indexName) see if an index has a column, if index isnt there its an exceptionstatic boolean
assertIndexHasColumn
(String tableName, String indexName, String columnName) see if an index has a column, if index isnt there its an exceptionstatic boolean
assertPrimaryKeyExists
(String tableName) See if table has a primary keystatic 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 boolean
assertTableThere
(boolean expectTrue, String tableName) see if table is therestatic boolean
static boolean
autoDdlFor
(GrouperVersion grouperVersion) static void
bootstrap
(boolean callFromCommandLine, boolean installDefaultGrouperData, boolean promptUser, boolean fromStartup) startup the process, if the version table is not there, print out that ddlstatic 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); } } });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 Object[]
columnNamesWithoutMaxLength
(String[] columnNamesWithMaxLength) input: col1, col2, col3(40), col4 output: object[] string[]: col1, col2, col3, col4 integer[]: null, null, 40, nullstatic String
convertUrlToDriverClassIfNeeded
(String connectionUrl, String driverClassName) if there is no driver class specified, then try to derive it from the URLstatic String
convertUrlToHibernateDialectIfNeeded
(String connectionUrl, String hibernateDialect) if there is no driver class specified, then try to derive it from the URLstatic String
if there is no quartz driver class specified, then try to derive it from the URLstatic String
returns mysql, postgres, oracle, or exceptionstatic 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 itstatic void
ddlutilsDropColumn
(Database database, String tableName, String columnName, DdlVersionBean ddlVersionBean) find and drop a column if it is there.static void
ddlutilsDropColumn
(Table table, String columnName, DdlVersionBean ddlVersionBean) find and drop a column if it is there also drop all related indexesstatic void
ddlutilsDropIndexes
(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 therestatic void
ddlutilsDropViewIfExists
(DdlVersionBean ddlVersionBean, String viewName, boolean falseIfDropBeforeCreate) drop a view if it is detected as existingstatic Column
ddlutilsFindColumn
(Database database, String tableName, String columnName, boolean exceptionIfNotFound) find table, if not exist, throw exceptionstatic Column
ddlutilsFindColumn
(Table table, String columnName, boolean exceptionOnNotFound) find column, if not exist, throw exceptionstatic Index
ddlutilsFindIndex
(Database database, String tableName, String indexName) add an index on a table.static Column
ddlutilsFindOrCreateColumn
(Table table, String columnName, int typeCode, String size, boolean primaryKey, boolean required) find or create column with various propertiesstatic Column
ddlutilsFindOrCreateColumn
(Table table, String columnName, int typeCode, String size, boolean primaryKey, boolean required, String defaultValue) find or create column with various propertiesstatic ForeignKey
ddlutilsFindOrCreateForeignKey
(Database database, String tableName, String foreignKeyName, String foreignTableName, String localColumnName, String foreignColumnName) add a foreign key on a table.static ForeignKey
ddlutilsFindOrCreateForeignKey
(Database database, String tableName, String foreignKeyName, String foreignTableName, List<String> localColumnNames, List<String> foreignColumnNames) add a foreign key on a table.static Index
ddlutilsFindOrCreateIndex
(Database database, DdlVersionBean ddlVersionBean, String tableName, String indexName, String customScript, boolean unique, String... columnNames) add an index on a table.static Index
ddlutilsFindOrCreateIndex
(Database database, String tableName, String indexName, boolean unique, String... columnNames) add an index on a table.static Table
ddlutilsFindOrCreateTable
(Database database, String tableName) find or create tablestatic Table
ddlutilsFindTable
(Database database, String tableName, boolean exceptionOnNotFound) find table, if not exist, throw exceptionstatic Column
ddlutilsFixSizeColumn
(Table table, String columnName, int typeCode, String size, boolean primaryKey, boolean required) find or create column with various propertiesstatic Column
ddlutilsFixSizeColumn
(Table table, String columnName, int typeCode, String size, boolean primaryKey, boolean required, String defaultValue) find or create column with various propertiesstatic ForeignKey
ddlutilsForeignKeyExists
(Database database, String tableName, String foreignKey) static void
ddlutilsTableComment
(DdlVersionBean ddlVersionBean, String tableName, String tableComment) add a table comment if the DB supports itstatic void
ddlutilsViewComment
(DdlVersionBean ddlVersionBean, String viewName, String tableComment) add a view comment if the DB supports itstatic DdlVersionBean
static void
ddlVersionBeanThreadLocalAssign
(DdlVersionBean ddlVersionBean) static void
static void
deleteDdlById
(String id) static void
delete all utf ddlsstatic boolean
doesConstraintExistOracle
(String constraintName) static boolean
doesFunctionExistOracle
(String functionName) static void
dropAllForeignKeys
(Database database) drop all foreign keys from a ddlutils database objectstatic void
dropAllForeignKeysScript
(GrouperDdlUtils.DbMetadataBean dbMetadataBean, DdlVersionBean ddlVersionBean) drop all foreign keys (database dependent), and generate the scriptfindDbMetadataBean
(DdlVersionable ddlVersionable) find the correct metadata for the DBstatic 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 String
static String
findScriptOverrideDatabase
(String connectionName) static int
getColumnType
(String tableName, String columnName) Returns the java.sql.Types value for the column -5 is bigint.static int
getTableCount
(String tableName, boolean exceptionIfTableDoesNotExist) Get the number of records in a tablestatic boolean
isColumnNullable
(String tableName, String columnName, String queryColumnName, long queryColumnValue) Checks if the columnName in the given tableName is allowed to be null.static boolean
isColumnNullable
(String tableName, String columnName, String queryColumnName, String queryColumnValue) Checks if the columnName in the given tableName is allowed to be null.static boolean
isMysql()
see if the config file seems to be mysqlstatic boolean
see if the config file seems to be mysqlstatic boolean
isOracle()
see if the config file seems to be oraclestatic boolean
see if the config file seems to be oraclestatic boolean
see if the config file seems to be postgresstatic boolean
isPostgres
(String connectionUrl) see if the config file seems to be postgresstatic boolean
see if the config file seems to be sql serverstatic boolean
isSQLServer
(String connectionUrl) see if the config file seems to be sql serverstatic void
kick off bootstrapstatic String
objectName
(Enum dbObjectVersion) find the object name from the db object versionstatic boolean
if we are inside the bootstrap, or if everything is ok, we are good to gostatic void
removeAllTables
(Database database) remove all objects, the foreign keys, then the tablesstatic DdlVersionable
retieveVersion
(String objectName, int version) retrieve a version of a ddl object versionablestatic Hib3GrouperDdl
static Hib3GrouperDdl
retrieveDdlByNameFromDatabase
(String objectName) retrieve a DDL by namestatic int
retrieveDdlDbVersion
(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 int
retrieveDdlJavaVersion
(String objectName) get the version of a ddl object in the DBstatic List<Hib3GrouperDdl>
get all the ddls, put grouper at the frontstatic StringBuilder
retrieveHistory
(String objectName) find history for a certain object nameget the object names from thestatic Platform
retrieve the ddl utils platformstatic Platform
retrievePlatform
(boolean useCache) retrieve the ddl utils platformstatic Platform
retrievePlatform
(boolean useCache, String databaseName) retrieve the ddl utils platformstatic String
runScriptFileIfShouldReturnString
(File scriptFile, boolean runScript) static String
runScriptFileIfShouldReturnString
(String connectionName, File scriptFile, boolean runScript) static void
runScriptIfShouldAndPrintOutput
(String script, boolean runScript) static String
runScriptIfShouldReturnString
(String script, boolean runScript, boolean deleteFileAfterwards) static String
runScriptIfShouldReturnString
(String connectionName, String script, boolean runScript, boolean deleteFileAfterwards) static String
sqlConcatenation
(String field1, String field2) Returns the sql to concatenate these two fields separated by the separatorstatic String
sqlConcatenation
(String field1, String field2, String separator) Returns the sql to concatenate these two fields separated by the separatorstatic String
run a script file against the default databasestatic String
sqlRun
(File scriptFile, String driver, String url, String user, String pass, boolean fromUnitTest, boolean printErrorToStdOut) run some sqlstatic Hib3GrouperDdl
storeAndReadUtfString
(String someUtfString, String id, String name) store and read a utf string, but dont commit it so its doesnt stay in the databasestatic Hib3GrouperDdl
storeDdl
(HibernateSession hibernateSession, String id, String name, String someUtfString) static boolean
supportsComments
(DdlVersionBean ddlVersionBean) if supports commentsstatic boolean
tableExists
(String tableName) see if tables are there (at least the grouper groups one)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)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)static int
versionIntFromEnum
(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() -
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, 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
-
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
-
runScriptIfShouldReturnString
-
runScriptFileIfShouldReturnString
-
runScriptFileIfShouldReturnString
-
runScriptIfShouldAndPrintOutput
-
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
-
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
-
doesFunctionExistOracle
-