`
kirenenko04
  • 浏览: 145052 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

Data Binding and Explicit Transactions

 
阅读更多

 Data Binding and Explicit Transactions

数据绑定和显式事物

 

Data Binding with Forms and Objects 数据绑定到表单和对象

The Demandware forms framework supports binding of persistent(持久) objects to form fields by automatically updating a persistent object with form data without having to issue an insert statement or calling a Demandware API. The reverse mechanism is also supported: pre-populating a form object with data from a persistent object.

 

The object that is bound to the form must be a persistent object (system or custom), and must be available in the pdict. The form metadata must have field(s) with the binding attribute specified. The field formid attribute is not used to make the match; only the binding attribute identifies what fields match between the form and the object.

 

This is because the NewsletterSubscription CO we want to bind this form to have firstName, lastName and email fields which are all custom attributes, as seen below since the fields don’t have a lock icon (they were added by you as custom attributes of the CO):

 

Using the UpdateObjectWithForm Pipelet

The UpdateObjectWithForm pipelet updates an existing persistent object with data from the form. It requires the object to update and the form object both available on the pdict. It is transactional by default since the object to be updated must be a persistent object.

 

Here is an example of how you define the properties of the pipelet using the newsletter form and NewsletterSubscription object we saw above:

 

Form: CurrentForms.newsletter

Object: Subscription

 

The pipelet will inspect(检查) the CurrentForms.newsletter form in the pdict, and try to match every field with a binding attribute to a column in the object called Subscription. This object must be an instance of NewsletterSubscription that was placed in the pdict by either creating a new instance (using CreateCustomObject pipelet) or by retrieving an existing instance (using SearchCustomObject pipelet).

If the Subscription object is null, or not an instance of NewsletterSubscription CO, or the form is not in the pdict, the pipelet will fail and the transaction will be rolled back. If the pipelet is successful the transaction will commit.

 

Using UpdateFormWithObject Pipelet

The UpdateFormWithObject pipelet updates a form with data from an object. It requires the form to update and the object to be both available on the pdict. It is not transactional since the updated form lives in the pdict scope, not in the database.

 

Notice that a form group may be updated with an object: as long as the bindings match, just that part of the form will be updated.

 

Form: CurrentForms.profile.customer

Object: CurrentCustomer.profile

 

In the example above, the profile.xml form has a customer group that will be updated with the existing profile data from the logged in customer.

 

Explicit Transaction Handling 显式事务处理

We already saw that transaction handling can be done implicitly by just executing a transactional pipelet: the commit or rollback is controlled by the PIPELET_NEXT or PIPELET_ERROR return values.

 

However, in some circumstances(情况) the transaction spans(跨越) several pipelets or steps: in this case you need to decide where the transaction begins and ends. This mechanism is called Explicit Transaction Handling.

 

Explicit Database Transaction Handling

This is implemented(应用于) at the pipeline level by changing the Transaction Control property of a transition or connector.

You Can use ‘Begin Transaction’, ‘Commit Transaction’, ‘Rollback Transaction’ for setting on the transition node, simply open the properties window for the transition, and select the type of Transaction Control you want.

 

This can be used to override(覆盖) the built-in(内置) implicit transaction in order to group changes that need to be an atomic transaction (原子事件).

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics