Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to pass PB arrays AS REFERENCE to Java using EJB client?

44 views
Skip to first unread message

Samanta

unread,
Feb 2, 2004, 6:34:19 AM2/2/04
to
Hi,

I´m trying to pass a PB array (e.g. long) to a Java method
using EJB client. This method call is executed as call by
value instead of call by reference (that I supposed because
Java does it in that way). Can anybody tell me, how to pass
the PB array as reference? I did not found an answer in the
manuals or in the internet.
I´m using the data type mapping as described in
Application Techniques manual with PB 9.0.1 6533 and JDK
1.4.

Bye. Samanta

*** PB code

long ll_value[1]
ll_value[1] = 3 //set value to 3
iejb_dtm.pblongarray(ll_value) //EJB client method call
st_3.text = string(ll_value[1]) //value is still 3

*** Java code

public void PBLongArray(int[] JavaInt)
{
JavaInt[0] += 1; //increment value by 1
}

Jim O'Neil [Sybase]

unread,
Feb 2, 2004, 9:04:50 AM2/2/04
to
In general, if you want to pass something by reference in Java, you
need to provide a holder class (also referred to as a boxed value)-
essentially a class that has a field (or fields) containing the values
you want passed by reference. Use that class as the argument to your
method versus the array itself. Once you do this in the Java
signature, the PowerBuilder side will take care of itself. In this
particular situation though, it would just be easier to return the
array from the method, wouldn't it?

On 2 Feb 2004 03:34:19 -0800, Samanta wrote:

>Hi,
>
>I=b4m trying to pass a PB array (e.g. long) to a Java method


>using EJB client. This method call is executed as call by
>value instead of call by reference (that I supposed because
>Java does it in that way). Can anybody tell me, how to pass
>the PB array as reference? I did not found an answer in the
>manuals or in the internet.

>I=b4m using the data type mapping as described in


>Application Techniques manual with PB 9.0.1 6533 and JDK
>1.4.
>
>Bye. Samanta
>
>*** PB code
>
>long ll_value[1]

>ll_value[1] =3d 3 //set value to 3


>iejb_dtm.pblongarray(ll_value) //EJB client method call

>st_3.text =3d string(ll_value[1]) //value is still 3


>
>*** Java code
>
>public void PBLongArray(int[] JavaInt)
>{

> JavaInt[0] +=3d 1; //increment value by 1
>}

Jim O'Neil
Principal Technical Support Engineer
Sybase, Inc.
Concord, MA

Samanta

unread,
Feb 2, 2004, 12:34:55 PM2/2/04
to
Hi Jim,

thank you for your answer. Of course, it would be esier to
use a single array as return value. But I need a separte
return value as status message.
Have you a source code example for me please? I understand
your description. But how can I write a Java class, which
member variables are known in PB? Or vice versa. Is this
fact described anywhere in the manuals?

Bye. Samanta.

Jim O'Neil [Sybase]

unread,
Feb 2, 2004, 3:11:44 PM2/2/04
to
Well, it's not addressed in the manuals, because it's more of a design
pattern for Java than it relates to PowerBuilder. Something like this
is all you need (my syntax will likely NOT compile here <g>)

public final class myArray {

int[] val;
}

public void PBLongArray(myArray JavaInt)
{
JavaInt.val[0] += 1; //increment value by 1
}

when PowerBuilder generates the proxies for PBLongArray method, it
will see another Java class reference (myArray) and create proxies for
that as well. Your PB code will look something like:

long ll_value[1]
myArray l_javaArray;

ejbConn.CreateJavaInstance(l_javaArray, "myArray")
l_javaArray.val[1] = 3
iejb_dtm.pblongarray(l_javaArray) //EJB client method call
st_3.text = string(l_javaArray[1]) //value is still 3


This should get you pretty close, but I didn't code this out so again
there may be some slight syntax issues here.

Samanta

unread,
Feb 3, 2004, 7:57:58 AM2/3/04
to
Hi Jim,

I´m back again. I realized it via holder class/boxed value
with separate get/set functions. That´s why, if I use a
direct write access like "l_javaArray.val = ll_value", PB
often crashes. If I use the get/set functions it works very
well. Also a mix of a set function (to ensure that the java
member variable of first index exists) and direct write
access (with PB long array or any array) results in a crach
of PB (in most cases). But a mix of set function and direct
read access works. ???
I think, this is a very important fact for the manuals,
because Java uses call by reference for arrays (also for
primitive types). PB does not.

Bye. Thanks for all.

0 new messages