public class DbOomQuery extends DbQuery<DbOomQuery>
DbQuery
.
OOM extension may map results to objects in two ways:
Modifier and Type | Class and Description |
---|---|
static class |
jodd.db.DbQueryBase.State
Query states.
|
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoClose |
protected boolean |
cacheEntities |
protected java.sql.CallableStatement |
callableStatement |
protected QueryConcurrencyType |
concurrencyType |
protected java.sql.Connection |
connection |
protected DbOom |
dbOom |
protected boolean |
debug |
protected long |
elapsed |
protected boolean |
entityAwareMode |
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 |
protected QueryHoldability |
holdability |
protected int |
maxRows |
protected java.sql.PreparedStatement |
preparedStatement |
protected jodd.db.DbQueryParser |
query |
protected jodd.db.DbQueryBase.State |
queryState |
protected java.util.Set<java.sql.ResultSet> |
resultSets |
protected DbSession |
session |
protected DbSqlGenerator |
sqlgen |
protected java.lang.String |
sqlString |
protected long |
start |
protected java.sql.Statement |
statement |
protected static int |
totalOpenResultSetCount |
protected QueryScrollType |
type |
Constructor and Description |
---|
DbOomQuery(DbOom dbOom,
java.sql.Connection conn,
DbSqlGenerator sqlgen) |
DbOomQuery(DbOom dbOom,
java.sql.Connection conn,
java.lang.String sqlString) |
DbOomQuery(DbOom dbOom,
DbSession session,
DbSqlGenerator sqlgen) |
DbOomQuery(DbOom dbOom,
DbSession session,
java.lang.String sqlString) |
DbOomQuery(DbOom dbOom,
DbSqlGenerator sqlgen) |
DbOomQuery(DbOom dbOom,
java.lang.String sqlString) |
Modifier and Type | Method and Description |
---|---|
protected Q |
_this() |
DbOomQuery |
autoClose()
Defines that query should be automatically closed immediately after using.
|
DbOomQuery |
cacheEntities(boolean cacheEntities)
Defines if entities should be cached in
ResultSetMapper . |
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.
|
Q |
closeAllResultSets()
Closes all result sets created by this query.
|
Q |
closeCursorsAtCommit() |
protected 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.
|
Q |
concurrentReadOnly() |
Q |
concurrentUpdatable() |
protected ResultSetMapper |
createResultSetMapper(java.sql.ResultSet resultSet)
Factory for result sets mapper.
|
DbOomQuery |
entityAwareMode(boolean entityAware)
Defines entity-aware mode for entities tracking in result collection.
|
java.sql.ResultSet |
execute()
Executes the query.
|
protected ResultSetMapper |
executeAndBuildResultSetMapper()
Executes the query and returns
builded ResultSet mapper . |
DbCallResult |
executeCall() |
long |
executeCount()
Special execute() for 'select count(*)' queries.
|
protected long |
executeCount(boolean close)
Executes count queries and optionally closes query 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.
|
<T> T |
find() |
<T> T |
find(java.lang.Class... types) |
protected <T> T |
find(java.lang.Class[] types,
boolean close,
java.sql.ResultSet resultSet) |
<T> T |
find(QueryMapper<T> queryMapper)
|
java.lang.Object |
findGeneratedColumns(java.lang.Class... types)
Finds generated columns.
|
<T> T |
findGeneratedKey(java.lang.Class<T> type)
Finds generated key column of given type.
|
Q |
forcePreparedStatement()
Forces creation of prepared statements.
|
QueryConcurrencyType |
getConcurrencyType() |
long |
getExecutionTime()
Returns query execution elapsed time in milliseconds.
|
int |
getFetchSize()
Returns fetch size.
|
java.lang.String[] |
getGeneratedColumnNames()
Returns generated column names.
|
java.sql.ResultSet |
getGeneratedColumns()
Returns generated columns.
|
long |
getGeneratedKey()
Returns generated key i.e. first generated column as
long . |
java.lang.Object |
getGeneratedKeyObject() |
QueryHoldability |
getHoldability() |
int |
getMaxRows()
Returns max rows.
|
int |
getOpenResultSetCount()
Returns number of created result sets that are still not explicitly closed.
|
jodd.db.DbQueryBase.State |
getQueryState()
Returns query state.
|
java.lang.String |
getQueryString()
Returns query SQL string.
|
DbSession |
getSession()
Returns used
DbSession . |
static int |
getTotalOpenResultSetCount()
Returns total number of open result sets.
|
QueryScrollType |
getType() |
Q |
holdCursorsOverCommit() |
void |
init()
Initializes the query if not already initialized.
|
protected void |
init(DbOom dbOom) |
protected void |
initializeJdbc()
Performs JDBC initialization of the query.
|
protected void |
initSession(DbSession session)
Initializes session.
|
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. |
<T> java.util.Iterator<T> |
iterate() |
<T> java.util.Iterator<T> |
iterate(java.lang.Class... types) |
protected <T> java.util.Iterator<T> |
iterate(java.lang.Class[] types,
boolean close) |
<T> java.util.List<T> |
list() |
<T> java.util.List<T> |
list(java.lang.Class... types) |
protected <T> java.util.List<T> |
list(java.lang.Class[] types,
int max,
boolean close)
Iterates result set, maps rows to classes and populates resulting array list.
|
<T> java.util.List<T> |
list(int max) |
<T> java.util.List<T> |
list(int max,
java.lang.Class... types) |
<T> java.util.List<T> |
list(QueryMapper<T> queryMapper)
|
<T> java.util.Set<T> |
listSet() |
<T> java.util.Set<T> |
listSet(java.lang.Class... types) |
protected <T> java.util.Set<T> |
listSet(java.lang.Class[] types,
int max,
boolean close) |
<T> java.util.Set<T> |
listSet(int max) |
<T> java.util.Set<T> |
listSet(int max,
java.lang.Class... types) |
<T> java.util.Set<T> |
listSet(QueryMapper<T> queryMapper)
|
void |
populateGeneratedKeys(java.lang.Object entity)
Populates entity with generated column values from executed query.
|
protected void |
prepareQuery()
Prepares the query after initialization.
|
protected java.lang.String |
preprocessSql(java.lang.String sqlString)
Pre-process SQL before using it.
|
static DbOomQuery |
query(java.sql.Connection conn,
DbSqlGenerator sqlgen) |
static DbOomQuery |
query(java.sql.Connection conn,
java.lang.String sqlString) |
static DbOomQuery |
query(DbSession session,
DbSqlGenerator sqlgen) |
static DbOomQuery |
query(DbSession session,
java.lang.String sqlString) |
static DbOomQuery |
query(DbSqlGenerator sqlgen) |
static DbOomQuery |
query(java.lang.String sqlString) |
Q |
resetGeneratedColumns()
Resets creating generated columns.
|
protected void |
resolveColumnDbSqlType(java.sql.Connection connection,
DbEntityColumnDescriptor dec)
Resolves column db sql type and populates it in column descriptor if missing.
|
protected java.lang.Object |
resolveRowResults(java.lang.Object[] row)
Prepares a row (array of rows mapped object) using hints.
|
protected void |
saveResultSet(java.sql.ResultSet rs)
Stores result set.
|
Q |
setConcurrencyType(QueryConcurrencyType concurrencyType) |
Q |
setDebug(boolean debug) |
Q |
setDebugMode() |
Q |
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.
|
Q |
setGeneratedColumns(java.lang.String... columns)
Specifies columns which values will be generated by database.
|
Q |
setGeneratedKey()
Specifies that database will generate some columns values,
usually the single id.
|
Q |
setHoldability(QueryHoldability holdability) |
Q |
setMaxRows(int maxRows)
Sets the limit for the maximum number of rows that any ResultSet object can contain to the given number.
|
Q |
setType(QueryScrollType type) |
java.lang.String |
toString() |
Q |
typeForwardOnly() |
Q |
typeScrollInsensitive() |
Q |
typeScrollSensitive() |
DbOomQuery |
withHints(java.lang.String... hints)
Specifies multiple hints for the query.
|
DbOomQuery |
withHints(java.lang.String hint)
Specifies hints for the query.
|
clearParameters, outBoolean, outBoolean, outByte, outByte, outDouble, outDouble, outFloat, outFloat, outInteger, outInteger, outLong, outLong, outString, outString, setArray, setArray, setAsciiStream, setAsciiStream, setAsciiStream, setAsciiStream, setBatch, setBatch, setBatch, 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
protected final DbSqlGenerator sqlgen
protected JoinHintResolver hintResolver
protected java.lang.String[] hints
protected boolean cacheEntities
protected boolean entityAwareMode
protected final DbOom dbOom
protected jodd.db.DbQueryBase.State 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.sql.CallableStatement callableStatement
protected java.util.Set<java.sql.ResultSet> resultSets
protected jodd.db.DbQueryParser query
protected boolean forcePreparedStatement
true
all created statements will be prepared.protected boolean autoClose
protected QueryScrollType type
protected QueryConcurrencyType concurrencyType
protected QueryHoldability holdability
protected boolean debug
protected java.lang.String[] generatedColumns
protected int fetchSize
protected int maxRows
protected long start
protected long elapsed
protected static int totalOpenResultSetCount
public DbOomQuery(DbOom dbOom, java.sql.Connection conn, java.lang.String sqlString)
public DbOomQuery(DbOom dbOom, java.lang.String sqlString)
public DbOomQuery(DbOom dbOom, java.sql.Connection conn, DbSqlGenerator sqlgen)
public DbOomQuery(DbOom dbOom, DbSession session, DbSqlGenerator sqlgen)
public DbOomQuery(DbOom dbOom, DbSqlGenerator sqlgen)
public static DbOomQuery query(java.sql.Connection conn, java.lang.String sqlString)
public static DbOomQuery query(DbSession session, java.lang.String sqlString)
public static DbOomQuery query(java.lang.String sqlString)
public static DbOomQuery query(java.sql.Connection conn, DbSqlGenerator sqlgen)
public static DbOomQuery query(DbSession session, DbSqlGenerator sqlgen)
public static DbOomQuery query(DbSqlGenerator sqlgen)
protected void init(DbOom dbOom)
protected void prepareQuery()
protected void resolveColumnDbSqlType(java.sql.Connection connection, DbEntityColumnDescriptor dec)
protected java.lang.String preprocessSql(java.lang.String sqlString)
public DbOomQuery withHints(java.lang.String hint)
public DbOomQuery withHints(java.lang.String... hints)
protected java.lang.Object resolveRowResults(java.lang.Object[] row)
public DbOomQuery cacheEntities(boolean cacheEntities)
ResultSetMapper
.
Overrides default value in DbEntityManager
.protected ResultSetMapper executeAndBuildResultSetMapper()
builded ResultSet mapper
.protected ResultSetMapper createResultSetMapper(java.sql.ResultSet resultSet)
public DbOomQuery entityAwareMode(boolean entityAware)
public <T> java.util.Iterator<T> iterate(java.lang.Class... types)
public <T> java.util.Iterator<T> iterate()
protected <T> java.util.Iterator<T> iterate(java.lang.Class[] types, boolean close)
public <T> java.util.List<T> list(java.lang.Class... types)
public <T> java.util.List<T> list()
public <T> java.util.List<T> list(int max, java.lang.Class... types)
public <T> java.util.List<T> list(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, -1
for allclose
- true
if query is closed at the end, otherwise false
.public <T> java.util.Set<T> listSet(java.lang.Class... types)
public <T> java.util.Set<T> listSet()
public <T> java.util.Set<T> listSet(int max, java.lang.Class... types)
public <T> java.util.Set<T> listSet(int max)
protected <T> java.util.Set<T> listSet(java.lang.Class[] types, int max, boolean close)
public <T> T find(java.lang.Class... types)
public <T> T find()
protected <T> T 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)
public void populateGeneratedKeys(java.lang.Object entity)
public DbOomQuery autoClose()
autoClose
in class DbQuery<DbOomQuery>
protected void close(ResultSetMapper rsm, boolean closeQuery)
protected Q _this()
public jodd.db.DbQueryBase.State 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 Q forcePreparedStatement()
public final void init()
protected void initSession(DbSession session)
null
),
session is fetched from session provider.protected void initializeJdbc()
public Q closeAllResultSets()
protected java.sql.SQLException closeQuery()
public void close()
close
in interface java.lang.AutoCloseable
public void closeResultSet(java.sql.ResultSet rs)
DbQueryBase.close()
method closes all created result sets.
Query remains active.public QueryScrollType getType()
public Q setType(QueryScrollType type)
public Q typeForwardOnly()
public Q typeScrollSensitive()
public Q typeScrollInsensitive()
public QueryConcurrencyType getConcurrencyType()
public Q setConcurrencyType(QueryConcurrencyType concurrencyType)
public Q concurrentReadOnly()
public Q concurrentUpdatable()
public QueryHoldability getHoldability()
public Q setHoldability(QueryHoldability holdability)
public Q holdCursorsOverCommit()
public Q closeCursorsAtCommit()
public boolean isInDebugMode()
public Q setDebug(boolean debug)
public Q setDebugMode()
public java.lang.String[] getGeneratedColumnNames()
public Q setGeneratedColumns(java.lang.String... columns)
public Q setGeneratedKey()
public Q resetGeneratedColumns()
public int getFetchSize()
setFetchSize(int)
public Q setFetchSize(int rows)
Statement.setFetchSize(int)
public int getMaxRows()
setMaxRows(int)
public Q setMaxRows(int maxRows)
Statement.setMaxRows(int)
public long getExecutionTime()
-1
if query is still not executed.public java.sql.ResultSet execute()
DbQueryBase.closeResultSet(ResultSet)
оr implicitly, during DbQueryBase.close()
.Statement.execute(String)
public DbCallResult executeCall()
public int executeUpdate()
auto close mode
is set.Statement.executeUpdate(String)
protected int executeUpdate(boolean closeQuery)
Statement.executeUpdate(String)
public long executeCount()
auto-close mode
is set.
Doesn't check if query is really a count query, so it would work for any
query that has number in the first column of result.
If result set returns zero rows (very unlikely), returns -1
.protected long executeCount(boolean close)
public <T> java.util.List<T> list(QueryMapper<T> queryMapper)
public <T> T find(QueryMapper<T> queryMapper)
public <T> java.util.Set<T> listSet(QueryMapper<T> queryMapper)
public java.sql.ResultSet getGeneratedColumns()
public long getGeneratedKey()
long
.public java.lang.Object getGeneratedKeyObject()
public java.lang.String getQueryString()
public java.lang.String toString()
toString
in class java.lang.Object
getQueryString()
public static int getTotalOpenResultSetCount()
getOpenResultSetCount()
public int getOpenResultSetCount()
getTotalOpenResultSetCount()
Copyright © 2003-present Jodd Team