org.datanucleus.store.rdbms.sql
Class SQLText

java.lang.Object
  extended by org.datanucleus.store.rdbms.sql.SQLText

public class SQLText
extends Object

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.


Constructor Summary
SQLText()
          Constructor
SQLText(String initialSQLText)
          Constructor
 
Method Summary
 SQLText append(char c)
          Append a character to the SQL.
 SQLText append(SQLExpression expr)
          Append an SQLExpression.
 SQLText append(SQLStatement stmt)
          Append an SQLStatement.
 SQLText append(SQLText st)
          Append a SQLText
 SQLText append(String s)
          Append some SQL as a string.
 SQLText appendParameter(String name, org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping, Object value)
          Append a parameter represented by a mapping (single datastore column).
 SQLText appendParameter(String name, org.datanucleus.store.mapped.mapping.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.store.ExecutionContext ec, PreparedStatement ps)
          Method to set the parameters in the supplied PreparedStatement using their mappings and provided values.
 void changeMappingForParameter(String parameterName, org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping)
          Convenience method to change the mapping used for a parameter, if it is referenced by this SQL text object.
 void clearStatement()
          Convenience method to reset the SQL for the statement.
 void encloseInParentheses()
          Set to enclose this SQL in parentheses.
 List<SQLStatementParameter> getParametersForStatement()
          Accessor for the parameters for this SQLText (including all sub SQLText)
 SQLText postpend(String s)
          Set the String to append at the end of the SQL.
 SQLText prepend(String s)
          Prepend some SQL as a string.
 String toSQL()
          Accessor for the SQL of the statement.
 String toString()
          Accessor for the string form of the statement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SQLText

public SQLText()
Constructor


SQLText

public SQLText(String initialSQLText)
Constructor

Parameters:
initialSQLText -
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(String s)
Set the String to append at the end of the SQL.

Parameters:
s - the string
Returns:
the SQLText

prepend

public SQLText prepend(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(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(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(String name,
                               org.datanucleus.store.mapped.mapping.JavaTypeMapping mapping,
                               Object value)
Append a parameter represented by a mapping (single datastore column).

Parameters:
name - The parameter name
mapping - the mapping
value - the parameter value
Returns:
the SQLText

appendParameter

public SQLText appendParameter(String name,
                               org.datanucleus.store.mapped.mapping.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 name
mapping - the mapping
value - the parameter value
columnNumber - Number of the column represented here
Returns:
the SQLText

changeMappingForParameter

public void changeMappingForParameter(String parameterName,
                                      org.datanucleus.store.mapped.mapping.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 parameter
mapping - The mapping to use instead

applyParametersToStatement

public void applyParametersToStatement(org.datanucleus.store.ExecutionContext ec,
                                       PreparedStatement ps)
Method to set the parameters in the supplied PreparedStatement using their mappings and provided values.

Parameters:
ec - execution context
ps - The PreparedStatement

getParametersForStatement

public 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 String toSQL()
Accessor for the SQL of the statement.

Returns:
The SQL text

toString

public String toString()
Accessor for the string form of the statement.

Overrides:
toString in class Object
Returns:
String form of the statement


Copyright © 2012. All Rights Reserved.