nl.knowledgeplaza.util.jpa
Class NativeQueryBuilder
java.lang.Object
nl.knowledgeplaza.util.jpa.NativeQueryBuilder
public class NativeQueryBuilder
- extends 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 $
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SOURCECODE_VERSION
public static final String SOURCECODE_VERSION
- Standard variable for determining version of a class file.
- See Also:
- Constant Field Values
NativeQueryBuilder
public NativeQueryBuilder()
append
public void append(String part)
append
public void append(String part,
Object parameter)
append
public void append(String part,
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 String getSql()
- Returns:
getParameters
public List<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:
SQLException
Copyright © 2011 KnowledgePlaza. All Rights Reserved.