Transaction.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
11 namespace wcmf\lib\persistence;
12 
13 /**
14  * Transaction implements the Unit of Work pattern as it defines
15  * the interface for maintaining a list of PersistentObject changes inside
16  * a business transaction and commit/rollback them.
17  * Transaction also serves as an Identity Map for loaded objects.
18  *
19  * @author ingo herwig <ingo@wemove.com>
20  */
21 interface Transaction {
22 
23  /**
24  * Set the transaction active (object changes will be recorded).
25  */
26  public function begin();
27 
28  /**
29  * Commit the object changes to the storage.
30  * Sets the transaction to inactive.
31  * @return Array of executed statements (see PersistenceMapper::getStatements())
32  */
33  public function commit();
34 
35  /**
36  * Collect object change statements. Acts like a normal commit, but does not execute the statements.
37  * Sets the transaction to inactive.
38  * @return Array of statements to be executed (see PersistenceMapper::getStatements())
39  */
40  public function commitCollect();
41 
42  /**
43  * Discard the object changes.
44  * Sets the transaction to inactive.
45  */
46  public function rollback();
47 
48  /**
49  * Check if the transaction is active.
50  * @return Boolean
51  */
52  public function isActive();
53 
54  /**
55  * Attach an object to the transaction. The returned object is the attached instance.
56  * @param $object The object
57  * @return PersistentObject
58  */
59  public function attach(PersistentObject $object);
60 
61  /**
62  * Detach an object from the transaction. All local changes will not
63  * be stored. Afterwards the object is unknown to the transaction.
64  * @param $oid The object id of the object
65  */
66  public function detach(ObjectId $oid);
67 
68  /**
69  * Get a loaded object.
70  * @param $oid ObjectId of the object
71  * @return PersistentObject instance or null if not loaded yet
72  */
73  public function getLoaded(ObjectId $oid);
74 
75  /**
76  * Get all objects currently involved in the transaction
77  * @return Array of PersistentObject instances
78  */
79  public function getObjects();
80 }
81 ?>
getObjects()
Get all objects currently involved in the transaction.
getLoaded(ObjectId $oid)
Get a loaded object.
Persistence layer related interfaces and classes.
Definition: namespaces.php:42
attach(PersistentObject $object)
Attach an object to the transaction.
begin()
Set the transaction active (object changes will be recorded).
rollback()
Discard the object changes.
ObjectId is the unique identifier of an object.
Definition: ObjectId.php:28
commitCollect()
Collect object change statements.
PersistentObject defines the interface of all persistent objects.
Transaction implements the Unit of Work pattern as it defines the interface for maintaining a list of...
Definition: Transaction.php:21
commit()
Commit the object changes to the storage.
detach(ObjectId $oid)
Detach an object from the transaction.
isActive()
Check if the transaction is active.