|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jaeksoft.pojodbc.Query
public class Query
Represents an SQL query. In JDBC view, a query contains at least a PreparedStatement. It can also contains a ResultSet. Statement and ResultSet are automatically closed when Query or Transaction is closed.
The most important behavior is to return a list of Pojo instead of a ResultSet.
The example show how to use it.
Transaction transaction = null; try { // Obtain a new transaction from the ConnectionManager transaction = connectionManager.getNewTransaction(false, javax.sql.Connection.TRANSACTION_READ_COMMITTED); // Start a new Query Query query = transaction.prepare("SELECT * FROM MyTable WHERE status=?"); query.getStatement().setString(1, "open"); query.setFirstResult(0); query.setMaxResults(10); // Get the result List<MyPojo> myPojoList = query.getResultList(MyPojo.class)); // do everything you need } finally { // Release the transaction if (transaction != null) transaction.close(); }
Nested Class Summary | |
---|---|
private class |
Query.MethodColumnIndex
|
Field Summary | |
---|---|
private int |
firstResult
|
protected static java.util.logging.Logger |
logger
|
private int |
maxResults
|
private java.util.List<?> |
resultList
|
private java.sql.ResultSet |
resultSet
|
private java.sql.PreparedStatement |
statement
|
Constructor Summary | |
---|---|
protected |
Query(java.sql.PreparedStatement statement)
|
Method Summary | |
---|---|
private void |
checkResultSet()
|
protected void |
closeAll()
Close all component of that query (ResultSet and Statement) |
private java.util.List<?> |
createBeanList(java.lang.Class<?> beanClass)
|
private java.util.List<Row> |
createRowList()
|
private static java.util.List<Row> |
createRowList(java.sql.ResultSet resultSet,
int limit)
|
java.util.List<Row> |
getGeneratedKeys()
Returns the generated keys after an insert statement |
int |
getResultCount()
FirstResult and MaxResults parameters are ignored. |
java.util.List<Row> |
getResultList()
|
java.util.List<?> |
getResultList(java.lang.Class<?> beanClass)
Returns the list of POJO. |
java.sql.ResultSet |
getResultSet()
Get the ResultSet used by that Query. |
java.sql.PreparedStatement |
getStatement()
Get the PreparedStatement used by that Query |
private void |
moveToFirstResult()
|
void |
reUse()
Release the last ResultSet (if any) and the last ResultList. |
void |
setFirstResult(int firstResult)
Set the first position of the result |
void |
setMaxResults(int maxResults)
Set the maximum number of rows |
int |
update()
Do a PreparedStatement.executeUpdate(). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.sql.ResultSet resultSet
private java.util.List<?> resultList
private java.sql.PreparedStatement statement
private int firstResult
private int maxResults
protected static java.util.logging.Logger logger
Constructor Detail |
---|
protected Query(java.sql.PreparedStatement statement)
Method Detail |
---|
public void setFirstResult(int firstResult)
firstResult
- public void setMaxResults(int maxResults)
maxResults
- protected void closeAll()
private java.util.List<?> createBeanList(java.lang.Class<?> beanClass) throws java.lang.Exception
java.lang.Exception
private void moveToFirstResult() throws java.sql.SQLException
java.sql.SQLException
private static java.util.List<Row> createRowList(java.sql.ResultSet resultSet, int limit) throws java.sql.SQLException
java.sql.SQLException
private java.util.List<Row> createRowList() throws java.sql.SQLException
java.sql.SQLException
public java.sql.PreparedStatement getStatement()
public void reUse()
private void checkResultSet() throws java.sql.SQLException
java.sql.SQLException
public java.util.List<?> getResultList(java.lang.Class<?> beanClass) throws java.lang.Exception
beanClass
- The class name of POJO returned in the list
java.sql.SQLException
java.lang.Exception
public java.util.List<Row> getResultList() throws java.sql.SQLException
java.sql.SQLException
public int update() throws java.sql.SQLException
java.sql.SQLException
public java.util.List<Row> getGeneratedKeys() throws java.sql.SQLException
java.sql.SQLException
public int getResultCount() throws java.sql.SQLException
java.sql.SQLException
public java.sql.ResultSet getResultSet() throws java.sql.SQLException
java.sql.SQLException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |