Thursday 18 November 2010 9:11:37 am
In this tutorial you learnt how to use a fundamental eZ Publish kernel class, eZPersistentObject. This class can be used to speed up the development of eZ publish extensions that need persistent facilities regardless of which database is used and according to a well established design pattern. As most of the kernel classes that are used in extensions inherit from this class, learning how to use this class can help understand how that others classes work.
So from now on, think twice before starting to write SQL commands in your extensions. Your homework is to create functions to make the operations described in this tutorial easier and learn how to use sorting and the conditions array.
This tutorial is available for offline reading :
Thiago Campos Viana - A Quick and Friendly Introduction to eZPersistentObject - PDF Version
Transactions are a fundamental notion of Database Management Systems. I warmly invite you to get acquainted with them, if not already the case, through reading this : http://en.wikipedia.org/wiki/Database_transaction
A typical use case is when an DB row needs to be deleted, while it may be accessed (read, updated) simultaneously by other threads/processes of one application. This does not only apply to high-concurrency types of applications, you should bear this in mind when crafting the DB-access parts of your business logics.
Here is an example of such : removing a row, through the eZPersistentObject API, should be encapsulated in a transaction. Elaborating on the previous DELETE example :
// Prime the transaction $db = eZDB::instance(); $db->begin(); // Do the delete. It will not be actually done until the transaction is committed $cond = array( 'user1_id' => 1, 'user2_id' => 3 ); $simpleObj = eZPersistentObject::fetchObject( TutorialFriendshipObject::definition(), null, $cond ); $simpleObj->remove(); // Commit all changes. The set of changes committed only contains one change here : the // deletion of a row. A transaction can contain a series of several changes. $db->commit();
The transaction API is much larger than only begin() and commit() presented above. Please refer to lib/ezdb/classes/ezdbinterface.php for a deeper insight.
Thiago Campos Viana is a web developer and eZ Publish enthusiast from Brazil.
This work is licensed under the Creative Commons – Share Alike license (http://creativecommons.org/licenses/by-sa/3.0 ).