Class DataModel

java.lang.Object
net.sf.jailer.datamodel.DataModel

public class DataModel extends Object
Relational data model.
Author:
Ralf Wisser
  • Field Details

    • TABLE_CSV_FILE

      public static final String TABLE_CSV_FILE
      See Also:
    • MODELNAME_CSV_FILE

      public static final String MODELNAME_CSV_FILE
      See Also:
    • namedAssociations

      public Map<String,Association> namedAssociations
      Maps association-names to associations;
    • decisionPending

      public Set<String> decisionPending
      Set of names of associations for which no decision has been made.
    • columnOrderPrio

      public final Map<String,DataModel.ColumnOrderPriority> columnOrderPrio
      Maps normalized column name to order priority.
    • version

      public long version
      Internal version number. Incremented on each modification.
    • DEFAULT_NAME

      public static final String DEFAULT_NAME
      Default model name.
      See Also:
  • Constructor Details

    • DataModel

      public DataModel(PrimaryKeyFactory primaryKeyFactory, Map<String,String> sourceSchemaMapping, ExecutionContext executionContext) throws IOException
      Reads in table.csv and association.csv and builds the relational data model.
      Parameters:
      primaryKeyFactory - factory for creating primary keys
      sourceSchemaMapping - mapping of source schema names
      executionContext - the execution context
      Throws:
      IOException
    • DataModel

      public DataModel(ExecutionContext executionContext) throws IOException
      Reads in table.csv and association.csv and builds the relational data model.
      Parameters:
      executionContext - the execution context
      Throws:
      IOException
    • DataModel

      public DataModel(KnownIdentifierMap knownIdentifiers, ExecutionContext executionContext) throws IOException
      Reads in table.csv and association.csv and builds the relational data model.
      Parameters:
      knownIdentifiers - map of known identifiers for name normalization
      executionContext - the execution context
      Throws:
      IOException
    • DataModel

      public DataModel(Map<String,String> sourceSchemaMapping, ExecutionContext executionContext, boolean failOnMissingTables) throws IOException
      Reads in table.csv and association.csv and builds the relational data model.
      Parameters:
      sourceSchemaMapping - mapping of source schema names
      executionContext - the execution context
      failOnMissingTables - true to throw an exception if the data model files are not found
      Throws:
      IOException
    • DataModel

      public DataModel(String additionalTablesFile, String additionalAssociationsFile, PrimaryKeyFactory primaryKeyFactory, ExecutionContext executionContext) throws IOException
      Reads in table.csv and association.csv and builds the relational data model.
      Parameters:
      additionalTablesFile - additional table file to read, or null
      additionalAssociationsFile - additional association file to read, or null
      primaryKeyFactory - factory for creating primary keys
      executionContext - the execution context
      Throws:
      IOException
    • DataModel

      public DataModel(String additionalTablesFile, String additionalAssociationsFile, ExecutionContext executionContext) throws IOException
      Reads in table.csv and association.csv and builds the relational data model.
      Parameters:
      additionalTablesFile - additional table file to read, or null
      additionalAssociationsFile - additional association file to read, or null
      executionContext - the execution context
      Throws:
      IOException
    • DataModel

      public DataModel(String additionalTablesFile, String additionalAssociationsFile, Map<String,String> sourceSchemaMapping, CsvFile.LineFilter assocFilter, ExecutionContext executionContext) throws IOException
      Reads in table.csv and association.csv and builds the relational data model.
      Parameters:
      additionalTablesFile - additional table file to read, or null
      additionalAssociationsFile - additional association file to read, or null
      sourceSchemaMapping - mapping of source schema names
      assocFilter - filter for association lines, or null
      executionContext - the execution context
      Throws:
      IOException
    • DataModel

      public DataModel(String additionalTablesFile, String additionalAssociationsFile, Map<String,String> sourceSchemaMapping, CsvFile.LineFilter assocFilter, PrimaryKeyFactory primaryKeyFactory, ExecutionContext executionContext, boolean failOnMissingTables) throws IOException
      Reads in table.csv and association.csv and builds the relational data model.
      Parameters:
      additionalTablesFile - additional table file to read, or null
      additionalAssociationsFile - additional association file to read, or null
      sourceSchemaMapping - mapping of source schema names
      assocFilter - filter for association lines, or null
      primaryKeyFactory - factory for creating primary keys
      executionContext - the execution context
      failOnMissingTables - true to throw an exception if the data model files are not found
      Throws:
      IOException
    • DataModel

      public DataModel(String additionalTablesFile, String additionalAssociationsFile, Map<String,String> sourceSchemaMapping, CsvFile.LineFilter assocFilter, PrimaryKeyFactory primaryKeyFactory, ExecutionContext executionContext, boolean failOnMissingTables, KnownIdentifierMap knownIdentifiers) throws IOException
      Reads in table.csv and association.csv and builds the relational data model.
      Parameters:
      additionalTablesFile - additional table file to read, or null
      additionalAssociationsFile - additional association file to read, or null
      sourceSchemaMapping - mapping of source schema names
      assocFilter - filter for association lines, or null
      primaryKeyFactory - factory for creating primary keys
      executionContext - the execution context
      failOnMissingTables - true to throw an exception if the data model files are not found
      knownIdentifiers - map of known identifiers for name normalization, or null
      Throws:
      IOException
  • Method Details

    • getDatamodelFolder

      public static String getDatamodelFolder(ExecutionContext executionContext)
      Gets name of data model folder.
      Parameters:
      executionContext - the execution context
      Returns:
      name of the data model folder
    • getTablesFile

      public static String getTablesFile(ExecutionContext executionContext)
      Gets name of file containing the table definitions.
      Parameters:
      executionContext - the execution context
      Returns:
      name of the file containing the table definitions
    • getModelNameFile

      public static String getModelNameFile(ExecutionContext executionContext)
      Gets name of file containing the model name.
      Parameters:
      executionContext - the execution context
      Returns:
      name of the file containing the model name
    • getDisplayNamesFile

      public static String getDisplayNamesFile(ExecutionContext executionContext)
      Gets name of file containing the display names.
      Parameters:
      executionContext - the execution context
      Returns:
      name of the file containing the display names
    • getColumnsFile

      public static String getColumnsFile(ExecutionContext executionContext)
      Gets name of file containing the column definitions.
      Parameters:
      executionContext - the execution context
      Returns:
      name of the file containing the column definitions
    • getAssociationsFile

      public static String getAssociationsFile(ExecutionContext executionContext)
      Gets name of file containing the association definitions.
      Parameters:
      executionContext - the execution context
      Returns:
      name of the file containing the association definitions
    • getCommentsFile

      public static String getCommentsFile(ExecutionContext executionContext)
      Gets name of file containing the comments.
      Parameters:
      executionContext - the execution context
      Returns:
      name of the file containing the comments
    • getExcludeFromDeletionFile

      public static String getExcludeFromDeletionFile(ExecutionContext executionContext)
      Gets name of file containing the list of tables to be excluded from deletion.
      Parameters:
      executionContext - the execution context
      Returns:
      name of the file containing tables excluded from deletion
    • getVersionFile

      public static String getVersionFile(ExecutionContext executionContext)
      Gets name of file containing the version number.
      Parameters:
      executionContext - the execution context
      Returns:
      name of the file containing the version number
    • getTable

      public Table getTable(String name)
      Gets a table by name.
      Parameters:
      name - the name of the table
      Returns:
      the table or null iff no table with the name exists
    • getTableByDisplayName

      public Table getTableByDisplayName(String displayName)
      Gets a table by display name.
      Parameters:
      displayName - the display name of the table
      Returns:
      the table or null iff no table with the display name exists
    • getName

      public String getName()
      Gets name of the model.
      Returns:
      name of the model
    • getLastModified

      public Long getLastModified()
      Gets time of last modification.
      Returns:
      time of last modification
    • getDisplayName

      public String getDisplayName(Table table)
      Gets display name of a table
      Parameters:
      table - the table
      Returns:
      the display name of the table
    • getTables

      public Collection<Table> getTables()
      Gets all tables.
      Returns:
      a collection of all tables
    • getRestrictionModel

      public RestrictionModel getRestrictionModel()
      Gets the restriction model.
      Returns:
      the restriction model
    • setRestrictionModel

      public void setRestrictionModel(RestrictionModel restrictionModel)
      Sets the restriction model.
      Parameters:
      restrictionModel - the restriction model
    • getIndependentTables

      public Set<Table> getIndependentTables(Set<Table> tableSet)
      Gets all independent tables (i.e. tables which don't depend on other tables in the set) of a given table-set.
      Parameters:
      tableSet - the table-set
      Returns:
      the sub-set of independent tables of the table-set
    • getIndependentTables

      public Set<Table> getIndependentTables(Set<Table> tableSet, Set<Association> associations)
      Gets all independent tables (i.e. tables which don't depend on other tables in the set) of a given table-set.
      Parameters:
      tableSet - the table-set
      associations - the associations to consider, null for all associations
      Returns:
      the sub-set of independent tables of the table-set
    • transpose

      public void transpose()
      Transposes the data-model.
    • toString

      public String toString()
      Stringifies the data model.
      Overrides:
      toString in class Object
    • getSortedTables

      public List<Table> getSortedTables()
      Gets list of tables sorted by name.
      Returns:
      list of tables sorted by name
    • normalize

      public Set<Table> normalize(Set<Table> tables)
      Normalizes a set of tables.
      Parameters:
      tables - set of tables
      Returns:
      set of all tables from this model for which a table with same name exists in tables
    • assignAssociationIDs

      public void assignAssociationIDs()
      Assigns a unique ID to each association.
    • getExportModus

      public String getExportModus()
      Gets export modus, SQL or XML. (GUI support).
      Returns:
      the export modus
    • setExportModus

      public void setExportModus(String modus)
      Sets export modus, SQL or XML. (GUI support).
      Parameters:
      modus - the export modus to set
    • getXmlSettings

      public DataModel.XmlSettings getXmlSettings()
      Gets XML settings for exportation into XML files.
      Returns:
      the XML settings
    • setXmlSettings

      public void setXmlSettings(DataModel.XmlSettings xmlSettings)
      Sets XML settings for exportation into XML files.
      Parameters:
      xmlSettings - the XML settings to set
    • getVersion

      public long getVersion()
      Gets internal version number. Incremented on each modification.
      Returns:
      internal version number. Incremented on each modification.
    • checkForPrimaryKey

      public Set<Table> checkForPrimaryKey(Set<Table> subjects, boolean hasRowID) throws DataModel.NoPrimaryKeyException
      Checks whether all tables in the closure of a given subject have primary keys.
      Parameters:
      subjects - the subjects
      hasRowID - true if row IDs are available as a substitute for primary keys
      Returns:
      the set of all tables in the closure that were checked
      Throws:
      DataModel.NoPrimaryKeyException - if a table has no primary key
    • getParameters

      public SortedSet<String> getParameters(String subjectCondition, List<ExtractionModel.AdditionalSubject> additionalSubjects)
      Gets all parameters which occur in subject condition, association restrictions or XML templates.
      Parameters:
      subjectCondition - the subject condition
      additionalSubjects - additional subjects to scan for parameters
      Returns:
      all parameters which occur in subject condition, association restrictions or XML templates
    • getLastModifiedAsString

      public String getLastModifiedAsString()
      Gets getLastModified() as String.
      Returns:
      getLastModified() as String
    • save

      public void save(String file, Table stable, SubjectLimitDefinition subjectLimitDefinition, String subjectCondition, ScriptFormat scriptFormat, List<RestrictionDefinition> restrictionDefinitions, Map<String,Map<String,double[]>> positions, List<ExtractionModel.AdditionalSubject> additionalSubjects, String currentModelSubfolder) throws FileNotFoundException
      Saves the data model.
      Parameters:
      file - the file name
      stable - the subject table
      subjectLimitDefinition - limit definition of the subject
      subjectCondition - the subject condition
      scriptFormat - the script format
      restrictionDefinitions - the restriction definitions to save
      positions - table positions or null
      additionalSubjects - additional subjects
      currentModelSubfolder - the current model subfolder
      Throws:
      FileNotFoundException
    • saveRestrictions

      public void saveRestrictions(File file, List<RestrictionDefinition> restrictionDefinitions) throws FileNotFoundException
      Saves restrictions only.
      Parameters:
      file - the file to save restrictions into
      restrictionDefinitions - the restriction definitions to save
      Throws:
      FileNotFoundException
    • saveColumnOrderPrio

      public void saveColumnOrderPrio() throws FileNotFoundException
      Saves the order priority of the columns.
      Throws:
      FileNotFoundException
    • getTableByOrdinal

      public Table getTableByOrdinal(int ordinal)
      Gets table by Table.getOrdinal().
      Parameters:
      ordinal - the ordinal
      Returns:
      the table
    • getFilterTemplates

      public List<FilterTemplate> getFilterTemplates()
      Gets the FilterTemplates ordered by priority.
      Returns:
      template list
    • deriveFilters

      public void deriveFilters()
      Removes all derived filters and renews them.
    • addRestrictedDependencyWithNulledFK

      public static void addRestrictedDependencyWithNulledFK(Set<Table> tables)
      Adds all tables that are part of a restricted dependency with nulled foreign key to the given set of tables.
      Parameters:
      tables - the set of tables to extend
    • getComment

      public String getComment(Table table, Column column)
      Gets the comment for a table or column.
      Parameters:
      table - the table
      column - the column, or null for table-level comments
      Returns:
      the comment, or null if none exists