Class DefaultSqlSession
- java.lang.Object
- 
- org.apache.ibatis.session.defaults.DefaultSqlSession
 
- 
- All Implemented Interfaces:
- java.io.Closeable,- java.lang.AutoCloseable,- SqlSession
 
 public class DefaultSqlSession extends java.lang.Object implements SqlSession The default implementation forSqlSession. Note that this class is not Thread-Safe.- Author:
- Clinton Begin
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classDefaultSqlSession.StrictMap<V>
 - 
Constructor SummaryConstructors Constructor Description DefaultSqlSession(Configuration configuration, Executor executor)DefaultSqlSession(Configuration configuration, Executor executor, boolean autoCommit)
 - 
Method SummaryModifier and Type Method Description voidclearCache()Clears local session cache.voidclose()Closes the session.voidcommit()Flushes batch statements and commits database connection.voidcommit(boolean force)Flushes batch statements and commits database connection.intdelete(java.lang.String statement)Execute a delete statement.intdelete(java.lang.String statement, java.lang.Object parameter)Execute a delete statement.java.util.List<BatchResult>flushStatements()Flushes batch statements.ConfigurationgetConfiguration()Retrieves current configuration.java.sql.ConnectiongetConnection()Retrieves inner database connection.<T> TgetMapper(java.lang.Class<T> type)Retrieves a mapper.intinsert(java.lang.String statement)Execute an insert statement.intinsert(java.lang.String statement, java.lang.Object parameter)Execute an insert statement with the given parameter object.voidrollback()Discards pending batch statements and rolls database connection back.voidrollback(boolean force)Discards pending batch statements and rolls database connection back.voidselect(java.lang.String statement, java.lang.Object parameter, ResultHandler handler)Retrieve a single row mapped from the statement key and parameter using aResultHandler.voidselect(java.lang.String statement, java.lang.Object parameter, RowBounds rowBounds, ResultHandler handler)Retrieve a single row mapped from the statement key and parameter using aResultHandlerandRowBounds.voidselect(java.lang.String statement, ResultHandler handler)Retrieve a single row mapped from the statement using aResultHandler.<T> Cursor<T>selectCursor(java.lang.String statement)A Cursor offers the same results as a List, except it fetches data lazily using an Iterator.<T> Cursor<T>selectCursor(java.lang.String statement, java.lang.Object parameter)A Cursor offers the same results as a List, except it fetches data lazily using an Iterator.<T> Cursor<T>selectCursor(java.lang.String statement, java.lang.Object parameter, RowBounds rowBounds)A Cursor offers the same results as a List, except it fetches data lazily using an Iterator.<E> java.util.List<E>selectList(java.lang.String statement)Retrieve a list of mapped objects from the statement key and parameter.<E> java.util.List<E>selectList(java.lang.String statement, java.lang.Object parameter)Retrieve a list of mapped objects from the statement key and parameter.<E> java.util.List<E>selectList(java.lang.String statement, java.lang.Object parameter, RowBounds rowBounds)Retrieve a list of mapped objects from the statement key and parameter, within the specified row bounds.<K,V>
 java.util.Map<K,V>selectMap(java.lang.String statement, java.lang.Object parameter, java.lang.String mapKey)The selectMap is a special case in that it is designed to convert a list of results into a Map based on one of the properties in the resulting objects.<K,V>
 java.util.Map<K,V>selectMap(java.lang.String statement, java.lang.Object parameter, java.lang.String mapKey, RowBounds rowBounds)The selectMap is a special case in that it is designed to convert a list of results into a Map based on one of the properties in the resulting objects.<K,V>
 java.util.Map<K,V>selectMap(java.lang.String statement, java.lang.String mapKey)The selectMap is a special case in that it is designed to convert a list of results into a Map based on one of the properties in the resulting objects.<T> TselectOne(java.lang.String statement)Retrieve a single row mapped from the statement key.<T> TselectOne(java.lang.String statement, java.lang.Object parameter)Retrieve a single row mapped from the statement key and parameter.intupdate(java.lang.String statement)Execute an update statement.intupdate(java.lang.String statement, java.lang.Object parameter)Execute an update statement.
 
