Iterate over all modifications made by a transaction.
MCO_RET mco_trans_iterate( /*IN*/ mco_trans_h t,
/*IN*/ mco_trans_iterator_callback_t callback,
/*IN*/ void* user_ctx);
t
mco_trans_h transaction handle returned by mco_trans_start().callback
user_ctx
This function provides the ability to iterate over all modifications made by a transaction, read the modified objects, and determine what kind of modifications were applied (new, update, delete). As one of the parameters, the API takes an application-defined callback function that inspects each object and determines whether it is subject to an external transaction. The callback receives a handle to the modified object, the class code of the object, the type of the modification operation and some application-specific context (anything that you want to pass into the callback). The application then has a choice of either continuing to commit the transaction, or discarding all modifications (rollback). This API can be used in concert with the two-phase commit API.
MCO_S_OK
MCO_S_NOTFOUND
MCO_E_NOMEM
MCO_S_DUPLICATE
MCO_E_TRANSACT
Application snippet:
const char * dbname = "SimpleDb";
mco_trans_iterator_callback_t my_iterator_callback( mco_trans_h trans,
MCO_Hf* obj,
int cid,
int operation_mask,
void* ctx)
{
printf("\nProcess transaction contents...\n");
return MCO_S_OK;
}
int main(int argc, char* argv[])
{
mco_db_h db;
MCO_RET rc;
mco_device_t dev;
mco_db_params_t db_params;
mco_trans_h t;
...
rc = mco_db_open_dev( dbname, simple_get_dictionary(), &dev, 1, &db_params );
if ( MCO_S_OK != rc )
{
rc = mco_db_connect( dbname, &db );
...
rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &t);
if ( MCO_S_OK == rc )
{
...
if ( MCO_S_OK == mco_trans_commit_phase1( t ) )
{
rc = mco_trans_iterate(t, my_iterator_callback, (void*)0 );
if (rc == MCO_S_OK)
{
...
if ( MCO_S_OK == rc = mco_trans_commit_phase2( t ) )
{
...
}
else
{
mco_trans_rollback( t );
}
...
}
}
else
{
mco_trans_rollback( t );
}
...
rc = mco_trans_commit( t );
...
}
}
...
}