Chapter 4: Performance (4)

Source: Internet
Author: User
This article is only for ax practitioners and fans to learn and discuss. Due to copyright issues in the original article, do not repost it.

Recordinsertlist and recordsortedlist classes
When inserting multiple records into a table, besides using the batch operator, dynamicsax also allows the recordinsertlist and recordsortedlist classes. When you prepare to insert a record, the dynamicsax application packs multiple records into a package and sends them to the database. The database executes a separate insert statement for each record in the package. The following example shows this. In this example, a recordinsertlist object is instantiated and records to be inserted into the database are added to the recordinsertlist object. When all objects are inserted into this object, call the insertdatabase method to ensure that all records are inserted into the database. Static   Void Copysizes (ARGs _ ARGs)
{
Inventsize inventsizeto;
Inventsize inventsizefrom;
Inventtable;
Recordinsertlist;
;
Ttsbegin;
Recordinsertlist =   New Recordinsertlist (tablenum (inventsize ));

While Select Itemid from inventtable
Where inventtable. Itemid =   ' Pb-metal shade '
Join inventsizeid, description, name from inventsizefrom
Where inventsizefrom. Itemid =   ' Pb-plasticshade '
{
Inventsizeto. Itemid=Inventtable. Itemid;
Inventsizeto. inventsizeid=Inventsizefrom. inventsizeid;
Inventsizeto. Name=Inventsizefrom. Name;
Recordinsertlist. Add (inventsizeto );
}
Recordinsertlist. insertdatabase ();

Ttscommit;

}

When the dynamicsax application runs and finds that the record added to the recordinsertlist object is sufficient to form a package, the record is packaged, sent to the database, and inserted at the database layer. This check occurs when the add method is called. When the application logic calls the insertdatabase method, the remaining records are inserted using the same mechanism.
Using these analogy has the benefit of while select: Because multiple records are sent at the same time, the number of times the AOS sends back and forth to the database is reduced. However, the insert statements executed by the database are the same.
Note: because the record insertion time depends on the record cache and package size, you cannot select a record in the database before calling the insertdatabase method. .
The preceding scenario can replace the recordinsertlist class with the recordsortedlist class, Code As follows: Static   Void Copysizes (ARGs _ ARGs)
{
Inventsize inventsizeto;
Inventsize inventsizefrom;
Inventtable;
Recordsortedlist;
;
Ttsbegin;
Recordsortedlist =   New Recordsortedlist (tablenum (inventsize ));
Recordsortedlist. sortorder (fieldnum (inventsize, Itemid ),
Fieldnum (inventsize, inventsizeid ));
While Select Itemid from inventtable
Where inventtable. Itemid =   ' Pb-metal shade '
Join inventsizeid, description, name from inventsizefrom
Where inventsizefrom. Itemid =   ' Pb-plastic shade '
{
Inventsizeto. Itemid = Inventtable. Itemid;
Inventsizeto. inventsizeid = Inventsizefrom. inventsizeid;
Inventsizeto. Description = Inventsizefrom. description;
Inventsizeto. Name = Inventsizefrom. Name;
Recordsortedlist. INS (inventsizeto ); // No record will be inserted
}
Recordsortedlist. insertdatabase (); // All records are inserted in Database
Ttscommit;


}

(Note: I encountered an error when running the above Code. The error message is: "records in inventsize cannot be created. To use the databaseinsert () method, recordsortedlist must be instantiated on the server side ". Put the sample code in the class and let it run smoothly on the server side. I don't know whether the original author has tested the sample code, or why it is configured or not, in addition, the error message is actually the method databaseinsert (), rather than the actually called insertdatabase ()
when the application logic uses the recordsortedlist object, the insertdatabase () is called () the record is passed and inserted into the database. The number of round trips and the number of inserted insert statements are the same as those of the recoreinsertlist object ).
the recordinsertlist and recordsortedlist objects may be downgraded to insert one by one in the Program logic of the application. In this case, each record must be sent to and from the database separately and then executed with an insert statement. If the inser or aosvalidateinsert method is overloaded, or fields containing the container or memo type in the table are downgraded. The Database Log configuration is used to record the insert operation or configure an alert triggered by the insert operation on the table, which does not cause degradation. After the records are sent and inserted to the database, the database logs and events are processed one by one.
when instantiating a recordinsertlist object, you can specify to skip the insert and aosvalidateinsert methods. If the operation is not degraded, you can also specify to skip database logs and events ). If the insert method is reloaded, set the second parameter of the new method of recordinsertlist to true to avoid degradation. For the second point, set the third parameter to true. Even if the operation is not degraded, it will still be recorded in the database log table. It is not clear why the author says it can be skipped, other places need to be set ?)

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.