Class QueryAssemblerHelper
java.lang.Object
org.apache.cayenne.access.translator.select.QueryAssemblerHelper
- Direct Known Subclasses:
OrderingTranslator,QualifierTranslator
public abstract class QueryAssemblerHelper extends Object
Translates parts of the query to SQL. Always works in the context of parent
Translator.
-
Field Summary
Fields Modifier and Type Field Description protected StringBuilderoutprotected QueryAssemblerqueryAssemblerprotected QuotingStrategystrategy -
Constructor Summary
Constructors Constructor Description QueryAssemblerHelper(QueryAssembler queryAssembler)Creates QueryAssemblerHelper initializing with parentQueryAssemblerand output buffer object. -
Method Summary
Modifier and Type Method Description protected voidappendDbPath(Expression pathExp)protected voidappendLikeEscapeCharacter(PatternMatchNode patternMatchNode)Outputs the standard JDBC (database agnostic) expression for supplying the escape character to the database server when supplying a LIKE clause.protected voidappendLiteral(Object val, DbAttribute attr, Expression parentExpression)Appends SQL code to the query buffer to handlevalas a parameter to the PreparedStatement being built.protected voidappendLiteralDirect(Object val, DbAttribute attr, Expression parentExpression)Appends SQL code to the query buffer to handlevalas a parameter to the PreparedStatement being built.protected voidappendObjPath(Expression pathExp)Processes parts of the OBJ_PATH expression.StringBuilderappendPart(StringBuilder out)protected abstract voiddoAppendPart()DbEntitygetDbEntity()ObjEntitygetObjEntity()protected DbAttributeparamsDbType(Expression e)Returns database type of expression parameters or null if it can not be determined.protected voidprocessColumn(DbAttribute dbAttr)protected voidprocessColumnWithQuoteSqlIdentifiers(DbAttribute dbAttr, Expression pathExp)protected voidprocessRelTermination(DbRelationship rel, JoinType joinType, String joinSplitAlias)Handles case when a DB_NAME expression ends with relationship.protected voidprocessRelTermination(ObjRelationship rel, JoinType joinType, String joinSplitAlias)Processes case when an OBJ_PATH expression ends with relationship.protected voidsetForceJoinForRelations(boolean forceJoinForRelations)Force joining tables for all relations, not only for toMany
-
Field Details
-
queryAssembler
-
out
-
strategy
-
-
Constructor Details
-
QueryAssemblerHelper
Creates QueryAssemblerHelper initializing with parentQueryAssemblerand output buffer object.
-
-
Method Details
-
getObjEntity
-
getDbEntity
-
appendPart
- Since:
- 3.0
-
doAppendPart
protected abstract void doAppendPart()- Since:
- 3.0
-
appendLikeEscapeCharacter
Outputs the standard JDBC (database agnostic) expression for supplying the escape character to the database server when supplying a LIKE clause. This has been factored-out because some database adaptors handle LIKE differently and they need access to this common method in order not to repeat this code.
If there is no escape character defined then this method will not output anything. An escape character of 0 will mean no escape character.
- Throws:
IOException- Since:
- 3.1
-
appendObjPath
Processes parts of the OBJ_PATH expression. -
appendDbPath
-
processColumn
-
processColumnWithQuoteSqlIdentifiers
-
appendLiteral
protected void appendLiteral(Object val, DbAttribute attr, Expression parentExpression) throws IOExceptionAppends SQL code to the query buffer to handlevalas a parameter to the PreparedStatement being built. Addsvalinto QueryAssembler parameter list.If
valis null, "NULL" is appended to the query.If
valis a DataObject, its primary key value is used as a parameter. Only objects with a single column primary key can be used.- Parameters:
val- object that should be appended as a literal to the query. Must be of one of "standard JDBC" types, null or a DataObject.attr- DbAttribute that has information on what type of parameter is being appended.- Throws:
IOException
-
appendLiteralDirect
protected void appendLiteralDirect(Object val, DbAttribute attr, Expression parentExpression) throws IOExceptionAppends SQL code to the query buffer to handlevalas a parameter to the PreparedStatement being built. Addsvalinto QueryAssembler parameter list.- Throws:
IOException
-
paramsDbType
Returns database type of expression parameters or null if it can not be determined. -
processRelTermination
protected void processRelTermination(ObjRelationship rel, JoinType joinType, String joinSplitAlias)Processes case when an OBJ_PATH expression ends with relationship. If this is a "to many" relationship, a join is added and a column expression for the target entity primary key. If this is a "to one" relationship, column expression for the source foreign key is added.- Since:
- 3.0
-
processRelTermination
Handles case when a DB_NAME expression ends with relationship. If this is a "to many" relationship, a join is added and a column expression for the target entity primary key. If this is a "to one" relationship, column expression for the source foreign key is added.- Since:
- 3.0
-
setForceJoinForRelations
protected void setForceJoinForRelations(boolean forceJoinForRelations)Force joining tables for all relations, not only for toMany- Since:
- 4.0
-