Object Oriented PowerBuilder
Download
Report
Transcript Object Oriented PowerBuilder
Transaction Management
with EAS
William B. Heys
Senior Consultant
7/17/2015
Copyright 2000, marchFIRST, Inc All
rights reserved
2
Stop me at any time for questions
Page: 3
Copyright 2000, marchFIRST, Inc All rights reserved
Agenda
Introducing Transactions
Client/Server Transaction Management
Transaction Management with EAS
Component Transaction Properties
TransactionServer Object
Transaction State Primitives
Stateful vs. Stateless Components
Component Deactivation
Connection Management
Transaction Coordinators
Component Design for Transaction Management
Page: 4
Copyright 2000, marchFIRST, Inc All rights reserved
Introducing Transactions
Transactions comprise one or more SQL statements in a
logical group or unit of work
A unit of work is atomic – it must succeed or fail as a whole
Ensures database consistency
All databases updated by an application must be left in a
consistent state
Database transactions provide isolation
Changes made by one user are isolated from changes made by
other uses running simultaneously
Page: 5
Copyright 2000, marchFIRST, Inc All rights reserved
Introducing Transactions
Transactions must be designed and managed properly to
maximize application concurrency
Otherwise, one user updating a database may cause long-duration
locks to be placed on large numbers of rows in the database
Until update locks are released, other uses are unable to access or
update these rows
Users may be placed into extended wait periods
To increase concurrency
Minimize scope and duration of transactions
At same time, carefully maintain database consistency
Page: 6
Copyright 2000, marchFIRST, Inc All rights reserved
Client/Server Transaction Management
In two-tier client/server applications, transaction
management is the responsibility of client application
A new database transaction is started when application
connects to the database
Transaction Management is scripted
A COMMIT or ROLLBACK issued by the client ends the current
transaction and begins a new transaction
Page: 7
Copyright 2000, marchFIRST, Inc All rights reserved
Database Transactions
Databases use a combination of logging and row locking to
support transactions
All changes made to the database are written to a log file
Deleted Rows – image of deleted row
Changed Rows – image of row before changes
New Rows – primary key of the new row
Database changes remain in “pending” state until the
outcome of the transaction is known
Page: 8
Copyright 2000, marchFIRST, Inc All rights reserved
Database Transactions
DBMS places locks on updated rows (or pages)
Locks prevent other users or applications from reading or
updating a row (or page) while an update is pending to that row (or
page)
The result is changes made by one user are isolated from
changes made by other users
But concurrency is reduced, waiting is increased
Locks remain until the current transaction is committed or
rolled back.
Page: 9
Copyright 2000, marchFIRST, Inc All rights reserved
Commit/Rollback Processing
When a transaction is committed, its changes are made permanent
All changes made by the application since the transaction began are made
permanent
When a transaction is rolled back, its changes are removed
All changes made by the application since the transaction began are reversed –
using the log
The database is returned to the original state when the transaction was started
For both Commit and Rollback
All update locks are released
The current transaction ends and a new transaction begins
Page: 10
Copyright 2000, marchFIRST, Inc All rights reserved
Transaction Management in EAS
Responsibility shifts from the client application to EAS
(Jaguar)
Jaguar manages transactions quite differently
Deployment-time component property rather than scripting
Database updates performed by multiple components can
be grouped into the same atomic unit of work
EAS components can participate in implicit transactions
EAS Transactions are not explicitly controlled using Commit or
Rollback requests
Page: 11
Copyright 2000, marchFIRST, Inc All rights reserved
Component Transaction Properties
EAS components have a new transaction support property
The transaction support property governs how a component
participates in EAS transactions – one of the following
values
Transaction Not Supported
Supports Transaction
Requires Transaction
Requires New Transaction
If a component is currently running within an implicit EAS
transaction it is a transactional component
Page: 12
Copyright 2000, marchFIRST, Inc All rights reserved
Component Transaction Properties
A component can choose not to participate in implicit EAS
transactions
Transaction Not Supported
Non-transactional components can issue Commit and Rollback
requests explicitly
Not the recommended approach
Page: 13
Copyright 2000, marchFIRST, Inc All rights reserved
Component Transaction Properties
Components which only support a transaction may or may
not participate in an implicit transaction
Supports Transaction
If invoked by a transactional component (one currently running
within an EAS transaction), this component will participate in the
invoking component’s transaction
If invoked by a non-transactional component or directly by the
client application, this component will not participate in an EAS
transaction
Page: 14
Copyright 2000, marchFIRST, Inc All rights reserved
Component Transaction Properties
If a component requires a transaction it will always
participate in an EAS transaction
Requires Transaction
If invoked by a transactional component (one currently running
within an EAS transaction), this component will participate in the
invoking component’s transaction
If invoked by a non-transactional component or directly by the
client application, this component will create a new EAS
transaction
Page: 15
Copyright 2000, marchFIRST, Inc All rights reserved
Component Transaction Properties
If a component requires a new transaction it will always
create a new EAS transaction
Requires New Transaction
If invoked by a transactional component (one currently running
within an EAS transaction), this component will create a new EAS
transaction, separate from the invoking component’s transaction
If invoked by a non-transactional component or directly by the
client application, this component will create a new EAS
transaction
Page: 16
Copyright 2000, marchFIRST, Inc All rights reserved
TransactionServer Object
Special PowerBuilder service context object
You must create a TransactionServer object to be able to
use EAS implicit transaction management
Declare an instance variable of type TransactionServer
Protected TransactionServer its_transaction_server
Create the TransactionServer object in the component’s activate
event
this.GetContextService (“TransactionServer”, & its_transaction_server)
Destroy the TransactionServer object in the component’s
deactivate event
Page: 17
Copyright 2000, marchFIRST, Inc All rights reserved
Transaction State Primitives
Components invoke transaction state primitives to
particpate in implicit EAS transactions
Each state primitive has a corresponding PowerBuilder
function
CompleteWork – SetComplete()
RollbackWork
– SetAbort()
ContinueWork – EnableCommit()
DisableCommit – DisableCommit()
InTransaction – IsInTransaction()
IsRollbackOnly – IsTransactionAborted()
Page: 18
Copyright 2000, marchFIRST, Inc All rights reserved
Transaction State Primitives
Transaction state primitives serve two purposes
Used by EAS components in place of SQL Commit or Rollback
requests to vote on the success or failure of the implicit
transaction
Component can only vote on the outcome of a transaction, it cannot control
the outcome
At the end of the transaction, if any no vote is received, the transaction is
rolled back. If only yes votes are received, the transaction is committed
Indicates whether the component should be deactivated at the end
of the method or remain bound to the client
Page: 19
Copyright 2000, marchFIRST, Inc All rights reserved
Transaction State Primitives
Primitive
Deactivate
Component
CompleteWork
Vote for
Transaction
Outcome
Succeeds
RollbackWork
Fails
Yes
ContinueWork
Succeeds
No
DisableCommit
Fails
No
Page: 20
Yes
Copyright 2000, marchFIRST, Inc All rights reserved
Transaction State Primitives
InTransaction – Allows a component to determine whether
the current method is running in a transaction
IsRollbackOnly - Allow a component to determine if the
transaction has already been aborted
Page: 21
Copyright 2000, marchFIRST, Inc All rights reserved
Stateful vs. Stateless Components
Stateful components maintain information on behalf of a
client - across method invocations
Stateful components must therefore remain bound to a
client across method invocations
While bound to a client, the component cannot be shared
with or used by other clients
Stateless components are deactivated and unbound from a
client following each method call
Stateless components are more scaleable because they can
be reused more quickly
Page: 22
Copyright 2000, marchFIRST, Inc All rights reserved
Stateful vs. Stateless Components
Stateful components have many disadvantages
Longer lifetimes
Require more resources
Require more instances to be created for a given set of clients
Tend to cause an increase in network traffic
Retrieve data into a datastore in the component
Bring data from the datastore back to the client
Applications using stateless components are more
scaleable
Better able to utilize server clusters
Better load balancing
Automatic failover at the component or server level
Page: 23
Copyright 2000, marchFIRST, Inc All rights reserved
Component Deactivation
Stateless components can support early deactivation - they
are automatically deactivated when a method call returns
Early deactivation is only possible if the component is
stateless
Set the component deployment-time property for automatic
demarcation/deactivation to TRUE
Stateless components in a transaction are also deactivated
after invoking a SetComplete or SetAbort request
Page: 24
Copyright 2000, marchFIRST, Inc All rights reserved
Component Deactivation
Stateful components must tell EAS when they can be
deactivated
If the stateful component participates in a transaction, the
transaction state primitives can be used to cause
component deactivation
SetComplete or SetAbort
If a stateful component must remain bound to a client it
uses a different set of state primitives for transaction
management
EnableCommit or DisableCommit
Page: 25
Copyright 2000, marchFIRST, Inc All rights reserved
Connection Management
EAS can maintain database connection caches
Connection caches (pooling) enable EAS to logically
connect and disconnect from the database
Performance is improved because the number of actual
physical connections and disconnections are reduced
Components request connections from the pool or cache
If available, a connection will be reused
If a connection is not available, a new one will be created and
physically connected to the database
Connection caching is required for EAS transactions
Page: 26
Copyright 2000, marchFIRST, Inc All rights reserved
Transaction Coordinators
EAS supports two transaction coordinators
The default transaction coordinator is the
SharedConnection coordinator
Connection caches are required if you are using the
SharedConnection coordinator
EAS also supports Microsoft’s Distributed Transaction
Coordinator (DTC)
DTC supports transactions spanning multiple database
connections (2-phase commits)
Must use ODBC and a DTC-compliant database (Microsoft SQL
Server)
Page: 27
Copyright 2000, marchFIRST, Inc All rights reserved
Transaction Coordinators
Jaguar will support additional transaction coordinators in
the future
Java Transaction Server (JTS)
CORBA Object Transaction Server (OTS)
Jaguar will also support Transarc Encina’s 2-phase commit
processing in the future
Page: 28
Copyright 2000, marchFIRST, Inc All rights reserved
Component Design
Component design may be significantly affected by
transaction management needs
Consider the example of an ATM
The customer wants to perform a single user transaction to
transfer money from one account to another
The system breaks this into multiple database requests
Account balance inquiry
Withdraw money from account one
Deposit money to account two
Write a log record to the audit file
Print a receipt
If either update fails, both must be rolled back
Page: 29
Copyright 2000, marchFIRST, Inc All rights reserved
Component Design
Account.getBalances()
Select Balance from Savings
Select Balance from Checking
DBMS
Client
Application
Server
Page: 30
Copyright 2000, marchFIRST, Inc All rights reserved
Log
Component Design
Account.Transfer()
Update Savings set balance...
Update Checking set balance…
Write Log…
Print Receipt...
DBMS
Client
Application
Server
Page: 31
Copyright 2000, marchFIRST, Inc All rights reserved
Log
Component Design
How should we design our components?
How many components should we have?
What transaction properties should we set?
Page: 32
Copyright 2000, marchFIRST, Inc All rights reserved
Component Design
Transaction Management
Customer.Withdraw(Savings)
Transactions
Customer Component
Transaction Required
AutoDemarcation TRUE
1
Customer.Deposit(Checking)
Client
2
Customer.WriteLog()
3
Page: 33
Copyright 2000, marchFIRST, Inc All rights reserved
Component Design
Transaction Management
Customer.Withdraw(Savings)
Transactions
Customer Component
Requires New Transaction
AutoDemarcation TRUE
1
Customer.Deposit(Checking)
Client
2
Customer.WriteLog()
3
Page: 34
Copyright 2000, marchFIRST, Inc All rights reserved
Component Design
Transaction Management
Customer.Withdraw(Savings)
Transactions
Customer Component
Transaction Not Supported
AutoDemarcation TRUE
Customer.Deposit(Checking)
Client
Customer.WriteLog()
Page: 35
Copyright 2000, marchFIRST, Inc All rights reserved
Component Design
Transaction Management
Customer.Withdraw(Savings)
Transactions
Customer Component
Transaction Supported
AutoDemarcation TRUE
Customer.Deposit(Checking)
Client
Customer.WriteLog()
Page: 36
Copyright 2000, marchFIRST, Inc All rights reserved
Component Design
Transaction Management
Savings.Withdraw()
Transactions
Savings Account
Component
Transaction Required
AutoDemarcation TRUE
1
Checking.Deposit()
Client
Checking Account
Component
Transaction Required
AutoDemarcation TRUE
2
Audit.WriteLog()
Audit Component
Component
Transaction Required
AutoDemarcation TRUE
3
Page: 37
Copyright 2000, marchFIRST, Inc All rights reserved
Component Design
Transaction Management
Customer
Component
New Transaction
Required
or
Transaction
Required
Client
Customer.Transfer()
Transactions
Savings.Withdraw()
Checking.Deposit()
Auto
Demarcation
TRUE
Audit.WriteLog()
Savings Account
Component
Transaction Required
AutoDemarcation TRUE
Checking Account
Component
Transaction Required
AutoDemarcation TRUE
Audit Component
Component
Transaction Required
AutoDemarcation TRUE
1
Page: 38
Copyright 2000, marchFIRST, Inc All rights reserved
Component Design
Transaction Management
Customer
Component
Transactions
Savings.Withdraw()
New Transaction
Required
or
Transaction Required
Client
Auto
Demarcation
TRUE
Checking.Deposit()
Savings Account
Component
Transaction Supported
AutoDemarcation TRUE
Checking Account
Component
Transaction Supported
AutoDemarcation TRUE
Customer.Transfer()
Audit.WriteLog()
Audit Component
Component
Transaction Supported
AutoDemarcation TRUE
1
Page: 39
Copyright 2000, marchFIRST, Inc All rights reserved
Component Design
Transaction Management
Customer
Component
Transaction Not
Supported
or
Transaction
Supported
Client
Customer.Transfer()
Transactions
Savings.Withdraw()
Checking.Deposit()
Auto
Demarcation
TRUE
Audit.WriteLog()
Page: 40
Savings Account
Component
Transaction Supported
AutoDemarcation TRUE
Checking Account
Component
Transaction Supported
AutoDemarcation TRUE
Audit Component
Component
Transaction Supported
AutoDemarcation TRUE
Copyright 2000, marchFIRST, Inc All rights reserved
Component Design
Transaction Management
Customer
Component
Client
Customer.Transfer()
New Transaction
Required
or
Transaction
Required
or
Transaction Not
Supported
or
Transaction
Supported
Transactions
Savings.Withdraw()
1
Checking.Deposit()
Checking Account
Component
New Trans. Required
AutoDemarcation TRUE
2
Audit.WriteLog()
Auto
Demarcation
TRUE
Savings Account
Component
NewTrans. Required
AutoDemarcation TRUE
Audit Component
Component
New Trans. Required
AutoDemarcation TRUE
3
Page: 41
Copyright 2000, marchFIRST, Inc All rights reserved
Component Design
Transaction Management
Customer
Component
Client
Customer.Transfer()
New Transaction
Required
or
Transaction
Required
or
Transaction Not
Supported
or
Transaction
Supported
Transactions
Savings.Withdraw()
Checking.Deposit()
Audit.WriteLog()
Auto
Demarcation
TRUE
Page: 42
Savings Account
Component
Trans. Not Supported
AutoDemarcation TRUE
Checking Account
Component
Trans. Not Supported
AutoDemarcation TRUE
Audit Component
Component
Trans. Not Supported
AutoDemarcation TRUE
Copyright 2000, marchFIRST, Inc All rights reserved
Component Design
Transaction Management
Customer
Component
Transactions
Savings.Withdraw()
Transaction
Not Supported or
Transaction
Supported
Client
Auto
Demarcation
TRUE
Savings Account
Component
Transaction Required
AutoDemarcation TRUE
1
Checking.Deposit()
Checking Account
Component
Transaction Required
AutoDemarcation TRUE
Customer.Transfer()
2
Audit.WriteLog()
Audit Component
Component
Transaction Required
AutoDemarcation TRUE
3
Page: 43
Copyright 2000, marchFIRST, Inc All rights reserved
About the Speaker
CPD Professional
Certified PowerBuilder Developer
Since 1994
Advanced CSI
Certified Sybase Instructor (Tools)
Since 1992
Founded Boston PowerBuilder User
Group in 1992
Page: 44
Copyright 2000, marchFIRST, Inc All rights reserved
Special Edition Using PowerBuilder 6
Page: 45
Copyright 2000, marchFIRST, Inc All rights reserved
Special Edition Using PowerBuilder 6
ISBN: 0-7897-1437-x
Macmillan (Que) website (www.mcp.com)
Go to Site Search, Book Information and enter ISBN
Amazon.Com (www.amazon.com)
Search on author: Heys, William
SoftPro Bookstore (www.SoftPro.com)
Page: 46
Copyright 2000, marchFIRST, Inc All rights reserved
Articles on the Web
“Improving Application Performance with the PowerBuilder Trace
Engine
and Application Profiler”
published online in Sybase Powerline magazine
“Application Partitioning – Architecting Applications for the Future”
published online at PowerCard99, sponsored by Sybase in U.K.
Page: 47
Copyright 2000, marchFIRST, Inc All rights reserved
Articles in
“EASy Does IT: Migrating Applications from Distributed
PowerBuilder to Enterprise Application Server 3.0”
published in PowerTimes, July-August 1999
“A Brighter future for PowerBuilder and Sybase”
Guest editorial published in PowerTimes, July-August 1999
“The New Millennium is Bugging Me, PowerBuilder and the
Year 2000 issue”
published in PowerTimes, January-February 1999 issue.
Page: 48
Copyright 2000, marchFIRST, Inc All rights reserved
Books and Articles by Bill Heys
Special Edition Using PowerBuilder 5.0.
Co-author, published by Que
June 1996
“NVO’s How and Why”
Posted to Compuserve (Go PBForum)
NVO Library Section
Filename is NVOHOW.Zip
August 1995
Page: 49
Copyright 2000, marchFIRST, Inc All rights reserved
PowerBuilder Advisor Columns
“How the PowerBuilder 5.0 Foundation Class Libraries
Implement a Service-Based Architecture.” NovemberDecember 1996
“New Language Features in PowerBuilder 5.0.”
September-October 1996
“Managing your PowerBuilder Objects.”
May-June 1996
“Encapsulating Your Objects”
March-April 1996
“Introduction to Custom Classes”
January-February 1996 (Premier Issue)
Page: 50
Copyright 2000, marchFIRST, Inc All rights reserved
You can reach me...
William B. Heys
Senior Consultant
+1 (781) 203-3171 direct
+1 (617) 513-0296 cell
bill.heys @ marchFIRST.com
bheys @ attglobal.net
[email protected]
Page: 51
marchFIRST, Inc.
128 Corporate Center
70 Blanchard Rd., 2nd Flooor
Burlington, MA 01803
+1 (781) 203-3000 tel
+1 (781) 203-3050 fax
www.marchFIRST.com
Copyright 2000, marchFIRST, Inc All rights reserved