Skip to content
This repository has been archived by the owner on Nov 16, 2017. It is now read-only.

Batching: begin, release and commit

stickupkid edited this page Aug 15, 2011 · 1 revision

Batching is away to enable you to process a series of commands as one statement rather than singular. If for instance you have to add a series of users to a database and you know you will have quite a few (more than 20 seems to be where you see a performance increase) then you can start using begin and commit. It's important to know how and when to use it.

table.begin();

for(var i : int = 0; i<2000; i++)
{
    const user : User = new User();
    user.name = 'User - ' + i;
    table.insert(user);
}

table.commit();

That's it! It's that simple, note that any statement inside of the begin and commit code (even in nested functions!) will be executed when commit is called.

If something fails in the Execution stage (this is in the commit method) of the commit then it will try and do a rollback to the previous safe state of the database. So nothing previously will be lost and anything new will be ignored. This actually uses SQLConnection.rollback command, so if in doubt read this rollback documentation to understand the gravitas of it.

Removing a statement from the queue How to remove something from the queue? You can't remove one item from the queue (yet!) but you could try and call release, but this will trash everything in the queue that has been made up, so you would have to recreate everything again.

table.begin();

for(var i : int = 0; i<2000; i++)
{
    const user : User = new User();
    user.name = 'User - ' + i;
    table.insert(user);
}

table.release(); // nothing in the queue
table.commit(); // nothing to commit.
Clone this wiki locally