Class SqlSessionManager

java.lang.Object
org.apache.ibatis.session.SqlSessionManager
All Implemented Interfaces:
Closeable, AutoCloseable, SqlSession, SqlSessionFactory

public class SqlSessionManager extends Object implements SqlSessionFactory, SqlSession
Author:
Larry Meadors
  • Method Details Link icon

    • newInstance Link icon

      public static SqlSessionManager newInstance(Reader reader)
    • newInstance Link icon

      public static SqlSessionManager newInstance(Reader reader, String environment)
    • newInstance Link icon

      public static SqlSessionManager newInstance(Reader reader, Properties properties)
    • newInstance Link icon

      public static SqlSessionManager newInstance(InputStream inputStream)
    • newInstance Link icon

      public static SqlSessionManager newInstance(InputStream inputStream, String environment)
    • newInstance Link icon

      public static SqlSessionManager newInstance(InputStream inputStream, Properties properties)
    • newInstance Link icon

      public static SqlSessionManager newInstance(SqlSessionFactory sqlSessionFactory)
    • startManagedSession Link icon

      public void startManagedSession()
    • startManagedSession Link icon

      public void startManagedSession(boolean autoCommit)
    • startManagedSession Link icon

      public void startManagedSession(Connection connection)
    • startManagedSession Link icon

      public void startManagedSession(TransactionIsolationLevel level)
    • startManagedSession Link icon

      public void startManagedSession(ExecutorType execType)
    • startManagedSession Link icon

      public void startManagedSession(ExecutorType execType, boolean autoCommit)
    • startManagedSession Link icon

      public void startManagedSession(ExecutorType execType, TransactionIsolationLevel level)
    • startManagedSession Link icon

      public void startManagedSession(ExecutorType execType, Connection connection)
    • isManagedSessionStarted Link icon

      public boolean isManagedSessionStarted()
    • openSession Link icon

      public SqlSession openSession()
      Specified by:
      openSession in interface SqlSessionFactory
    • openSession Link icon

      public SqlSession openSession(boolean autoCommit)
      Specified by:
      openSession in interface SqlSessionFactory
    • openSession Link icon

      public SqlSession openSession(Connection connection)
      Specified by:
      openSession in interface SqlSessionFactory
    • openSession Link icon

      public SqlSession openSession(TransactionIsolationLevel level)
      Specified by:
      openSession in interface SqlSessionFactory
    • openSession Link icon

      public SqlSession openSession(ExecutorType execType)
      Specified by:
      openSession in interface SqlSessionFactory
    • openSession Link icon

      public SqlSession openSession(ExecutorType execType, boolean autoCommit)
      Specified by:
      openSession in interface SqlSessionFactory
    • openSession Link icon

      public SqlSession openSession(ExecutorType execType, TransactionIsolationLevel level)
      Specified by:
      openSession in interface SqlSessionFactory
    • openSession Link icon

      public SqlSession openSession(ExecutorType execType, Connection connection)
      Specified by:
      openSession in interface SqlSessionFactory
    • getConfiguration Link icon

      public Configuration getConfiguration()
      Description copied from interface: SqlSession
      Retrieves current configuration.
      Specified by:
      getConfiguration in interface SqlSession
      Specified by:
      getConfiguration in interface SqlSessionFactory
      Returns:
      Configuration
    • selectOne Link icon

      public <T> T selectOne(String statement)
      Description copied from interface: SqlSession
      Retrieve a single row mapped from the statement key.
      Specified by:
      selectOne in interface SqlSession
      Type Parameters:
      T - the returned object type
      Parameters:
      statement - the statement
      Returns:
      Mapped object
    • selectOne Link icon

      public <T> T selectOne(String statement, Object parameter)
      Description copied from interface: SqlSession
      Retrieve a single row mapped from the statement key and parameter.
      Specified by:
      selectOne in 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
    • selectMap Link icon

      public <K, V> Map<K,V> selectMap(String statement, 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 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.
    • selectMap Link icon

      public <K, V> Map<K,V> selectMap(String statement, Object parameter, 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 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.
    • selectMap Link icon

      public <K, V> Map<K,V> selectMap(String statement, Object parameter, 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 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.
    • selectCursor Link icon

      public <T> Cursor<T> selectCursor(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 interface SqlSession
      Type Parameters:
      T - the returned cursor element type.
      Parameters:
      statement - Unique identifier matching the statement to use.
      Returns:
      Cursor of mapped objects
    • selectCursor Link icon

      public <T> Cursor<T> selectCursor(String statement, 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 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
    • selectCursor Link icon

      public <T> Cursor<T> selectCursor(String statement, 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 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
    • selectList Link icon

      public <E> List<E> selectList(String statement)
      Description copied from interface: SqlSession
      Retrieve a list of mapped objects from the statement key.
      Specified by:
      selectList in interface SqlSession
      Type Parameters:
      E - the returned list element type
      Parameters:
      statement - Unique identifier matching the statement to use.
      Returns:
      List of mapped object
    • selectList Link icon

      public <E> List<E> selectList(String statement, Object parameter)
      Description copied from interface: SqlSession
      Retrieve a list of mapped objects from the statement key and parameter.
      Specified by:
      selectList in 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
    • selectList Link icon

      public <E> List<E> selectList(String statement, 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 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
    • select Link icon

      public void select(String statement, ResultHandler handler)
      Description copied from interface: SqlSession
      Retrieve a single row mapped from the statement using a ResultHandler.
      Specified by:
      select in interface SqlSession
      Parameters:
      statement - Unique identifier matching the statement to use.
      handler - ResultHandler that will handle each retrieved row
    • select Link icon

      public void select(String statement, Object parameter, ResultHandler handler)
      Description copied from interface: SqlSession
      Retrieve a single row mapped from the statement key and parameter using a ResultHandler.
      Specified by:
      select in 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
    • select Link icon

      public void select(String statement, Object parameter, RowBounds rowBounds, ResultHandler handler)
      Description copied from interface: SqlSession
      Retrieve a single row mapped from the statement key and parameter using a ResultHandler and RowBounds.
      Specified by:
      select in interface SqlSession
      Parameters:
      statement - Unique identifier matching the statement to use.
      parameter - the parameter
      rowBounds - RowBound instance to limit the query results
      handler - ResultHandler that will handle each retrieved row
    • insert Link icon

      public int insert(String statement)
      Description copied from interface: SqlSession
      Execute an insert statement.
      Specified by:
      insert in interface SqlSession
      Parameters:
      statement - Unique identifier matching the statement to execute.
      Returns:
      int The number of rows affected by the insert.
    • insert Link icon

      public int insert(String statement, 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 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.
    • update Link icon

      public int update(String statement)
      Description copied from interface: SqlSession
      Execute an update statement. The number of rows affected will be returned.
      Specified by:
      update in interface SqlSession
      Parameters:
      statement - Unique identifier matching the statement to execute.
      Returns:
      int The number of rows affected by the update.
    • update Link icon

      public int update(String statement, Object parameter)
      Description copied from interface: SqlSession
      Execute an update statement. The number of rows affected will be returned.
      Specified by:
      update in 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.
    • delete Link icon

      public int delete(String statement)
      Description copied from interface: SqlSession
      Execute a delete statement. The number of rows affected will be returned.
      Specified by:
      delete in interface SqlSession
      Parameters:
      statement - Unique identifier matching the statement to execute.
      Returns:
      int The number of rows affected by the delete.
    • delete Link icon

      public int delete(String statement, Object parameter)
      Description copied from interface: SqlSession
      Execute a delete statement. The number of rows affected will be returned.
      Specified by:
      delete in 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.
    • getMapper Link icon

      public <T> T getMapper(Class<T> type)
      Description copied from interface: SqlSession
      Retrieves a mapper.
      Specified by:
      getMapper in interface SqlSession
      Type Parameters:
      T - the mapper type
      Parameters:
      type - Mapper interface class
      Returns:
      a mapper bound to this SqlSession
    • getConnection Link icon

      public Connection getConnection()
      Description copied from interface: SqlSession
      Retrieves inner database connection.
      Specified by:
      getConnection in interface SqlSession
      Returns:
      Connection
    • clearCache Link icon

      public void clearCache()
      Description copied from interface: SqlSession
      Clears local session cache.
      Specified by:
      clearCache in interface SqlSession
    • commit Link icon

      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 call SqlSession.commit(boolean)
      Specified by:
      commit in interface SqlSession
    • commit Link icon

      public void commit(boolean force)
      Description copied from interface: SqlSession
      Flushes batch statements and commits database connection.
      Specified by:
      commit in interface SqlSession
      Parameters:
      force - forces connection commit
    • rollback Link icon

      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 call SqlSession.rollback(boolean)
      Specified by:
      rollback in interface SqlSession
    • rollback Link icon

      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 interface SqlSession
      Parameters:
      force - forces connection rollback
    • flushStatements Link icon

      public List<BatchResult> flushStatements()
      Description copied from interface: SqlSession
      Flushes batch statements.
      Specified by:
      flushStatements in interface SqlSession
      Returns:
      BatchResult list of updated records
    • close Link icon

      public void close()
      Description copied from interface: SqlSession
      Closes the session.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface SqlSession