EJBConnection

Description

The EJBConnection class connects to an EJB server and locates an EJB.

Methods

EJBConnection has five member functions:

ConnectToServer

CreateJavaInstance

DisconnectServer

GetEJBTransaction

Lookup

ConnectToServer

Description

Connects a client application to an EJB server. The client application must call ConnectToServer before it can use a remote object on the server.

Syntax

connection.ConnectToServer ( string properties[ ] ) 

Argument

Description

connection

The name of the EJBConnection object you want to use to establish the connection

properties[ ]

A string array used to pass name/value pairs that specify how the connection will be established


Return value

None

Throws

NamingException

Examples

In this example, the client application connects to a WebLogic server application using the Connection object called conn:

ejbconnection conn
helloejbhome hellohome
helloejb hello
string properties[ ]
string msg

// Type each of the following statements on one line
properties[1]="javax.naming.Context.INITIAL_CONTEXT_FACTORY=weblogic.jndi.WLInitialContextFactory"
properties[2]="javax.naming.Context.PROVIDER_URL=t3://svr1:7001"
properties[3]="javax.naming.Context.SECURITY_PRINCIPAL=myid"
properties[4]="javax.naming.Context.SECURITY_CREDENTIALS=mypass"
conn = create ejbconnection
TRY
   conn.connectToServer(properties)
CATCH (remoteexception re)
   messagebox("remoteexception", re.GetMessage())
CATCH (createexception ce)
   messagebox("createexception", ce.GetMessage())
END TRY

Usage

You must provide ConnectToServer with a set of properties that specify how the connection will be established. Before calling ConnectToServer, declare a string array variable and assign values for the javax.naming.Context constants shown in the following table to the elements of the array.

javax.naming.context constant

Value

INITIAL_CONTEXT_FACTORY

Server dependent. For example:

WebLogic:

weblogic.jndi.WLInitialContextFactory

WebSphere:

com.ibm.websphere.naming.WsnInitialContextFactory

PROVIDER_URL

URL for the Server's port. For example: iiop://myserver:9000

SECURITY_PRINCIPAL

User name required for access to the server.

SECURITY_CREDENTIALS

Credentials associated with the user name, typically a password.


See also

CreateJavaInstance

Lookup

CreateJavaInstance

Description

Creates an instance of a Java object from a proxy name.

Deprecated function

This function is maintained for backward compatibility. You should use the CreateJavaInstance function on the JavaVM object for new development. You do not need to be connected to a server to create a local instance of a Java object.

Syntax

connection.CreateJavaInstance (powerobject proxyobject, string proxyname ) 

Argument

Description

connection

The name of the EJBConnection object used to establish the connection.

proxyobject

PowerObject into which the function places a reference to the object specified by proxyname. This argument is passed by reference.

proxyname

The name of the proxy object for the local Java class.


Return value

Long.

Returns 0 for success and one of the following values for failure:

-1 -- Failed to create Java class.

-2 -- Invalid proxy name.

-3 -- Failed to create proxy object.

See also

CreateJavaInstance

DisconnectServer

Description

Disconnects a client application from an EJB server application.

Syntax

connection.DisconnectServer ( ) 

Argument

Description

connection

The name of the EJBConnection object used to establish the connection you want to sever


Return value

None

Throws

NamingException

Examples

In this example, the client application disconnects from the server application using the EJBConnection object myconnect:

myconnect.DisconnectServer()

See also

ConnectToServer

GetEJBTransaction

Description

Returns a reference to the EJBTransaction object associated with the client.

Syntax

connection.GetEJBTransaction ( ) 

Argument

Description

connection

The name of the EJBConnection object used to establish the connection


Return value

EJBTransaction

Examples

This example shows the use of GetEJBTransaction to return a reference to the EJBTransaction object so that you can control transactions from the client:

// Instance variables:
// EJBConnection myconnect
EJBTransaction mytrans
long ll_status

mytrans = myconnect.GetEJBTransaction()
ll_status = mytrans.GetStatus()

Usage

The PowerBuilder client can control the transaction demarcation of EJBs. After a transaction has been started with the EJBTransaction Begin method, GetEJBTransaction can be used to return the name of the transaction.

See also

Begin

Commit

GetStatus

Rollback

SetRollbackOnly

SetTransactionTimeout

Lookup

Description

Allows a PowerBuilder client to obtain the home interface of an EJB component in an application server in order to create an instance of the component.

Syntax

connection.Lookup (string proxyname, string JNDIname, string homeinterfacename ) 

Argument

Description

connection

The name of the EJBConnection object used to establish the connection

proxyname

The name of the proxy object for the EJB component

JNDIname 

The JNDI name of the EJB component

homeinterfacename 

The fully-qualified class name of the EJB home interface


Return value

Powerobject. A proxy object for the home interface of the EJB.

Throws

NamingException

Examples

The following example uses lookup to locate the home interface of the Multiply session EJB in the Java package com.xyz.math. The example assumes the connection to the EJB server has already been established:

// Instance variable:
// EJBConnection myconnect
Multiply myMultiply
MultiplyHome myMultiplyHome
long ll_product

TRY
   myMultiplyHome = myconnect.lookup("MultiplyHome", &
      "Math/Multiply", "com.xyz.math.MultiplyHome")
   myMultiply = myMultiplyHome.create()
   ll_product = myMultiply.multiply(1234, 4567)
catch (remoteexception re)
   messagebox("remoteexception", re.GetMessage())
catch (createexception ce)
   messagebox("createexception", ce.GetMessage())
CATCH (exception e)
   MessageBox("Exception", e.getmessage())
END TRY

The style used for the JNDI name depends on the EJB server.

See also

ConnectToServer