Invoking component methods – PB Docs 80

Invoking component methods

Once a connection to EAServer has been established and a proxy
object or objects created, the client application can begin using
the server components.

Invoking a component method

To invoke a method on most component types, you need to execute
the PowerScript statements required to perform these operations:

  1. Use the CreateInstance
    method to create an instance of the component.
  2. Invoke the method.

You use a different technique to invoke EJB component methods.
See “Invoking an EJB component
method”
.

Example 1 This script instantiates a component on the server and invokes
a component method. In this example, the CreateInstance method does
not specify a package; therefore, EAServer uses the default package
specified in the Application property of the Connection object:

Example 2 This script instantiates a component on the server and assigns
the object reference to a variable whose data type is an ancestor
of the class for the component. The second argument to the CreateInstance
function specifies the class name for the component as well as the
EAServer package name:

Invoking an EJB component method

To invoke an EJB component method, you need to execute the
PowerScript statements required to perform these operations:

  1. Use the Lookup function
    to access the component’s home interface
  2. Invoke the method on the interface to create or
    find an instance of the component and get a reference to the component’s
    remote interface
  3. Invoke the business methods on the remote interface

Specifying the home interface name

PowerBuilder provides an optional third argument to the Lookup
function to specify the name of the home interface. EJB components
have a property in EAServer called com.sybase.jaguar.component.home.ids.
You do not need to specify the third argument to the Lookup function
if the home.ids property looks like this:

For example:

In most cases, however, the home.ids property uses the java
package naming scheme and you should use the third argument to make
sure that the EJB home interface can be located. The string that
you specify for this argument must match the component’s
com.sybase.jaguar.component.home.ids property without the leading IDL:
and
trailing :1.0
.

For example, suppose the home.ids property is this:

Your Lookup function call should look like this::

Alternatively, you can use the fully-qualified java class
name of the home interface specified in dot notation. For example:

note.gif Lookup is case sensitive Lookup in EAServer is case sensitive. Make sure that the case
in the string you specify for the arguments to the lookup function
matches the case in the home.ids property.

Creating or finding an instance of an EJB

EAServer 3.x supports two types of EJBs–session beans
and entity beans. A session bean is created
in
response to a client request. A client usually has exclusive use
of the session bean for the duration of that client session. An entity
bean represents persistent information stored in a database. A client
uses an entity bean concurrently with other clients. Since an entity
bean persists beyond the lifetime of the client, you must use a
primary key class name to identify or find
this
preexisting component.

The following examples assume that an EJB component that provides
e-commerce shopping cart functionality is running on EAServer. This component
is called Cart and is included in a package called Shopping.

Example 1 This script instantiates the Cart component and invokes several component
methods. In this example, the second argument to the Lookup method
specifies the component name as well as the EAServer package name:

Example 2 If the Cart EJB component is defined as an entity bean, then
the script must use the findByPrimaryKey method to find and reference
a preexisting or persistent component:

Restrictions

PowerBuilder clients to EJB objects act as CORBA clients,
which means that they do not have the full capabilities of Java
clients. Java clients can use methods inherited from the javax.ejb.EJBObject
interface.

For example, a Java client can obtain a handle for a remote
interface instance. The handle is a binary encoding of the session
state between the client and the Bean. The client can obtain a handle,
save it to disk or mail it to another location, then reestablish
the session at a later time. PowerBuilder clients can obtain similar
functionality using the Object_To_String and String_To_Object functions
of the JaguarORB object.

Handling exceptions

The remote interface of an EJB component can indicate errors
or warnings. Standard exceptions thrown by the EJB component are
mapped to CORBA system exceptions. The EJB component can also throw
user exceptions. For information about handling exceptions thrown
by EAServer components, see “Handling errors “.

For information about calling an EJB component from a PowerBuilder component
in EAServer, see “Accessing an EJB component”

Destroying instances

Destroying the proxy object instance

After you have finished using an EAServer component, you can
explicitly destroy the EAServer proxy object by using the DESTROY
statement, or you can let PowerBuilder’s garbage collection
facility clear the object out of memory for you automatically. In
either case, the destruction of the client-side proxy object has
no effect on the lifecycle of the server component. Destruction of
the server component is handled by EAServer.

Deactivating the component instance

If the Automatic Demarcation/Deactivation setting
is disabled for a component, and you close the client application
while the component is still bound to the client (the component
did not call SetComplete or SetAbort), the component is not
deactivated.
To ensure that the component instance is deactivated, you can do
one of the following things:

  • In the Close event
    of the client application, invoke a method of the server component
    that deactivates the component (by calling SetComplete or SetAbort).
  • Set the Timeout property for the component to a
    value other than 0. If the component’s Timeout property
    is set to 0, the component will never time out.

Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x