- 
- 
- 
Constructor Detail- 
DefaultSqlSessionpublic DefaultSqlSession(Configuration configuration, Executor executor, boolean autoCommit) 
 - 
DefaultSqlSessionpublic DefaultSqlSession(Configuration configuration, Executor executor) 
 
- 
 - 
Method Detail- 
selectOnepublic <T> T selectOne(java.lang.String statement) Description copied from interface:SqlSessionRetrieve a single row mapped from the statement key.- Specified by:
- selectOnein interface- SqlSession
- Type Parameters:
- T- the returned object type
- Returns:
- Mapped object
 
 - 
selectOnepublic <T> T selectOne(java.lang.String statement, java.lang.Object parameter)Description copied from interface:SqlSessionRetrieve a single row mapped from the statement key and parameter.- Specified by:
- selectOnein interface- SqlSession
- Type Parameters:
- T- the returned object type
- Parameters:
- statement- Unique identifier matching the statement to use.
- parameter- A parameter object to pass to the statement.
- Returns:
- Mapped object
 
 - 
selectMappublic <K,V> java.util.Map<K,V> selectMap(java.lang.String statement, java.lang.String mapKey)Description copied from interface:SqlSessionThe selectMap is a special case in that it is designed to convert a list of results into a Map based on one of the properties in the resulting objects. Eg. Return a of Map[Integer,Author] for selectMap("selectAuthors","id")- Specified by:
- selectMapin interface- SqlSession
- Type Parameters:
- K- the returned Map keys type
- V- the returned Map values type
- Parameters:
- statement- Unique identifier matching the statement to use.
- mapKey- The property to use as key for each value in the list.
- Returns:
- Map containing key pair data.
 
 - 
selectMappublic <K,V> java.util.Map<K,V> selectMap(java.lang.String statement, java.lang.Object parameter, java.lang.String mapKey)Description copied from interface:SqlSessionThe selectMap is a special case in that it is designed to convert a list of results into a Map based on one of the properties in the resulting objects.- Specified by:
- selectMapin interface- SqlSession
- Type Parameters:
- K- the returned Map keys type
- V- the returned Map values type
- Parameters:
- statement- Unique identifier matching the statement to use.
- parameter- A parameter object to pass to the statement.
- mapKey- The property to use as key for each value in the list.
- Returns:
- Map containing key pair data.
 
 - 
selectMappublic <K,V> java.util.Map<K,V> selectMap(java.lang.String statement, java.lang.Object parameter, java.lang.String mapKey, RowBounds rowBounds)Description copied from interface:SqlSessionThe selectMap is a special case in that it is designed to convert a list of results into a Map based on one of the properties in the resulting objects.- Specified by:
- selectMapin interface- SqlSession
- Type Parameters:
- K- the returned Map keys type
- V- the returned Map values type
- Parameters:
- statement- Unique identifier matching the statement to use.
- parameter- A parameter object to pass to the statement.
- mapKey- The property to use as key for each value in the list.
- rowBounds- Bounds to limit object retrieval
- Returns:
- Map containing key pair data.
 
 - 
selectCursorpublic <T> Cursor<T> selectCursor(java.lang.String statement) Description copied from interface:SqlSessionA Cursor offers the same results as a List, except it fetches data lazily using an Iterator.- Specified by:
- selectCursorin interface- SqlSession
- Type Parameters:
- T- the returned cursor element type.
- Parameters:
- statement- Unique identifier matching the statement to use.
- Returns:
- Cursor of mapped objects
 
 - 
selectCursorpublic <T> Cursor<T> selectCursor(java.lang.String statement, java.lang.Object parameter) Description copied from interface:SqlSessionA Cursor offers the same results as a List, except it fetches data lazily using an Iterator.- Specified by:
- selectCursorin interface- SqlSession
- Type Parameters:
- T- the returned cursor element type.
- Parameters:
- statement- Unique identifier matching the statement to use.
- parameter- A parameter object to pass to the statement.
- Returns:
- Cursor of mapped objects
 
 - 
