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.
Controls
Connection objects, TransactionServer objects
Syntax
|
1 |
<span>objname</span>.<span>Lookup</span> (<span>objectvariable , componentname {, homeid}</span> ) |
|
Argument |
Description |
|---|---|
|
objname |
The name of the Connection object used |
|
objectvariable |
A global, instance, or local variable |
|
componentname |
A string whose value is the name of the |
|
homeid |
A string whose value is the name of the |
Return Values
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 in the PowerBuilder
Extension Reference.
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/<span>domain</span>/<span>project</span>/<span>CompName</span>Home: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 |
ts.lookup(MyCartHome, "shopping/cart", &<br>   "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 |
ts.lookup(MyCartHome, "shopping/cart", &<br>   "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 |
// Instance variable: |
|
1 |
// Connection myconnect |
|
1 |
Multiply myMultiply |
|
1 |
MultiplyHome myMultiplyHome |
|
1 |
long ll_result, ll_product |
|
1 |
|
1 |
ll_result = & |
|
1 |
   myconnect.<span>lookup</span>(myMultiplyHome,"Math/Multiply", &<br>     "abc.xyz.math.MultiplyHome) |
|
1 |
IF ll_result <> = 0 THEN |
|
1 |
   MessageBox("Lookup failed", myconnect.errtext) |
|
1 |
ELSE |
|
1 |
try |
|
1 |
myMultiply = myMultiplyHome.create() |
|
1 |
catch (ctscomponents_createexception ce) |
|
1 |
MessageBox("Create exception", ce.getmessage()) |
|
1 |
// handle exception |
|
1 |
end try |
|
1 |
ll_product = myMultiply.multiply(1234, 4567) |
|
1 |
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 |
// Instance variable: |
|
1 |
// Connection myconnect |
|
1 |
Cart myCart |
|
1 |
CartHome myCartHome |
|
1 |
long ll_result |
|
1 |
|
1 |
ll_result = & |
|
1 |
myconnect.<span>lookup</span>(myCartHome,"Shopping/Cart", &<br>     "com.mybiz.shopping.CartHome") |
|
1 |
IF ll_result <> = 0 THEN |
|
1 |
MessageBox("Lookup failed", myconnect.errtext) |
|
1 |
ELSE |
|
1 |
TRY |
|
1 |
     myCart = myCartHome.findByPrimaryKey("DirkDent") |
|
1 |
     myCart.addItem(101)<br>  CATCH ( ctscomponents_finderexception fe )     MessageBox("Finder exception", &<br>         fe.getmessage())   END TRY |
|
1 |
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 |
CalcHome MyCalcHome |
|
1 |
Calc MyCalc |
|
1 |
TransactionServer ts |
|
1 |
ErrorLogging errlog |
|
1 |
long ll_result |
|
1 |
|
1 |
this.GetContextService("TransactionServer", ts) |
|
1 |
this.GetContextService("ErrorLogging", errlog) |
|
1 |
ll_result = ts.lookup(MyCalcHome, "Utilities/Calc", &<br>   "com.biz.access.utilities.CalcHome") |
|
1 |
IF ll_result <> 0 THEN |
|
1 |
errlog.log("Lookup failed: " + string(ll_result)) |
|
1 |
ELSE |
|
1 |
  TRY<br>     MyCalc = MyCalcHome.create() |
|
1 |
     MyCalc.square(12)<br>  CATCH (ctscomponents_createexception ce)<br>     errlog.log("Create exception: " + ce.getmessage()) |
|
1 |
  END TRY |
|
1 |
END IF |