java.lang.Object
org.postgresql.pljava.internal.Backend

public class Backend extends Object
Provides access to some useful routines in the PostgreSQL server.
Author:
Thomas Hallgren
  • Field Details

    • THREADLOCK

      public static final Object THREADLOCK
      All native calls synchronize on this object.
    • IAMPGTHREAD

      public static final ThreadLocal<Boolean> IAMPGTHREAD
      Will be Boolean.TRUE on the one primordial thread first entered from PG, and null on any other thread.
    • validateBodies

      public static final BooleanSupplier validateBodies
  • Constructor Details

    • Backend

      public Backend()
  • Method Details

    • doInPG

      public static <T, E extends Throwable> T doInPG(Checked.Supplier<T,E> op) throws E
      Do an operation on a thread with serialized access to call into PostgreSQL, returning a result.
      Throws:
      E
    • doInPG

      public static <E extends Throwable> void doInPG(Checked.Runnable<E> op) throws E
      Specialization of doInPG for operations that return no result. This version must be present, as the Java compiler will not automagically match a void lambda or method reference to Supplier<Void>.
      Throws:
      E
    • doInPG

      public static <E extends Throwable> boolean doInPG(Checked.BooleanSupplier<E> op) throws E
      Specialization of doInPG for operations that return a boolean result. This method need not be present: without it, the Java compiler will happily match boolean lambdas or method references to the generic method, at the small cost of some boxing/unboxing; providing this method simply allows that to be avoided.
      Throws:
      E
    • doInPG

      public static <E extends Throwable> double doInPG(Checked.DoubleSupplier<E> op) throws E
      Specialization of doInPG for operations that return a double result. This method need not be present: without it, the Java compiler will happily match double lambdas or method references to the generic method, at the small cost of some boxing/unboxing; providing this method simply allows that to be avoided.
      Throws:
      E
    • doInPG

      public static <E extends Throwable> int doInPG(Checked.IntSupplier<E> op) throws E
      Specialization of doInPG for operations that return an int result. This method need not be present: without it, the Java compiler will happily match int lambdas or method references to the generic method, at the small cost of some boxing/unboxing; providing this method simply allows that to be avoided.
      Throws:
      E
    • doInPG

      public static <E extends Throwable> long doInPG(Checked.LongSupplier<E> op) throws E
      Specialization of doInPG for operations that return a long result. This method need not be present: without it, the Java compiler will happily match long lambdas or method references to the generic method, at the small cost of some boxing/unboxing; providing this method simply allows that to be avoided.
      Throws:
      E
    • doInPG

      public static <E extends Throwable> float doInPG(Checked.FloatSupplier<E> op) throws E
      Specialization of doInPG for operations that return a float result. This method need not be present: without it, the Java compiler will happily match float lambdas or method references to the generic method, at the small cost of some boxing/unboxing; providing this method simply allows that to be avoided.
      Throws:
      E
    • doInPG

      public static <E extends Throwable> short doInPG(Checked.ShortSupplier<E> op) throws E
      Specialization of doInPG for operations that return a short result. This method need not be present: without it, the Java compiler will happily match short lambdas or method references to the generic method, at the small cost of some boxing/unboxing; providing this method simply allows that to be avoided.
      Throws:
      E
    • doInPG

      public static <E extends Throwable> char doInPG(Checked.CharSupplier<E> op) throws E
      Specialization of doInPG for operations that return a char result. This method need not be present: without it, the Java compiler will happily match char lambdas or method references to the generic method, at the small cost of some boxing/unboxing; providing this method simply allows that to be avoided.
      Throws:
      E
    • doInPG

      public static <E extends Throwable> byte doInPG(Checked.ByteSupplier<E> op) throws E
      Specialization of doInPG for operations that return a byte result. This method need not be present: without it, the Java compiler will happily match int lambdas or method references to the generic method, at the small cost of some boxing/unboxing; providing this method simply allows that to be avoided.
      Throws:
      E
    • threadMayEnterPG

      public static boolean threadMayEnterPG()
      Return true if the current thread may JNI-call into Postgres.

      In PL/Java's threading model, only one thread (or only one thread at a time, depending on the setting of pljava.java_thread_pg_entry) may make calls into the native PostgreSQL code.

      Note: The setting pljava.java_thread_pg_entry=error is an exception; under that setting this method will return true for any thread that acquires the THREADLOCK monitor, but any such thread that isn't the actual original PG thread will have an exception thrown if it calls into PG.

      Under the setting pljava.java_thread_pg_entry=throw, this method will only return true for the one primordial PG thread (and there is no THREADLOCK object to do any monitor operations on).

      Returns:
      true if the current thread is the one prepared to enter PG.
    • getConfigOption

      public static String getConfigOption(String key)
      Returns the configuration option as read from the Global Unified Config package (GUC).
      Parameters:
      key - The name of the option.
      Returns:
      The value of the option.
    • getListConfigOption

      public static List<Lexicals.Identifier.Simple> getListConfigOption(String key) throws SQLException
      Throws:
      SQLException
    • getStatementCacheSize

      public static int getStatementCacheSize()
      Returns the size of the statement cache.
      Returns:
      the size of the statement cache.
    • log

      public static void log(int logLevel, String str)
      Log a message using the internal elog command.
      Parameters:
      logLevel - The log level as defined in ELogHandler.
      str - The message
    • clearFunctionCache

      public static void clearFunctionCache()
    • isCreatingExtension

      public static boolean isCreatingExtension()
    • myLibraryPath

      public static String myLibraryPath() throws SQLException
      Returns the path of PL/Java's shared library.
      Throws:
      SQLException - if for some reason it can't be determined.
    • isCallingJava

      public static boolean isCallingJava()
      Returns true if the backend is awaiting a return from a call into the JVM. This method will only return false when called from a thread other then the main thread and the main thread has returned from the call into the JVM.
    • isReleaseLingeringSavepoints

      public static boolean isReleaseLingeringSavepoints()
      Returns the value of the GUC custom variable pljava.release_lingering_savepoints.