transactions

Directory

eXtremeDB_rt/samples/transactions

Description

Demonstrates the different eXtremeDB/rt transaction types (Read-Only / Read-Write).

Used API

mco_trans_start(), mco_trans_rollback(), mco_trans_commit(), mco_trans_checkpoint(), mco_trans_upgrade()

Code snippet

 
    rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &t);
         if ( MCO_S_OK == rc ) {
           /* A ReadOnly transaction is intended for lookups and data extraction.
             Mutiple R-O transactions can be started simultaneously with the MURSIW transaction manager.
             But only one R-O transaction can be started with the EXCLUSIVE transaction manager.
           */
           ... 
           /* Do lookups and data extraction */    
   
           /* Commit or rollback - there are no differences for read-only transactions */
           mco_trans_rollback( t ); /* or mco_trans_commit( t ); */
   
         ....
   
   
   
    /* Start read-write transaction */
         rc = mco_trans_start(db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t);
         if ( MCO_S_OK == rc ) {
           /* R-W transactions are intended for lookups and data extraction, as well as creation and deletion.
             Only one R-W transaction at a time can be started with MURSIW and EXCLUSIVE transaction managers.
           */
           
           ....
   
           /* Do lookups, create and destroy objects, modify data */
   
           /* It is possible to force indexes to be updated during the transaction using mco_trans_checkpoint() */
           mco_trans_checkpoint( t );
           sample_rc_check("\t\tTransaction Checkpoint", rc );
                         
           /* Commit to confirm and store changes or rollback to cancel updates made during this transaction */
           mco_trans_commit( t ); /* Or mco_trans_rollback( t ); */
   
        ....
   
    printf( "\n\n\tTransactions can be upgraded to R-W to update data.\n" );
   
           /* Get transaction type */
           mco_trans_type( t,  &t_type );
           printf( "\n\t\tTransaction type is %s\n", t_type == MCO_READ_ONLY ? "R-O" : "R-W" );
   
           /* Upgrade it to R-W */
           rc = mco_trans_upgrade(t);
           sample_rc_check("\t\tUpgrade transaction", rc );

What to expect as an output

 
       A ReadOnly transaction has been successfully started.

		R-O transactions are intended for lookups and data extraction.
		Multiple R-O transactions can be started simultaneously with
		the MURSIW transaction manager.  But only one R-O
		can be started with the EXCLUSIVE transaction manager.


	A ReadWrite transaction has been successfully started.

		R-W transactions are intended for lookups and data extraction,
		as well as data creation and deletion.
		Only one R-W transaction at a time can be started with
		the MURSIW and EXCLUSIVE transaction managers.
		Transaction Checkpoint : Successful

	Transactions can be upgraded to R-W to update data.

		Transaction type is R-O

		Upgrade transaction : Successful

		Now Transaction type is R-W