Class TreeElement

java.lang.Object
org.pgcodekeeper.core.model.difftree.TreeElement

public final class TreeElement extends Object
Wrapper for database objects representing the state between old and new database schemas. Provides hierarchical tree structure for organizing database objects and their relationships during schema comparison operations.
  • Constructor Details

    • TreeElement

      public TreeElement(String name, DbObjType type, TreeElement.DiffSide side)
      Creates a tree element with specified properties.
      Parameters:
      name - the element name
      type - the database object type
      side - the diff side
    • TreeElement

      public TreeElement(IStatement statement, TreeElement.DiffSide side)
      Creates a tree element from a database statement.
      Parameters:
      statement - the database statement
      side - the diff side
  • Method Details

    • getName

      public String getName()
      Gets the name of this tree element.
      Returns:
      the element name
    • getType

      public DbObjType getType()
      Gets the database object type of this element.
      Returns:
      the object type
    • getSide

      public TreeElement.DiffSide getSide()
      Gets the diff side of this element.
      Returns:
      the diff side (LEFT, RIGHT, or BOTH)
    • getChildren

      public List<TreeElement> getChildren()
      Gets the list of child elements.
      Returns:
      unmodifiable list of children
    • getParent

      public TreeElement getParent()
      Gets the parent element.
      Returns:
      the parent element, can be null for root
    • isSelected

      public boolean isSelected()
      Checks if this element is selected.
      Returns:
      true if selected, false otherwise
    • setSelected

      public void setSelected(boolean selected)
      Sets the selection state of this element.
      Parameters:
      selected - true to select, false to deselect
    • hasChildren

      public boolean hasChildren()
      Checks if this element has child elements.
      Returns:
      true if has children, false otherwise
    • addChild

      public void addChild(TreeElement child)
      Adds a child element to this element.
      Parameters:
      child - the child element to add
      Throws:
      IllegalStateException - if child already has a parent
    • getChild

      public TreeElement getChild(String name, DbObjType type)
      Gets a child element by name and type.
      Parameters:
      name - the child name to find
      type - the child type to match, can be null to match any type
      Returns:
      the matching child element, or null if not found
    • getChild

      public TreeElement getChild(String name)
      Gets a child element by name (any type).
      Parameters:
      name - the child name to find
      Returns:
      the matching child element, or null if not found
    • getChild

      public TreeElement getChild(int index)
      Gets a child element by index.
      Parameters:
      index - the child index
      Returns:
      the child element at the specified index
    • countDescendants

      public int countDescendants()
      Counts all descendant elements recursively.
      Returns:
      total number of descendants
    • countChildren

      public int countChildren()
      Counts direct child elements.
      Returns:
      number of direct children
    • getStatement

      public IStatement getStatement(IDatabase db)
      Gets corresponding database statement from the specified database.
      Parameters:
      db - the database to retrieve statement from
      Returns:
      the corresponding database statement
      Throws:
      IllegalArgumentException - if no statement found for parent
    • getStatementSide

      public IStatement getStatementSide(IDatabase left, IDatabase right)
      Gets statement from the corresponding database based on diff side. BOTH side uses left database.
      Parameters:
      left - the left database
      right - the right database
      Returns:
      statement from the appropriate database
    • findElement

      public TreeElement findElement(IStatement st)
      Finds an element in the tree by database statement.
      Parameters:
      st - the database statement to find
      Returns:
      the matching tree element, or null if not found
    • getRevertedCopy

      public TreeElement getRevertedCopy()
      Creates a copy of elements starting from current with sides reverted: left -> right, right -> left, both -> both
      Returns:
      reverted copy of this element and its children
    • getCopy

      public TreeElement getCopy()
      Creates a copy of elements starting from current element.
      Returns:
      copy of this element and its children
    • setAllChecked

      public void setAllChecked()
      Marks all elements as selected starting from current element.
    • isSubTreeSelected

      public boolean isSubTreeSelected()
      Checks if there are selected elements in subtree starting from current node.
      Returns:
      true if any elements in subtree are selected
    • isContainer

      public boolean isContainer()
      Checks if this element is a container type (table or view).
      Returns:
      true if element is a container type
    • isSubElement

      public boolean isSubElement()
      Checks if this element is a sub-element of a container.
      Returns:
      true if parent is a container type
    • hashCode

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

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

      public String getContainerQName()
      Gets the qualified name of the container path.
      Returns:
      qualified name of container hierarchy
    • getQualifiedName

      public String getQualifiedName()
      Gets the qualified name of this element. Note: the name itself is not quoted as it may include function parameters.
      Returns:
      this element's qualified name
    • toString

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

      @Deprecated public void setParent(TreeElement el)
      Deprecated.
      this method should only be used for column relationships
      Sets parent element - use only for columns to create one-way relationship for getting object from database.
      Parameters:
      el - the parent element