460 likes | 973 Views
The ProDataSet in OpenEdge™ 10. John Sadd Progress Fellow and OpenEdge Evangelist. Agenda. ProDataSet Overview Syntax Specifics and Demo ProDataSet Directions. The ProDataSet. Data-Source1. Database. Field Map CustNum Name Contact. Query… Q1 for Customer. CustomerTT. OrderTT.
E N D
The ProDataSet inOpenEdge™ 10 John SaddProgress Fellow and OpenEdge Evangelist
Agenda • ProDataSet Overview • Syntax Specifics and Demo • ProDataSet Directions
The ProDataSet Data-Source1 Database Field MapCustNum Name Contact Query…Q1 for Customer CustomerTT OrderTT Data-Source2 6 1 01/05/9336 1 01/19/9379 1 02/10/93 1 Lift Line Skiing 2 Urpon Frisbee 3 Hoops Croquet Field MapOrderNum CustNum OrderDate Query… Q2 for Order Order Event Logic Customer 1 53 01/01/93 2 81 01/04/93 3 66 01/04/93 Lift Line Skiing Urpon Frisbee Hoops Croquet Dataset:Before-fillBuffer:Before-fillBefore-row-fill Row-Add Row-Delete… ProDataSet Data-Relation1
The Bigger Picture – Today and Tomorrow .NET User Interface Jonas Grumby OK 110 Desert Isle Path Cancel Minnow, HI 4GL C# • ProDataSets become a driving force in OpenEdge Applications OpenEdgeBusiness Logic OpenEdge.NET Interface Purchase Order Business Logic PurchaseOrderProxy PO ProDataSet HeaderData DetailData OtherData WebClient / HTML User Interface OpenEdge4GL Interface 4GL or WebSpeed Interface Jonas Grumby OK 110 Desert Isle Path Cancel Minnow, HI OpenEdgeWeb Services Interface
ProDataSet to ADO.NET DataSet • ProDataSet is a Progress in-memory data store • ProDataSet maps directly to an ADO.NET DataSet: • Design a .NET interface in terms of .NET DataSets • Build business logic in Progress
Agenda • Distributed Data Management in Version 9 • ProDataSet Overview • Syntax Specifics and Demo • Futures
A ProDataSet is made of Temp-Tables • Define temp-tables in the usual way DEFINE TEMP-TABLE ttOrder /* fields from Order db table */ FIELD OrderTotal AS DECIMAL FIELD CustName LIKE Customer.Name FIELD RepName LIKE SalesRep.RepName. DEFINE TEMP-TABLE ttOrderLine… DEFINE TEMP-TABLE ttItem…
Define the DataSet • Define the DataSet in terms of the temp-tables it combines DEFINE DATASET dsOrder FOR ttOrder, ttOline, ttItem DATA-RELATION OrderLine FOR ttOrder, ttOline RELATION-FIELDS (OrderNum, OrderNum) DATA-RELATION LineItem FOR ttOline, ttItem RELATION-FIELDS (ItemNum, ItemNum) REPOSITION.
Populating with Data-Relations OrderTT 6 1 01/05/9336 1 01/19/9379 1 02/10/93 …DATA-RELATION OrderLine FOR ttOrder, ttOline RELATION-FIELDS (OrderNum, OrderNum)… • When a DataSet is populated, Progress retrieves children of the current parent ProDataSet Data-Relation OrderLineTT 6 1 000096 2 000096 3 00011 36 1 0000936 2 0000936 3 00011
Navigating with Data-Relations OrderTT 6 1 01/05/9336 1 01/19/9379 1 02/10/93 …DATA-RELATION OrderLine FOR ttOrder, ttOline RELATION-FIELDS (OrderNum, OrderNum)… • When a DataSet is navigated, Progress filters on children of the current parent ProDataSet Data-Relation OrderLineTT 6 1 000096 2 000096 3 00011 36 1 0000936 2 0000936 3 00011
Defining Data-Sources Order • You can define a Data-Source for each temp-table buffer in the DataSet • Each Data-Source can define database buffers or a query or both • Data-Source is separate from any DataSet ProDataSet Data-Source SrcOrder OrderTT Query…Q1 for Order Database OrderLineTT Data-Source SrcOline OrderLine 1 53 01/01/93 2 81 01/04/93 3 66 01/04/93 1 53 01/01/93 2 81 01/04/93 3 66 01/04/93 Query… Q2 for OrderLine
Defining a Data-Source with a Query • Define a query for a top-level table • For example, which Order(s) to start with • Or to define a join between buffers DEFINE QUERY qOrder FOR Order, Customer, SalesRep. DEFINE DATA-SOURCE srcOrder FOR QUERY qOrder Order KEYS (OrderNum), Customer KEYS (CustNum), SalesRep KEYS (SalesRep). QUERY qOrder:QUERY-PREPARE ("FOR EACH Order WHERE Order.OrderNum = " + STRING(iOrderNum) +", FIRST Customer OF Order, FIRST SalesRep OF Order").
Defining a Data-Source without a Query OrderTT 6 1 01/05/9336 1 01/19/9379 1 02/10/93 ProDataSet Data-Relation OrderLineTT 6 1 000096 2 000096 3 00011 • If there’s a Data-Relation, its fields can tell Progress how to construct a query …DATA-RELATION OrderLine FOR ttOrder, ttOline RELATION-FIELDS (OrderNum, OrderNum)… DEFINE DATA-SOURCE srcOline FOR OrderLine KEYS (OrderNum).
Attaching Data-Sources ProDataSet Order OrderTT 6 1 01/05/9336 1 01/19/9379 1 02/10/93 • Data-Sources are defined separately from the DataSet • You can attach a particular Data-Source without changing the DataSet definition • Data-Sources do not travel with the DataSet Database Data-Source SrcOrder 1 53 01/01/93 2 81 01/04/93 3 66 01/04/93 Query…Q1 for Order
ATTACH-DATA-SOURCE Method • Relates a Data-Source to a DataSet buffer • Optional arguments: • Field mapping for fields with different names • Except-list to skip unwanted fields, or • Include-list to include only certain fields BUFFER ttOrder:ATTACH-DATA-SOURCE (DATA-SOURCE srcOrder:HANDLE, "Customer.Name,CustName"). BUFFER ttOline:ATTACH-DATA-SOURCE (DATA-SOURCE srcOline:HANDLE). BUFFER ttItem:ATTACH-DATA-SOURCE (DATA-SOURCE srcItem:HANDLE).
Populating a ProDataSet • Use the FILL method to populate the DataSet • FILL on the DataSet fills every table starting with top-level buffers • FILL on a buffer fills that table and its descendents • FILL-MODE • NO-FILL – skip this table • EMPTY – empty the table first • APPEND – add more records to the table • MERGE – add recs & eliminate dups • REPLACE – replace existing recs
Event Callback Procedures • You can define event procedures for: • Before and After FILL of the ProDataSet • Before and After FILL of any temp-table buffer • Before and After FILL of any record • Use ProDataSet events to prepare queries, attach Data-Sources, etc. • Use Buffer events to manipulate the table • Use Record events to populate calculated fields • You can use these events when there is no Data-Source at all
Record-level Event Procedure • Fills a calculated OrderTotal field hBuff:SET-CALLBACK-PROCEDURE ("AFTER-ROW-FILL","postRecordFill",THIS-PROCEDURE). PROCEDURE postRecordFill: DEFINE INPUT PARAMETER DATASET FOR dsOrder. hBuff = hDset:GET-BUFFER-HANDLE(“ttOrder”). FOR EACH OrderLine WHERE OrderLine.OrderNum = INTEGER(hBuff:BUFFER-FIELD("OrderNum"):BUFFER-VALUE): dTotal = dTotal + OrderLine.ExtendedPrice. END. hBuff:BUFFER-FIELD("OrderTotal"):BUFFER-VALUE = dTotal. END PROCEDURE.
Passing a ProDataSet as a Parameter • You can pass a DataSet parameter as: • DATASET – static reference like TABLE for temp-tables • DATASET-HANDLE – dynamic reference to the DataSet and its definition, like TABLE-HANDLE for a temp-table • HANDLE – passes a simple DataSet handle to a local procedure • Note! • Within a single session DataSet parameters can be passed BY-REFERENCE
Local DataSet Parameter OrderTT ProDataSet 6 1 01/05/9336 1 01/19/9379 1 02/10/93 RUN OrderDset.p ON hSession (INPUT iOrderNum, OUTPUT DATASET dsOrder BY-REFERENCE). /* OrderDset.p -- Test proc for Order Dataset */ {dsOrderTT.i} {dsOrder.i} DEFINE INPUT PARAMETER iOrderNum AS INTEGER. DEFINE OUTPUT PARAMETER DATASET FOR dsOrder.
Remote DataSet Parameter OrderTT OrderTT ProDataSet ProDataSet 6 1 01/05/9336 1 01/19/9379 1 02/10/93 6 1 01/05/9336 1 01/19/9379 1 02/10/93 AppServer RUN OrderDset.p ON hSession(INPUT iOrderNum, OUTPUT DATASET dsOrder BY-REFERENCE). /* OrderDset.p */ DEFINE OUTPUT PARAMETER DATASET FOR dsOrder. Client
Dynamic ProDataSets • Every element of a ProDataSet can be dynamic • CREATE DATASET • ADD-BUFFER() • ADD-RELATION() • A Data-Source can also be dynamic: • CREATE DATA-SOURCE • And a DataSet can use dynamic temp-tables • CREATE TEMP-TABLE • Attributes and methods manipulate the DataSet through its handle
Updating Through the ProDataSet • ProDataSet tables have a companion before-image temp-table to record updates (add/change/delete) • Used to pass changes to the server to be made in the Data-Source • Maps to .NET support for update versions
Before-Image Table for a DataSet OrderTT 6 1 01/05/9336 1 01/19/9379 1 02/10/93 • Original values for every modified record • Initial values for every added record • Original values for every deleted record ProDataSet Data-Relation OrderLineTT 6 1 000096 2 000106 3 00011 6 4 00077 0 0 00000 A 6 2 00009 M 6 5 00022 D
Saving Changes To The Database • Use ATTACH-DATA-SOURCE to reattach the DataSet to the database tables for it • SAVE-ROW-CHANGES method for saving a row to the database • Uses the before-table for optimistic locking • Allows full control in the event of a conflict • ERROR, ERROR-STRING, REJECTED, DATA-SOURCE-MODIFIED attributes
Agenda • Distributed Data Management in Version 9 • ProDataSet Overview • Syntax Specifics and Demo • ProDataSet Directions
Enhancements in OpenEdge 10.0B and 10.0B01 • COPY-DATASET method enhancements • Also COPY-TEMP-TABLE • Behavior changed to allow copies between non-identical tables and DataSets • GET-CHANGES and MERGE-CHANGES • include parents of modified rows • FILL-MODE “REPLACE” • Refreshes rows already in the tables • Slower than MERGE because it requires FINDing each row as it is added to the temp-table
Enhancements in OpenEdge 10.0B and 10.0B01 -- continued • Additional events to support data retrieval transparency • OFF-END for a ProDataSet query • FIND-FAILED for a FIND on a buffer • Extended support for data batching • BATCH-SIZE attribute for a buffer • LAST-BATCH attribute signals end of data • NEXT-ROWID for repositioning a query • See white paper for examples: • psdn.progress.com/library/product_info/ oera/index.ssp
ProDataSet Features in OE10.1 • Direct to-or-from XML conversion • This supports ProDataSets as parameters to Web services • Mapping from ProDataSets to Java SDOs • REFERENCE-ONLY to use called procedure’s ProDataSet instance • Also parameter passing BY-REFERENCE for temp-tables
New dynamic syntax in 10.1 • Combines a dynamic ProDataSet reference with static names • hDataSet:ttOrderLine.Price • Simplifies logic to pass dynamic reference for flexibility
In Conclusion… • The ProDataSet is a key part of the future of 4GL applications • It is part of a focus on building complex data definitions and business logic in the 4GL • The ProDataSet is a standards-conformant object that will integrate with .NET and Web services as part of a global Service-Oriented Architecture
Additional Resources • Expert Series book: Using ProDataSets • Now available through amazon.com • PSDN white paper on Using Advanced ProDataSet Language Features • Part of a series on implementing the OERA • Instructor-led course: Using ProDataSets • OpenEdge online documentation