selectCursorpublic <T> Cursor<T> selectCursor(java.lang.String statement, java.lang.Object parameter, RowBounds rowBounds) Description copied from interface:SqlSessionA Cursor offers the same results as a List, except it fetches data lazily using an Iterator.- Specified by:
- selectCursorin interface- SqlSession
- Type Parameters:
- T- the returned cursor element type.
- Parameters:
- statement- Unique identifier matching the statement to use.
- parameter- A parameter object to pass to the statement.
- rowBounds- Bounds to limit object retrieval
- Returns:
- Cursor of mapped objects
 
 - 
selectListpublic <E> java.util.List<E> selectList(java.lang.String statement) Description copied from interface:SqlSessionRetrieve a list of mapped objects from the statement key and parameter.- Specified by:
- selectListin interface- SqlSession
- Type Parameters:
- E- the returned list element type
- Parameters:
- statement- Unique identifier matching the statement to use.
- Returns:
- List of mapped object
 
 - 
selectListpublic <E> java.util.List<E> selectList(java.lang.String statement, java.lang.Object parameter)Description copied from interface:SqlSessionRetrieve a list of mapped objects from the statement key and parameter.- Specified by:
- selectListin interface- SqlSession
- Type Parameters:
- E- the returned list element type
- Parameters:
- statement- Unique identifier matching the statement to use.
- parameter- A parameter object to pass to the statement.
- Returns:
- List of mapped object
 
 - 
selectListpublic <E> java.util.List<E> selectList(java.lang.String statement, java.lang.Object parameter, RowBounds rowBounds)Description copied from interface:SqlSessionRetrieve a list of mapped objects from the statement key and parameter, within the specified row bounds.- Specified by:
- selectListin interface- SqlSession
- Type Parameters:
- E- the returned list element type
- Parameters:
- statement- Unique identifier matching the statement to use.
- parameter- A parameter object to pass to the statement.
- rowBounds- Bounds to limit object retrieval
- Returns:
- List of mapped object
 
 - 
selectpublic void select(java.lang.String statement, java.lang.Object parameter, ResultHandler handler)Description copied from interface:SqlSessionRetrieve a single row mapped from the statement key and parameter using aResultHandler.- Specified by:
- selectin interface- SqlSession
- Parameters:
- statement- Unique identifier matching the statement to use.
- parameter- A parameter object to pass to the statement.
- handler- ResultHandler that will handle each retrieved row
 
 - 
selectpublic void select(java.lang.String statement, ResultHandler handler)Description copied from interface:SqlSessionRetrieve a single row mapped from the statement using aResultHandler.- Specified by:
- selectin interface- SqlSession
- Parameters:
- statement- Unique identifier matching the statement to use.
- handler- ResultHandler that will handle each retrieved row
 
 - 
selectpublic void select(java.lang.String statement, java.lang.Object parameter, RowBounds rowBounds, ResultHandler handler)Description copied from interface:SqlSessionRetrieve a single row mapped from the statement key and parameter using aResultHandlerandRowBounds.- Specified by:
- selectin interface- SqlSession
- Parameters:
- statement- Unique identifier matching the statement to use.
- rowBounds- RowBound instance to limit the query results
- handler- ResultHandler that will handle each retrieved row
 
 - 
insertpublic int insert(java.lang.String statement) Description copied from interface:SqlSessionExecute an insert statement.- Specified by:
- insertin interface- SqlSession
- Parameters:
- statement- Unique identifier matching the statement to execute.
- Returns:
- int The number of rows affected by the insert.
 
 - 
insertpublic int insert(java.lang.String statement, java.lang.Object parameter)Description copied from interface:SqlSessionExecute an insert statement with the given parameter object. Any generated autoincrement values or selectKey entries will modify the given parameter object properties. Only the number of rows affected will be returned.- Specified by:
- insertin interface- SqlSession
- Parameters:
- statement- Unique identifier matching the statement to execute.
- parameter- A parameter object to pass to the statement.
- Returns:
- int The number of rows affected by the insert.
 
 - 
