Request Quote

Using Transactions In Joomla to maintaining ACID Property

Using Transactions In Joomla to maintaining ACID Property: A transaction is a very small unit of a program and it may contain several lowlevel tasks. A transaction in a database system must maintain Atomicity, Consistency, Isolation, and Durability − commonly known as ACID properties − in order to ensure accuracy, completeness, and data integrity.

Atomicity :

A transaction must be an atomic unit of work; either all of its data modifications are performed, or none of them is performed.

Consistency :

When completed, a transaction must leave all data in a consistent state. In a relational database, all rules must be applied to the transaction’s modifications to maintain all data integrity. All internal data structures, such as B-tree indexes or doubly-linked lists, must be correct at the end of the transaction.

Isolation :

Modifications made by concurrent transactions must be isolated from the modifications made by any other concurrent transactions. A transaction either recognizes data in the state it was in before another concurrent transaction modified it, or it recognizes the data after the second transaction has completed, but it does not recognize an intermediate state.

Durability :

After a transaction has completed, its effects are permanently in place in the system. The modifications persist even in the event of a system failure.

Example

This will play an important role where we have to perform operations on more than one table at a time.

eg: we have 4 separate Insert query for 4 different tables and we want that if any one of query fails, then all query must be rollback. i.e. either all 4 query execute successfully or none of them.

/**
 * Webkul Software.
 *
 * @category Webkul
 * @author Webkul <support@webkul.com>
 * @copyright Copyright (c) 2010-2018 Webkul Software Private Limited
 * @license https://store.webkul.com/license.html
 */
 //to get instance of JDatabaseDriver class
 $db=JFactory::getDBO();
 try {
  //Method to initialize a transaction
  $db->transactionStart();
  //initialize JDatabaseQuery object for query
  $query1=$db->getQuery(true);
  $values = array($db->quote('VALUE_1'),
                  $db->quote('VALUE_2'),
                  $db->quote('VALUE_3'));
  $query->insert($db->quoteName('#__YOUR_TABLE'));
  $query->columns($db->quoteName(
                 array('FIELD_1',
                       'FIELD_2', 
                       'FIELD_3')));
  $query->values(implode(',',$values));
  $db->setQuery($query);
  $result = $db->execute();
  //It is used to commit Transaction. 
  $db->transactionCommit();  
 }
 catch (Exception $e) {
  // catch any database errors.
  //It is used to rollback Transactions if query fails.
  $db->transactionRollback();
  JErrorPage::render($e);
 }

Conclusion:

  • transactionStart:  Method to initialize a transaction.

Definition : transactionStart(boolean $asSavepoint = false) : void

  • transactionCommit: Method to commit a transaction.

Definition :transactionCommit(boolean $toSavepoint = false) : void

  • transactionRollback: Method to roll back a transaction.

Definition :transactionRollback(boolean $toSavepoint = false) : void

 

 

Support

For any query regarding Joomla virtuemart Extensions and add-ons you can communicate with us at:
support@webkul.com

Please visit this link to find more extensions of joomla Webkul Joomla extensions

 

. . .

Comment

Add Your Comment

Be the first to comment.

css.php

Index