Class JdbcSession

java.lang.Object
me.ahoo.cosid.store.jdbc.JdbcSession

public final class JdbcSession extends Object
One borrowed connection of a JDBC store, as a JdbcDialect sees it: the connection in auto-commit mode, the table names, and statements that carry the store timeout (StoreConfig.timeout as queryTimeout).
  • Method Details

    • connection

      public Connection connection()
      The connection; in auto-commit mode outside transaction(me.ahoo.cosid.store.jdbc.JdbcSession.SqlWork<T>).
      Returns:
      the connection
    • tables

      public JdbcTables tables()
      The table names of the store.
      Returns:
      the table names
    • prepare

      public PreparedStatement prepare(String sql) throws SQLException
      Prepares a statement with the store timeout.
      Parameters:
      sql - the SQL
      Returns:
      the statement; the caller closes it
      Throws:
      SQLException - if the driver fails
    • prepare

      public PreparedStatement prepare(String sql, int autoGeneratedKeys) throws SQLException
      Prepares a statement with the store timeout that reports generated keys.
      Parameters:
      sql - the SQL
      autoGeneratedKeys - Statement.RETURN_GENERATED_KEYS or NO_GENERATED_KEYS
      Returns:
      the statement; the caller closes it
      Throws:
      SQLException - if the driver fails
    • transaction

      public <T> T transaction(JdbcSession.SqlWork<T> work) throws SQLException
      Runs work in one READ COMMITTED transaction (06 §2.1), then puts the auto-commit mode and the isolation level of the pooled connection back. Rolls back when work throws.
      Type Parameters:
      T - the result type
      Parameters:
      work - the work
      Returns:
      the result of work
      Throws:
      SQLException - if the work or the driver fails