Package org.apache.openjpa.jdbc.sql
Class SQLBuffer
java.lang.Object
org.apache.openjpa.jdbc.sql.SQLBuffer
- All Implemented Interfaces:
Serializable
,Cloneable
Buffer for SQL statements that can be used to create
java.sql.PreparedStatements.
This buffer holds the SQL statement parameters and their corresponding
columns. The parameters introduced by the runtime system are distinguished
from the parameters set by the user.
- Since:
- 0.2.4
- Author:
- Marc Prud'hommeaux, Abe White, Pinaki Poddar
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCastForParam
(String oper, Val val) Replace SQL '?'append
(DBIdentifier name) append
(Select sel, JDBCFetchConfiguration fetch) Append a subselect.Append all SQL and parameters of the given buffer.appendCount
(Select sel, JDBCFetchConfiguration fetch) Append a subselect count.appendParamOnly
(SQLBuffer buf) Append parameters only if the given buffer at the given positions.Append a parameter value.appendValue
(Object o, Column col) Append a system inserted parameter value for a specific column.appendValue
(Object o, Column col, Parameter userParam) Append a user parameter value for a specific column.appendValue
(Object o, Column col, Parameter userParam, boolean useParamToken) clone()
Perform a shallow clone of this SQL Buffer.boolean
Return the list of parameter values.getSQL()
Return the SQL for this buffer.getSQL
(boolean replaceParams) Returns the SQL for this buffer.Get the user parameter positions in the list of parameters.int
hashCode()
boolean
isEmpty()
Return true if the buffer is emtpy.prepareCall
(Connection conn) Create and populate the parameters of a prepared statement using the SQL in this buffer.prepareCall
(Connection conn, int rsType, int rsConcur) Create and populate the parameters of a prepared statement using the SQL in this buffer.prepareCall
(Connection conn, JDBCFetchConfiguration fetch, int rsType, int rsConcur) Create and populate the parameters of a prepred statement using the SQL in this buffer and the given fetch configuration.prepareStatement
(Connection conn) Create and populate the parameters of a prepared statement using the SQL in this buffer.prepareStatement
(Connection conn, int rsType, int rsConcur) Create and populate the parameters of a prepared statement using the SQL in this buffer.prepareStatement
(Connection conn, JDBCFetchConfiguration fetch, int rsType, int rsConcur) Create and populate the parameters of a prepred statement using the SQL in this buffer and the given fetch configuration.boolean
Replace a subselect.void
replaceSqlString
(int start, int end, String newString) Replace current buffer string with the new stringvoid
Populate the parameters of an existing PreparedStatement with values from this buffer.void
setParameters
(List params) boolean
Compare internal SQL without resolving subselects or stringifying parameters.
-
Constructor Details
-
SQLBuffer
Default constructor. -
SQLBuffer
Copy constructor.
-
-
Method Details
-
clone
Perform a shallow clone of this SQL Buffer. -
isEmpty
public boolean isEmpty()Return true if the buffer is emtpy. -
append
Append all SQL and parameters of the given buffer. -
appendParamOnly
Append parameters only if the given buffer at the given positions. -
append
-
append
-
append
-
append
-
append
-
append
Append a subselect. This delays resolution of the select SQL. -
appendCount
Append a subselect count. This delays resolution of the select SQL. -
replace
Replace a subselect. -
appendValue
Append a parameter value. -
appendValue
Append a system inserted parameter value for a specific column. -
appendValue
Append a user parameter value for a specific column. User parameters are marked as opposed to the parameters inserted by the internal runtime system. This helps to reuse the buffer by reparmeterizing it with new set of user parameters while the 'internal' parameters remain unchanged.- Parameters:
userParam
- if non-null, designates a 'user' parameter.
-
appendValue
-
getParameters
Return the list of parameter values. -
getUserParameters
Get the user parameter positions in the list of parameters. The odd element of the returned list contains an integer index that refers to the position in thegetParameters()
list. The even element of the returned list refers to the user parameter key. This structure is preferred over a normal map because a user parameter may occur more than one in the parameters. -
getSQL
Return the SQL for this buffer. -
getSQL
Returns the SQL for this buffer.- Parameters:
replaceParams
- if true, then replace parameters with the actual parameter values
-
prepareStatement
Create and populate the parameters of a prepared statement using the SQL in this buffer.- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(Connection conn, int rsType, int rsConcur) throws SQLException Create and populate the parameters of a prepared statement using the SQL in this buffer.- Throws:
SQLException
-
prepareStatement
public PreparedStatement prepareStatement(Connection conn, JDBCFetchConfiguration fetch, int rsType, int rsConcur) throws SQLException Create and populate the parameters of a prepred statement using the SQL in this buffer and the given fetch configuration.- Throws:
SQLException
-
prepareCall
Create and populate the parameters of a prepared statement using the SQL in this buffer.- Throws:
SQLException
-
prepareCall
Create and populate the parameters of a prepared statement using the SQL in this buffer.- Throws:
SQLException
-
prepareCall
public CallableStatement prepareCall(Connection conn, JDBCFetchConfiguration fetch, int rsType, int rsConcur) throws SQLException Create and populate the parameters of a prepred statement using the SQL in this buffer and the given fetch configuration.- Throws:
SQLException
-
setParameters
Populate the parameters of an existing PreparedStatement with values from this buffer.- Throws:
SQLException
-
hashCode
public int hashCode() -
sqlEquals
Compare internal SQL without resolving subselects or stringifying parameters. -
equals
-
addCastForParam
Replace SQL '?' with CAST string if required by DB platform- Parameters:
oper
-val
-
-
replaceSqlString
Replace current buffer string with the new string- Parameters:
start
- replace start positionend
- replace end positionnewString
-
-
setParameters
-
getColumns
-