Class PrimaryKey

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

public class PrimaryKey extends Object
Primary-key of a Table.
Author:
Ralf Wisser
  • Field Details

    • numberOfIndexedPKColumns

      public int numberOfIndexedPKColumns
  • Constructor Details

    • PrimaryKey

      public PrimaryKey(List<Column> columns, boolean needsOrderedMatch)
      Constructor.
      Parameters:
      columns - the primary-key columns
      needsOrderedMatch - true if match with UPK must be ordered
  • Method Details

    • getColumns

      public List<Column> getColumns()
      Gets the primary-key columns.
      Returns:
      the primary-key columns
    • match

      public Map<Column,Column> match(PrimaryKey primaryKey)
      Matches the columns with the columns of primaryKey s.t. each column of primaryKey is assigned to a column of this PK with same type.
      Parameters:
      primaryKey - to match
      Returns:
      a match of all columns of primaryKey
    • isAssignable

      public static boolean isAssignable(Column uPKColumn, Column entityColumn)
      Checks whether a universal primary key column can be assigned to an entity column (i.e. the UPK column type is compatible with and at least as large as the entity column type).
      Parameters:
      uPKColumn - the universal primary key column
      entityColumn - the entity column to check against
      Returns:
      true if the UPK column is assignable to the entity column
    • columnList

      public String columnList(String prefix)
      Creates a comma-separated list of column names.
      Parameters:
      prefix - an optional prefix for each PK-column
      Returns:
      comma-separated list of column names
    • columnList

      public String columnList(String prefix, Quoting quoting)
      Creates a comma-separated list of column names.
      Parameters:
      prefix - an optional prefix for each PK-column
      quoting - optional quoting to apply to column names
      Returns:
      comma-separated list of column names
    • toSQL

      public String toSQL(String columnPrefix)
      Returns the primary key in SQL syntax.
      Parameters:
      columnPrefix - an optional prefix for each PK-column
      Returns:
      the primary key definition in SQL syntax
    • toSQL

      public String toSQL(String columnPrefix, boolean withContraints)
      Returns the primary key in SQL syntax.
      Parameters:
      columnPrefix - an optional prefix for each PK-column
      withContraints - true to include NOT NULL constraints
      Returns:
      the primary key definition in SQL syntax
    • toSQL

      public String toSQL(String columnPrefix, String contraint, Map<String,String> typeReplacement)
      Returns the primary key in SQL syntax.
      Parameters:
      columnPrefix - an optional prefix for each PK-column
      contraint - the constraint expression to append after each column definition
      typeReplacement - column type replacements
      Returns:
      the primary key definition in SQL syntax
    • toString

      public String toString()
      Returns a string representation of the primary key.
      Overrides:
      toString in class Object
      Returns:
      the primary key definition in SQL syntax
    • assign

      public void assign(List<Column> primaryKeyColumns)
      Replaces the current primary-key columns with the given list.
      Parameters:
      primaryKeyColumns - the new primary-key columns
    • isIncreasable

      public static boolean isIncreasable(Column uPKColumn, Column column)
      Checks whether a universal primary key column can be increased in size to accommodate the given column.
      Parameters:
      uPKColumn - the universal primary key column
      column - the column whose size requirements must be met
      Returns:
      true if the UPK column can be increased to fit the given column