Package com.avoka.core.cayenne
Class SelectQueryJoinTranslator
- java.lang.Object
-
- org.apache.cayenne.access.translator.select.QueryAssembler
-
- org.apache.cayenne.access.translator.select.DefaultSelectTranslator
-
- com.avoka.core.cayenne.SelectQueryJoinTranslator
-
- All Implemented Interfaces:
org.apache.cayenne.access.translator.select.SelectTranslator
public class SelectQueryJoinTranslator extends org.apache.cayenne.access.translator.select.DefaultSelectTranslator
Add to a SQL SELECT by specifying custom JOIN expressions and additional WHERE clauses- Since:
- 19.5.0
-
-
Field Summary
Fields Modifier and Type Field Description static String
PLACEHOLDER_TARGET_TABLE_ALIAS
The placeholder for the target table (main table the SelectQuery is based on) that can be used in additionalJoinString and additionalClauseString
-
Constructor Summary
Constructors Constructor Description SelectQueryJoinTranslator(org.apache.cayenne.query.Query query, org.apache.cayenne.dba.DbAdapter adapter, org.apache.cayenne.map.EntityResolver entityResolver)
Create a SelectQueryJoinTranslator instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doTranslate()
protected int
getWhereEndIndex()
boolean
isUseCountQuery()
Return whether the translator will change the SELECT query to a SELECT COUNT query, returning the number of rows rather than the rows themselves.void
setAdditionalClauseString(String additionalClauseString)
The string to be inserted at the end of the FROM section of the select query.void
setAdditionalJoinParameters(List<Pair<org.apache.cayenne.map.DbAttribute,Object>> additionalJoinParameters)
Query parameters to be used in the additional join string.void
setAdditionalJoinString(String additionalJoinString)
The string to be inserted at the end of the FROM section of the select query.void
setUseCountQuery(boolean useCountQuery)
If true, the translater will change the SELECT query to a SELECT COUNT query, returning the number of rows rather than the rows themselves.-
Methods inherited from class org.apache.cayenne.access.translator.select.DefaultSelectTranslator
appendGroupByColumn, appendGroupByColumns, appendLimitAndOffsetClauses, appendSelectColumns, buildDistinctStatement, buildResultColumns, createJoinStack, dbRelationshipAdded, getAliasForExpression, getAttributeOverrides, getCurrentAlias, getJoinStack, getResultColumns, hasJoins, isSuppressingDistinct, isUnsupportedForDistinct, resetJoinStack, supportsTableAliases
-
Methods inherited from class org.apache.cayenne.access.translator.select.QueryAssembler
addToParamList, ensureTranslated, getAdapter, getBindings, getEntityResolver, getPathAliases, getQuery, getQueryMetadata, getSql, setAddBindingListener
-
-
-
-
Field Detail
-
PLACEHOLDER_TARGET_TABLE_ALIAS
public static final String PLACEHOLDER_TARGET_TABLE_ALIAS
The placeholder for the target table (main table the SelectQuery is based on) that can be used in additionalJoinString and additionalClauseString- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SelectQueryJoinTranslator
public SelectQueryJoinTranslator(org.apache.cayenne.query.Query query, org.apache.cayenne.dba.DbAdapter adapter, org.apache.cayenne.map.EntityResolver entityResolver)
Create a SelectQueryJoinTranslator instance- Parameters:
query
- the SelectQuery (required)adapter
- the DbAdapter (required)entityResolver
- the Cayenne entity resolver (required)
-
-
Method Detail
-
setAdditionalJoinString
public void setAdditionalJoinString(String additionalJoinString)
The string to be inserted at the end of the FROM section of the select query. Aliasing needs to be done by the caller and match aliasing in the additionalClauseString. You can reference the alias of the target table name by using {@link this.PLACEHOLDER_TARGET_TABLE_ALIAS} You can also- Parameters:
additionalJoinString
- the additional join string (e.g. LEFT JOIN with additional criteria) Example: setAdditionalJoinString("LEFT JOIN job_property jp1 ON (" + SelectQueryJoinTranslator.PLACEHOLDER_TARGET_TABLE_ALIAS + ".job_oid = jp1.job_oid AND jp1.name = ?)")
-
setAdditionalJoinParameters
public void setAdditionalJoinParameters(List<Pair<org.apache.cayenne.map.DbAttribute,Object>> additionalJoinParameters)
Query parameters to be used in the additional join string. If specified, the bindings for these parameters will be inserted at the start of the binding list.- Parameters:
additionalJoinParameters
- the additional join parameters (as pairs of DbAttributes and the value to be bound)
-
setAdditionalClauseString
public void setAdditionalClauseString(String additionalClauseString)
The string to be inserted at the end of the FROM section of the select query. Aliasing needs to be done by the caller and match aliasing in the additionalClauseString. You can reference the alias of the target table name by using {@link this.PLACEHOLDER_TARGET_TABLE_ALIAS} DO NOT include a leading "WHERE" or "AND" keyword as this will be inserted by the translator as needed.- Parameters:
additionalClauseString
- the additional where clause string Example: setAdditionalClauseString("(jp1.value IS NULL)")
-
isUseCountQuery
public boolean isUseCountQuery()
Return whether the translator will change the SELECT query to a SELECT COUNT query, returning the number of rows rather than the rows themselves.- Returns:
- whether the query will be modified to a SELECT COUNT query
-
setUseCountQuery
public void setUseCountQuery(boolean useCountQuery)
If true, the translater will change the SELECT query to a SELECT COUNT query, returning the number of rows rather than the rows themselves.- Parameters:
useCountQuery
- whether the query should be modified to a SELECT COUNT query (off by default)
-
doTranslate
protected void doTranslate()
- Overrides:
doTranslate
in classorg.apache.cayenne.access.translator.select.DefaultSelectTranslator
-
getWhereEndIndex
protected int getWhereEndIndex()
-
-