Managing GemFire XD Transactions

GFXDClientConnection implements methods to help you delimit GemFire XD transactions in your application code. You begin and commit transactions using the connection object itself.

The following example uses an GFXDDataAdapter object to insert and update table data within as a single transaction.
string gfxdHost = "localhost";
int gfxdPort = 1527;
string connectionStr = string.Format(@"server={0}:{1}", gfxdHost, gfxdPort);

GFXDClientConnection connection = null;

try
{
    // Open connection, disable auto-commit, and start transaction
    connection = new GFXDClientConnection(connectionStr);
    connection.AutoCommit = false;
    connection.BeginGFXDTransaction(IsolationLevel.ReadCommitted);

    GFXDCommand command = connection.CreateCommand();
    command.CommandType = CommandType.Text;

    connection.Open();

    // Get product info
    command.CommandText = "SELECT * FROM product WHERE product_id=?";
    GFXDDataAdapter adapter = command.CreateDataAdapter();
    DataTable table = new DataTable("product");
    adapter.Fill(table);

    // Create new order
    command.CommandText = "INSERT INTO orders VALUES(?, ?, ?, ?, ?)";                
    command.ExecuteNonQuery();

    // Create new order detail
    command.CommandText = "INSERT INTO orderdetail VALUES(?, ?, ?, ?, ?)";
    command.ExecuteNonQuery();

    // Update product quantity
    command.CommandText = "UPDATE product SET quantity=? WHERE product_id=?";
    command.ExecuteNonQuery();

    // Commit transaction
    connection.Commit();
}
catch (Exception e)
{
    ///
    /// Log or re-throw exception
    /// 
}
finally
{
    connection.Close();
}