Package org.datanucleus.store.rdbms.sql
Class SQLText
- java.lang.Object
-
- org.datanucleus.store.rdbms.sql.SQLText
-
public class SQLText extends java.lang.ObjectRepresentation 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
Fields Modifier and Type Field Description private java.util.List<java.lang.Object>appendedprivate booleanencloseInParenthesesprivate java.util.List<SQLStatementParameter>parametersprivate java.lang.Stringpostpendprivate java.lang.StringsqlCached SQL if already generated.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SQLTextappend(char c)Append a character to the SQL.SQLTextappend(java.lang.String s)Append some SQL as a string.SQLTextappend(SQLExpression expr)Append an SQLExpression.SQLTextappend(SQLExpression.ColumnExpressionList exprList)Append a ColumnExpressionList.SQLTextappend(SQLStatement stmt)Append an SQLStatement.SQLTextappend(SQLText st)Append a SQLTextSQLTextappendParameter(java.lang.String name, JavaTypeMapping mapping, java.lang.Object value)Append a parameter represented by a mapping (single datastore column).SQLTextappendParameter(java.lang.String name, JavaTypeMapping mapping, java.lang.Object value, int columnNumber)Append a parameter represented by a mapping, for a column of a multi-column mapping.voidapplyParametersToStatement(org.datanucleus.ExecutionContext ec, java.sql.PreparedStatement ps)Method to set the parameters in the supplied PreparedStatement using their mappings and provided values.private voidcalculateSQL()voidchangeMappingForParameter(java.lang.String parameterName, JavaTypeMapping mapping)Convenience method to change the mapping used for a parameter, if it is referenced by this SQL text object.voidclearStatement()Convenience method to reset the SQL for the statement.voidencloseInParentheses()Set to enclose this SQL in parentheses.java.util.List<SQLStatementParameter>getParametersForStatement()Accessor for the parameters for this SQLText (including all sub SQLText)SQLTextpostpend(java.lang.String s)Set the String to append at the end of the SQL.SQLTextprepend(java.lang.String s)Prepend some SQL as a string.SQLTextremoveLastPrependAppend()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 (").java.lang.StringtoSQL()Accessor for the SQL of the statement.java.lang.StringtoString()Accessor for the string form of the statement.
-
-
-
Field Detail
-
sql
private java.lang.String sql
Cached SQL if already generated.
-
parameters
private java.util.List<SQLStatementParameter> parameters
-
encloseInParentheses
private boolean encloseInParentheses
-
postpend
private java.lang.String postpend
-
appended
private java.util.List<java.lang.Object> appended
-
-
Method Detail
-
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
public SQLText postpend(java.lang.String s)
Set the String to append at the end of the SQL.- Parameters:
s- the string- Returns:
- the SQLText
-
prepend
public SQLText prepend(java.lang.String s)
Prepend some SQL as a string.- Parameters:
s- The string- Returns:
- The SQLText
-
append
public SQLText append(char c)
Append a character to the SQL.- Parameters:
c- the char- Returns:
- the SQLText
-
append
public SQLText append(java.lang.String s)
Append some SQL as a string.- Parameters:
s- the String- Returns:
- the SQLText
-
append
public SQLText append(SQLStatement stmt)
Append an SQLStatement.- Parameters:
stmt- the SQL Statement- Returns:
- the SQLText
-
append
public SQLText append(SQLExpression.ColumnExpressionList exprList)
Append a ColumnExpressionList.- Parameters:
exprList- the ColumnExpression list- Returns:
- the SQLText
-
append
public SQLText append(SQLText st)
Append a SQLText- Parameters:
st- the SQLText- Returns:
- the SQLText
-
append
public SQLText append(SQLExpression expr)
Append an SQLExpression.- Parameters:
expr- the SQLExpression- Returns:
- the SQLText
-
appendParameter
public SQLText appendParameter(java.lang.String name, JavaTypeMapping mapping, java.lang.Object value)
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(java.lang.String name, JavaTypeMapping mapping, java.lang.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
public 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
public void changeMappingForParameter(java.lang.String parameterName, JavaTypeMapping mapping)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
public void applyParametersToStatement(org.datanucleus.ExecutionContext ec, java.sql.PreparedStatement ps)Method to set the parameters in the supplied PreparedStatement using their mappings and provided values.- Parameters:
ec- execution contextps- The PreparedStatement
-
getParametersForStatement
public java.util.List<SQLStatementParameter> 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
public java.lang.String 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
public java.lang.String toString()
Accessor for the string form of the statement.- Overrides:
toStringin classjava.lang.Object- Returns:
- String form of the statement
-
-