Syntax 2: For instances of an EJB component
Description
Allows a PowerBuilder client or component to obtain the home
interface of an EJB component in EAServer in order to create an instance
of the component.
Applies to
Connection objects, TransactionServer objects
Syntax
|
1 |
objname.Lookup (objectvariable , componentname {, homeid} ) |
|
Argument |
Description |
|---|---|
|
objname |
The name of the Connection object used to establish the |
|
objectvariable |
A global, instance, or local variable of the type of the |
|
componentname |
A string whose value is the name of the EJB component to |
|
homeid |
A string whose value is the name of the home interface |
Return value
Long.
Returns 0 if it succeeds and a negative number if an error
occurs.
Usage
EJBConnection
You can also use the Lookup method of the EJBConnection
PowerBuilder extension object to create an instance of an EJB
component running on any J2EE compliant application server. For more
information, see Lookup.
The Lookup function creates an instance of the home interface of
an EJB component so that you can use it to create an instance of the
EJB. Use the Connection object’s Lookup function to enable a
PowerBuilder client to access a component running in EAServer. You can
supply a server name or a list of server names in the location property
of the Connection object. Use the TransactionServer object’s Lookup
function to enable a PowerBuilder component running in EAServer to
access an EJB component running on the same server.
The Lookup function uses the standard CORBA naming service to
resolve componentname to a CORBA object that is then narrowed to the
home interface name of the component. If you do not specify the third
argument to the Lookup function, PowerBuilder expects the home interface
name to have the format PackageName/CompNameHome. However, most EJB
components use a standard Java package directory structure and the home
interface name has a format such as
com/domain/project/CompNameHome.
You can ensure that a PowerBuilder client or component can locate
the component’s home interface by supplying the third argument to the
Lookup function to specify the home interface name. A component’s home
interface name is defined in the com.sybase.jaguar.component.home.ids
property in the EAServer repository. The home.ids property has a format
like this:
|
1 |
IDL:com/domain/project/CompNameHome:1.0 |
The third argument should be the value of the component’s home.ids
string without the leading IDL: and trailing :1.0. For example:
|
1 2 |
ts.lookup(MyCartHome, "shopping/cart", & "com/sybase/shopping/CartHome") |
Alternatively, you can use the fully-qualified Java class name of
the home interface specified in dot notation. For example:
|
1 2 |
ts.lookup(MyCartHome, "shopping/cart", & "com.sybase.shopping.CartHome") |
Lookup is case sensitive
Lookup in EAServer is case sensitive. Make sure that the case in
the string you specify in the argument to the lookup function matches
the case in the ejb.home property.
Examples
The following example uses Lookup with the Connection object to
locate the home interface of the Multiply session EJB in the Java
package abc.xyz.math:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
// Instance variable: // Connection myconnect Multiply myMultiply MultiplyHome myMultiplyHome long ll_result, ll_product ll_result = & myconnect.lookup(myMultiplyHome,"Math/Multiply", & "abc.xyz.math.MultiplyHome) IF ll_result <> = 0 THEN MessageBox("Lookup failed", myconnect.errtext) ELSE try myMultiply = myMultiplyHome.create() catch (ctscomponents_createexception ce) MessageBox("Create exception", ce.getmessage()) // handle exception end try ll_product = myMultiply.multiply(1234, 4567) END IF |
Entity beans have a findByPrimaryKey method that you can use to
find an EJB saved in the previous session. This example uses that method
to find a shopping cart saved for Dirk Dent:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
// Instance variable: // Connection myconnect Cart myCart CartHome myCartHome long ll_result ll_result = & myconnect.lookup(myCartHome,"Shopping/Cart", & "com.mybiz.shopping.CartHome") IF ll_result <> = 0 THEN MessageBox("Lookup failed", myconnect.errtext) ELSE TRY myCart = myCartHome.findByPrimaryKey("DirkDent") myCart.addItem(101) CATCH ( ctscomponents_finderexception fe ) MessageBox("Finder exception", & fe.getmessage()) END TRY END IF |
Nonvisual objects deployed from PowerBuilder to EAServer can use
an instance of the TransactionServer context object to locate the home
interface of an EJB component in the same server:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
CalcHome MyCalcHome Calc MyCalc TransactionServer ts ErrorLogging errlog long ll_result this.GetContextService("TransactionServer", ts) this.GetContextService("ErrorLogging", errlog) ll_result = ts.lookup(MyCalcHome, "Utilities/Calc", & "com.biz.access.utilities.CalcHome") IF ll_result <> 0 THEN errlog.log("Lookup failed: " + string(ll_result)) ELSE TRY MyCalc = MyCalcHome.create() MyCalc.square(12) CATCH (ctscomponents_createexception ce) errlog.log("Create exception: " + ce.getmessage()) END TRY END IF |
See also