- 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 Summary
Fields Modifier and Type Field Description static ThreadLocal<Boolean>
IAMPGTHREAD
Will beBoolean.TRUE
on the one primordial thread first entered from PG, and null on any other thread.static Object
THREADLOCK
All native calls synchronize on this object.
-
Constructor Summary
Constructors Constructor Description Backend()
-
Method Summary
Modifier and Type Method Description static void
clearFunctionCache()
static <E extends Throwable>
booleandoInPG(Checked.BooleanSupplier<E> op)
Specialization ofdoInPG
for operations that return a boolean result.static <E extends Throwable>
doubledoInPG(Checked.DoubleSupplier<E> op)
Specialization ofdoInPG
for operations that return a double result.static <E extends Throwable>
intdoInPG(Checked.IntSupplier<E> op)
Specialization ofdoInPG
for operations that return an int result.static <E extends Throwable>
longdoInPG(Checked.LongSupplier<E> op)
Specialization ofdoInPG
for operations that return a long result.static <E extends Throwable>
voiddoInPG(Checked.Runnable<E> op)
Specialization ofdoInPG
for operations that return no result.static <T,E extends Throwable>
TdoInPG(Checked.Supplier<T,E> op)
Do an operation on a thread with serialized access to call into PostgreSQL, returning a result.static String
getConfigOption(String key)
Returns the configuration option as read from the Global Unified Config package (GUC).static List<Lexicals.Identifier.Simple>
getListConfigOption(String key)
static int
getStatementCacheSize()
Returns the size of the statement cache.static boolean
isCallingJava()
Returnstrue
if the backend is awaiting a return from a call into the JVM.static boolean
isCreatingExtension()
static boolean
isReleaseLingeringSavepoints()
Returns the value of the GUC custom variablepljava.release_lingering_savepoints
.static void
log(int logLevel, String str)
Log a message using the internal elog command.static String
myLibraryPath()
Returns the path of PL/Java's shared library.static boolean
threadMayEnterPG()
Return true if the current thread may JNI-call into Postgres.
-
-
-
Field Detail
-
THREADLOCK
public static final Object THREADLOCK
All native calls synchronize on this object.
-
IAMPGTHREAD
public static final ThreadLocal<Boolean> IAMPGTHREAD
Will beBoolean.TRUE
on the one primordial thread first entered from PG, and null on any other thread.
-
-
Method Detail
-
doInPG
public static <T,E extends Throwable> T doInPG(Checked.Supplier<T,E> op) throws E extends Throwable
Do an operation on a thread with serialized access to call into PostgreSQL, returning a result.- Throws:
E extends Throwable
-
doInPG
public static <E extends Throwable> void doInPG(Checked.Runnable<E> op) throws E extends Throwable
Specialization ofdoInPG
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 toSupplier<Void>
.- Throws:
E extends Throwable
-
doInPG
public static <E extends Throwable> boolean doInPG(Checked.BooleanSupplier<E> op) throws E extends Throwable
Specialization ofdoInPG
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 extends Throwable
-
doInPG
public static <E extends Throwable> double doInPG(Checked.DoubleSupplier<E> op) throws E extends Throwable
Specialization ofdoInPG
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 extends Throwable
-
doInPG
public static <E extends Throwable> int doInPG(Checked.IntSupplier<E> op) throws E extends Throwable
Specialization ofdoInPG
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 extends Throwable
-
doInPG
public static <E extends Throwable> long doInPG(Checked.LongSupplier<E> op) throws E extends Throwable
Specialization ofdoInPG
for operations that return a long 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 extends Throwable
-
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 theTHREADLOCK
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 noTHREADLOCK
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 inELogHandler
.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()
Returnstrue
if the backend is awaiting a return from a call into the JVM. This method will only returnfalse
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 variablepljava.release_lingering_savepoints
.
-
-