Class SafeStmtPtr


  • public class SafeStmtPtr
    extends java.lang.Object
    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
    • Field Detail

      • db

        private final DB db
      • ptr

        private final long ptr
      • closed

        private volatile boolean closed
      • closedRC

        private int closedRC
      • closeException

        private java.sql.SQLException closeException
    • Constructor Detail

      • SafeStmtPtr

        public SafeStmtPtr​(DB db,
                           long ptr)
        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 deadlocks
        ptr - the raw pointer
    • Method Detail

      • isClosed

        public boolean isClosed()
        Check whether this pointer has been closed
        Returns:
        whether this pointer has been closed
      • close

        public int close()
                  throws java.sql.SQLException
        Close this pointer
        Returns:
        the return code of the close callback function
        Throws:
        java.sql.SQLException - if the close callback throws an SQLException, or the pointer is locked elsewhere
      • internalClose

        private int internalClose()
                           throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • safeRunInt

        public <E extends java.lang.Throwable> int safeRunInt​(SafeStmtPtr.SafePtrIntFunction<E> run)
                                                       throws java.sql.SQLException,
                                                              E extends java.lang.Throwable
        Run a callback with the wrapped pointer safely.
        Parameters:
        run - the function to run
        Returns:
        the return of the passed in function
        Throws:
        java.sql.SQLException - if the pointer is utilized elsewhere
        E extends java.lang.Throwable
      • safeRunLong

        public <E extends java.lang.Throwable> long safeRunLong​(SafeStmtPtr.SafePtrLongFunction<E> run)
                                                         throws java.sql.SQLException,
                                                                E extends java.lang.Throwable
        Run a callback with the wrapped pointer safely.
        Parameters:
        run - the function to run
        Returns:
        the return of the passed in function
        Throws:
        java.sql.SQLException - if the pointer is utilized elsewhere
        E extends java.lang.Throwable
      • safeRunDouble

        public <E extends java.lang.Throwable> double safeRunDouble​(SafeStmtPtr.SafePtrDoubleFunction<E> run)
                                                             throws java.sql.SQLException,
                                                                    E extends java.lang.Throwable
        Run a callback with the wrapped pointer safely.
        Parameters:
        run - the function to run
        Returns:
        the return of the passed in function
        Throws:
        java.sql.SQLException - if the pointer is utilized elsewhere
        E extends java.lang.Throwable
      • safeRun

        public <T,​E extends java.lang.Throwable> T safeRun​(SafeStmtPtr.SafePtrFunction<T,​E> run)
                                                          throws java.sql.SQLException,
                                                                 E extends java.lang.Throwable
        Run a callback with the wrapped pointer safely.
        Parameters:
        run - the function to run
        Returns:
        the return code of the function
        Throws:
        java.sql.SQLException - if the pointer is utilized elsewhere
        E extends java.lang.Throwable
      • safeRunConsume

        public <E extends java.lang.Throwable> void safeRunConsume​(SafeStmtPtr.SafePtrConsumer<E> run)
                                                            throws java.sql.SQLException,
                                                                   E extends java.lang.Throwable
        Run a callback with the wrapped pointer safely.
        Parameters:
        run - the function to run
        Throws:
        java.sql.SQLException - if the pointer is utilized elsewhere
        E extends java.lang.Throwable
      • ensureOpen

        private void ensureOpen()
                         throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object