Class JdbcConnection

java.lang.Object
scriptella.spi.AbstractConnection
scriptella.jdbc.JdbcConnection
All Implemented Interfaces:
Connection, NativeConnectionProvider
Direct Known Subclasses:
OracleConnection

public class JdbcConnection extends AbstractConnection implements NativeConnectionProvider
Represents a JDBC connection. TODO Extract JDBCConnectionParameters class and JDBCStatementFactory as described in statement cache
Version:
1.0
Author:
Fyodor Kupolov
  • Field Details

    • STATEMENT_CACHE_KEY

      public static final String STATEMENT_CACHE_KEY
      See Also:
    • STATEMENT_SEPARATOR_KEY

      public static final String STATEMENT_SEPARATOR_KEY
      See Also:
    • STATEMENT_SEPARATOR_SINGLELINE_KEY

      public static final String STATEMENT_SEPARATOR_SINGLELINE_KEY
      See Also:
    • STATEMENT_BATCH_SIZE

      public static final String STATEMENT_BATCH_SIZE
      See Also:
    • STATEMENT_FETCH_SIZE

      public static final String STATEMENT_FETCH_SIZE
      See Also:
    • KEEPFORMAT_KEY

      public static final String KEEPFORMAT_KEY
      See Also:
    • AUTOCOMMIT_KEY

      public static final String AUTOCOMMIT_KEY
      See Also:
    • AUTOCOMMIT_SIZE_KEY

      public static final String AUTOCOMMIT_SIZE_KEY
      See Also:
    • FLUSH_BEFORE_QUERY

      public static final String FLUSH_BEFORE_QUERY
      See Also:
    • TRANSACTION_ISOLATION_KEY

      public static final String TRANSACTION_ISOLATION_KEY
      See Also:
    • TRANSACTION_ISOLATION_READ_UNCOMMITTED

      public static final String TRANSACTION_ISOLATION_READ_UNCOMMITTED
      See Also:
    • TRANSACTION_ISOLATION_READ_COMMITTED

      public static final String TRANSACTION_ISOLATION_READ_COMMITTED
      See Also:
    • TRANSACTION_ISOLATION_REPEATABLE_READ

      public static final String TRANSACTION_ISOLATION_REPEATABLE_READ
      See Also:
    • TRANSACTION_ISOLATION_SERIALIZABLE

      public static final String TRANSACTION_ISOLATION_SERIALIZABLE
      See Also:
    • statementCacheSize

      protected int statementCacheSize
    • statementBatchSize

      protected int statementBatchSize
    • statementFetchSize

      protected int statementFetchSize
    • flushBeforeQuery

      protected boolean flushBeforeQuery
    • separator

      protected String separator
    • separatorSingleLine

      protected boolean separatorSingleLine
    • keepformat

      protected boolean keepformat
    • autocommitSize

      protected int autocommitSize
  • Constructor Details

  • Method Details

    • init

      protected void init(ConnectionParameters parameters)
      Called in constructor
      Parameters:
      parameters - connection parameters.
    • initDialectIdentifier

      protected void initDialectIdentifier()
      Initializes dialect identifier for connection. If driver doesn't support DatabaseMetaData or other problem occurs, DialectIdentifier.NULL_DIALECT is used.

      May be overriden by subclasses.

    • executeScript

      public void executeScript(Resource scriptContent, ParametersCallback parametersCallback)
      Description copied from interface: Connection
      Executes a script specified by its content.

      scriptContent may be used as a key for caching purposes, i.e. provider may precompile scripts and use compiled versions for subsequent executions. Please note that only inline text resources can be safely cached.

      Specified by:
      executeScript in interface Connection
      Parameters:
      scriptContent - script content. Cannot be null.
      parametersCallback - callback to get parameter values. Cannot be null.
    • executeQuery

      public void executeQuery(Resource queryContent, ParametersCallback parametersCallback, QueryCallback queryCallback)
      Description copied from interface: Connection
      Executes a query specified by its content.

      Specified by:
      executeQuery in interface Connection
      Parameters:
      queryContent - query content. Cannot be null.
      parametersCallback - callback to get parameter values. Cannot be null.
      queryCallback - callback to call for each result set element produced by this query. Cannot be null.
      See Also:
    • newStatementCache

      protected scriptella.jdbc.StatementCache newStatementCache()
      Creates an instance of statement cache.
      Returns:
      new instance of statement cache.
    • commit

      public void commit()
      Description copied from interface: Connection
      Commits a current transaction (if any).

      Throwing an error during commit phase cause rollback.

      Specified by:
      commit in interface Connection
      Overrides:
      commit in class AbstractConnection
    • rollback

      public void rollback()
      Description copied from interface: Connection
      Rolls back a current transaction (if any).
      Specified by:
      rollback in interface Connection
      Overrides:
      rollback in class AbstractConnection
    • flush

      public void flush() throws ProviderException
      Throws:
      ProviderException
    • close

      public void close()
      Description copied from interface: Connection
      Closes the connection and releases all related resources.
      Specified by:
      close in interface Connection
    • getNativeConnection

      public Connection getNativeConnection()
      Description copied from interface: NativeConnectionProvider
      Returns the native connection which is wrapped by this object or null if this information is not available.
      Specified by:
      getNativeConnection in interface NativeConnectionProvider
      Returns:
      native connection which is wrapped by this object.
    • toString

      public String toString()
      Specified by:
      toString in interface Connection
      Overrides:
      toString in class AbstractConnection
      Returns:
      meaningful label for connection