Framework  3.9
transaction.inc
Go to the documentation of this file.
1 <?php
5 /**************************************************************
6 
7  Copyright (c) 2007-2010 Sonjara, Inc
8 
9  Permission is hereby granted, free of charge, to any person
10  obtaining a copy of this software and associated documentation
11  files (the "Software"), to deal in the Software without
12  restriction, including without limitation the rights to use,
13  copy, modify, merge, publish, distribute, sublicense, and/or sell
14  copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following
16  conditions:
17 
18  The above copyright notice and this permission notice shall be
19  included in all copies or substantial portions of the Software.
20 
21  Except as contained in this notice, the name(s) of the above
22  copyright holders shall not be used in advertising or otherwise
23  to promote the sale, use or other dealings in this Software
24  without prior written authorization.
25 
26  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
28  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
30  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
31  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
32  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33  OTHER DEALINGS IN THE SOFTWARE.
34 
35 *****************************************************************/
36 
48 {
49  var $conn;
50  var $tx;
51 
55  function DataTransaction()
56  {
57  $this->conn = ConnectionManager::newConnection();
58  if (!$this->conn->beginTransaction())
59  {
60  throw new DataItemException("Unable to initiate transaction");
61  }
62  }
63 
67  function rollback()
68  {
69  if (!$this->conn)
70  {
71  throw new DataItemException("Attempt to rollback a previously completed transaction");
72  }
73 
74  $this->conn->rollback();
75  $this->conn = null;
76  }
77 
81  function commit()
82  {
83  if (!$this->conn)
84  {
85  throw new DataItemException("Attempt to commit a previously completed transaction");
86  }
87 
88  $this->conn->commit();
89  $this->conn = null;
90  }
91 
96  function getConnection()
97  {
98  if (!$this->conn)
99  {
100  throw new DataItemException("Transaction has already been closed");
101  }
102 
103  return $this->conn;
104  }
105 }
106 ?>
static newConnection()
Returns a new connection to the database.
The DataTransaction class wraps the underlying database's transaction model.
Definition: transaction.inc:48
DataTransaction()
Creates a new DataTransaciton.
Definition: transaction.inc:55
getConnection()
Return the database connection for this transaction.
Definition: transaction.inc:96
rollback()
Roll back any changes made during this transaction.
Definition: transaction.inc:67
commit()
Commit the changes made during this transaction.
Definition: transaction.inc:81