Mage_Core_Model_Resource_Transaction Class Reference

List of all members.

Public Member Functions

 __construct ()
 addObject (Mage_Core_Model_Abstract $object, $alias='')
 save ()
 delete ()

Protected Member Functions

 _startTransaction ()
 _commitTransaction ()
 _rollbackTransaction ()

Protected Attributes

 $_objects = array()
 $_objectsByAlias = array()
 $_resources = array()


Detailed Description

Definition at line 36 of file Transaction.php.


Constructor & Destructor Documentation

__construct (  ) 

Enter description here...

Definition at line 64 of file Transaction.php.

00065     {
00066 
00067     }


Member Function Documentation

_commitTransaction (  )  [protected]

Enter description here...

Returns:
Mage_Core_Model_Resource_Transaction

Definition at line 87 of file Transaction.php.

00088     {
00089         foreach ($this->_objects as $object) {
00090             $object->getResource()->commit();
00091         }
00092         return $this;
00093     }

_rollbackTransaction (  )  [protected]

Enter description here...

Returns:
Mage_Core_Model_Resource_Transaction

Definition at line 100 of file Transaction.php.

00101     {
00102         foreach ($this->_objects as $object) {
00103             $object->getResource()->rollBack();
00104         }
00105         return $this;
00106     }

_startTransaction (  )  [protected]

Enter description here...

Returns:
Mage_Core_Model_Resource_Transaction

Definition at line 74 of file Transaction.php.

00075     {
00076         foreach ($this->_objects as $object) {
00077             $object->getResource()->beginTransaction();
00078         }
00079         return $this;
00080     }

addObject ( Mage_Core_Model_Abstract object,
alias = '' 
)

Adding object for using in transaction

Parameters:
Mage_Core_Model_Abstract $object
string $alias
Returns:
Mage_Core_Model_Resource_Transaction

Definition at line 115 of file Transaction.php.

00116     {
00117         $this->_objects[] = $object;
00118         if (!empty($alias)) {
00119             $this->_objectsByAlias[$alias] = $object;
00120         }
00121         return $this;
00122     }

delete (  ) 

Initialize objects delete transaction

Returns:
Mage_Core_Model_Resource_Transaction

Definition at line 171 of file Transaction.php.

00172     {
00173         $this->_startTransaction();
00174         try {
00175             foreach ($this->_objects as $object) {
00176                 $object->delete();
00177             }
00178             $this->_commitTransaction();
00179         }
00180         catch (Exception $e) {
00181             $this->_rollbackTransaction();
00182             throw $e;
00183         }
00184         return $this;
00185     }

save (  ) 

Initialize objects save transaction

Returns:
Mage_Core_Model_Resource_Transaction

Definition at line 129 of file Transaction.php.

00130     {
00131         $this->_startTransaction();
00132         $commit = true;
00133         $errors = array();
00134 
00135         foreach ($this->_objects as $object) {
00136             try {
00137                 $object->save();
00138             }
00139             catch (Exception $e) {
00140                 $commit = false;
00141                 $errors[] = $e->getMessage();
00142             }
00143         }
00144 
00145         if ($commit) {
00146             $this->_commitTransaction();
00147         }
00148         else {
00149             $this->_rollbackTransaction();
00150             Mage::throwException(join("\n", $errors));
00151         }
00152 
00153 //        try {
00154 //            foreach ($this->_objects as $object) {
00155 //                $object->save();
00156 //            }
00157 //            $this->_commitTransaction();
00158 //        }
00159 //        catch (Exception $e) {
00160 //            $this->_rollbackTransaction();
00161 //            throw $e;
00162 //        }
00163         return $this;
00164     }


Member Data Documentation

$_objects = array() [protected]

Definition at line 44 of file Transaction.php.

$_objectsByAlias = array() [protected]

Definition at line 51 of file Transaction.php.

$_resources = array() [protected]

Definition at line 58 of file Transaction.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:00 2009 for Magento by  doxygen 1.5.8