Class Join<T extends PersistentDomainObject<T>,J extends PersistentDomainObject<J>>

java.lang.Object
org.tentackle.persist.Join<T,J>
Type Parameters:
T - the PDO type holding the relation to the joined PDO
J - the joined PDO type

public class Join<T extends PersistentDomainObject<T>,J extends PersistentDomainObject<J>> extends Object
PDO join.

Joins two PDOs within the same select.
Used by eager joins and explicit domain-driven joins.
Works for composite and non-composite relations.

Author:
harald
  • Constructor Details

    • Join

      public Join(org.tentackle.sql.JoinType type, String columnName, String joinedColumnName, Class<J> joinedClass, String joinAlias, String extraSql, BiConsumer<T,J> joiner)
      Creates a join.
      Parameters:
      type - the join type
      columnName - the column name of the PDO (includung table alias!)
      joinedColumnName - the column name of the joined PDO (includung table alias!)
      joinedClass - the joined class
      joinAlias - the alias of the joined pdo
      extraSql - optional SQL code (usually a WHERE clause)
      joiner - the joiner
    • Join

      public Join(org.tentackle.sql.JoinType type, String columnName, String joinedColumnName, Class<J> joinedClass, String joinAlias, BiConsumer<T,J> joiner)
      Creates a join.
      Parameters:
      type - the join type
      columnName - the column name of the PDO (includung table alias!)
      joinedColumnName - the column name of the joined PDO (includung table alias!)
      joinedClass - the joined class
      joinAlias - the alias of the joined pdo
      joiner - the joiner
  • Method Details

    • getType

      public org.tentackle.sql.JoinType getType()
      Gets the join type.
      Returns:
      the type
    • isListJoin

      public boolean isListJoin()
      Returns whether joined to list or object.
      Returns:
      true if to list
    • isExplicitIdAliasRequired

      public boolean isExplicitIdAliasRequired()
      Returne whether an extra ID-alias must be added to the joined select statement. This is true for multi-table inherited object relations.
      Returns:
      true if ID alias necessary
    • getColumnName

      public String getColumnName()
      Gets the column name of the PDO.
      Returns:
      the column name
    • getJoinedColumnName

      public String getJoinedColumnName()
      Gets the joined column name.
      Returns:
      the column name, "id" if object join, else list join
    • getJoinedClass

      public Class<J> getJoinedClass()
      Gets the joined PDO class.
      Returns:
      the class
    • getJoinAlias

      public String getJoinAlias()
      Gets the alias of the joined PDO.
      Returns:
      the alias
    • getJoiner

      public BiConsumer<T,J> getJoiner()
      Gets the joiner.
      Returns:
      the joiner
    • getExtraSql

      public String getExtraSql()
      Gets optional SQL code.
      Returns:
      sql code, null or empty if none
    • addJoin

      public Join<T,J> addJoin(Join<J,?> join)
      Adds a cascaded join.
      Parameters:
      join - the cascaded join
      Returns:
      me (to allow fluent style setup)
    • getJoins

      public List<Join<J,?>> getJoins()
      Gets the cascaded joins.
      Returns:
      the cascaded joins, never null
    • initialize

      public void initialize()
      Initializes the join.
    • createJoinedPdo

      public J createJoinedPdo(T pdo)
      Creates a new PDO to join to given pdo.
      Parameters:
      pdo - the pdo to join to
      Returns:
      the pdo to join
    • join

      public J join(T pdo, J pdoToJoin)
      Joins a pdo with another pdo.
      Parameters:
      pdo - the pdo that gets the join
      pdoToJoin - the pdo to join, null to finish the joining process
      Returns:
      the new or already joined pdo