Tài liệu Using ColdFusion MX with Databases

Thảo luận trong 'Thiết Kế Web' bắt đầu bởi Thúy Viết Bài, 5/12/13.

  1. Thúy Viết Bài

    Thành viên vàng

    Bài viết:
    198,891
    Được thích:
    173
    Điểm thành tích:
    0
    Xu:
    0Xu
    CFTRANSACTION and exception handling
    The default behavior of the CFTRANSACTION tag is such that if you do not explicitly command
    it to commit or rollback, it does so implicitly for you. This is the technique shown in Listings
    10-1 and 10-3. Many ColdFusion developers are used to coding that way, but if you rely on the
    implicit behavior that CFTRANSACTION automatically commits and rolls back for you, stop
    doing so right now. In our own tests, ColdFusion MX slows to a crawl if CFTRANSACTION tags
    are not explicitly coded with BEGIN, COMMIT, and ROLLBACK commands.
    To make sure that you are committing only if everything works correctly and rolling back
    only if it doesn’t, you should be very aware of CFTRANSACTION’s behavior with respect to
    exception handling and also how to correctly nest CFTRANSACTION and CFTRY tags.
    The best practice for coding CFTRANSACTION is as follows:
    1. CFSET a flag variable TRUE.
    2. Begin a CFTRANSACTION.
    3. Open a CFTRY block.
    4. Code any database queries you need.
    5. Test for exceptions with CFCATCH blocks as necessary.
    6. Within any and all CFCATCH blocks that would indicate a failure of any part of the transaction,
    CFSET the flag FALSE.
    7. Close the CFTRY block.
    8. Test the flag: Commit the transaction if TRUE and roll it back if FALSE.
    9. Close the CFTRANSACTION.
    Listing 10-4 rewrites Listing 10-1 to incorporate CFTRANSACTION best practices
     

    Các file đính kèm:

Đang tải...