Class Database

java.lang.Object
org.jumpmind.db.model.Database
All Implemented Interfaces:
Serializable, Cloneable

public class Database extends Object implements 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 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

      public static void logMissingDependentTableNames(List<Table> tables)
    • findMissingDependentTableNames

      public static Map<String,List<String>> findMissingDependentTableNames(List<Table> tables)
    • 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

      protected static Integer mergeChannels(Set<Integer> parentTablesChannels, Map<Integer,Set<Table>> dependencyMap, Map<Table,Integer> resolvedPosition)
    • printTables

      public static String printTables(List<Table> tables)
    • sortByForeignKeys

      public static Table[] sortByForeignKeys(Table... tables)
    • sortByForeignKeys

      public static List<Table> sortByForeignKeys(List<Table> tables)
    • mergeWith

      public void mergeWith(Database otherDb) throws ModelException
      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

      public String getName()
      Returns the name of this database model.
      Returns:
      The name
    • setName

      public void setName(String name)
      Sets the name of this database model.
      Parameters:
      name - The name
    • getCatalog

      public String getCatalog()
    • setCatalog

      public void setCatalog(String catalog)
    • getSchema

      public String getSchema()
    • setSchema

      public void setSchema(String schema)
    • getVersion

      public String getVersion()
      Returns the version of this database model.
      Returns:
      The version
    • setVersion

      public void setVersion(String version)
      Sets the version of this database model.
      Parameters:
      version - The version
    • getIdMethod

      public String getIdMethod()
      Returns the method for generating primary key values.
      Returns:
      The method
    • setIdMethod

      public void setIdMethod(String idMethod)
      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

      public Table[] getTables()
      Returns the tables in this model.
      Returns:
      The tables
    • getTable

      public Table getTable(int idx)
      Returns the table at the specified position.
      Parameters:
      idx - The index of the table
      Returns:
      The table
    • addTable

      public void addTable(Table table)
      Adds a table.
      Parameters:
      table - The table to add
    • addTable

      public void addTable(int idx, Table table)
      Adds a table at the specified position.
      Parameters:
      idx - The index where to insert the table
      table - The table to add
    • addTables

      public void addTables(Collection<Table> tables)
      Adds the given tables.
      Parameters:
      tables - The tables to add
    • addTables

      public void addTables(Table[] tables)
    • removeTable

      public void removeTable(Table table)
      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

      public void initialize() throws ModelException
      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

      public Table findTable(String name)
      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

      public Table findTable(String name, boolean caseSensitive)
      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
      caseSensitive - 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

      public Table findTable(String catalogName, String schemaName, String tableName)
    • resetTableIndexCache

      public void resetTableIndexCache()
    • removeAllTablesExcept

      public void removeAllTablesExcept(String... tableNames)
    • copy

      public Database copy()
    • clone

      public Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toVerboseString

      public String toVerboseString()
      Returns a verbose string representation of this database.
      Returns:
      The string representation