13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

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.

Updategrams have been designed to provide three levels of protection aga<strong>in</strong>st this k<strong>in</strong>dof conflict, as follows:• Bl<strong>in</strong>d updates You specify only the primary key of the record <strong>in</strong> the block. In this case, the change is persisted without firstcheck<strong>in</strong>g whether the current status of the record is consistent with theexpected one.• Partial conflict detection The block conta<strong>in</strong>s the primary keyas well as any other field you plan to update. When the Updategramexecutes, the change is applied only if the specified fields haven't beenchanged <strong>in</strong> the meantime.• Total conflict detection All the columns <strong>in</strong> the row are checked, andthe change fails if any of them has been modified. You can obta<strong>in</strong> this<strong>for</strong>m of protection either by list<strong>in</strong>g all the fields <strong>in</strong> the block orby us<strong>in</strong>g the table timestamp column, if one exists. A timestamp columnwill be updated whenever a user writes someth<strong>in</strong>g to the row.Updategrams and DiffGramsIf you're familiar with ADO.<strong>NET</strong>, you'll no doubt notice a close similarity, bothconceptual and physical, between Updategrams and DiffGrams. Although ADO.<strong>NET</strong>DiffGrams are a newer <strong>for</strong>mat—and perhaps the <strong>for</strong>mat of the future—currently, SQLServer 2000 natively supports only Updategrams.In the section "SQL<strong>XML</strong> Managed Classes," on page 386, we'll take a quick tour of themanaged classes <strong>in</strong> SQL<strong>XML</strong> 3.0. You'll notice that some of these classes apparentlyenable you to send DiffGrams to SQL Server. Although this is possible, the actualimplementation is not particularly effective. The source DiffGram is <strong>in</strong> fact <strong>in</strong>ternallytrans<strong>for</strong>med <strong>in</strong>to an Updategram and then processed by SQL Server.Apart from the patent similarity <strong>in</strong> their schemas, Updategrams and DiffGrams haveslightly different goals. Updategrams have been designed to update SQL Server;DiffGrams are mostly a stateful way to persist the contents of a DataSet object.(ADO.<strong>NET</strong> DiffGrams are covered <strong>in</strong> Chapter 10.) Convert<strong>in</strong>g DiffGrams toUpdategrams is certa<strong>in</strong>ly possible at the schema level, but Updategrams areunquestionably more powerful objects. Together with SQL<strong>XML</strong> 3.0 and the SQL Server<strong>XML</strong> extensions, Updategrams let you control concurrency, control the order ofupdates, per<strong>for</strong>m transactional updates, and specify parameters.On the other hand, there is not yet a .<strong>NET</strong> Framework class that works like anUpdategram. (And SQL<strong>XML</strong> 3.0 is still a hybrid, half COM and half managed code.)Most of the batch update features you f<strong>in</strong>d <strong>in</strong> Updategrams can be implemented <strong>in</strong>ADO.<strong>NET</strong> us<strong>in</strong>g the DataSet object's Update method and the provider-specific dataadapter object. Noth<strong>in</strong>g comes <strong>for</strong> free, though, and you must write a lot of code toemulate Updategrams <strong>in</strong> the .<strong>NET</strong> Framework.<strong>XML</strong> Batch UpdateIn ADO.<strong>NET</strong>, as well as <strong>in</strong> ADO, you can persist the changes made to a set of recordsstored <strong>in</strong> memory us<strong>in</strong>g a procedure called a batch update. This procedure consists ofa loop that looks up <strong>for</strong> changed records <strong>in</strong> the DataSet object (or the Recordsetobject <strong>in</strong> ADO) and issues a command to the back-end database. From theprogrammer's perspective, a batch update is ideal <strong>for</strong> work<strong>in</strong>g <strong>in</strong> disconnectedscenarios and <strong>in</strong> ADO.<strong>NET</strong>—although it is not yet perfect, it has been significantlyimproved and made applicable to real-world usage.Thanks to the ADO.<strong>NET</strong> <strong>XML</strong> serialization mechanism (see Chapter 9), you can loada DataSet object from <strong>XML</strong> data, enter the needed changes, and then proceed withthe batch update. The ADO.<strong>NET</strong> DiffGram is one of the possible <strong>XML</strong> representations<strong>for</strong> a DataSet object. Although, all <strong>in</strong> all, the Updategram is a more powerful and richer313

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

Saved successfully!

Ooh no, something went wrong!