Package org.jumpmind.db.model
Class Database
java.lang.Object
org.jumpmind.db.model.Database
- All Implemented Interfaces:
Serializable
,Cloneable
Represents the database model, ie. the tables in the database. It also contains the corresponding dyna classes for creating dyna beans for the objects stored
in the tables.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a table at the specified position.void
Adds a table.void
addTables
(Collection<Table> tables) Adds the given tables.void
clone()
copy()
boolean
findMissingDependentTableNames
(List<Table> tables) Finds the table with the specified name, using case insensitive matching.Finds the table with the specified name, using case insensitive matching.Catalog & Schema aware finder for ddlutils Database classReturns the method for generating primary key values.getName()
Returns the name of this database model.getTable
(int idx) Returns the table at the specified position.int
Returns the number of tables in this model.Table[]
Returns the tables in this model.Returns the version of this database model.int
hashCode()
void
Initializes the model by establishing the relationships between elements in this model encoded eg.static void
logMissingDependentTableNames
(List<Table> tables) protected static Integer
mergeChannels
(Set<Integer> parentTablesChannels, Map<Integer, Set<Table>> dependencyMap, Map<Table, Integer> resolvedPosition) void
Adds all tables from the other database to this database.static String
printTables
(List<Table> tables) void
removeAllTablesExcept
(String... tableNames) void
removeTable
(int idx) Removes the indicated table.void
removeTable
(Table table) Removes the given table.void
static void
resolveForeignKeyOrder
(Table t, Map<String, Table> allTables, Set<Table> resolved, Set<Table> temporary, List<Table> finalList, Table parentTable, Map<Table, Set<String>> missingDependencyMap, Map<Integer, Set<Table>> dependencyMap, org.apache.commons.lang3.mutable.MutableInt depth, org.apache.commons.lang3.mutable.MutableInt position, Map<Table, Integer> resolvedPosition, org.apache.commons.lang3.mutable.MutableInt parentPosition) void
setCatalog
(String catalog) void
setIdMethod
(String idMethod) Sets the method for generating primary key values.void
Sets the name of this database model.void
void
setVersion
(String version) Sets the version of this database model.sortByForeignKeys
(List<Table> tables) sortByForeignKeys
(List<Table> tables, Map<String, Table> allTables, Map<Integer, Set<Table>> dependencyMap, Map<Table, Set<String>> missingDependencyMap) Implements modified topological sort of tables (@see topological sorting).static Table[]
sortByForeignKeys
(Table... tables) toString()
Returns a verbose string representation of this database.
-
Constructor Details
-
Database
public Database()
-
-
Method Details
-
sortByForeignKeys
public static List<Table> sortByForeignKeys(List<Table> tables, Map<String, Table> allTables, Map<Integer, Set<Table>> dependencyMap, Map<Table, Set<String>> missingDependencyMap) Implements modified topological sort of tables (@see topological sorting). The 'depth-first search' is implemented in order to detect and ignore cycles.- Parameters:
tables
- List of tables to sort.allTables
- List of tables in database, if null the tables param will be used.tablePrefix
- The SymmetricDS runtime table prefix.dependencyMap
- Map to separate dependent tables into groups. The key will be an integer based counter (1,2...) to identify the grouping. The value will contain all the tables that are dependent on each other but independent for other tables in other groups. Used to identify which tables could be placed in a specific group. This should be passed in empty so that it can be used by reference after the method finishes.missingDependencyMap
- This is a used for any tables that are missing from the tables param that should be included in synchronization to avoid FK issues.- Returns:
- List of tables in their dependency order - if table A has a foreign key for table B then table B will precede table A in the list.
-
logMissingDependentTableNames
-
findMissingDependentTableNames
-
resolveForeignKeyOrder
public static void resolveForeignKeyOrder(Table t, Map<String, Table> allTables, Set<Table> resolved, Set<Table> temporary, List<Table> finalList, Table parentTable, Map<Table, Set<String>> missingDependencyMap, Map<Integer, Set<Table>> dependencyMap, org.apache.commons.lang3.mutable.MutableInt depth, org.apache.commons.lang3.mutable.MutableInt position, Map<Table, Integer> resolvedPosition, org.apache.commons.lang3.mutable.MutableInt parentPosition) -
mergeChannels
-
printTables
-
sortByForeignKeys
-
sortByForeignKeys
-
mergeWith
Adds all tables from the other database to this database. Note that the other database is not changed.- Parameters:
otherDb
- The other database model- Throws:
ModelException
-
getName
Returns the name of this database model.- Returns:
- The name
-
setName
Sets the name of this database model.- Parameters:
name
- The name
-
getCatalog
-
setCatalog
-
getSchema
-
setSchema
-
getVersion
Returns the version of this database model.- Returns:
- The version
-
setVersion
Sets the version of this database model.- Parameters:
version
- The version
-
getIdMethod
Returns the method for generating primary key values.- Returns:
- The method
-
setIdMethod
Sets the method for generating primary key values. Note that this value is ignored by DdlUtils and only for compatibility with Torque.- Parameters:
idMethod
- The method
-
getTableCount
public int getTableCount()Returns the number of tables in this model.- Returns:
- The number of tables
-
getTables
Returns the tables in this model.- Returns:
- The tables
-
getTable
Returns the table at the specified position.- Parameters:
idx
- The index of the table- Returns:
- The table
-
addTable
Adds a table.- Parameters:
table
- The table to add
-
addTable
Adds a table at the specified position.- Parameters:
idx
- The index where to insert the tabletable
- The table to add
-
addTables
Adds the given tables.- Parameters:
tables
- The tables to add
-
addTables
-
removeTable
Removes the given table.- Parameters:
table
- The table to remove
-
removeTable
public void removeTable(int idx) Removes the indicated table.- Parameters:
idx
- The index of the table to remove
-
initialize
Initializes the model by establishing the relationships between elements in this model encoded eg. in foreign keys etc. Also checks that the model elements are valid (table and columns have a name, foreign keys rference existing tables etc.)- Throws:
ModelException
-
findTable
Finds the table with the specified name, using case insensitive matching. Note that this method is not called getTable to avoid introspection problems.- Parameters:
name
- The name of the table to find- Returns:
- The table or
null
if there is no such table
-
findTable
Finds the table with the specified name, using case insensitive matching. Note that this method is not called getTable) to avoid introspection problems.- Parameters:
name
- The name of the table to findcaseSensitive
- Whether case matters for the names- Returns:
- The table or
null
if there is no such table
-
findTable
public Table findTable(String catalogName, String schemaName, String tableName, boolean caseSensitive) Catalog & Schema aware finder for ddlutils Database class- Parameters:
catalogName
-schemaName
-tableName
-caseSensitive
-- Returns:
-
findTable
-
resetTableIndexCache
public void resetTableIndexCache() -
removeAllTablesExcept
-
copy
-
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-
equals
-
hashCode
public int hashCode() -
toString
-
toVerboseString
Returns a verbose string representation of this database.- Returns:
- The string representation
-