Module org.tentackle.persistence
Package org.tentackle.persist
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 PDOJ- 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 Summary
Constructors Constructor Description Join(org.tentackle.sql.JoinType type, String columnName, String joinedColumnName, Class<J> joinedClass, String joinAlias, String extraSql, BiConsumer<T,J> joiner)Creates a join.Join(org.tentackle.sql.JoinType type, String columnName, String joinedColumnName, Class<J> joinedClass, String joinAlias, BiConsumer<T,J> joiner)Creates a join.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Join<T,J>addJoin(Join<J,?> join)Adds a cascaded join.JcreateJoinedPdo(T pdo)Creates a new PDO to join to given pdo.StringgetColumnName()Gets the column name of the PDO.StringgetExtraSql()Gets optional SQL code.StringgetJoinAlias()Gets the alias of the joined PDO.Class<J>getJoinedClass()Gets the joined PDO class.StringgetJoinedColumnName()Gets the joined column name.BiConsumer<T,J>getJoiner()Gets the joiner.List<Join<J,?>>getJoins()Gets the cascaded joins.org.tentackle.sql.JoinTypegetType()Gets the join type.voidinitialize()Initializes the join.booleanisExplicitIdAliasRequired()Returne whether an extra ID-alias must be added to the joined select statement.booleanisListJoin()Returns whether joined to list or object.Jjoin(T pdo, J pdoToJoin)Joins a pdo with another pdo.
-
-
-
Constructor Detail
-
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 typecolumnName- the column name of the PDO (includung table alias!)joinedColumnName- the column name of the joined PDO (includung table alias!)joinedClass- the joined classjoinAlias- the alias of the joined pdoextraSql- 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 typecolumnName- the column name of the PDO (includung table alias!)joinedColumnName- the column name of the joined PDO (includung table alias!)joinedClass- the joined classjoinAlias- the alias of the joined pdojoiner- the joiner
-
-
Method Detail
-
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
-
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
-
-