Support for Transactions

Hi,

I used to use WebORB for java, and I liked especially the UnitOfWork class to group multiple database operations into a single request.
Does Backendless API allows transactions with support for transaction rollback?

Thanks in advance,

Regards,

Christophe

Hi Christophe,

When you create/update/delete a complex object with related objects included into the scope of the parent, Backendless runs it in a single transaction. For example, say you have an object PhoneBook, with a collection of PhoneBookEntry instances. You can save that instance and all the related instances will be saves transactionally.

This is as close as it gets to UnitOfWork at the moment.

Regards,
Mark

Hi Mark,

I found the PhoneBook example (http://backendless.com/documentation/data/flex/data_relations_save_update.htm) and I understand now.
It’s really handy and powerful.

I thank you so much.

Regards,

Christophe

Hi,

if i want to increase value in a table by 1.
will the code down the link work in a transnational manner? E.g. no one will be able to modify the value between read and write?
http://backendless.com/documentation/data/android/data_updating_data_objects.htm

Hi Anatoliy,

It depends on how you implement it. If your implementation is like this:

  1. Client A: Read value from DB (server reads and sends value to the client)
  2. Client A: Send new value to DB (client sends new value to the server which then writes it to the DB).

Then it is entirely possible that Client B may update the same value between the two steps above.

Regards,
Mark

And if i want to avoid this, i believe i should do following:

  1. Send from Client a message to Server to update specific object (object id and operation).

  2. Server updates specific object (increases value by 1)

What tool should i use to send the message to the server?

BR,
AY

Hi Anatoliy,

You’re still running a risk that another client would change the value. A better (recommended) way is to use Backendless Counters. They are atomic and would work exactly as you’d expect in a high load environment: http://backendless.com/documentation/utilities/android/ut_atomic_counters_api_android.htm

To “link” a counter with your object, you could create a column in your table and keep in there the name of the counter.

Regards,
Mark