Inside dynamics axapta source code appreciation (5)

Source: Internet
Author: User
Chapter 2 The database layer
1. Change recversion
Ax4.0 uses Optimistic Concurrency Control and recversion is used to identify the recorded version. Static   Void Recversionchange (ARGs _ ARGs)
{
Custtable custtableselected;
Custtable custtableselectedforupdate;
Custtable custtableupdated;
;
Ttsbegin;

Select custtableselected
Where custtableselected. accountnum =   ' 4000 ' ;

Select forupdate custtableselectedforupdate
Where custtableselectedforupdate. accountnum =   ' 4000 ' ;

Select forupdate custtableupdated
Where custtableupdated. accountnum =   ' 4000 ' ;

// At this point, recversion in all three buffers are equal.

Custtableupdated. creditmax = Custtableupdated. creditmax;
Custtableupdated. Update ();

Print custtableupdated. recversion;
Print custtableselectedforupdate. recversion;
Print custtableselected. recversion;


// At this point, recversion is changed in the custtableupdated
// And custtableselectedforupdate buffers. custtableselected still
// Has its original value in recversion.

Ttscommit;
Pause;
}

2. Skip the forupdate, ttsbegin, and ttscommit checks.

Custtable;
;
Ttsbegin;
Select custtable where custtable. accountnum =   ' 4000 ' ;
Custtable. creditmax =   1000 ;

Custtable. skipttscheck ( True );
Custtable. Update ();
Ttscommit;

This can be skipped, but why?
3. Use of temporary tables.
You can use settmp and data methods. Static   Void Tmpcusttable (ARGs _ ARGs)
{
Custtable;
Custtable custtabletmp;
;
Custtabletmp. settmp ();
Ttsbegin;
While Select custtable
{
Custtabletmp. Data (custtable );
Custtabletmp. doinsert ();
}
Ttscommit;
}

Table has two methods: Data () and settmpdata (). Data () is a copy of the data, and settmpdata () is only used for Object Reference transfer.
4. Empty temporary tables
When a temporary table is assigned null, the memory is cleared and the temporary file is deleted.

Static   Void Tmpledgertable (ARGs _ ARGs)
{
Tmpledgertable;
;
Tmpledgertable. companyid =   ' Dat ' ;
Tmpledgertable. accountnum =   ' 1000 ' ;
Tmpledgertable. accountname =   ' Name ' ;
Tmpledgertable. insert (); // Insert into first dataset.

Tmpledgertable =   Null ; // Allocated memory is freed
// And file is deleted.
Tmpledgertable. companyid =   ' Dat ' ;
Tmpledgertable. accountnum =   ' 1000 ' ;
Tmpledgertable. accountname =   ' Name ' ;
Tmpledgertable. insert (); // Insert into new dataset.

// Check it
While Select * From tmpledgertable
{
Print tmpledgertable. accountname;
 
}
Pause;
}

5. The following sectionCodeAs mentioned above, settmpdata points to the same object.

Static   Void Tmpledgertable (ARGs _ ARGs)
{
Tmpledgertable tmpledgertable1;
Tmpledgertable tmpledgertable2;
;
Tmpledgertable2.settmpdata (tmpledgertable1 );

Tmpledgertable1.companyid =   ' Dat ' ;
Tmpledgertable1.accountnum =   ' 1000 ' ;
Tmpledgertable1.accountname =   ' Name ' ;
Tmpledgertable1.insert (); // Insert into shared dataset.

Tmpledgertable2.companyid =   ' Dat ' ;
Tmpledgertable2.accountnum =   ' 1000 ' ;
Tmpledgertable2.accountname =   ' Name ' ;
Tmpledgertable2.insert (); // Insert will fail with dublicate value.
}

6. ttsabort is used to ignore record changes or inserts.
The rest of the code is about transactions and locks. It is similar to the database theory and will not be excerpted here.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.