Transaction.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2017 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 Map of oid changes (key: oid string before commit, value: oid string after commit)
32  */
33  public function commit();
34 
35  /**
36  * Discard the object changes.
37  * Sets the transaction to inactive.
38  */
39  public function rollback();
40 
41  /**
42  * Check if the transaction is active.
43  * @return Boolean
44  */
45  public function isActive();
46 
47  /**
48  * Attach an object to the transaction. The returned object is the attached instance.
49  * @param $object The object
50  * @return PersistentObject
51  */
52  public function attach(PersistentObject $object);
53 
54  /**
55  * Detach an object from the transaction. All local changes will not
56  * be stored. Afterwards the object is unknown to the transaction.
57  * @param $oid The object id of the object
58  */
59  public function detach(ObjectId $oid);
60 
61  /**
62  * Get a loaded object.
63  * @param $oid ObjectId of the object
64  * @return PersistentObject instance or null if not loaded yet
65  */
66  public function getLoaded(ObjectId $oid);
67 
68  /**
69  * Get all objects currently involved in the transaction
70  * @return Array of PersistentObject instances
71  */
72  public function getObjects();
73 }
74 ?>
detach(ObjectId $oid)
Detach an object from the transaction.
getLoaded(ObjectId $oid)
Get a loaded object.
Persistence layer related interfaces and classes.
Definition: namespaces.php:42
ObjectId is the unique identifier of an object.
Definition: ObjectId.php:27
attach(PersistentObject $object)
Attach an object to the transaction.
rollback()
Discard the object changes.
begin()
Set the transaction active (object changes will be recorded).
isActive()
Check if the transaction is active.
Transaction implements the Unit of Work pattern as it defines the interface for maintaining a list of...
Definition: Transaction.php:21
getObjects()
Get all objects currently involved in the transaction.
commit()
Commit the object changes to the storage.
PersistentObject defines the interface of all persistent objects.