@@ -203,10 +203,13 @@ static void elogExceptionMessage(JNIEnv* env, jthrowable exh, int logLevel)
203203 ereport (logLevel , (errcode (sqlState ), errmsg ("%s" , buf .data )));
204204}
205205
206- static void printStacktrace (JNIEnv * env , jobject exh )
206+ static void printStacktrace (JNIEnv * env , jobject exh , int elevel )
207207{
208- #ifndef _MSC_VER
209- if (DEBUG1 >= log_min_messages || DEBUG1 >= client_min_messages )
208+ #if 100002 <=PG_VERSION_NUM || \
209+ 90607 <=PG_VERSION_NUM && PG_VERSION_NUM < 100000 || \
210+ 90511 <=PG_VERSION_NUM && PG_VERSION_NUM < 90600 || \
211+ ! defined(_MSC_VER )
212+ if (elevel >= log_min_messages || elevel >= client_min_messages )
210213#else
211214 /* This is gross, but only happens as often as an exception escapes Java
212215 * code to be rethrown. There is some renewed interest on pgsql-hackers to
@@ -217,7 +220,7 @@ static void printStacktrace(JNIEnv* env, jobject exh)
217220 || 0 == strncmp ("debug" , PG_GETCONFIGOPTION ("client_min_messages" ), 5 ) )
218221#endif
219222 {
220- int currLevel = Backend_setJavaLogLevel (DEBUG1 );
223+ int currLevel = Backend_setJavaLogLevel (elevel );
221224 (* env )-> CallVoidMethod (env , exh , Throwable_printStackTrace );
222225 (* env )-> ExceptionOccurred (env ); /* sop for JNI exception-check check */
223226 Backend_setJavaLogLevel (currLevel );
@@ -236,7 +239,7 @@ static void endCall(JNIEnv* env)
236239 jniEnv = env ;
237240 if (exh != 0 )
238241 {
239- printStacktrace (env , exh );
242+ printStacktrace (env , exh , DEBUG1 );
240243 if ((* env )-> IsInstanceOf (env , exh , ServerException_class ))
241244 {
242245 /* Rethrow the server error.
@@ -266,7 +269,7 @@ static void endCallMonitorHeld(JNIEnv* env)
266269 jniEnv = env ;
267270 if (exh != 0 )
268271 {
269- printStacktrace (env , exh );
272+ printStacktrace (env , exh , DEBUG1 );
270273 if ((* env )-> IsInstanceOf (env , exh , ServerException_class ))
271274 {
272275 /* Rethrow the server error.
@@ -329,8 +332,7 @@ bool beginNative(JNIEnv* env)
329332 * backend at this point.
330333 */
331334 env = JNI_setEnv (env );
332- Exception_throw (ERRCODE_INTERNAL_ERROR ,
333- "An attempt was made to call a PostgreSQL backend function after an elog(ERROR) had been issued" );
335+ Exception_throw_unhandled ();
334336 JNI_setEnv (env );
335337 return false;
336338 }
@@ -950,12 +952,20 @@ void JNI_exceptionDescribe(void)
950952 if (exh != 0 )
951953 {
952954 (* env )-> ExceptionClear (env );
953- printStacktrace (env , exh );
955+ printStacktrace (env , exh , DEBUG1 );
954956 elogExceptionMessage (env , exh , WARNING );
955957 }
956958 END_JAVA
957959}
958960
961+ void JNI_exceptionStacktraceAtLevel (jthrowable exh , int elevel )
962+ {
963+ BEGIN_JAVA
964+ elogExceptionMessage (env , exh , elevel );
965+ printStacktrace (env , exh , elevel );
966+ END_JAVA
967+ }
968+
959969jthrowable JNI_exceptionOccurred (void )
960970{
961971 jthrowable result ;
@@ -1612,6 +1622,13 @@ void JNI_setShortArrayRegion(jshortArray array, jsize start, jsize len, jshort*
16121622 END_JAVA
16131623}
16141624
1625+ void JNI_setStaticObjectField (jclass clazz , jfieldID field , jobject value )
1626+ {
1627+ BEGIN_JAVA
1628+ (* env )-> SetStaticObjectField (env , clazz , field , value );
1629+ END_JAVA
1630+ }
1631+
16151632void JNI_setThreadLock (jobject lockObject )
16161633{
16171634 BEGIN_JAVA
0 commit comments