Class CachedStatement<S extends Statement>

java.lang.Object
ghidra.features.bsim.query.client.tables.CachedStatement<S>
Type Parameters:
S - Statement implementation class

public class CachedStatement<S extends Statement> extends Object
CachedStatement provides a cached Statement container which is intended to supply a reusable instance for use within a single thread. Attempts to use the statement in multiple threads is considered unsafe.
  • Constructor Details

    • CachedStatement

      public CachedStatement()
  • Method Details

    • prepareIfNeeded

      public S prepareIfNeeded(StatementSupplier<S> statementSupplier) throws SQLException
      Get the associated cached Statement or prepare one via the specified statementSupplier if not yet established. Tf the supplier is used the owner thread for the statement will be established based on the Thread.currentThread().
      Parameters:
      statementSupplier - statement supplier function which must return a valid instance or throw an exception.
      Returns:
      statement
      Throws:
      SQLException - if supplier fails to produce a statement
      RuntimeException - if the current thread does not correspond to the owner thread of a previously established statement. This is considered a programming error if this occurs.
    • setStatement

      public void setStatement(S s)
      Set the associated Statement instance. This method may be used in place of prepareIfNeeded(StatementSupplier) although it is not preferred since it can result in replacement of one previously established. The getStatement() should be used first to ensure one was not previously set. An error will be logged if the invocation replaces an existing statement which will be forced closed.

      The owner thread for the statement will be established based on the Thread.currentThread().

      Parameters:
      s - statement to be cached
    • getStatement

      public S getStatement()
      Get the current cached Statement.
      Returns:
      the current cached Statement or null if not yet established.
      Throws:
      RuntimeException - if the current thread does not correspond to the owner thread of a previously established statement. This is considered a programming error if this occurs.
    • close

      public void close()
      Close the currently cached Statement. This method may be invoked from any thread but should be properly coordinated with its use in the statement owner thread.