Class JKSession

java.lang.Object
com.jk.data.datasource.JKSession

public class JKSession extends Object
This class represents a session for database operations.
Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Summary

    Constructors
    Constructor
    Description
    JKSession(JKDataSource connectionManager)
    This method constructs a new JKSession using the provided connection manager.
    JKSession(JKSession parentSession)
    This method constructs a new JKSession with a nested session within the provided parent session.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This method closes the session.
    void
    close(boolean commit)
    This method closes the session and performs a commit or roll-back operation based on the specified parameter.
    protected void
    commit(boolean commit)
    This method sets the commit or roll-back status for this session.
    This method returns the database connection associated with this session.
    This method returns the connection manager responsible for managing the database connections.
    This method returns the parent session if this session is nested within another session.
    boolean
    This method checks whether the session is closed.
    boolean
    This method checks whether a commit operation is requested.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JKSession

      public JKSession(JKDataSource connectionManager) throws JKDataAccessException
      This method constructs a new JKSession using the provided connection manager.
      Parameters:
      connectionManager - Specifies the connection manager responsible for providing connections.
      Throws:
      JKDataAccessException - if there is an error while obtaining a connection.
    • JKSession

      public JKSession(JKSession parentSession)
      This method constructs a new JKSession with a nested session within the provided parent session.
      Parameters:
      parentSession - Specifies the parent session.
  • Method Details

    • close

      public void close() throws JKDataAccessException
      This method closes the session.

      If this is a stand-alone session, it will commit or roll-back the transaction based on the session's state and then close the connection.

      If this is a nested session, it will return without closing the connection, as the parent session is responsible for that.

      Throws:
      JKDataAccessException - if there is an error during the commit, roll-back, or closing operations.
    • close

      public void close(boolean commit) throws JKDataAccessException
      This method closes the session and performs a commit or roll-back operation based on the specified parameter.
      Parameters:
      commit - Indicates whether to commit the transaction (true) or roll-back (false).
      Throws:
      JKDataAccessException - if there is an error during the commit, roll-back, or closing operations.
    • commit

      protected void commit(boolean commit)
      This method sets the commit or roll-back status for this session.
      Parameters:
      commit - Indicates whether to commit the transaction (true) or roll-back (false).
    • getConnection

      public Connection getConnection()
      This method returns the database connection associated with this session.
      Returns:
      the database connection.
    • getConnectionManager

      public JKDataSource getConnectionManager()
      This method returns the connection manager responsible for managing the database connections.

      If this is a nested session, it will return the parent session's connection manager.

      Returns:
      the connection manager.
    • getParentSession

      public JKSession getParentSession()
      This method returns the parent session if this session is nested within another session.
      Returns:
      the parent session or null if this is a stand-alone session.
    • isClosed

      public boolean isClosed()
      This method checks whether the session is closed.
      Returns:
      true, if session is closed, false otherwise.
    • isCommit

      public boolean isCommit()
      This method checks whether a commit operation is requested.
      Returns:
      true, if commit is requested, false otherwise.