Fakoli Framework
DataTransaction Class Reference

The DataTransaction class wraps the underlying database's transaction model. More...

Public Member Functions

 DataTransaction ()
 Creates a new DataTransaciton. More...
 
 rollback ()
 Roll back any changes made during this transaction. More...
 
 commit ()
 Commit the changes made during this transaction. More...
 
 getConnection ()
 Return the database connection for this transaction. More...
 

Public Attributes

 $conn
 
 $tx
 

Detailed Description

The DataTransaction class wraps the underlying database's transaction model.

DataTransactions automatically start an isolated database transaction upon creation. The DataTransaction class can then be used with Query and DataItem objects. Each DataTransaction instance maintains its own dedicated connection to the database.

Author
andy

Definition at line 44 of file transaction.inc.

Member Function Documentation

◆ commit()

DataTransaction::commit ( )

Commit the changes made during this transaction.

Definition at line 78 of file transaction.inc.

79  {
80  if (!$this->conn)
81  {
82  throw new DataItemException("Attempt to commit a previously completed transaction");
83  }
84 
85  $this->conn->commit();
86  $this->conn = null;
87  }

◆ DataTransaction()

DataTransaction::DataTransaction ( )

Creates a new DataTransaciton.

Definition at line 52 of file transaction.inc.

53  {
54  $this->conn = ConnectionManager::newConnection();
55  if (!$this->conn->beginTransaction())
56  {
57  throw new DataItemException("Unable to initiate transaction");
58  }
59  }
static newConnection()
Returns a new connection to the database.

◆ getConnection()

DataTransaction::getConnection ( )

Return the database connection for this transaction.

Returns
PDO database connection

Definition at line 93 of file transaction.inc.

94  {
95  if (!$this->conn)
96  {
97  throw new DataItemException("Transaction has already been closed");
98  }
99 
100  return $this->conn;
101  }

◆ rollback()

DataTransaction::rollback ( )

Roll back any changes made during this transaction.

Definition at line 64 of file transaction.inc.

65  {
66  if (!$this->conn)
67  {
68  throw new DataItemException("Attempt to rollback a previously completed transaction");
69  }
70 
71  $this->conn->rollback();
72  $this->conn = null;
73  }

Member Data Documentation

◆ $conn

DataTransaction::$conn

Definition at line 46 of file transaction.inc.

◆ $tx

DataTransaction::$tx

Definition at line 47 of file transaction.inc.


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