Class TreeElement
java.lang.Object
org.pgcodekeeper.core.model.difftree.TreeElement
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents the side of difference in schema comparison. -
Constructor Summary
ConstructorsConstructorDescriptionTreeElement(String name, DbObjType type, TreeElement.DiffSide side) Creates a tree element with specified properties.TreeElement(IStatement statement, TreeElement.DiffSide side) Creates a tree element from a database statement. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChild(TreeElement child) Adds a child element to this element.intCounts direct child elements.intCounts all descendant elements recursively.booleanFinds an element in the tree by database statement.getChild(int index) Gets a child element by index.Gets a child element by name (any type).Gets a child element by name and type.Gets the list of child elements.Gets the qualified name of the container path.getCopy()Creates a copy of elements starting from current element.getName()Gets the name of this tree element.Gets the parent element.Gets the qualified name of this element.Creates a copy of elements starting from current with sides reverted: left -> right, right -> left, both -> bothgetSide()Gets the diff side of this element.Gets corresponding database statement from the specified database.getStatementSide(IDatabase left, IDatabase right) Gets statement from the corresponding database based on diff side.getType()Gets the database object type of this element.booleanChecks if this element has child elements.inthashCode()booleanChecks if this element is a container type (table or view).booleanChecks if this element is selected.booleanChecks if this element is a sub-element of a container.booleanChecks if there are selected elements in subtree starting from current node.voidMarks all elements as selected starting from current element.voidsetParent(TreeElement el) Deprecated.this method should only be used for column relationshipsvoidsetSelected(boolean selected) Sets the selection state of this element.toString()
-
Constructor Details
-
TreeElement
Creates a tree element with specified properties.- Parameters:
name- the element nametype- the database object typeside- the diff side
-
TreeElement
Creates a tree element from a database statement.- Parameters:
statement- the database statementside- the diff side
-
-
Method Details
-
getName
Gets the name of this tree element.- Returns:
- the element name
-
getType
Gets the database object type of this element.- Returns:
- the object type
-
getSide
Gets the diff side of this element.- Returns:
- the diff side (LEFT, RIGHT, or BOTH)
-
getChildren
Gets the list of child elements.- Returns:
- unmodifiable list of children
-
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
Adds a child element to this element.- Parameters:
child- the child element to add- Throws:
IllegalStateException- if child already has a parent
-
getChild
Gets a child element by name and type.- Parameters:
name- the child name to findtype- the child type to match, can be null to match any type- Returns:
- the matching child element, or null if not found
-
getChild
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
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
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
Gets statement from the corresponding database based on diff side. BOTH side uses left database.- Parameters:
left- the left databaseright- the right database- Returns:
- statement from the appropriate database
-
findElement
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
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
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() -
equals
-
getContainerQName
Gets the qualified name of the container path.- Returns:
- qualified name of container hierarchy
-
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
-
setParent
Deprecated.this method should only be used for column relationshipsSets parent element - use only for columns to create one-way relationship for getting object from database.- Parameters:
el- the parent element
-