Transaction.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2015 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  * Register a loaded object. Mappers must call this method on each
25  * loaded object. The returned object is the registered instance.
26  * @param $object PersistentObject instance
27  * @return PersistentObject instance
28  */
29  public function registerLoaded(PersistentObject $object);
30 
31  /**
32  * Register a newly created object
33  * @param $object PersistentObject instance
34  */
35  public function registerNew(PersistentObject $object);
36 
37  /**
38  * Register a dirty object.
39  * @param $object PersistentObject instance
40  */
41  public function registerDirty(PersistentObject $object);
42 
43  /**
44  * Register a deleted object.
45  * @param $object PersistentObject instance
46  */
47  public function registerDeleted(PersistentObject $object);
48 
49  /**
50  * Set the transaction active (object changes will be recorded).
51  */
52  public function begin();
53 
54  /**
55  * Commit the object changes to the storage.
56  * Sets the transaction to inactive.
57  * @return Map of oid changes (key: oid string before commit, value: oid string after commit)
58  */
59  public function commit();
60 
61  /**
62  * Discard the object changes.
63  * Sets the transaction to inactive.
64  */
65  public function rollback();
66 
67  /**
68  * Check if the transaction is active.
69  * @return Boolean
70  */
71  public function isActive();
72 
73  /**
74  * Get a loaded object.
75  * @param $oid ObjectId of the object
76  * @return PersistentObject instance or null if not loaded yet
77  */
78  public function getLoaded(ObjectId $oid);
79 
80  /**
81  * Detach an object from the transaction. All local changes will not
82  * be stored. Afterwards the object is unknown to the transaction.
83  * @param $oid The object id of the object
84  */
85  public function detach(ObjectId $oid);
86 
87  /**
88  * Get all objects currently involved in the transaction
89  * @return Array of PersistentObject instances
90  */
91  public function getObjects();
92 }
93 ?>
registerDeleted(PersistentObject $object)
Register a deleted object.
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
registerDirty(PersistentObject $object)
Register a dirty object.
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
registerLoaded(PersistentObject $object)
Register a loaded object.
getObjects()
Get all objects currently involved in the transaction.
registerNew(PersistentObject $object)
Register a newly created object.
commit()
Commit the object changes to the storage.
PersistentObject defines the interface of all persistent objects.