Package org.sqlite.core
Class SafeStmtPtr
java.lang.Object
org.sqlite.core.SafeStmtPtr
A class for safely wrapping calls to a native pointer to a statement, ensuring no other thread
has access to the pointer while it is run
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceSafeStmtPtr.SafePtrConsumer<E extends Throwable>static interfaceSafeStmtPtr.SafePtrDoubleFunction<E extends Throwable>static interfaceSafeStmtPtr.SafePtrFunction<T,E extends Throwable> static interfaceSafeStmtPtr.SafePtrIntFunction<E extends Throwable>static interfaceSafeStmtPtr.SafePtrLongFunction<E extends Throwable> -
Constructor Summary
ConstructorsConstructorDescriptionSafeStmtPtr(DB db, long ptr) Construct a new Safe Pointer Wrapper to ensure a pointer is properly handled -
Method Summary
Modifier and TypeMethodDescriptionintclose()Close this pointerbooleaninthashCode()booleanisClosed()Check whether this pointer has been closed<T,E extends Throwable>
TsafeRun(SafeStmtPtr.SafePtrFunction<T, E> run) Run a callback with the wrapped pointer safely.<E extends Throwable>
voidRun a callback with the wrapped pointer safely.<E extends Throwable>
doubleRun a callback with the wrapped pointer safely.<E extends Throwable>
intRun a callback with the wrapped pointer safely.<E extends Throwable>
longRun a callback with the wrapped pointer safely.
-
Constructor Details
-
SafeStmtPtr
Construct a new Safe Pointer Wrapper to ensure a pointer is properly handled- Parameters:
db- the database that made this pointer. Always locked before any safe run function is executed to avoid deadlocksptr- the raw pointer
-
-
Method Details
-
isClosed
public boolean isClosed()Check whether this pointer has been closed- Returns:
- whether this pointer has been closed
-
close
Close this pointer- Returns:
- the return code of the close callback function
- Throws:
SQLException- if the close callback throws an SQLException, or the pointer is locked elsewhere
-
safeRunInt
public <E extends Throwable> int safeRunInt(SafeStmtPtr.SafePtrIntFunction<E> run) throws SQLException, E Run a callback with the wrapped pointer safely.- Parameters:
run- the function to run- Returns:
- the return of the passed in function
- Throws:
SQLException- if the pointer is utilized elsewhereE extends Throwable
-
safeRunLong
public <E extends Throwable> long safeRunLong(SafeStmtPtr.SafePtrLongFunction<E> run) throws SQLException, E Run a callback with the wrapped pointer safely.- Parameters:
run- the function to run- Returns:
- the return of the passed in function
- Throws:
SQLException- if the pointer is utilized elsewhereE extends Throwable
-
safeRunDouble
public <E extends Throwable> double safeRunDouble(SafeStmtPtr.SafePtrDoubleFunction<E> run) throws SQLException, E Run a callback with the wrapped pointer safely.- Parameters:
run- the function to run- Returns:
- the return of the passed in function
- Throws:
SQLException- if the pointer is utilized elsewhereE extends Throwable
-
safeRun
public <T,E extends Throwable> T safeRun(SafeStmtPtr.SafePtrFunction<T, E> run) throws SQLException, ERun a callback with the wrapped pointer safely.- Parameters:
run- the function to run- Returns:
- the return code of the function
- Throws:
SQLException- if the pointer is utilized elsewhereE extends Throwable
-
safeRunConsume
public <E extends Throwable> void safeRunConsume(SafeStmtPtr.SafePtrConsumer<E> run) throws SQLException, E Run a callback with the wrapped pointer safely.- Parameters:
run- the function to run- Throws:
SQLException- if the pointer is utilized elsewhereE extends Throwable
-
equals
-
hashCode
public int hashCode()
-