Example #1
0
 /**
  * 
  * Save the specified or already existing data for this record to the db.
  * 
  * This save operation is gaurded by the PDO transaction mechanism. 
  * If the save operation fails all changes are rolled back.
  * 
  * If there is no transaction mechanism available a 
  * \LeanOrm\Model\RecordOperationNotSupportedByDriverException Exception is 
  * thrown.
  * 
  * @param \GDAO\Model\RecordInterface|array $data_2_save
  * 
  * @throws \LeanOrm\Model\RecordOperationNotSupportedByDriverException
  * 
  * @return bool true for a successful save, false for failed save, null: no changed data to save
  * 
  */
 public function saveInTransaction($data_2_save = null)
 {
     $pdo_obj = $this->_model->getPDO();
     if ($pdo_obj instanceof \PDO) {
         // start the transaction
         $pdo_obj->beginTransaction();
         try {
             $save_status = $this->save($data_2_save);
             // attempt the save
             if ($save_status === true) {
                 // entire save was valid, keep it
                 $pdo_obj->commit();
                 return true;
             } else {
                 if ($save_status === false) {
                     // at least one part of the save was *not* valid.
                     // throw it all away.
                     $pdo_obj->rollBack();
                     return false;
                 } else {
                     return null;
                     //$save_status === null nothing was done
                 }
             }
         } catch (\Exception $e) {
             // roll back and throw the exception
             $pdo_obj->rollBack();
             throw $e;
         }
     } else {
         $msg = get_class($this) . ' Does Not Support ' . __FUNCTION__ . '(...)';
         throw new RecordOperationNotSupportedByDriverException($msg);
     }
 }