Description
The EJB transaction class enables PowerBuilder clients to control a transaction on an EJB server. EJBTransaction maps closely to the javax.transaction.UserTransaction interface.
Methods
EJBTransaction has six member functions:
Description
Creates a new transaction and associates it with the current thread.
Syntax
ejbtrans.Begin ( )
Return value
None
Examples
The following example shows the use of begin to create a transaction from a client:
EJBTransaction trans
EJBConnection conn
string properties[ ]
// set properties
.....
conn = create ejbconnection
TRY
   conn.connectToServer(properties)
   trans = conn.GetEjbTransaction
   trans.begin()
CATCH (exception e)
   messagebox("exception", e.getmessage())
END TRYSee also
GetEJBTransaction (EJBConnection class)
Description
Declares that the calling thread transaction should be committed.
Syntax
ejbtrans.Commit ( )
Return value
None
Examples
In this example, the client calls the dopayroll method on the CmpnyAcct EJB component, which processes a company payroll. If the company has sufficient funds to meet the payroll, the client commits the transaction. Otherwise, an exception is thrown and the client rolls back the transaction:
// Instance variables:
// EJBTransaction trans
// EJBConnection conn
// CmpnyAcctHome AcctHome
// CmpnyAcct Acct
TRY
   trans.begin()
   AcctHome = conn.lookup("CmpnyAcctHome",
      "Sample/CmpnyAcct", "sample.CmpnyAcctHome")
   Acct = AcctHome.create()
   Acct.dopayroll()
   trans.commit()
CATCH (remoteexception re)
   messagebox("remoteexception", re.GetMessage())
CATCH (createexception ce)
   messagebox("createexception", ce.GetMessage())
CATCH (exception e1) 
   MessageBox ("exception", e1.getmessage() )
   TRY 
      trans.rollback();
     CATCH (exception e2)
      MessageBox ("exception", e2.getmessage() )
   END TRY
END TRYUsage
The Commit method completes the transaction associated with the calling thread. The transaction is not completed if any other participants in the transaction vote to roll back the transaction.
See also
GetEJBTransaction (EJBConnection class)
Description
Returns the status of the EJB transaction associated with the client.
Syntax
ejbtrans.GetStatus ( )
Return value
A long value representing the transaction status
Possible values are:
1 -- Status active
2 -- Status marked rollback
3 -- Status prepared
4 -- Status committed
5 -- Status rolled back
6 -- Status unknown
7 -- Status no transaction
8 -- Status preparing
9 -- Status committing
10 -- Status rolling back
Examples
This example shows the use of GetStatus to obtain the state of the current transaction:
// Instance variables: // EJBConnection myconnect EJBTransaction mytrans long ll_status mytrans = myconnect.GetEJBTransaction() ll_status = mytrans.GetStatus()
Usage
The GetStatus method can be used to determine the current status of a transaction by the client that initiated the transaction using the Begin method.
See also
GetEJBTransaction (EJBConnection class)
Description
Rolls back the transaction associated with the calling thread.
Syntax
ejbtrans.Rollback ( )
Return value
None
Examples
This example shows the use of Rollback to roll back a transaction when an update does not succeed:
// Instance variables:
// EJBTransaction trans
// 
TRY
   trans.begin()
   Acct.updateChecking(amount)
   trans.commit()
CATCH (exception e1)
   TRY
      trans.rollback()
   CATCH (exception e2)
      MessageBox("Rollback failed", e2.getMessage())
   END TRY
   MessageBox("Transaction failed", e1.getMessage())
END TRYSee also
GetEJBTransaction (EJBConnection class)
Description
Modifies a transaction associated with a calling thread so that the only possible outcome is to roll back the transaction.
Syntax
ejbtrans.SetRollbackOnly ( )
Return value
None
Examples
In this example, a participant in a transaction has determined that it should be rolled back. The participant gets a reference to the current transaction and votes to roll back the transaction:
// Instance variables: // EJBConnection conn // EJBTransaction trans trans = conn.GetEJBTransaction() trans.SetRollbackOnly()
Usage
Rollback is typically called by the originator of the transaction, but another participant in a transaction can call SetRollbackOnly to vote that the transaction should be rolled back.
See also
GetEJBTransaction (EJBConnection class)
Description
Sets the timeout value for subsequent transactions. The transaction is rolled back if it does not complete before the timeout expires.
Syntax
ejbtrans.SetTransactionTimeout (long seconds )
| 
                                  Argument  | 
                              
                                  Description  | 
                           
|---|---|
| 
                                  ejbtrans  | 
                              
                                  The name of an EJBTransaction object  | 
                           
| 
                                  seconds  | 
                              
                                  A long that specifies the number of seconds that elapse before a transaction is rolled back  | 
                           
Return value
None
Examples
This example shows the use of SetTransactionTimeout to set the timeout period to five minutes:
// Instance variables:
// EJBConnection conn
// EJBTransaction trans
TRY
   trans.SetTransactionTimeout(300)
   trans.begin()
CATCH (exception e)
   MessageBox("Exception", e.getMessage())
END TRYUsage
The SetTransactionTimeout method specifies the number of seconds that can elapse before a transaction is rolled back. The timeout period applies to transactions created by subsequent invocations of Begin. If seconds is 0, no timeout period is in effect.
See also
GetEJBTransaction (EJBConnection class)


