Class SyncPair<U extends AbstractUnit,P extends AbstractUnit>

java.lang.Object
com.wisecoders.dbs.dbms.sync.engine.nodes.SyncPair<U,P>
Type Parameters:
U - The class of the elements (Table, Column, Constraint, Index )
P - The class of the parent element ( Schema for Tables, Table for Columns, Indexes, Constraints...)
All Implemented Interfaces:
SyncDiff
Direct Known Subclasses:
EditorSyncRoot

public class SyncPair<U extends AbstractUnit,P extends AbstractUnit> extends Object implements SyncDiff
A pair of two elements which are compared, and their parents. It can be two columns, foreign keys, constriants, indexes, etc. One of elements can be empty (is missing) which will result in a TableExistsDiff, ColumnExistsDiff, IndexExistsDiff, etc. The parents ( which is in most cases the schema ) is required to be able to handle the element missing differences.
  • Field Details

  • Constructor Details

    • SyncPair

      public SyncPair(U left, SchemaMapping mapping, U right)
      Can synchronize using a specific schema mapping. Used in : - Synchronize with the database - Synchronize with a file.
      Parameters:
      left - project
      mapping - between schemas
      right - project
    • SyncPair

      public SyncPair(U left, U right)
      Used in: - diagram generate selected unit sql - drop item in table detail pane, workspace - schema script generator
      Parameters:
      left - unit
      right - unit
    • SyncPair

      public SyncPair(P leftParent, U left, P rightParent, U right, boolean descendIntoChildren, SchemaMapping mapping)
      Used in : - clone column by create fk on drag and drop - clone unit in diagram
      Parameters:
      leftParent - of left
      left - unit
      rightParent - of right
      right - unit
      descendIntoChildren - synchronize children
      mapping - to map the model schema to a different schema in the database
  • Method Details

    • getMapping

      public SchemaMapping getMapping()
    • synchronize

      public void synchronize()
    • hasDifferences

      public boolean hasDifferences()
    • getDiffCount

      public int getDiffCount()
    • setAction

      public void setAction(SyncAction action, boolean recursive)
      Set an action for this and all sub-nodes. This is similar with the Synchronization dialog, like clicking an action for each element. SyncAction.toLeft would mean to modify the model, toRight to modify the database.
      Specified by:
      setAction in interface SyncDiff
      Parameters:
      action - SyncAction.toLeft, toRight or none
      recursive - To apply this recursive to all sub-nodes.
    • getChildrenPairs

      public List<SyncPair<?,?>> getChildrenPairs()
    • getDifferences

      public List<AbstractDiff<?,?>> getDifferences()
      Get a list of differences for this node. A node can be a pair of tables, or columns, and differences can be rename, exists diff, data type diff, mandatory diff, etc.
      Returns:
      A list of differences
    • hasNodesWithAction

      public boolean hasNodesWithAction(SyncAction action)
    • actionWillDrop

      public int actionWillDrop(SyncAction action, SyncSide into, boolean onlyTablesColumns)
      Get the count of dropped items if this action is applied.
      Parameters:
      action - to be applied
      into - which direction
      onlyTablesColumns - consider only tables and columns (no indexes, fks )
      Returns:
      The count of dropped items.
    • toString

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

      public String toString(int level)
    • getAction

      public SyncAction getAction()
      Specified by:
      getAction in interface SyncDiff
    • toSql

      public void toSql(String dbId, SyncAction onlyAction, SyncSide into, PrintWriter writer) throws IOException
      Generate the script for a Synchronization operation.
      Parameters:
      dbId - The DBMS name
      onlyAction - Synchronize only this actions. The rest will be ignored.
      into - In which direction to syncronize. This is similar with the SyncDialog (left-local model, right-database ).
      writer - To write the script into
      Throws:
      IOException
    • commitIntoDatabase

      public void commitIntoDatabase(Connector connector, SyncSide into, SyncAction onlyAction) throws Exception
      Apply the selected actions in to the database. This require to do first syncPair.setAction(SyncSide.toRight)
      Parameters:
      connector - the database connection
      into - the direction to commit to
      onlyAction - the actions to filter
      Throws:
      Exception - is most of the times an SQLException
    • generateCommitScript

      public AlterScript generateCommitScript(String dbId, SyncAction onlyAction, SyncSide into)
      Generate the commit script
      Parameters:
      dbId - is the DBMS
      onlyAction - only the given actions
      into - in which direction to generate the commit. Usually is SyncSide.toRight (database )
      Returns:
      a script as a list of statements.
    • generateCommitScript

      public AlterScript generateCommitScript(String dbId, SyncAction onlyAction, SyncSide into, boolean includeForeignKeysInCreateTable)
    • mergeInto

      public void mergeInto(SyncSide into, SyncAction onlyAction)
      Merge differences into the local model
      Parameters:
      into - use SyncSide.toLeft to apply to the local model
      onlyAction - filter only the given action
    • mergeInto

      public void mergeInto(SyncSide into, SyncAction onlyAction, com.wisecoders.dbs.diagram.fx.GenericLayoutPane layoutPane)
    • getUnit

      public U getUnit(SyncSide side)
      Specified by:
      getUnit in interface SyncDiff
    • getUnit

      public U getUnit()
    • getParent

      public P getParent(SyncSide side)
    • filter

      public void filter(com.wisecoders.dbs.dbms.sync.model.SyncFilter filter)
      Filter all tree using a given filter. The rejected differences will be removed
      Parameters:
      filter - to use for filtering
    • getNodeDiff

      public AbstractDiff<?,?> getNodeDiff()
      Specified by:
      getNodeDiff in interface SyncDiff
    • removeChildrenWithAction

      public void removeChildrenWithAction(SyncAction action)
    • canSkipInDisplayAndShowChildrenDiffs

      public boolean canSkipInDisplayAndShowChildrenDiffs()
    • matches

      public boolean matches(SyncDiffFilter filter)
      Specified by:
      matches in interface SyncDiff
    • setAlwaysIncludeFks

      public void setAlwaysIncludeFks(boolean alwaysIncludeFks)