Class CachedStatement<S extends Statement>
java.lang.Object
ghidra.features.bsim.query.client.tables.CachedStatement<S>
- Type Parameters:
S-Statementimplementation class
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the currently cachedStatement.Get the current cachedStatement.prepareIfNeeded(StatementSupplier<S> statementSupplier) Get the associated cachedStatementor prepare one via the specifiedstatementSupplierif not yet established.voidsetStatement(S s) Set the associatedStatementinstance.
-
Constructor Details
-
CachedStatement
public CachedStatement()
-
-
Method Details
-
prepareIfNeeded
Get the associated cachedStatementor prepare one via the specifiedstatementSupplierif not yet established. Tf the supplier is used the owner thread for the statement will be established based on theThread.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 statementRuntimeException- 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
Set the associatedStatementinstance. This method may be used in place ofprepareIfNeeded(StatementSupplier)although it is not preferred since it can result in replacement of one previously established. ThegetStatement()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
Get the current cachedStatement.- Returns:
- the current cached
Statementor 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 cachedStatement. This method may be invoked from any thread but should be properly coordinated with its use in the statement owner thread.
-