Package org.apache.ibatis.session
Class SqlSessionManager
- java.lang.Object
-
- org.apache.ibatis.session.SqlSessionManager
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,SqlSession
,SqlSessionFactory
public class SqlSessionManager extends java.lang.Object implements SqlSessionFactory, SqlSession
- Author:
- Larry Meadors
-
-
Method Summary
Modifier and Type Method Description void
clearCache()
Clears local session cache.void
close()
Closes the session.void
commit()
Flushes batch statements and commits database connection.void
commit(boolean force)
Flushes batch statements and commits database connection.int
delete(java.lang.String statement)
Execute a delete statement.int
delete(java.lang.String statement, java.lang.Object parameter)
Execute a delete statement.java.util.List<BatchResult>
flushStatements()
Flushes batch statements.Configuration
getConfiguration()
Retrieves current configuration.java.sql.Connection
getConnection()
Retrieves inner database connection.<T> T
getMapper(java.lang.Class<T> type)
Retrieves a mapper.int
insert(java.lang.String statement)
Execute an insert statement.int
insert(java.lang.String statement, java.lang.Object parameter)
Execute an insert statement with the given parameter object.boolean
isManagedSessionStarted()
static SqlSessionManager
newInstance(java.io.InputStream inputStream)
static SqlSessionManager
newInstance(java.io.InputStream inputStream, java.lang.String environment)
static SqlSessionManager
newInstance(java.io.InputStream inputStream, java.util.Properties properties)
static SqlSessionManager
newInstance(java.io.Reader reader)
static SqlSessionManager
newInstance(java.io.Reader reader, java.lang.String environment)
static SqlSessionManager
newInstance(java.io.Reader reader, java.util.Properties properties)
static SqlSessionManager
newInstance(SqlSessionFactory sqlSessionFactory)
SqlSession
openSession()
SqlSession
openSession(boolean autoCommit)
SqlSession
openSession(java.sql.Connection connection)
SqlSession
openSession(ExecutorType execType)
SqlSession
openSession(ExecutorType execType, boolean autoCommit)
SqlSession
openSession(ExecutorType execType, java.sql.Connection connection)
SqlSession
openSession(ExecutorType execType, TransactionIsolationLevel level)
SqlSession
openSession(TransactionIsolationLevel level)
void
rollback()
Discards pending batch statements and rolls database connection back.void
rollback(boolean force)
Discards pending batch statements and rolls database connection back.void
select(java.lang.String statement, java.lang.Object parameter, ResultHandler handler)
Retrieve a single row mapped from the statement key and parameter using aResultHandler
.void
select(java.lang.String statement, java.lang.Object parameter, RowBounds rowBounds, ResultHandler handler)
Retrieve a single row mapped from the statement key and parameter using aResultHandler
andRowBounds
.void
select(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> T
selectOne(java.lang.String statement)
Retrieve a single row mapped from the statement key.<T> T
selectOne(java.lang.String statement, java.lang.Object parameter)
Retrieve a single row mapped from the statement key and parameter.void
startManagedSession()
void
startManagedSession(boolean autoCommit)
void
startManagedSession(java.sql.Connection connection)
void
startManagedSession(ExecutorType execType)
void
startManagedSession(ExecutorType execType, boolean autoCommit)
void
startManagedSession(ExecutorType execType, java.sql.Connection connection)
void
startManagedSession(ExecutorType execType, TransactionIsolationLevel level)
void
startManagedSession(TransactionIsolationLevel level)
int
update(java.lang.String statement)
Execute an update statement.int
update(java.lang.String statement, java.lang.Object parameter)
Execute an update statement.
-
-
-
Method Detail
-
newInstance
public static SqlSessionManager newInstance(java.io.Reader reader)
-
newInstance
public static SqlSessionManager newInstance(java.io.Reader reader, java.lang.String environment)
-
newInstance
public static SqlSessionManager newInstance(java.io.Reader reader, java.util.Properties properties)
-
newInstance
public static SqlSessionManager newInstance(java.io.InputStream inputStream)
-
newInstance
public static SqlSessionManager newInstance(java.io.InputStream inputStream, java.lang.String environment)
-
newInstance
public static SqlSessionManager newInstance(java.io.InputStream inputStream, java.util.Properties properties)
-
newInstance
public static SqlSessionManager newInstance(SqlSessionFactory sqlSessionFactory)
-
startManagedSession
public void startManagedSession()
-
startManagedSession
public void startManagedSession(boolean autoCommit)
-
startManagedSession
public void startManagedSession(java.sql.Connection connection)
-
startManagedSession
public void startManagedSession(TransactionIsolationLevel level)
-
startManagedSession
public void startManagedSession(ExecutorType execType)
-
startManagedSession
public void startManagedSession(ExecutorType execType, boolean autoCommit)
-
startManagedSession
public void startManagedSession(ExecutorType execType, TransactionIsolationLevel level)
-
startManagedSession
public void startManagedSession(ExecutorType execType, java.sql.Connection connection)
-
isManagedSessionStarted
public boolean isManagedSessionStarted()
-
openSession
public SqlSession openSession()
- Specified by:
openSession
in interfaceSqlSessionFactory
-
openSession
public SqlSession openSession(boolean autoCommit)
- Specified by:
openSession
in interfaceSqlSessionFactory
-
openSession
public SqlSession openSession(java.sql.Connection connection)
- Specified by:
openSession
in interfaceSqlSessionFactory
-
openSession
public SqlSession openSession(TransactionIsolationLevel level)
- Specified by:
openSession
in interfaceSqlSessionFactory
-
openSession
public SqlSession openSession(ExecutorType execType)
- Specified by:
openSession
in interfaceSqlSessionFactory
-
openSession
public SqlSession openSession(ExecutorType execType, boolean autoCommit)
- Specified by:
openSession
in interfaceSqlSessionFactory
-
openSession
public SqlSession openSession(ExecutorType execType, TransactionIsolationLevel level)
- Specified by:
openSession
in interfaceSqlSessionFactory
-
openSession
public SqlSession openSession(ExecutorType execType, java.sql.Connection connection)
- Specified by:
openSession
in interfaceSqlSessionFactory
-
getConfiguration
public Configuration getConfiguration()
Description copied from interface:SqlSession
Retrieves current configuration.- Specified by:
getConfiguration
in interfaceSqlSession
- Specified by:
getConfiguration
in interfaceSqlSessionFactory
- Returns:
- Configuration
-
selectOne
public <T> T selectOne(java.lang.String statement)
Description copied from interface:SqlSession
Retrieve a single row mapped from the statement key.- Specified by:
selectOne
in interfaceSqlSession
- Type Parameters:
T
- the returned object type- Returns:
- Mapped object
-
selectOne
public <T> T selectOne(java.lang.String statement, java.lang.Object parameter)
Description copied from interface:SqlSession
Retrieve a single row mapped from the statement key and parameter.- Specified by:
selectOne
in interfaceSqlSession
- 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
-
selectMap
public <K,V> java.util.Map<K,V> selectMap(java.lang.String statement, java.lang.String mapKey)
Description copied from interface:SqlSession
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. Eg. Return a of Map[Integer,Author] for selectMap("selectAuthors","id")- Specified by:
selectMap
in interfaceSqlSession
- Type Parameters:
K
- the returned Map keys typeV
- 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.
-
selectMap
public <K,V> java.util.Map<K,V> selectMap(java.lang.String statement, java.lang.Object parameter, java.lang.String mapKey)
Description copied from interface:SqlSession
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.- Specified by:
selectMap
in interfaceSqlSession
- Type Parameters:
K
- the returned Map keys typeV
- 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.
-
selectMap
public <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:SqlSession
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.- Specified by:
selectMap
in interfaceSqlSession
- Type Parameters:
K
- the returned Map keys typeV
- 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.
-
selectCursor
public <T> Cursor<T> selectCursor(java.lang.String statement)
Description copied from interface:SqlSession
A Cursor offers the same results as a List, except it fetches data lazily using an Iterator.- Specified by:
selectCursor
in interfaceSqlSession
- Type Parameters:
T
- the returned cursor element type.- Parameters:
statement
- Unique identifier matching the statement to use.- Returns:
- Cursor of mapped objects
-
selectCursor
public <T> Cursor<T> selectCursor(java.lang.String statement, java.lang.Object parameter)
Description copied from interface:SqlSession
A Cursor offers the same results as a List, except it fetches data lazily using an Iterator.- Specified by:
selectCursor
in interfaceSqlSession
- 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
-
selectCursor
public <T> Cursor<T> selectCursor(java.lang.String statement, java.lang.Object parameter, RowBounds rowBounds)
Description copied from interface:SqlSession
A Cursor offers the same results as a List, except it fetches data lazily using an Iterator.- Specified by:
selectCursor
in interfaceSqlSession
- 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
-
selectList
public <E> java.util.List<E> selectList(java.lang.String statement)
Description copied from interface:SqlSession
Retrieve a list of mapped objects from the statement key and parameter.- Specified by:
selectList
in interfaceSqlSession
- Type Parameters:
E
- the returned list element type- Parameters:
statement
- Unique identifier matching the statement to use.- Returns:
- List of mapped object
-
selectList
public <E> java.util.List<E> selectList(java.lang.String statement, java.lang.Object parameter)
Description copied from interface:SqlSession
Retrieve a list of mapped objects from the statement key and parameter.- Specified by:
selectList
in interfaceSqlSession
- 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
-
selectList
public <E> java.util.List<E> selectList(java.lang.String statement, java.lang.Object parameter, RowBounds rowBounds)
Description copied from interface:SqlSession
Retrieve a list of mapped objects from the statement key and parameter, within the specified row bounds.- Specified by:
selectList
in interfaceSqlSession
- 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
-
select
public void select(java.lang.String statement, ResultHandler handler)
Description copied from interface:SqlSession
Retrieve a single row mapped from the statement using aResultHandler
.- Specified by:
select
in interfaceSqlSession
- Parameters:
statement
- Unique identifier matching the statement to use.handler
- ResultHandler that will handle each retrieved row
-
select
public void select(java.lang.String statement, java.lang.Object parameter, ResultHandler handler)
Description copied from interface:SqlSession
Retrieve a single row mapped from the statement key and parameter using aResultHandler
.- Specified by:
select
in interfaceSqlSession
- 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
-
select
public void select(java.lang.String statement, java.lang.Object parameter, RowBounds rowBounds, ResultHandler handler)
Description copied from interface:SqlSession
Retrieve a single row mapped from the statement key and parameter using aResultHandler
andRowBounds
.- Specified by:
select
in interfaceSqlSession
- Parameters:
statement
- Unique identifier matching the statement to use.rowBounds
- RowBound instance to limit the query resultshandler
- ResultHandler that will handle each retrieved row
-
insert
public int insert(java.lang.String statement)
Description copied from interface:SqlSession
Execute an insert statement.- Specified by:
insert
in interfaceSqlSession
- Parameters:
statement
- Unique identifier matching the statement to execute.- Returns:
- int The number of rows affected by the insert.
-
insert
public int insert(java.lang.String statement, java.lang.Object parameter)
Description copied from interface:SqlSession
Execute 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:
insert
in interfaceSqlSession
- 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.
-
update
public int update(java.lang.String statement)
Description copied from interface:SqlSession
Execute an update statement. The number of rows affected will be returned.- Specified by:
update
in interfaceSqlSession
- Parameters:
statement
- Unique identifier matching the statement to execute.- Returns:
- int The number of rows affected by the update.
-
update
public int update(java.lang.String statement, java.lang.Object parameter)
Description copied from interface:SqlSession
Execute an update statement. The number of rows affected will be returned.- Specified by:
update
in interfaceSqlSession
- 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.
-
delete
public int delete(java.lang.String statement)
Description copied from interface:SqlSession
Execute a delete statement. The number of rows affected will be returned.- Specified by:
delete
in interfaceSqlSession
- Parameters:
statement
- Unique identifier matching the statement to execute.- Returns:
- int The number of rows affected by the delete.
-
delete
public int delete(java.lang.String statement, java.lang.Object parameter)
Description copied from interface:SqlSession
Execute a delete statement. The number of rows affected will be returned.- Specified by:
delete
in interfaceSqlSession
- 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.
-
getMapper
public <T> T getMapper(java.lang.Class<T> type)
Description copied from interface:SqlSession
Retrieves a mapper.- Specified by:
getMapper
in interfaceSqlSession
- Type Parameters:
T
- the mapper type- Parameters:
type
- Mapper interface class- Returns:
- a mapper bound to this SqlSession
-
getConnection
public java.sql.Connection getConnection()
Description copied from interface:SqlSession
Retrieves inner database connection.- Specified by:
getConnection
in interfaceSqlSession
- Returns:
- Connection
-
clearCache
public void clearCache()
Description copied from interface:SqlSession
Clears local session cache.- Specified by:
clearCache
in interfaceSqlSession
-
commit
public void commit()
Description copied from interface:SqlSession
Flushes 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:
commit
in interfaceSqlSession
-
commit
public void commit(boolean force)
Description copied from interface:SqlSession
Flushes batch statements and commits database connection.- Specified by:
commit
in interfaceSqlSession
- Parameters:
force
- forces connection commit
-
rollback
public void rollback()
Description copied from interface:SqlSession
Discards 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:
rollback
in interfaceSqlSession
-
rollback
public void rollback(boolean force)
Description copied from interface:SqlSession
Discards 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:
rollback
in interfaceSqlSession
- Parameters:
force
- forces connection rollback
-
flushStatements
public java.util.List<BatchResult> flushStatements()
Description copied from interface:SqlSession
Flushes batch statements.- Specified by:
flushStatements
in interfaceSqlSession
- Returns:
- BatchResult list of updated records
-
close
public void close()
Description copied from interface:SqlSession
Closes the session.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceSqlSession
-
-