runTransaction method

Future<void> runTransaction(
  1. {@required AGConnectCloudDBTransaction transaction}
)

This method is called to perform a specified transaction operation.

Comply with the following rules when invoking this method:

  • You can call this method to perform transaction operations only when Cloud DB zone is opened. Otherwise, the transaction fails to be executed.
  • You can call this method to perform transaction operations only when the Cloud DB zone synchronization mode is cache mode.
  • Multiple data operations can be performed in a transaction.
  • The written and deleted object records contained in a transaction must be less than or equal to 1000. Otherwise, the transaction fails to be executed.

Implementation

Future<void> runTransaction({
  @required AGConnectCloudDBTransaction transaction,
}) async {
  if (transaction == null) {
    throw FormatException('Value of transaction cannot be null.', transaction);
  }

  try {
    return await _methodChannel.invokeMethod<void>(
      MethodConstants.RUN_TRANSACTION,
      <String, dynamic>{
        KeyConstants.ZONE_ID: this._id,
        KeyConstants.TRANSACTION_ELEMENTS: transaction.transactionElements,
      },
    );
  } catch (e) {
    throw AGConnectCloudDBException.from(e);
  }
}