Package org.datanucleus.store.rdbms.sql
Class SQLText
java.lang.Object
org.datanucleus.store.rdbms.sql.SQLText
Representation of a snippet of an SQL statement. May contain parameters.
A 'parameter' in this context is an input parameter to the query (which will map on to a JDBC '?'
in the resultant SQL).
Call "applyParametersToStatement()" to set the parameter values in the PreparedStatement.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private List
<SQLStatementParameter> private String
private String
Cached SQL if already generated. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappend
(char c) Append a character to the SQL.Append some SQL as a string.append
(SQLExpression expr) Append an SQLExpression.append
(SQLExpression.ColumnExpressionList exprList) Append a ColumnExpressionList.append
(SQLStatement stmt) Append an SQLStatement.Append a SQLTextappendParameter
(String name, JavaTypeMapping mapping, Object value) Append a parameter represented by a mapping (single datastore column).appendParameter
(String name, JavaTypeMapping mapping, Object value, int columnNumber) Append a parameter represented by a mapping, for a column of a multi-column mapping.void
applyParametersToStatement
(org.datanucleus.ExecutionContext ec, PreparedStatement ps) Method to set the parameters in the supplied PreparedStatement using their mappings and provided values.private void
void
changeMappingForParameter
(String parameterName, JavaTypeMapping mapping) Convenience method to change the mapping used for a parameter, if it is referenced by this SQL text object.void
Convenience method to reset the SQL for the statement.void
Set to enclose this SQL in parentheses.Accessor for the parameters for this SQLText (including all sub SQLText)Set the String to append at the end of the SQL.Prepend some SQL as a string.Convenience method for the specific situation where you want to remove a DISTINCT that was just applied, hence removing the last append (of ")") and prepend (of "DISTINCT (").toSQL()
Accessor for the SQL of the statement.toString()
Accessor for the string form of the statement.
-
Field Details
-
sql
Cached SQL if already generated. -
parameters
-
encloseInParentheses
private boolean encloseInParentheses -
postpend
-
appended
-
-
Constructor Details
-
SQLText
public SQLText()Constructor -
SQLText
Constructor- Parameters:
initialSQLText
- SQL text to start from
-
-
Method Details
-
clearStatement
public void clearStatement()Convenience method to reset the SQL for the statement. This is used when updating an expression internally, and need to regenerate the statement. -
encloseInParentheses
public void encloseInParentheses()Set to enclose this SQL in parentheses. -
postpend
Set the String to append at the end of the SQL.- Parameters:
s
- the string- Returns:
- the SQLText
-
prepend
Prepend some SQL as a string.- Parameters:
s
- The string- Returns:
- The SQLText
-
append
Append a character to the SQL.- Parameters:
c
- the char- Returns:
- the SQLText
-
append
Append some SQL as a string.- Parameters:
s
- the String- Returns:
- the SQLText
-
append
Append an SQLStatement.- Parameters:
stmt
- the SQL Statement- Returns:
- the SQLText
-
append
Append a ColumnExpressionList.- Parameters:
exprList
- the ColumnExpression list- Returns:
- the SQLText
-
append
Append a SQLText- Parameters:
st
- the SQLText- Returns:
- the SQLText
-
append
Append an SQLExpression.- Parameters:
expr
- the SQLExpression- Returns:
- the SQLText
-
appendParameter
Append a parameter represented by a mapping (single datastore column).- Parameters:
name
- The parameter namemapping
- the mappingvalue
- the parameter value- Returns:
- the SQLText
-
appendParameter
public SQLText appendParameter(String name, JavaTypeMapping mapping, Object value, int columnNumber) Append a parameter represented by a mapping, for a column of a multi-column mapping.- Parameters:
name
- The parameter namemapping
- the mappingvalue
- the parameter valuecolumnNumber
- Number of the column represented here- Returns:
- the SQLText
-
removeLastPrependAppend
Convenience method for the specific situation where you want to remove a DISTINCT that was just applied, hence removing the last append (of ")") and prepend (of "DISTINCT (").- Returns:
- the SQLText
-
changeMappingForParameter
Convenience method to change the mapping used for a parameter, if it is referenced by this SQL text object.- Parameters:
parameterName
- Name of the parametermapping
- The mapping to use instead
-
applyParametersToStatement
Method to set the parameters in the supplied PreparedStatement using their mappings and provided values.- Parameters:
ec
- execution contextps
- The PreparedStatement
-
getParametersForStatement
Accessor for the parameters for this SQLText (including all sub SQLText)- Returns:
- The list of parameters (in the order they appear in the SQL)
-
toSQL
Accessor for the SQL of the statement. Synchronized so that we don't have a race condition on creation of the SQL.- Returns:
- The SQL text
-
calculateSQL
private void calculateSQL() -
toString
Accessor for the string form of the statement.
-