nl.knowledgeplaza.util.jpa
Class NativeQueryBuilder
java.lang.Object
nl.knowledgeplaza.util.jpa.NativeQueryBuilder
public class NativeQueryBuilder
- extends java.lang.Object
A utility class to build SQL in a source code readable form.
It allows spreading the SQL over multiple lines and concats using a StringBuffer,
and at the same time allows placing the parameter values next to the place where they are used (instead of all the way at the end).
For example:
SqlBuilder lSqlBuilder = new SqlBuilder();
lSqlBuilder.append("select field1");
lSqlBuilder.append(" from table");
lSqlBuilder.append(" where field2 = ?", new Integer(1)); // or just 1 in Java 1.5+ with autocasting
lSqlBuilder.append(" and field2 = ?", new Long(2));
lSqlBuilder.append(" and field3 = ? or field4 = ?", new Object[]{ new Long(3), new Long(4)} );
- Version:
- $Revision: 1.3 $
|
Field Summary |
static java.lang.String |
SOURCECODE_VERSION
Standard variable for determining version of a class file. |
|
Method Summary |
void |
append(java.lang.String part)
|
void |
append(java.lang.String part,
java.lang.Object parameter)
|
void |
append(java.lang.String part,
java.lang.Object[] parameters)
|
void |
appendValuesText()
Append a values text with the same number of ? |
javax.persistence.Query |
createNativeQuery(javax.persistence.EntityManager entityManager)
Create native query with the parameters already filled (setXXX calls). |
java.util.List<java.lang.Object> |
getParameters()
|
java.lang.String |
getSql()
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SOURCECODE_VERSION
public static final java.lang.String SOURCECODE_VERSION
- Standard variable for determining version of a class file.
- See Also:
- Constant Field Values
NativeQueryBuilder
public NativeQueryBuilder()
append
public void append(java.lang.String part)
append
public void append(java.lang.String part,
java.lang.Object parameter)
append
public void append(java.lang.String part,
java.lang.Object[] parameters)
appendValuesText
public void appendValuesText()
- Append a values text with the same number of ? as there are parameters
e.g. when there are three parameters, this will generate " values(?,?,?)"
getSql
public java.lang.String getSql()
- Returns:
getParameters
public java.util.List<java.lang.Object> getParameters()
- Returns:
createNativeQuery
public javax.persistence.Query createNativeQuery(javax.persistence.EntityManager entityManager)
- Create native query with the parameters already filled (setXXX calls).
- Parameters:
connection -
- Returns:
-
- Throws:
java.sql.SQLException
Copyright © 2010. All Rights Reserved.