13.01.2013 Views

OpenEdge Data Management: DataServer for Microsoft SQL Server

OpenEdge Data Management: DataServer for Microsoft SQL Server

OpenEdge Data Management: DataServer for Microsoft SQL Server

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 2: Initial Programming Considerations<br />

Transactions<br />

With <strong>Data</strong><strong>Server</strong> operations, a MS <strong>SQL</strong> <strong>Server</strong> data source handles its own transaction<br />

roll back and recovery operations. However, the <strong>OpenEdge</strong> transaction scoping rules<br />

apply: a transaction ends when the code exits the outermost block that per<strong>for</strong>ms an<br />

update. With the <strong>Data</strong><strong>Server</strong>, ABL per<strong>for</strong>ms as follows:<br />

• Sends a COMMIT to the data source, when a transaction that updates a MS <strong>SQL</strong><br />

<strong>Server</strong> data source ends successfully.c<br />

• Sends a ROLLBACK to the data source if you interrupt the transaction.<br />

See <strong>OpenEdge</strong> Getting Started: ABL Essentials <strong>for</strong> details on how ABL handles<br />

transactions and error conditions.<br />

Transaction scoping and buffer management<br />

The <strong>Data</strong><strong>Server</strong> and an <strong>OpenEdge</strong> database hold locks differently at transaction<br />

boundaries. The <strong>OpenEdge</strong> database will hold a lock past the transaction boundary<br />

where the <strong>Data</strong><strong>Server</strong> will not. This causes different behavior in the use of buffers.<br />

Consider the following example:<br />

DEFINE BUFFER st_buf1 FOR state.<br />

DEFINE BUFFER st_buf2 FOR state.<br />

DO TRANSACTION: /* Transaction 1 */<br />

FIND st_buf1 WHERE st_buf1.state EQ "NH" EXCLUSIVE-LOCK.<br />

DISPLAY st_buf1.state-name. /* state-name = "New Hampshire" */<br />

END.<br />

/* During this pause, state-name is changed from "New Hampshire" to "Granite<br />

State" by an external user */<br />

PAUSE MESSAGE " state.state-name ".<br />

DO TRANSACTION: /* Transaction 2 */<br />

FIND st_buf2 WHERE st_buf2.state EQ "NH" EXCLUSIVE-LOCK.<br />

DISPLAY st_buf1.state-name st_buf2.state-name.<br />

END.<br />

Executing the above code against an <strong>OpenEdge</strong> database will downgrade the<br />

EXCLUSIVE-LOCK in Transaction 1 to a SHARE-LOCK. This occurs at the end of<br />

Transaction 1 and remains in effect at the time of the PAUSE statement and prior to the<br />

start of Transaction 2. This SHARE-LOCK prevents another user from modifying the<br />

state-name value between the transactions. As an optimization, when Transaction 2<br />

is executed, the client does not refresh the st_buf1 buffer since the SHARE-LOCK<br />

prevented its contents from becoming stale between transactions. Also, since st_buf2<br />

will have the same data integrity as st_buf1, they share the same buffer content.<br />

Executing the above code against the <strong>Data</strong><strong>Server</strong> will have different results because<br />

the <strong>Data</strong><strong>Server</strong> does not retain any lock conditions beyond the scope of the transaction<br />

boundary. The <strong>Data</strong><strong>Server</strong> will release the EXCLUSIVE-LOCK on the record at the END<br />

statement of Transaction 1. This leaves the record exposed to modification by another<br />

client during the PAUSE statement. If another client modifies the state-name value to<br />

“Granite State” during the PAUSE, Transaction 2 will read the updated value during the<br />

FIND statement. However, because of <strong>OpenEdge</strong> buffering rules and record scoping,<br />

neither buffer is refreshed with the updated value and the DISPLAY statement displays<br />

“New Hampshire New Hampshire.”<br />

100 <strong>OpenEdge</strong> <strong>Data</strong> <strong>Management</strong>: <strong>Data</strong><strong>Server</strong> <strong>for</strong> <strong>Microsoft</strong> <strong>SQL</strong> <strong>Server</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!