Package org.jooq

Interface ResourceManagingScope

  • All Superinterfaces:
    Scope
    All Known Subinterfaces:
    BindingSetSQLOutputContext<U>, BindingSetStatementContext<U>

    public interface ResourceManagingScope
    extends Scope
    A scope that can manage resources.

    This is a type of Scope that can manage resources on behalf of the call site, and free / close those resources once the scope ends.

    For example, Binding implementations may wish to create Clob or InputStream or other kinds of resources in order to bind them to JDBC. Instead of remembering to close them manually through some delicate logic involving e.g. clever usage of ThreadLocal, implementations can register their resources with the methods exposed here, and jOOQ will take care of freeing / closing them at the right moment.

    Example:

     class StreamingLobBinding implements Binding<String, File> {
         ...
         public void set(BindingSetStatementContext<File> ctx) {
             ctx.statement()
                .setBinaryStream(ctx.index(), ctx.closeAfterExecution(new FileInputStream(ctx.value())));
         }
     }
     
    Author:
    Lukas Eder
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      <R extends java.io.Closeable>
      R
      autoClose​(R closeable)
      Register a Closeable for auto closing after this scope ends.
      java.sql.Array autoFree​(java.sql.Array array)
      Register a Array for auto freeing after this scope ends.
      java.sql.Blob autoFree​(java.sql.Blob blob)
      Register a Blob for auto freeing after this scope ends.
      java.sql.Clob autoFree​(java.sql.Clob clob)
      Register a Clob for auto freeing after this scope ends.
      java.sql.SQLXML autoFree​(java.sql.SQLXML xml)
      Register a SQLXML for auto freeing after this scope ends.
    • Method Detail

      • autoFree

        java.sql.Array autoFree​(java.sql.Array array)
        Register a Array for auto freeing after this scope ends.
        Returns:
        The argument array, for convenience.
      • autoFree

        java.sql.Blob autoFree​(java.sql.Blob blob)
        Register a Blob for auto freeing after this scope ends.
        Returns:
        The argument blob, for convenience.
      • autoFree

        java.sql.Clob autoFree​(java.sql.Clob clob)
        Register a Clob for auto freeing after this scope ends.
        Returns:
        The argument clob, for convenience.
      • autoFree

        java.sql.SQLXML autoFree​(java.sql.SQLXML xml)
        Register a SQLXML for auto freeing after this scope ends.
        Returns:
        The argument xml, for convenience.
      • autoClose

        <R extends java.io.Closeable> R autoClose​(R closeable)
        Register a Closeable for auto closing after this scope ends.
        Returns:
        The argument closeable, for convenience.
      • autoClose

        <R extends java.lang.AutoCloseable> R autoClose​(R closeable)
        Register an AutoCloseable for auto closing after this scope ends.
        Returns:
        The argument closeable, for convenience.