|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjodd.db.DbQuery
jodd.db.orm.DbOrmQuery
public class DbOrmQuery
A simple ORM extension for DbQuery.
ORM extension may map results to objects in two ways:
| Field Summary | |
|---|---|
static int |
CLOSE_CURSORS_AT_COMMIT
|
static int |
CONCUR_READ_ONLY
|
static int |
CONCUR_UPDATABLE
|
protected int |
concurrencyType
|
protected java.sql.Connection |
connection
|
protected DbOrmManager |
dbOrmManager
|
protected boolean |
debug
|
static int |
DEFAULT_HOLDABILITY
Default holdability. |
protected int |
fetchSize
|
protected boolean |
forcePreparedStatement
If set to true all created statements will be prepared. |
protected java.lang.String[] |
generatedColumns
|
protected JoinHintResolver |
hintResolver
|
protected java.lang.String[] |
hints
|
static int |
HOLD_CURSORS_OVER_COMMIT
|
protected int |
holdability
|
protected int |
maxRows
|
protected java.sql.PreparedStatement |
preparedStatement
|
protected jodd.db.DbQueryParser |
query
|
static int |
QUERY_CLOSED
|
static int |
QUERY_CREATED
|
static int |
QUERY_INITIALIZED
|
protected int |
queryState
|
protected java.util.Set<java.sql.ResultSet> |
resultSets
|
protected DbSession |
session
|
protected DbSqlGenerator |
sqlgen
|
protected java.lang.String |
sqlString
|
protected java.sql.Statement |
statement
|
protected static int |
totalOpenResultSetCount
|
protected int |
type
|
static int |
TYPE_FORWARD_ONLY
|
static int |
TYPE_SCROLL_INSENSITIVE
|
static int |
TYPE_SCROLL_SENSITIVE
|
| Constructor Summary | |
|---|---|
DbOrmQuery(java.sql.Connection conn,
DbSqlGenerator sqlgen)
|
|
DbOrmQuery(java.sql.Connection conn,
java.lang.String sqlString)
|
|
DbOrmQuery(DbSession session,
DbSqlGenerator sqlgen)
|
|
DbOrmQuery(DbSession session,
java.lang.String sqlString)
|
|
DbOrmQuery(DbSqlGenerator sqlgen)
|
|
DbOrmQuery(java.lang.String sqlString)
|
|
| Method Summary | ||
|---|---|---|
protected ResultSetMapper |
buildResultSetMapper(java.sql.ResultSet resultSet)
Factory for result sets mapper. |
|
protected void |
checkCreated()
Checks if query is created (and not yet initialized or closed) and throws an exception if it is not. |
|
protected void |
checkInitialized()
Checks if query is initialized and throws an exception if it is not. |
|
protected void |
checkNotClosed()
Checks if query is not closed and throws an exception if it is. |
|
void |
close()
Closes the query and all created results sets and detaches itself from the session. |
|
protected void |
close(ResultSetMapper rsm,
boolean closeQuery)
Closes results set or whole query. |
|
void |
closeAllResultSets()
Closes all result sets created by this query. |
|
void |
closeCursorsAtCommit()
|
|
protected java.util.List<java.sql.SQLException> |
closeQuery()
Closes all assigned result sets and then closes the query. |
|
void |
closeResultSet(java.sql.ResultSet rs)
Closes single result set that was created by this query, It is not necessary to close result sets explicitly, since DbQueryBase.close() method closes all created result sets. |
|
void |
concurReadOnly()
|
|
void |
concurUpdatable()
|
|
java.sql.ResultSet |
execute()
Executes the query. |
|
protected ResultSetMapper |
executeAndBuildResultSetMapper()
Executes the query and returns builded ResultSet mapper. |
|
long |
executeCount()
Special execute() for 'select count(*)' queries. |
|
protected long |
executeCount(boolean close)
Executes count queries and optionally closes query afterwards. |
|
long |
executeCountAndClose()
Executes count queries and closes afterwards. |
|
int |
executeUpdate()
Executes UPDATE, INSERT or DELETE queries. |
|
protected int |
executeUpdate(boolean closeQuery)
Executes UPDATE, INSERT or DELETE queries and optionally closes the query. |
|
int |
executeUpdateAndClose()
Executes UPDATE, INSERT or DELETE queries and closes query afterwards. |
|
java.lang.Object |
find()
|
|
java.lang.Object |
find(java.lang.Class... types)
|
|
protected java.lang.Object |
find(java.lang.Class[] types,
boolean close,
java.sql.ResultSet resultSet)
|
|
java.lang.Object |
findAndClose()
|
|
java.lang.Object |
findAndClose(java.lang.Class... types)
|
|
java.lang.Object |
findGeneratedColumns(java.lang.Class... types)
|
|
|
findGeneratedKey(java.lang.Class<T> type)
|
|
java.lang.Object |
findOne()
|
|
|
findOne(java.lang.Class<T> type)
|
|
protected
|
findOne(java.lang.Class<T> type,
boolean close,
java.sql.ResultSet resultSet)
|
|
java.lang.Object |
findOneAndClose()
|
|
|
findOneAndClose(java.lang.Class<T> type)
|
|
void |
forcePreparedStatement()
Forces creation of prepared statements. |
|
int |
getConcurrencyType()
|
|
int |
getFetchSize()
|
|
java.lang.String[] |
getGeneratedColumnNames()
Returns generated column names. |
|
java.sql.ResultSet |
getGeneratedColumns()
Returns generated columns. |
|
long |
getGeneratedKey()
Returns generated key i.e. first genereted column as long. |
|
int |
getHoldability()
|
|
DbOrmManager |
getManager()
Returns used ORM manager. |
|
int |
getMaxRows()
|
|
int |
getOpenResultSetCount()
Returns number of created result sets that are still not explicitly closed. |
|
int |
getQueryState()
Returns query state. |
|
java.lang.String |
getQueryString()
Returns query SQL string. |
|
static int |
getTotalOpenResultSetCount()
Returns total number of open result sets. |
|
int |
getType()
|
|
void |
holdCursorsOverCommit()
|
|
void |
init()
Initializes the query if not already initialized. |
|
protected void |
initializeJdbc()
Performs JDBC initialization of the query. |
|
boolean |
isActive()
Returns true if query is active: created and possibly initialized. |
|
boolean |
isClosed()
Returns true if query is closed. |
|
boolean |
isInDebugMode()
|
|
boolean |
isInitialized()
Returns true if query is initialized. |
|
|
iterate()
|
|
|
iterate(java.lang.Class... types)
|
|
protected
|
iterate(java.lang.Class[] types,
boolean close)
|
|
|
iterateAndClose()
|
|
|
iterateAndClose(java.lang.Class... types)
|
|
|
iterateOne()
|
|
|
iterateOne(java.lang.Class<T> type)
|
|
protected
|
iterateOne(java.lang.Class<T> type,
boolean close)
|
|
|
iterateOneAndClose()
|
|
|
iterateOneAndClose(java.lang.Class<T> type)
|
|
|
list()
|
|
|
list(java.lang.Class... types)
|
|
protected
|
list(java.lang.Class[] types,
int max,
boolean close)
Iterates result set, maps rows to classes and populates the array list. |
|
|
list(int max)
|
|
|
list(int max,
java.lang.Class... types)
|
|
|
listAndClose()
|
|
|
listAndClose(java.lang.Class... types)
|
|
|
listAndClose(int max)
|
|
|
listAndClose(int max,
java.lang.Class... types)
|
|
|
listOne()
|
|
|
listOne(java.lang.Class<T> type)
|
|
protected
|
listOne(java.lang.Class<T> type,
int max,
boolean close)
Iterates results set, maps rows to just one class and populates the array list. |
|
|
listOne(int max)
|
|
|
listOne(int max,
java.lang.Class<T> type)
|
|
|
listOneAndClose()
|
|
|
listOneAndClose(java.lang.Class<T> type)
|
|
|
listOneAndClose(int max)
|
|
|
listOneAndClose(int max,
java.lang.Class<T> type)
|
|
|
listSet()
|
|
|
listSet(java.lang.Class... types)
|
|
protected
|
listSet(java.lang.Class[] types,
int max,
boolean close)
|
|
|
listSet(int max)
|
|
|
listSet(int max,
java.lang.Class... types)
|
|
|
listSetAndClose()
|
|
|
listSetAndClose(java.lang.Class... types)
|
|
|
listSetAndClose(int max)
|
|
|
listSetAndClose(int max,
java.lang.Class... types)
|
|
|
listSetOne()
|
|
|
listSetOne(java.lang.Class<T> type)
|
|
protected
|
listSetOne(java.lang.Class<T> type,
int max,
boolean close)
|
|
|
listSetOne(int max)
|
|
|
listSetOne(int max,
java.lang.Class<T> type)
|
|
|
listSetOneAndClose()
|
|
|
listSetOneAndClose(java.lang.Class<T> type)
|
|
|
listSetOneAndClose(int max)
|
|
|
listSetOneAndClose(int max,
java.lang.Class<T> type)
|
|
protected void |
prepareQuery()
Prepares the query after initialization. |
|
protected java.lang.Object |
prepareRow(java.lang.Object[] row)
Prepares a row (array of rows mapped object) using hints. |
|
static DbOrmQuery |
query(java.sql.Connection conn,
DbSqlGenerator sqlgen)
|
|
static DbOrmQuery |
query(java.sql.Connection conn,
java.lang.String sqlString)
|
|
static DbOrmQuery |
query(DbSession session,
DbSqlGenerator sqlgen)
|
|
static DbOrmQuery |
query(DbSession session,
java.lang.String sqlString)
|
|
static DbOrmQuery |
query(DbSqlGenerator sqlgen)
|
|
static DbOrmQuery |
query(java.lang.String sqlString)
|
|
void |
resetGeneratedColumns()
Resets creating generated columns. |
|
protected void |
saveResultSet(java.sql.ResultSet rs)
Stores result set. |
|
void |
setConcurrencyType(int concurrencyType)
|
|
void |
setDebug(boolean debug)
|
|
void |
setDebugMode()
|
|
void |
setFetchSize(int rows)
Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed. |
|
void |
setGeneratedColumns(java.lang.String... columns)
Specifies columns which values will be generated by database. |
|
void |
setGeneratedKey()
Specifies that database will generate some columns values, usually the single id. |
|
void |
setHoldability(int holdability)
|
|
void |
setMaxRows(int maxRows)
Sets the limit for the maximum number of rows that any ResultSet object can contain to the given number. |
|
void |
setType(int type)
|
|
java.lang.String |
toString()
|
|
void |
typeForwardOnly()
|
|
void |
typeScrollInsensitive()
|
|
void |
typeScrollSensitive()
|
|
DbOrmQuery |
withHints(java.lang.String hint)
Specifies hints for the query. |
|
DbOrmQuery |
withHints(java.lang.String[] hints)
Specifies multiple hints for the query. |
|
| Methods inherited from class jodd.db.DbQuery |
|---|
clearParameters, setArray, setArray, setAsciiStream, setAsciiStream, setAsciiStream, setAsciiStream, setBean, setBigDecimal, setBigDecimal, setBigInteger, setBigInteger, setBlob, setBlob, setBoolean, setBoolean, setBoolean, setBoolean, setByte, setByte, setByte, setByte, setBytes, setBytes, setCharacterStream, setCharacterStream, setClob, setClob, setDate, setDate, setDouble, setDouble, setDouble, setDouble, setFloat, setFloat, setFloat, setFloat, setInteger, setInteger, setInteger, setInteger, setLong, setLong, setLong, setLong, setMap, setNull, setNull, setNull, setNull, setObject, setObject, setObject, setObject, setObject, setObject, setObjects, setObjects, setRef, setRef, setShort, setShort, setShort, setShort, setString, setString, setTime, setTime, setTimestamp, setTimestamp, setURL, setURL |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected DbSqlGenerator sqlgen
protected DbOrmManager dbOrmManager
protected java.lang.String[] hints
protected JoinHintResolver hintResolver
public static final int QUERY_CREATED
public static final int QUERY_INITIALIZED
public static final int QUERY_CLOSED
protected int queryState
protected java.sql.Connection connection
protected DbSession session
protected java.lang.String sqlString
protected java.sql.Statement statement
protected java.sql.PreparedStatement preparedStatement
protected java.util.Set<java.sql.ResultSet> resultSets
protected jodd.db.DbQueryParser query
protected boolean forcePreparedStatement
true all created statements will be prepared.
public static final int TYPE_FORWARD_ONLY
ResultSet.TYPE_FORWARD_ONLY,
Constant Field Valuespublic static final int TYPE_SCROLL_SENSITIVE
ResultSet.TYPE_SCROLL_SENSITIVE,
Constant Field Valuespublic static final int TYPE_SCROLL_INSENSITIVE
ResultSet.TYPE_SCROLL_INSENSITIVE,
Constant Field Valuesprotected int type
public static final int CONCUR_READ_ONLY
ResultSet.CONCUR_READ_ONLY,
Constant Field Valuespublic static final int CONCUR_UPDATABLE
ResultSet.CONCUR_UPDATABLE,
Constant Field Valuesprotected int concurrencyType
public static final int DEFAULT_HOLDABILITY
public static final int CLOSE_CURSORS_AT_COMMIT
ResultSet.CLOSE_CURSORS_AT_COMMIT,
Constant Field Valuespublic static final int HOLD_CURSORS_OVER_COMMIT
ResultSet.HOLD_CURSORS_OVER_COMMIT,
Constant Field Valuesprotected int holdability
protected boolean debug
protected java.lang.String[] generatedColumns
protected int fetchSize
protected int maxRows
protected static int totalOpenResultSetCount
| Constructor Detail |
|---|
public DbOrmQuery(java.sql.Connection conn,
java.lang.String sqlString)
public DbOrmQuery(DbSession session,
java.lang.String sqlString)
public DbOrmQuery(java.lang.String sqlString)
public DbOrmQuery(java.sql.Connection conn,
DbSqlGenerator sqlgen)
public DbOrmQuery(DbSession session,
DbSqlGenerator sqlgen)
public DbOrmQuery(DbSqlGenerator sqlgen)
| Method Detail |
|---|
public static DbOrmQuery query(java.sql.Connection conn,
java.lang.String sqlString)
public static DbOrmQuery query(DbSession session,
java.lang.String sqlString)
public static DbOrmQuery query(java.lang.String sqlString)
public static DbOrmQuery query(java.sql.Connection conn,
DbSqlGenerator sqlgen)
public static DbOrmQuery query(DbSession session,
DbSqlGenerator sqlgen)
public static DbOrmQuery query(DbSqlGenerator sqlgen)
public DbOrmManager getManager()
protected void prepareQuery()
public DbOrmQuery withHints(java.lang.String hint)
public DbOrmQuery withHints(java.lang.String[] hints)
protected java.lang.Object prepareRow(java.lang.Object[] row)
protected ResultSetMapper executeAndBuildResultSetMapper()
builded ResultSet mapper.
protected ResultSetMapper buildResultSetMapper(java.sql.ResultSet resultSet)
public <T> java.util.Iterator<T> iterateOne(java.lang.Class<T> type)
public <T> java.util.Iterator<T> iterateOneAndClose(java.lang.Class<T> type)
public <T> java.util.Iterator<T> iterateOne()
public <T> java.util.Iterator<T> iterateOneAndClose()
protected <T> java.util.Iterator<T> iterateOne(java.lang.Class<T> type,
boolean close)
public <T> java.util.Iterator<T> iterate(java.lang.Class... types)
public <T> java.util.Iterator<T> iterateAndClose(java.lang.Class... types)
public <T> java.util.Iterator<T> iterate()
public <T> java.util.Iterator<T> iterateAndClose()
protected <T> java.util.Iterator<T> iterate(java.lang.Class[] types,
boolean close)
public <T> java.util.List<T> listOne(java.lang.Class<T> type)
public <T> java.util.List<T> listOneAndClose(java.lang.Class<T> type)
public <T> java.util.List<T> listOne()
public <T> java.util.List<T> listOneAndClose()
public <T> java.util.List<T> listOne(int max,
java.lang.Class<T> type)
public <T> java.util.List<T> listOneAndClose(int max,
java.lang.Class<T> type)
public <T> java.util.List<T> listOne(int max)
public <T> java.util.List<T> listOneAndClose(int max)
protected <T> java.util.List<T> listOne(java.lang.Class<T> type,
int max,
boolean close)
type - target typemax - max number of rows to collect, 0 for allclose - true if query is closed at the end, otherwise false
- Returns:
- list of mapped entities
public <T> java.util.List<T> list(java.lang.Class... types)
public <T> java.util.List<T> listAndClose(java.lang.Class... types)
public <T> java.util.List<T> list()
public <T> java.util.List<T> listAndClose()
public <T> java.util.List<T> list(int max,
java.lang.Class... types)
public <T> java.util.List<T> listAndClose(int max,
java.lang.Class... types)
public <T> java.util.List<T> list(int max)
public <T> java.util.List<T> listAndClose(int max)
protected <T> java.util.List<T> list(java.lang.Class[] types,
int max,
boolean close)
types - mapping typesmax - max number of rows to collect, 0 for allclose - true if query is closed at the end, otherwise false
- Returns:
- list of mapped entities
public <T> java.util.Set<T> listSetOne(java.lang.Class<T> type)
public <T> java.util.Set<T> listSetOneAndClose(java.lang.Class<T> type)
public <T> java.util.Set<T> listSetOne()
public <T> java.util.Set<T> listSetOneAndClose()
public <T> java.util.Set<T> listSetOne(int max,
java.lang.Class<T> type)
public <T> java.util.Set<T> listSetOneAndClose(int max,
java.lang.Class<T> type)
public <T> java.util.Set<T> listSetOne(int max)
public <T> java.util.Set<T> listSetOneAndClose(int max)
protected <T> java.util.Set<T> listSetOne(java.lang.Class<T> type,
int max,
boolean close)
public <T> java.util.Set<T> listSet(java.lang.Class... types)
public <T> java.util.Set<T> listSetAndClose(java.lang.Class... types)
public <T> java.util.Set<T> listSet()
public <T> java.util.Set<T> listSetAndClose()
public <T> java.util.Set<T> listSet(int max,
java.lang.Class... types)
public <T> java.util.Set<T> listSetAndClose(int max,
java.lang.Class... types)
public <T> java.util.Set<T> listSet(int max)
public <T> java.util.Set<T> listSetAndClose(int max)
protected <T> java.util.Set<T> listSet(java.lang.Class[] types,
int max,
boolean close)
public <T> T findOne(java.lang.Class<T> type)
public <T> T findOneAndClose(java.lang.Class<T> type)
public java.lang.Object findOne()
public java.lang.Object findOneAndClose()
protected <T> T findOne(java.lang.Class<T> type,
boolean close,
java.sql.ResultSet resultSet)
public java.lang.Object find(java.lang.Class... types)
public java.lang.Object findAndClose(java.lang.Class... types)
public java.lang.Object find()
public java.lang.Object findAndClose()
protected java.lang.Object find(java.lang.Class[] types,
boolean close,
java.sql.ResultSet resultSet)
public <T> T findGeneratedKey(java.lang.Class<T> type)
public java.lang.Object findGeneratedColumns(java.lang.Class... types)
protected void close(ResultSetMapper rsm,
boolean closeQuery)
public int getQueryState()
protected void checkNotClosed()
protected void checkCreated()
protected void checkInitialized()
public boolean isClosed()
true if query is closed.
public boolean isActive()
true if query is active: created and possibly initialized.
Opened query may be not initialized.
public boolean isInitialized()
true if query is initialized. Initialized query is the one that has
created JDBC statements.
protected void saveResultSet(java.sql.ResultSet rs)
public void forcePreparedStatement()
public final void init()
protected void initializeJdbc()
public void closeAllResultSets()
protected java.util.List<java.sql.SQLException> closeQuery()
public void close()
public void closeResultSet(java.sql.ResultSet rs)
DbQueryBase.close() method closes all created result sets.
Query remains active.
public int getType()
public void setType(int type)
public void typeForwardOnly()
public void typeScrollSensitive()
public void typeScrollInsensitive()
public int getConcurrencyType()
public void setConcurrencyType(int concurrencyType)
public void concurReadOnly()
public void concurUpdatable()
public int getHoldability()
public void setHoldability(int holdability)
public void holdCursorsOverCommit()
public void closeCursorsAtCommit()
public boolean isInDebugMode()
public void setDebug(boolean debug)
public void setDebugMode()
public java.lang.String[] getGeneratedColumnNames()
public void setGeneratedColumns(java.lang.String... columns)
public void setGeneratedKey()
public void resetGeneratedColumns()
public int getFetchSize()
public void setFetchSize(int rows)
Statement.setFetchSize(int)public int getMaxRows()
public void setMaxRows(int maxRows)
Statement.setMaxRows(int)public java.sql.ResultSet execute()
DbQueryBase.closeResultSet(ResultSet)
оr implicitly, during DbQueryBase.close().
Statement.execute(String)public int executeUpdate()
Statement.executeUpdate(String)public int executeUpdateAndClose()
Statement.executeUpdate(String)protected int executeUpdate(boolean closeQuery)
Statement.executeUpdate(String)public long executeCount()
-1.
public long executeCountAndClose()
protected long executeCount(boolean close)
public java.sql.ResultSet getGeneratedColumns()
public long getGeneratedKey()
long.
public java.lang.String getQueryString()
public java.lang.String toString()
toString in class java.lang.ObjectgetQueryString()public static int getTotalOpenResultSetCount()
getOpenResultSetCount()public int getOpenResultSetCount()
getTotalOpenResultSetCount()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||