JavaClearParameterList Function

Action

When calling a Java method that takes parameters, the parameters are added one by one to a parameter list. There is a parameter list for each Java object, and a list for all static method or constructor calls. Parameter lists are automatically cleared when a method or constructor is invoked.

In some cases, for example when an event handler is used, the actual transaction may be over before the method or constructor is invoked, so the parameter list is not cleared. In such cases, the parameter list must be cleared by hand before new parameters are set for the next method or constructor call.

Include file

JavaBase.bdh

Syntax

JavaClearParameterList( in hObject: number ): boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
hObject Valid handle to a Java object or JAVA_STATIC_METHOD.

Example

dcluser
  user
    JavaUser
  transactions
    TInit               : begin;      
    TMyJavaTransBad     : 1;
    TMyJavaTransGood    : 1;
    TEnd                : end;
     

dclevent
  handler Handler1 <EVENT_RAISE_ERROR>
  var
    hStrGood, hStrBad :number;
    buffer            :string;
  begin
    if GetErrorCode(GetLastError()) = 9999 then
      Print("Here we are");
      // first the bad example
      hStrGood := JavaLoadObject("java/lang/String");
      Print("something messed us up here; we wanted to create an empty String, but will get something unexpected:");
      JavaCallMethod(hStrGood, "toString");
      JavaGetString(hStrGood, buffer);
      Print("buffer = '"+buffer+"'");
    else
    if GetErrorCode(GetLastError()) = 9998 then
      // then the good example
      JavaClearParameterList(JAVA_STATIC_METHOD);
      hStrGood := JavaLoadObject("java/lang/String");
      Print("there should be an empty String if JavaClearParameterList() worked");      JavaCallMethod(hStrGood, "toString");
      JavaGetString(hStrGood, buffer);
      Print("buffer = '"+buffer+"'");
    else
      throw;
    end;
  end;
  end Handler1;


// Java Framework Transactions Section
dcltrans
  transaction TInit
  var
    hPerf : number;
  begin    
    JavaCreateJavaVM();
  end TInit;


  transaction TMyJavaTransBad
  var
    hSomeJavaObject : number;
  begin
    JavaSetString(JAVA_STATIC_METHOD, "some text");
    // let’s assume, code execution jumps to event handler from here
    RaiseError(9999, "just wanted to show event handler sample");
    // if no event is raised, execution continues here
    hSomeJavaObject := JavaLoadObject("java/lang/String");
    JavaFreeObject(hSomeJavaObject);
  end TMyJavaTransBad;  

  transaction TMyJavaTransGood
  var
    hSomeJavaObject : number;
  begin
    JavaSetString(JAVA_STATIC_METHOD, "some text");
    // let’s assume, code execution jumps to event handler from here
    RaiseError(9998, "just wanted to show event handler sample");
    // if no event is raised, execution continues here
    hSomeJavaObject := JavaLoadObject("java/lang/String");
    JavaFreeObject(hSomeJavaObject);
  end TMyJavaTransGood;
 

  transaction TEnd
  begin
  end TEnd;