updatepublic int update(java.lang.String statement) Description copied from interface:SqlSessionExecute an update statement. The number of rows affected will be returned.- Specified by:
- updatein interface- SqlSession
- Parameters:
- statement- Unique identifier matching the statement to execute.
- Returns:
- int The number of rows affected by the update.
 
 - 
updatepublic int update(java.lang.String statement, java.lang.Object parameter)Description copied from interface:SqlSessionExecute an update statement. The number of rows affected will be returned.- Specified by:
- updatein interface- SqlSession
- Parameters:
- statement- Unique identifier matching the statement to execute.
- parameter- A parameter object to pass to the statement.
- Returns:
- int The number of rows affected by the update.
 
 - 
deletepublic int delete(java.lang.String statement) Description copied from interface:SqlSessionExecute a delete statement. The number of rows affected will be returned.- Specified by:
- deletein interface- SqlSession
- Parameters:
- statement- Unique identifier matching the statement to execute.
- Returns:
- int The number of rows affected by the delete.
 
 - 
deletepublic int delete(java.lang.String statement, java.lang.Object parameter)Description copied from interface:SqlSessionExecute a delete statement. The number of rows affected will be returned.- Specified by:
- deletein interface- SqlSession
- Parameters:
- statement- Unique identifier matching the statement to execute.
- parameter- A parameter object to pass to the statement.
- Returns:
- int The number of rows affected by the delete.
 
 - 
commitpublic void commit() Description copied from interface:SqlSessionFlushes batch statements and commits database connection. Note that database connection will not be committed if no updates/deletes/inserts were called. To force the commit callSqlSession.commit(boolean)- Specified by:
- commitin interface- SqlSession
 
 - 
commitpublic void commit(boolean force) Description copied from interface:SqlSessionFlushes batch statements and commits database connection.- Specified by:
- commitin interface- SqlSession
- Parameters:
- force- forces connection commit
 
 - 
rollbackpublic void rollback() Description copied from interface:SqlSessionDiscards pending batch statements and rolls database connection back. Note that database connection will not be rolled back if no updates/deletes/inserts were called. To force the rollback callSqlSession.rollback(boolean)- Specified by:
- rollbackin interface- SqlSession
 
 - 
rollbackpublic void rollback(boolean force) Description copied from interface:SqlSessionDiscards pending batch statements and rolls database connection back. Note that database connection will not be rolled back if no updates/deletes/inserts were called.- Specified by:
- rollbackin interface- SqlSession
- Parameters:
- force- forces connection rollback
 
 - 
flushStatementspublic java.util.List<BatchResult> flushStatements() Description copied from interface:SqlSessionFlushes batch statements.- Specified by:
- flushStatementsin interface- SqlSession
- Returns:
- BatchResult list of updated records
 
 - 
closepublic void close() Description copied from interface:SqlSessionCloses the session.- Specified by:
- closein interface- java.lang.AutoCloseable
- Specified by:
- closein interface- java.io.Closeable
- Specified by:
- closein interface- SqlSession
 
 - 
getConfigurationpublic Configuration getConfiguration() Description copied from interface:SqlSessionRetrieves current configuration.- Specified by:
- getConfigurationin interface- SqlSession
- Returns:
- Configuration
 
 - 
getMapperpublic <T> T getMapper(java.lang.Class<T> type) Description copied from interface:SqlSessionRetrieves a mapper.- Specified by:
- getMapperin interface- SqlSession
- Type Parameters:
- T- the mapper type
- Parameters:
- type- Mapper interface class
- Returns:
- a mapper bound to this SqlSession
 
 - 
getConnectionpublic java.sql.Connection getConnection() Description copied from interface:SqlSessionRetrieves inner database connection.- Specified by:
- getConnectionin interface- SqlSession
- Returns:
- Connection
 
 - 
clearCachepublic void clearCache() Description copied from interface:SqlSessionClears local session cache.- Specified by:
- clearCachein interface- SqlSession
 
 
- 
 
-